Skip to content

Commit

Permalink
Disable location edit for individuals belonging to a group
Browse files Browse the repository at this point in the history
Reason for disabled edit explained in location picker title

Requires:
openimis/openimis-fe-location_js#91
openimis/openimis-fe-core_js#259
  • Loading branch information
weilu committed Dec 13, 2024
1 parent bf7c5c7 commit 8dce8aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
40 changes: 26 additions & 14 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,27 @@ export function fetchWorkflows() {
return graphql(payload, ACTION_TYPE.GET_WORKFLOWS);
}

const INDIVIDUAL_FULL_PROJECTION = (mm) => [
'id',
'isDeleted',
'dateCreated',
'dateUpdated',
'firstName',
'lastName',
'dob',
'jsonExt',
'version',
'userUpdated {username}',
`location${mm.getProjection('location.Location.FlatProjection')}`,
];
const INDIVIDUAL_FULL_PROJECTION = (mm, withGroupIndividuals = false) => {
const fields = [
'id',
'isDeleted',
'dateCreated',
'dateUpdated',
'firstName',
'lastName',
'dob',
'jsonExt',
'version',
'userUpdated {username}',
`location${mm.getProjection('location.Location.FlatProjection')}`,
];

if (withGroupIndividuals) {
fields.push('groupindividuals (isDeleted: false) { edges { node { group { id } } } }');
}

return fields;
};

const GROUP_INDIVIDUAL_FULL_PROJECTION = [
'id',
Expand Down Expand Up @@ -163,7 +171,11 @@ export function fetchGroups(mm, params) {
}

export function fetchIndividual(mm, params) {
const payload = formatPageQuery('individual', params, INDIVIDUAL_FULL_PROJECTION(mm));
const payload = formatPageQuery(
'individual',
params,
INDIVIDUAL_FULL_PROJECTION(mm, true),
);
return graphql(payload, ACTION_TYPE.GET_INDIVIDUAL);
}

Expand Down
8 changes: 7 additions & 1 deletion src/components/IndividualHeadPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
withModulesManager,
FormPanel,
TextInput,
formatMessage,
FormattedMessage,
PublishedComponent,
} from '@openimis/fe-core';
Expand All @@ -22,10 +23,13 @@ const styles = (theme) => ({
class IndividualHeadPanel extends FormPanel {
render() {
const {
edited, classes, mandatoryFieldsEmpty,
intl, edited, classes, mandatoryFieldsEmpty,
} = this.props;
const individual = { ...edited };
const currentDate = new Date();
const locReadOnly = individual.groupindividuals?.edges?.length > 0;
const locTitle = locReadOnly ? formatMessage(intl, 'individual', 'individual.locationEditDisabledTitle') : '';

return (
<>
<Grid container className={classes.tableTitle}>
Expand Down Expand Up @@ -94,9 +98,11 @@ class IndividualHeadPanel extends FormPanel {
pubRef="location.DetailedLocation"
withNull
required={false}
readOnly={locReadOnly}
value={!edited ? null : edited.location}
onChange={(v) => this.updateAttribute('location', v)}
filterLabels={false}
title={locTitle}
/>
</Grid>
</Grid>
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"lastName": "Last Name",
"dob": "Day of birth",
"location": "Location",
"locationEditDisabledTitle": "Individual belongs to a group; Please edit location on their group",
"isDeleted": "Show Deleted",
"hasNoLocation": "Missing Location",
"addButtonTooltip": "Add Individual to Group",
Expand Down

0 comments on commit 8dce8aa

Please sign in to comment.