Skip to content

Commit

Permalink
CM-953: moved advanced criteria directly to payroll form
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Jul 17, 2024
1 parent d6a3b1e commit 9cd5cce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 44 deletions.
32 changes: 4 additions & 28 deletions src/components/payroll/AdvancedFiltersDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,13 @@ function AdvancedFiltersDialog({
const [currentFilter, setCurrentFilter] = useState({
field: '', filter: '', type: '', value: '', amount: '',
});
const [filters, setFilters] = useState(getDefaultAppliedCustomFilters());
const [filters, setFilters] = useState(getDefaultAppliedCustomFilters(objectToSave.jsonExt));

const getBenefitPlanDefaultCriteria = () => {
const { jsonExt } = edited?.benefitPlan ?? {};
try {
console.log(jsonExt, 'jsex');
const jsonData = JSON.parse(jsonExt);
return jsonData.advanced_criteria || [];
} catch (error) {
console.log(error, 'error jsex');
return [];
}
};
useEffect(() => {
setFilters(getDefaultAppliedCustomFilters(objectToSave.jsonExt));
}, [objectToSave.jsonExt]);

useEffect(() => {
console.log('wwwww');
setFilters(getBenefitPlanDefaultCriteria());
}, [edited]);

const createParams = (moduleName, objectTypeName, uuidOfObject = null, additionalParams = null) => {
Expand All @@ -82,11 +72,6 @@ function AdvancedFiltersDialog({

const fetchFilters = (params) => fetchCustomFilter(params);

const handleOpen = () => {
setFilters(getDefaultAppliedCustomFilters());
setIsOpen(true);
};

const handleClose = () => {
setCurrentFilter(CLEARED_STATE_FILTER);
};
Expand Down Expand Up @@ -148,7 +133,6 @@ function AdvancedFiltersDialog({
fetchFilters(paramsToFetchFilters);
}
}, [object]);
console.log(filters);
return (
<>
{filters.map((filter, index) => (
Expand Down Expand Up @@ -209,14 +193,6 @@ function AdvancedFiltersDialog({
paddingRight: '16px',
}}
>
<Button
onClick={handleClose}
variant="outlined"
autoFocus
style={{ margin: '0 16px' }}
>
{formatMessage(intl, 'payroll', 'payroll.advancedFilters.button.cancel')}
</Button>
<Button
onClick={saveCriteria}
variant="contained"
Expand Down
34 changes: 22 additions & 12 deletions src/components/payroll/PayrollHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,32 @@ class PayrollHeadPanel extends FormPanel {
};
}

componentDidMount() {
this.setStateFromProps(this.props);
}

setStateFromProps = (props) => {
const { jsonExt } = props?.edited ?? {};
if (jsonExt) {
const filters = this.getDefaultAppliedCustomFilters(jsonExt);
this.setState({ appliedCustomFilters: filters, appliedFiltersRowStructure: filters });
}
};

updateJsonExt = (value) => {
this.updateAttributes({
jsonExt: value,
});
};

getDefaultAppliedCustomFilters = () => {
console.log(this.props?.edited, 'xx');
const { jsonExt } = this.props?.edited ?? {};
console.log(jsonExt, 'xx');
// eslint-disable-next-line class-methods-use-this
getDefaultAppliedCustomFilters = (jsonExt) => {
try {
const jsonData = JSON.parse(jsonExt);
const advancedCriteria = jsonData.advanced_criteria || [];
console.log(advancedCriteria, 'ad');
return advancedCriteria.map(({ custom_filter_condition }) => {
const transformedCriteria = advancedCriteria.map(({ custom_filter_condition }) => {
const [field, filter, typeValue] = custom_filter_condition.split('__');
const [type, value] = typeValue.split('=');
console.log(custom_filter_condition);
return {
custom_filter_condition,
field,
Expand All @@ -61,8 +69,8 @@ class PayrollHeadPanel extends FormPanel {
value,
};
});
return transformedCriteria;
} catch (error) {
console.log(error, 'xxx');
return [];
}
};
Expand Down Expand Up @@ -181,9 +189,11 @@ class PayrollHeadPanel extends FormPanel {
<FormattedMessage module="contributionPlan" id="paymentPlan.advancedCriteria" />
</div>
</Typography>
<div className={classes.item}>
<FormattedMessage module="contributionPlan" id="paymentPlan.advancedCriteria.tip" />
</div>
{!readOnly && (
<div className={classes.item}>
<FormattedMessage module="contributionPlan" id="paymentPlan.advancedCriteria.tip" />
</div>
)}
<Divider />
<Grid container className={classes.item}>

Expand All @@ -199,7 +209,7 @@ class PayrollHeadPanel extends FormPanel {
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure}
updateAttributes={this.updateJsonExt}
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters}
getDefaultAppliedCustomFilters={() => this.getDefaultAppliedCustomFilters(payroll.jsonExt)}
readOnly={readOnly}
edited={this.props.edited}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
"payroll.advancedFilters.filter": "Filter",
"payroll.advancedFilters.value": "Value",
"payroll.advancedFilters.amount": "Amount",
"payroll.advancedFilters.button.advancedFilters": "Advanced Filters",
"payroll.advancedFilters.button.addFilters": "Add filter",
"payroll.advancedFilters.button.clearAllFilters": "Clear All Filters",
"payroll.advancedFilters.button.advancedFilters": "Advanced Criteria",
"payroll.advancedFilters.button.addFilters": "Add Criterion",
"payroll.advancedFilters.button.clearAllFilters": "Clear All Criteria",
"payroll.advancedFilters.button.cancel": "Cancel",
"payroll.advancedFilters.button.filter": "Filter",
"payroll.advancedFilters.button.filter": "Confirm Criteria",
"payroll.tooltip.edit": "Edit",

"payroll.payroll.payrollStatusPicker": "Status",
Expand Down

0 comments on commit 9cd5cce

Please sign in to comment.