-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from openimis/feature/CM-711
CM-711: Frontend development for Program Selection and Filter Application
- Loading branch information
Showing
13 changed files
with
1,174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* eslint-disable max-len */ | ||
/* eslint-disable camelcase */ | ||
import React from 'react'; | ||
import { injectIntl } from 'react-intl'; | ||
|
||
import { Grid, Divider } from '@material-ui/core'; | ||
import { withStyles, withTheme } from '@material-ui/core/styles'; | ||
|
||
import { | ||
decodeId, | ||
FormPanel, | ||
PublishedComponent, | ||
formatMessage, | ||
withModulesManager, | ||
} from '@openimis/fe-core'; | ||
import AdvancedCriteriaForm from './dialogs/AdvancedCriteriaForm'; | ||
import { CLEARED_STATE_FILTER } from '../constants'; | ||
|
||
const styles = (theme) => ({ | ||
tableTitle: theme.table.title, | ||
item: theme.paper.item, | ||
fullHeight: { | ||
height: '100%', | ||
}, | ||
}); | ||
|
||
class EnrollmentHeadPanel extends FormPanel { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
appliedCustomFilters: [CLEARED_STATE_FILTER], | ||
appliedFiltersRowStructure: [CLEARED_STATE_FILTER], | ||
}; | ||
} | ||
|
||
updateJsonExt = (value) => { | ||
this.updateAttributes({ | ||
jsonExt: value, | ||
}); | ||
}; | ||
|
||
getDefaultAppliedCustomFilters = () => { | ||
const { jsonExt } = this.props?.edited ?? {}; | ||
try { | ||
const jsonData = JSON.parse(jsonExt); | ||
const advancedCriteria = jsonData.advanced_criteria || []; | ||
return advancedCriteria.map(({ custom_filter_condition }) => { | ||
const [field, filter, typeValue] = custom_filter_condition.split('__'); | ||
const [type, value] = typeValue.split('='); | ||
return { | ||
custom_filter_condition, | ||
field, | ||
filter, | ||
type, | ||
value, | ||
}; | ||
}); | ||
} catch (error) { | ||
return []; | ||
} | ||
}; | ||
|
||
setAppliedCustomFilters = (appliedCustomFilters) => { | ||
this.setState({ appliedCustomFilters }); | ||
}; | ||
|
||
setAppliedFiltersRowStructure = (appliedFiltersRowStructure) => { | ||
this.setState({ appliedFiltersRowStructure }); | ||
}; | ||
|
||
render() { | ||
// eslint-disable-next-line no-unused-vars | ||
const { edited, classes, intl } = this.props; | ||
const enrollment = { ...edited }; | ||
const { appliedCustomFilters, appliedFiltersRowStructure } = this.state; | ||
return ( | ||
<> | ||
<Grid container className={classes.item}> | ||
<Grid item xs={3} className={classes.item}> | ||
<PublishedComponent | ||
pubRef="socialProtection.BenefitPlanPicker" | ||
withNull | ||
required | ||
filterLabels={false} | ||
onChange={(benefitPlan) => this.updateAttribute('benefitPlan', benefitPlan)} | ||
value={enrollment?.benefitPlan} | ||
/> | ||
</Grid> | ||
<Grid item xs={3} className={classes.item}> | ||
<PublishedComponent | ||
pubRef="socialProtection.BeneficiaryStatusPicker" | ||
required | ||
withNull={false} | ||
filterLabels={false} | ||
onChange={(status) => this.updateAttribute('status', status)} | ||
value={enrollment?.status} | ||
/> | ||
</Grid> | ||
</Grid> | ||
<Divider /> | ||
<Grid> | ||
<> | ||
<div className={classes.item}> | ||
{formatMessage(intl, 'individual', 'individual.enrollment.criteria')} | ||
</div> | ||
<Divider /> | ||
<Grid container className={classes.item}> | ||
<AdvancedCriteriaForm | ||
object={enrollment.benefitPlan} | ||
objectToSave={enrollment} | ||
moduleName="individual" | ||
objectType="Individual" | ||
setAppliedCustomFilters={this.setAppliedCustomFilters} | ||
appliedCustomFilters={appliedCustomFilters} | ||
appliedFiltersRowStructure={appliedFiltersRowStructure} | ||
setAppliedFiltersRowStructure={this.setAppliedFiltersRowStructure} | ||
updateAttributes={this.updateJsonExt} | ||
getDefaultAppliedCustomFilters={this.getDefaultAppliedCustomFilters} | ||
additionalParams={enrollment?.benefitPlan ? { benefitPlan: `${decodeId(enrollment.benefitPlan.id)}` } : null} | ||
/> | ||
</Grid> | ||
</> | ||
</Grid> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
export default withModulesManager(injectIntl(withTheme(withStyles(styles)(EnrollmentHeadPanel)))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.