Skip to content

Commit

Permalink
CM-359: update individual searcher to support selection of fields fro…
Browse files Browse the repository at this point in the history
…m json_ext
  • Loading branch information
Jan committed Jan 11, 2024
1 parent 96c0932 commit 53b6586
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
formatPageQueryWithCount,
formatMutation,
formatGQLString,
formatQuery,
} from '@openimis/fe-core';
import { ACTION_TYPE } from './reducer';
import {
Expand Down Expand Up @@ -84,6 +85,11 @@ export function fetchGroupHistory(params) {
return graphql(payload, ACTION_TYPE.SEARCH_GROUP_HISTORY);
}

export function fetchBenefitPlanSchemaFields(params) {
const payload = formatQuery('benefitPlanSchemaField', params, ['schemaFields']);
return graphql(payload, ACTION_TYPE.GET_FIELDS_FROM_BF_SCHEMA);
}

export function deleteIndividual(individual, clientMutationLabel) {
const individualUuids = `ids: ["${individual?.id}"]`;
const mutation = formatMutation('deleteIndividual', individualUuids, clientMutationLabel);
Expand Down
47 changes: 32 additions & 15 deletions src/components/IndividualSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import {
import EditIcon from '@material-ui/icons/Edit';
import DeleteIcon from '@material-ui/icons/Delete';
import {
fetchIndividuals, deleteIndividual, downloadIndividuals, clearIndividualExport,
fetchIndividuals, deleteIndividual, downloadIndividuals, clearIndividualExport, fetchBenefitPlanSchemaFields,
} from '../actions';
import {
DEFAULT_PAGE_SIZE,
ROWS_PER_PAGE_OPTIONS,
EMPTY_STRING,
RIGHT_INDIVIDUAL_UPDATE,
RIGHT_INDIVIDUAL_DELETE, BENEFIT_PLAN_LABEL, SOCIAL_PROTECTION_MODULE_NAME,
RIGHT_INDIVIDUAL_DELETE, BENEFIT_PLAN_LABEL, SOCIAL_PROTECTION_MODULE_NAME, RIGHT_SCHEMA_SEARCH,
} from '../constants';
import { applyNumberCircle } from '../util/searcher-utils';
import IndividualFilter from './IndividualFilter';
Expand Down Expand Up @@ -61,13 +61,36 @@ function IndividualSearcher({
downloadIndividuals,
individualExport,
errorIndividualExport,
fieldsFromBfSchema,
fetchingFieldsFromBfSchema,
fetchedFieldsFromBfSchema,
fetchBenefitPlanSchemaFields,
}) {
const [individualToDelete, setIndividualToDelete] = useState(null);
const [appliedCustomFilters, setAppliedCustomFilters] = useState([CLEARED_STATE_FILTER]);
const [appliedFiltersRowStructure, setAppliedFiltersRowStructure] = useState([CLEARED_STATE_FILTER]);
const [deletedIndividualUuids, setDeletedIndividualUuids] = useState([]);
const [exportFields, setExportFields] = useState([
'id',
'first_name',
'last_name',
'dob',
]);
const exportFieldsColumns = {
id: 'ID',
first_name: formatMessage(intl, 'individual', 'export.firstName'),
last_name: formatMessage(intl, 'individual', 'export.lastName'),
dob: formatMessage(intl, 'individual', 'export.dob'),
};
const prevSubmittingMutationRef = useRef();

useEffect(() => {
if (!fetchedFieldsFromBfSchema && !fetchingFieldsFromBfSchema && rights.includes(RIGHT_SCHEMA_SEARCH)) {
fetchBenefitPlanSchemaFields(['bfType: INDIVIDUAL']);
}
setExportFields([...exportFields, ...fieldsFromBfSchema]);
}, [fetchedFieldsFromBfSchema, fetchingFieldsFromBfSchema]);

function individualUpdatePageUrl(individual) {
return `${modulesManager.getRef('individual.route.individual')}/${individual?.id}`;
}
Expand Down Expand Up @@ -241,19 +264,8 @@ function IndividualSearcher({
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={setAppliedFiltersRowStructure}
applyNumberCircle={applyNumberCircle}
exportFields={[
'id',
'first_name',
'last_name',
'dob',
'json_ext', // Unfolded by backend and removed from csv
]}
exportFieldsColumns={{
id: 'ID',
first_name: formatMessage(intl, 'individual', 'export.firstName'),
last_name: formatMessage(intl, 'individual', 'export.lastName'),
dob: formatMessage(intl, 'individual', 'export.dob'),
}}
exportFields={exportFields}
exportFieldsColumns={exportFieldsColumns}
exportFieldLabel={formatMessage(intl, 'individual', 'export.label')}
chooseExportableColumns
cacheFiltersKey="individualsFilterCache"
Expand Down Expand Up @@ -289,6 +301,10 @@ const mapStateToProps = (state) => ({
individualExport: state.individual.individualExport,
individualExportPageInfo: state.individual.individualExportPageInfo,
errorIndividualExport: state.individual.errorIndividualExport,
fieldsFromBfSchema: state.individual.fieldsFromBfSchema,
fetchingFieldsFromBfSchema: state.individual.fetchingFieldsFromBfSchema,
fetchedFieldsFromBfSchema: state.individual.fetchedFieldsFromBfSchema,
errorFieldsFromBfSchema: state.individual.errorFieldsFromBfSchema,
});

const mapDispatchToProps = (dispatch) => bindActionCreators(
Expand All @@ -297,6 +313,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators(
deleteIndividual,
downloadIndividuals,
clearIndividualExport,
fetchBenefitPlanSchemaFields,
coreConfirm,
clearConfirm,
journalize,
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const RIGHT_GROUP_CREATE = 180002;
export const RIGHT_GROUP_UPDATE = 180003;
export const RIGHT_GROUP_DELETE = 180004;

export const RIGHT_SCHEMA_SEARCH = 171001;

export const BENEFIT_PLANS_LIST_TAB_VALUE = 'BenefitPlansListTab';
export const INDIVIDUALS_LIST_TAB_VALUE = 'IndividualsListTab';
export const INDIVIDUAL_CHANGELOG_TAB_VALUE = 'IndividualChangelogTab';
Expand Down
27 changes: 27 additions & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const ACTION_TYPE = {
GROUP_INDIVIDUAL_EXPORT: 'GROUP_INDIVIDUAL_EXPORT',
SEARCH_INDIVIDUAL_HISTORY: 'SEARCH_INDIVIDUAL_HISTORY',
SEARCH_GROUP_HISTORY: 'SEARCH_GROUP_HISTORY',
GET_FIELDS_FROM_BF_SCHEMA: 'GET_FIELDS_FROM_BF_SCHEMA',
};

function reducer(
Expand Down Expand Up @@ -92,10 +93,22 @@ function reducer(
groupHistory: [],
groupHistoryPageInfo: {},
groupHistoryTotalCount: 0,
fieldsFromBfSchema: [],
fetchingFieldsFromBfSchema: false,
fetchedFieldsFromBfSchema: false,
errorFieldsFromBfSchema: null,
},
action,
) {
switch (action.type) {
case REQUEST(ACTION_TYPE.GET_FIELDS_FROM_BF_SCHEMA):
return {
...state,
fieldsFromBfSchema: [],
fetchingFieldsFromBfSchema: true,
fetchedFieldsFromBfSchema: false,
errorFieldsFromBfSchema: null,
};
case REQUEST(ACTION_TYPE.SEARCH_INDIVIDUALS):
return {
...state,
Expand Down Expand Up @@ -162,6 +175,14 @@ function reducer(
groupHistoryTotalCount: 0,
errorGroupHistory: null,
};
case SUCCESS(ACTION_TYPE.GET_FIELDS_FROM_BF_SCHEMA):
return {
...state,
fieldsFromBfSchema: action?.payload?.data?.benefitPlanSchemaField?.schemaFields || [],
fetchingFieldsFromBfSchema: false,
fetchedFieldsFromBfSchema: true,
errorFieldsFromBfSchema: formatGraphQLError(action.payload),
};
case SUCCESS(ACTION_TYPE.SEARCH_INDIVIDUALS):
return {
...state,
Expand Down Expand Up @@ -268,6 +289,12 @@ function reducer(
}))?.[0],
errorGroup: null,
};
case ERROR(ACTION_TYPE.GET_FIELDS_FROM_BF_SCHEMA):
return {
...state,
fetchingFieldsFromBfSchema: false,
errorFieldsFromBfSchema: formatGraphQLError(action.payload),
};
case ERROR(ACTION_TYPE.SEARCH_INDIVIDUALS):
return {
...state,
Expand Down

0 comments on commit 53b6586

Please sign in to comment.