Skip to content

Commit

Permalink
Merge pull request #3397 from bettyblocks/feat/laod-hasmany-pagevar-v…
Browse files Browse the repository at this point in the history
…alues-PAGE-4132

Feat/load hasmany pagevar values page 4132
  • Loading branch information
JorisPannekeet authored Mar 14, 2024
2 parents cf4094b + 67063ae commit be97b69
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 15 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# [2.184.0](https://github.com/bettyblocks/material-ui-component-set/compare/v2.183.0...v2.184.0) (2024-03-08)


### Features

* added richtext support for pagevariables ([81702c7](https://github.com/bettyblocks/material-ui-component-set/commit/81702c7bed107d9975e0fd4c6159c17996f08399))

# [2.183.0](https://github.com/bettyblocks/material-ui-component-set/compare/v2.182.2...v2.183.0) (2024-03-08)


### Bug Fixes

* remove console ([91dd925](https://github.com/bettyblocks/material-ui-component-set/commit/91dd925faa0cd93a1c367f7a5491799739ce22c5))


### Features

* added pagevariable belongsto support for radio, select and autocomplete components ([3658315](https://github.com/bettyblocks/material-ui-component-set/commit/365831587307934ebeef96e0ff19e53f56e1c23b))

## [2.182.2](https://github.com/bettyblocks/material-ui-component-set/compare/v2.182.1...v2.182.2) (2024-03-04)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "component-set",
"version": "2.182.2",
"version": "2.184.0",
"main": "dist/templates.json",
"license": "UNLICENSED",
"private": false,
Expand Down
20 changes: 20 additions & 0 deletions src/components/checkboxGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@
// split the string and trim spaces
if (Array.isArray(value)) return value;

// check wether our value is an object array.
try {
const parsed = JSON.parse(value);
if (
Array.isArray(parsed) &&
parsed.every((item) => typeof item === 'object' && 'id' in item)
) {
return parsed.map((obj) => String(obj.id));
}
} catch (error) {
return value
.split(',')
.filter((part) => part !== '')
.map((str) => str.trim());
}

return value
.split(',')
.filter((part) => part !== '')
Expand All @@ -125,6 +141,10 @@

const [values, setValues] = useState(getValues());

useEffect(() => {
setValues(getValues());
}, [defaultValueText]);

const orderBySanitized = orderBy.id === '' ? undefined : orderBy;

const orderByArray = [orderBySanitized].flat();
Expand Down
53 changes: 39 additions & 14 deletions src/components/multiAutoCompleteInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,39 @@

const valueProperty = isListProperty ? modelProperty : idProperty;
const defaultValue = useText(valueRaw, { rawValue: true });
let initialValue = defaultValue.replace(/\n/g, '');

if (defaultValue.trim() === '') {
initialValue = [];
} else {
initialValue = defaultValue
.trim()
.split(',')
.map((x) => x.trim());
}
const isPageVariableValue = valueRaw[0] && valueRaw[0].path;
const getValues = () => {
const value = defaultValue.replace(/\n/g, '');
try {
const parsed = JSON.parse(value);
if (
Array.isArray(parsed) &&
parsed.length &&
parsed.every((item) => typeof item === 'object' && 'id' in item)
) {
return parsed.map((obj) => String(obj.id));
}
if (!parsed.length) {
if (isPageVariableValue) {
return [''];
}
return [];
}
} catch (error) {
if (value.trim() === '') {
if (isPageVariableValue) {
return [''];
}
return [];
}
return value
.trim()
.split(',')
.map((x) => x.trim());
}
return value;
};
const initialValue = getValues();
const validationMessage = (validityObject) => {
if (!validityObject) {
return '';
Expand Down Expand Up @@ -210,7 +233,6 @@
*
*/
const [value, setValue] = useState(initialValue);

useEffect(() => {
if (isDev && typeof value === 'string') {
if (value.trim() === '') {
Expand All @@ -225,7 +247,9 @@
}
}
}, [multiple]);

useEffect(() => {
setValue(initialValue);
}, [defaultValue]);
/*
* User input in the autocomplete. In case of freeSolo this is the same as `value`
*/
Expand Down Expand Up @@ -301,8 +325,9 @@

// check if the value option has a relation with an id key
const relationPropertyId = valueRaw[0] && valueRaw[0].id;
const relationProperty = getProperty(relationPropertyId || '');

const relationProperty = relationPropertyId
? getProperty(relationPropertyId || '')
: getProperty('');
// check if the value option has a relational property
if (relationProperty && relationProperty.inverseAssociationId) {
const parentProperty = getIdProperty(relationProperty.modelId);
Expand Down

0 comments on commit be97b69

Please sign in to comment.