diff --git a/src/dialogs/AdvancedCriteriaDialog.js b/src/dialogs/AdvancedCriteriaDialog.js
index 4cae67d..3350f08 100644
--- a/src/dialogs/AdvancedCriteriaDialog.js
+++ b/src/dialogs/AdvancedCriteriaDialog.js
@@ -37,18 +37,43 @@ const AdvancedCriteriaDialog = ({
setAppliedFiltersRowStructure,
updateAttributes,
getDefaultAppliedCustomFilters,
+ additionalParams,
+ confirmed,
+ edited,
}) => {
const [isOpen, setIsOpen] = useState(false);
const [currentFilter, setCurrentFilter] = useState({ field: "", filter: "", type: "", value: "", amount: "" })
const [filters, setFilters] = useState(getDefaultAppliedCustomFilters());
- const createParams = (moduleName, objectTypeName, uuidOfObject=null) => {
- return [
+ const getBenefitPlanDefaultCriteria = () => {
+ const { jsonExt } = edited?.benefitPlan ?? {};
+ try {
+ const jsonData = JSON.parse(jsonExt);
+ return jsonData.advanced_criteria || [];
+ } catch (error) {
+ return [];
+ }
+ };
+
+ useEffect(() => {
+ if (!getDefaultAppliedCustomFilters().length) {
+ setFilters(getBenefitPlanDefaultCriteria());
+ }
+ }, [edited]);
+
+ const createParams = (moduleName, objectTypeName, uuidOfObject = null, additionalParams = null) => {
+ const params = [
`moduleName: "${moduleName}"`,
`objectTypeName: "${objectTypeName}"`,
- uuidOfObject !== null ? `uuidOfObject: "${uuidOfObject}"`: ``,
];
+ if (uuidOfObject) {
+ params.push(`uuidOfObject: "${uuidOfObject}"`);
+ }
+ if (additionalParams) {
+ params.push(`additionalParams: ${JSON.stringify(JSON.stringify(additionalParams))}`);
+ }
+ return params;
};
const fetchFilters = (params) => fetchCustomFilter(params);
@@ -60,13 +85,6 @@ const AdvancedCriteriaDialog = ({
const handleClose = () => {
setCurrentFilter(CLEARED_STATE_FILTER);
- setIsOpen(false);
- };
-
- const handleRemoveFilter = () => {
- setCurrentFilter(CLEARED_STATE_FILTER);
- setAppliedFiltersRowStructure([CLEARED_STATE_FILTER]);
- setFilters([CLEARED_STATE_FILTER]);
};
const handleAddFilter = () => {
@@ -85,6 +103,12 @@ const AdvancedCriteriaDialog = ({
return updatedJsonExt;
}
+ const handleRemoveFilter = () => {
+ setCurrentFilter(CLEARED_STATE_FILTER);
+ setAppliedFiltersRowStructure([CLEARED_STATE_FILTER]);
+ setFilters([]);
+ };
+
const saveCriteria = () => {
setAppliedFiltersRowStructure(filters);
const outputFilters = JSON.stringify(
@@ -101,6 +125,7 @@ const AdvancedCriteriaDialog = ({
handleClose();
};
+
useEffect(() => {
if (object && isEmptyObject(object) === false) {
let paramsToFetchFilters = [];
@@ -108,55 +133,22 @@ const AdvancedCriteriaDialog = ({
paramsToFetchFilters = createParams(
moduleName,
objectType,
- isBase64Encoded(object.id) ? decodeId(object.id) : object.id
+ isBase64Encoded(object.id) ? decodeId(object.id) : object.id,
+ additionalParams,
);
} else {
paramsToFetchFilters = createParams(
moduleName,
objectType,
+ additionalParams,
);
}
fetchFilters(paramsToFetchFilters);
}
}, [object]);
-
- useEffect(() => {}, [filters]);
return (
<>
-
-
- >
+
+ >
);
-};
+}
const mapStateToProps = (state, props) => ({
rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [],
diff --git a/src/dialogs/AdvancedCriteriaRowValue.js b/src/dialogs/AdvancedCriteriaRowValue.js
index 8f6bc64..824af8c 100644
--- a/src/dialogs/AdvancedCriteriaRowValue.js
+++ b/src/dialogs/AdvancedCriteriaRowValue.js
@@ -33,6 +33,7 @@ const AdvancedCriteriaRowValue = ({
index,
filters,
setFilters,
+ readOnly,
}) => {
const onAttributeChange = (attribute) => (value) => {
@@ -79,6 +80,7 @@ const AdvancedCriteriaRowValue = ({
return (