Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CM-296: add custom filtering to individuals and groups #28

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/GroupSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import {
import {
DEFAULT_PAGE_SIZE,
ROWS_PER_PAGE_OPTIONS,
RIGHT_GROUP_UPDATE, RIGHT_GROUP_DELETE,
RIGHT_GROUP_UPDATE, RIGHT_GROUP_DELETE, SOCIAL_PROTECTION_MODULE_NAME, BENEFIT_PLAN_LABEL,
} from '../constants';
import GroupFilter from './GroupFilter';
import { applyNumberCircle } from '../util/searcher-utils';

function GroupSearcher({
intl,
Expand All @@ -55,9 +56,12 @@ function GroupSearcher({
coreConfirm,
clearConfirm,
journalize,
CLEARED_STATE_FILTER,
}) {
const [groupToDelete, setGroupToDelete] = useState(null);
const [deletedGroupUuids, setDeletedGroupUuids] = useState([]);
const [appliedCustomFilters, setAppliedCustomFilters] = useState([CLEARED_STATE_FILTER]);
const [appliedFiltersRowStructure, setAppliedFiltersRowStructure] = useState([CLEARED_STATE_FILTER]);
const prevSubmittingMutationRef = useRef();

function groupUpdatePageUrl(group) {
Expand Down Expand Up @@ -224,6 +228,15 @@ function GroupSearcher({
exportFieldLabel={formatMessage(intl, 'individual', 'export.label')}
cacheFiltersKey="groupsFilterCache"
resetFiltersOnUnmount
isCustomFiltering
moduleName={SOCIAL_PROTECTION_MODULE_NAME}
objectType={BENEFIT_PLAN_LABEL}
additionalCustomFilterParams={{ type: 'GROUP' }}
appliedCustomFilters={appliedCustomFilters}
setAppliedCustomFilters={setAppliedCustomFilters}
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={setAppliedFiltersRowStructure}
applyNumberCircle={applyNumberCircle}
rowDisabled={isRowDisabled}
rowLocked={isRowDisabled}
/>
Expand Down
19 changes: 18 additions & 1 deletion src/components/IndividualSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
withHistory,
historyPush,
downloadExport,
CLEARED_STATE_FILTER,
} from '@openimis/fe-core';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
Expand All @@ -31,8 +32,9 @@ import {
ROWS_PER_PAGE_OPTIONS,
EMPTY_STRING,
RIGHT_INDIVIDUAL_UPDATE,
RIGHT_INDIVIDUAL_DELETE,
RIGHT_INDIVIDUAL_DELETE, BENEFIT_PLAN_LABEL, SOCIAL_PROTECTION_MODULE_NAME,
} from '../constants';
import { applyNumberCircle } from '../util/searcher-utils';
import IndividualFilter from './IndividualFilter';

function IndividualSearcher({
Expand Down Expand Up @@ -61,6 +63,8 @@ function IndividualSearcher({
errorIndividualExport,
}) {
const [individualToDelete, setIndividualToDelete] = useState(null);
const [appliedCustomFilters, setAppliedCustomFilters] = useState([CLEARED_STATE_FILTER]);
const [appliedFiltersRowStructure, setAppliedFiltersRowStructure] = useState([CLEARED_STATE_FILTER]);
const [deletedIndividualUuids, setDeletedIndividualUuids] = useState([]);
const prevSubmittingMutationRef = useRef();

Expand Down Expand Up @@ -197,6 +201,10 @@ function IndividualSearcher({
return filters;
};

useEffect(() => {
// refresh when appliedCustomFilters is changed
}, [appliedCustomFilters]);

return (
<div>
<Searcher
Expand Down Expand Up @@ -224,6 +232,15 @@ function IndividualSearcher({
rowLocked={isRowDisabled}
exportable
exportFetch={downloadIndividuals}
isCustomFiltering
moduleName={SOCIAL_PROTECTION_MODULE_NAME}
objectType={BENEFIT_PLAN_LABEL}
additionalCustomFilterParams={{ type: 'INDIVIDUAL' }}
appliedCustomFilters={appliedCustomFilters}
setAppliedCustomFilters={setAppliedCustomFilters}
appliedFiltersRowStructure={appliedFiltersRowStructure}
setAppliedFiltersRowStructure={setAppliedFiltersRowStructure}
applyNumberCircle={applyNumberCircle}
exportFields={[
'id',
'first_name',
Expand Down
4 changes: 4 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ export const GROUP_INDIVIDUAL_ROLES = {
export const GROUP_INDIVIDUAL_ROLES_LIST = [
GROUP_INDIVIDUAL_ROLES.HEAD, GROUP_INDIVIDUAL_ROLES.RECIPIENT,
];

export const BENEFIT_PLAN_LABEL = 'BenefitPlan';

export const SOCIAL_PROTECTION_MODULE_NAME = 'social_protection';
23 changes: 23 additions & 0 deletions src/util/searcher-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

// eslint-disable-next-line import/prefer-default-export
export const applyNumberCircle = (number) => (
<div style={{
color: '#ffffff',
backgroundColor: '#006273',
borderRadius: '50%',
padding: '5px',
minWidth: '40px',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
fontWeight: 'bold',
fontSize: '12px',
width: '20px',
height: '45px',
marginTop: '7px',
}}
>
{number}
</div>
);
Loading