Skip to content

Commit

Permalink
Minor refactoring to improve consistency
Browse files Browse the repository at this point in the history
Also address linter complaints
  • Loading branch information
weilu committed Jul 23, 2024
1 parent b156256 commit 309acb5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 0 additions & 2 deletions src/components/BenefitPlanBeneficiariesSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {
DEFAULT_PAGE_SIZE,
RIGHT_BENEFICIARY_SEARCH,
ROWS_PER_PAGE_OPTIONS,
MODULE_NAME,
BENEFIT_PLAN_LABEL,
RIGHT_BENEFICIARY_UPDATE,
} from '../constants';
import BenefitPlanBeneficiariesFilter from './BenefitPlanBeneficiariesFilter';
Expand Down
13 changes: 8 additions & 5 deletions src/components/BenefitPlanEligibilityCriteriaPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import AddCircle from '@material-ui/icons/Add';
import {
Button, Divider, Grid, Paper, Typography,
} from '@material-ui/core';
import { CLEARED_STATE_FILTER, BENEFICIARY_STATUS } from '../constants';
import {
CLEARED_STATE_FILTER,
BENEFICIARY_STATUS,
DEFAULT_BENEFICIARY_STATUS,
} from '../constants';
import { isBase64Encoded } from '../util/advanced-criteria-utils';

const useStyles = makeStyles((theme) => ({
Expand All @@ -35,7 +39,6 @@ function BenefitPlanEligibilityCriteriaPanel({
const { formatMessage, formatMessageWithValues } = useTranslations('socialProtection', modulesManager);
const customFilters = useSelector((state) => state.core.customFilters);
const [filters, setFilters] = useState([]);
const defaultFilterStatus = 'POTENTIAL';

const status = Object.values(BENEFICIARY_STATUS).find((value) => (
activeTab.toUpperCase().includes(value)
Expand All @@ -50,7 +53,7 @@ function BenefitPlanEligibilityCriteriaPanel({
// For backward compatibility POTENTIAL status take on the old filters
let criteria = jsonData?.advanced_criteria || {};
if (Array.isArray(criteria)) {
criteria = { [defaultFilterStatus]: criteria };
criteria = { [DEFAULT_BENEFICIARY_STATUS]: criteria };
}

return criteria[status] || [];
Expand Down Expand Up @@ -105,8 +108,8 @@ function BenefitPlanEligibilityCriteriaPanel({
const jsonData = JSON.parse(jsonExt);
let advancedCriteria = jsonData?.advanced_criteria || {};
// migrate old advanced_criteria
if (Array.isArray(jsonData?.advanced_criteria)) {
advancedCriteria = { [defaultFilterStatus]: jsonData?.advanced_criteria };
if (Array.isArray(advancedCriteria)) {
advancedCriteria = { [DEFAULT_BENEFICIARY_STATUS]: jsonData?.advanced_criteria };
}
const editedAdvancedCriteria = { ...advancedCriteria, [status]: filters };
const json = { ...jsonData, advanced_criteria: editedAdvancedCriteria };
Expand Down
3 changes: 0 additions & 3 deletions src/components/BenefitPlanGroupBeneficiariesSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ import {
RIGHT_BENEFICIARY_UPDATE,
ROWS_PER_PAGE_OPTIONS,
CLEARED_STATE_FILTER,
BENEFIT_PLAN_LABEL,
MODULE_NAME,
} from '../constants';
import BenefitPlanGroupBeneficiariesFilter from './BenefitPlanGroupBeneficiariesFilter';
import BeneficiaryStatusPicker from '../pickers/BeneficiaryStatusPicker';
import { applyNumberCircle } from '../util/searcher-utils';


function BenefitPlanGroupBeneficiariesSearcher({
rights,
intl,
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const BENEFICIARY_STATUS = {
SUSPENDED: 'SUSPENDED',
};

export const DEFAULT_BENEFICIARY_STATUS = 'POTENTIAL';

export const FIELD_TYPES = {
INTEGER: 'integer',
NUMBER: 'number',
Expand Down

0 comments on commit 309acb5

Please sign in to comment.