Skip to content

Commit

Permalink
Merge branch 'long-term/remove-tp' into adjust-pp-model
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlo-mk authored Nov 4, 2024
2 parents aec82ad + b2111fc commit a76f5dd
Show file tree
Hide file tree
Showing 11 changed files with 510 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import { useBaseUrl } from '@hooks/useBaseUrl';
import { useSnackbar } from '@hooks/useSnackBar';
import { Box, Divider, Grid, Typography } from '@mui/material';
import { FormikCheckboxField } from '@shared/Formik/FormikCheckboxField';
import { FormikTextField } from '@shared/Formik/FormikTextField';
import { getTargetingCriteriaVariables } from '@utils/targetingUtils';
import { Field, FieldArray, Form, Formik } from 'formik';
Expand All @@ -19,9 +18,10 @@ import { AndDivider, AndDividerLabel } from '../AndDivider';
import { Exclusions } from '../CreateTargetPopulation/Exclusions';
import { PaperContainer } from '../PaperContainer';
import { EditTargetPopulationHeader } from './EditTargetPopulationHeader';
import { TargetingCriteriaDisplay } from '../TargetingCriteriaDisplay/TargetingCriteriaDisplay';
import { AddFilterTargetingCriteriaDisplay } from '../TargetingCriteriaDisplay/AddFilterTargetingCriteriaDisplay';
import { ProgramCycleAutocompleteRest } from '@shared/autocompletes/rest/ProgramCycleAutocompleteRest';
import { ReactElement } from 'react';
import { CreateAndEditTPCheckboxes } from '@containers/pages/targeting/CreateAndEditTPCheckboxes';

interface EditTargetPopulationProps {
targetPopulation: TargetPopulationQuery['targetPopulation'];
Expand Down Expand Up @@ -193,14 +193,13 @@ export const EditTargetPopulation = ({
<FieldArray
name="targetingCriteria"
render={(arrayHelpers) => (
<TargetingCriteriaDisplay
<AddFilterTargetingCriteriaDisplay
helpers={arrayHelpers}
rules={values.targetingCriteria}
isEdit
screenBeneficiary={screenBeneficiary}
isStandardDctType={isStandardDctType}
isSocialDctType={isSocialDctType}
category={category}
/>
)}
/>
Expand Down Expand Up @@ -242,62 +241,11 @@ export const EditTargetPopulation = ({
</Grid>
)}
</Grid>
<Box mt={3} p={3}>
<Grid container spacing={3}>
{isStandardDctType && (
<Grid item xs={6}>
<Field
name="flagExcludeIfActiveAdjudicationTicket"
label={t(
'Exclude Households with Active Adjudication Ticket',
)}
color="primary"
component={FormikCheckboxField}
data-cy="input-active-households-adjudication-ticket"
/>
</Grid>
)}
{isSocialDctType && (
<Grid item xs={6}>
<Field
name="flagExcludeIfActiveAdjudicationTicket"
label={t(
'Exclude People with Active Adjudication Ticket',
)}
color="primary"
component={FormikCheckboxField}
data-cy="input-active-people-adjudication-ticket"
/>
</Grid>
)}
{screenBeneficiary && isSocialDctType && (
<Grid item xs={6}>
<Field
name="flagExcludeIfOnSanctionList"
label={t(
'Exclude People with an Active Sanction Screen Flag',
)}
color="primary"
component={FormikCheckboxField}
data-cy="input-active-people-sanction-flag"
/>
</Grid>
)}
{screenBeneficiary && isStandardDctType && (
<Grid item xs={6}>
<Field
name="flagExcludeIfOnSanctionList"
label={t(
'Exclude Households with an Active Sanction Screen Flag',
)}
color="primary"
component={FormikCheckboxField}
data-cy="input-active-sanction-flag"
/>
</Grid>
)}
</Grid>
</Box>
<CreateAndEditTPCheckboxes
isStandardDctType={isStandardDctType}
isSocialDctType={isSocialDctType}
screenBeneficiary={screenBeneficiary}
/>
</>
) : null}
</PaperContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { TargetingHouseholds } from './TargetingHouseholds';
import { useBaseUrl } from '@hooks/useBaseUrl';
import { TargetPopulationPeopleTable } from '@containers/tables/targeting/TargetPopulationPeopleTable';
import { ResultsForPeople } from '@components/targeting/ResultsForPeople';
import { TargetingCriteriaDisplay } from './TargetingCriteriaDisplay/TargetingCriteriaDisplay';
import { ReactElement } from 'react';
import { AddFilterTargetingCriteriaDisplay } from './TargetingCriteriaDisplay/AddFilterTargetingCriteriaDisplay';

const Label = styled.p`
color: #b1b1b5;
Expand All @@ -36,7 +36,6 @@ interface TargetPopulationCoreProps {
screenBeneficiary: boolean;
isStandardDctType: boolean;
isSocialDctType: boolean;
category: string;
}

export const TargetPopulationCore = ({
Expand All @@ -46,7 +45,6 @@ export const TargetPopulationCore = ({
screenBeneficiary,
isStandardDctType,
isSocialDctType,
category,
}: TargetPopulationCoreProps): ReactElement => {
const { t } = useTranslation();
const { businessArea } = useBaseUrl();
Expand Down Expand Up @@ -111,13 +109,12 @@ export const TargetPopulationCore = ({
{individualIds}
</IdContainer>
)}
<TargetingCriteriaDisplay
<AddFilterTargetingCriteriaDisplay
rules={targetPopulation.targetingCriteria?.rules || []}
targetPopulation={targetPopulation}
screenBeneficiary={screenBeneficiary}
isStandardDctType={isStandardDctType}
isSocialDctType={isSocialDctType}
category={category}
/>
</PaperContainer>
) : null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { TargetingCriteriaForm } from '@containers/forms/TargetingCriteriaForm';
import {
DataCollectingTypeType,
TargetPopulationQuery,
} from '@generated/graphql';
import { useBaseUrl } from '@hooks/useBaseUrl';
import { useCachedImportedIndividualFieldsQuery } from '@hooks/useCachedImportedIndividualFields';
import { AddCircleOutline } from '@mui/icons-material';
import { Box, Button, Checkbox, FormControlLabel, Grid } from '@mui/material';
import { FormikCheckboxField } from '@shared/Formik/FormikCheckboxField';
import { Field } from 'formik';
import { Box, Button } from '@mui/material';
import { Fragment, ReactElement, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { useProgramContext } from 'src/programContext';
import styled from 'styled-components';
import { Criteria } from './Criteria';
import { ExcludeCheckboxes } from './ExcludeCheckboxes';
import {
ContentWrapper,
TargetingCriteriaDisplayDisabled,
} from './TargetingCriteriaDisplayDisabled';
import { VulnerabilityScoreComponent } from './VulnerabilityScoreComponent';
import { useProgramContext } from 'src/programContext';
import { useCachedImportedIndividualFieldsQuery } from '@hooks/useCachedImportedIndividualFields';
import { useBaseUrl } from '@hooks/useBaseUrl';
import { TargetingCriteriaForm } from '@containers/forms/TargetingCriteriaForm';

const Title = styled.div`
padding: ${({ theme }) => theme.spacing(3)} ${({ theme }) => theme.spacing(4)};
Expand Down Expand Up @@ -72,11 +71,7 @@ const AddCriteria = styled.div`
}
`;

const NoWrapCheckbox = styled(FormControlLabel)`
white-space: nowrap;
`;

interface TargetingCriteriaDisplayProps {
interface AddFilterTargetingCriteriaDisplayProps {
rules?;
helpers?;
targetPopulation?: TargetPopulationQuery['targetPopulation'];
Expand All @@ -86,15 +81,15 @@ interface TargetingCriteriaDisplayProps {
isStandardDctType: boolean;
}

export const TargetingCriteriaDisplay = ({
export const AddFilterTargetingCriteriaDisplay = ({
rules,
helpers,
targetPopulation,
isEdit,
screenBeneficiary,
isSocialDctType,
isStandardDctType,
}: TargetingCriteriaDisplayProps): ReactElement => {
}: AddFilterTargetingCriteriaDisplayProps): ReactElement => {
const { t } = useTranslation();
const location = useLocation();
const { selectedProgram } = useProgramContext();
Expand Down Expand Up @@ -213,6 +208,9 @@ export const TargetingCriteriaDisplay = ({
individualsFiltersBlocks={
criteria.individualsFiltersBlocks || []
}
collectorsFiltersBlocks={
criteria.collectorsFiltersBlocks || []
}
editFunction={() => editCriteria(criteria, index)}
removeFunction={() => helpers.remove(index)}
/>
Expand All @@ -237,151 +235,13 @@ export const TargetingCriteriaDisplay = ({
</AddCriteria>
)}
</Box>
<Box>
{isDetailsPage ? (
<Box mt={3} p={3}>
<Grid container spacing={3}>
<Grid item xs={6}>
{isStandardDctType && (
<NoWrapCheckbox
disabled
control={
<Checkbox
name="flagExcludeIfActiveAdjudicationTicket"
color="primary"
data-cy="checkbox-exclude-if-active-adjudication-ticket"
checked={Boolean(
targetPopulation?.targetingCriteria
?.flagExcludeIfActiveAdjudicationTicket,
)}
/>
}
label={t(
'Exclude Households with Active Adjudication Ticket',
)}
/>
)}
{isSocialDctType && (
<NoWrapCheckbox
disabled
control={
<Checkbox
name="flagExcludeIfActiveAdjudicationTicket"
color="primary"
data-cy="checkbox-exclude-people-if-active-adjudication-ticket"
checked={Boolean(
targetPopulation?.targetingCriteria
?.flagExcludeIfActiveAdjudicationTicket,
)}
/>
}
label={t(
'Exclude People with Active Adjudication Ticket',
)}
/>
)}
</Grid>
<Grid item xs={6}>
{screenBeneficiary && isSocialDctType && (
<NoWrapCheckbox
disabled
control={
<Checkbox
name="flagExcludeIfOnSanctionList"
color="primary"
data-cy="checkbox-exclude-if-on-sanction-list"
/>
}
checked={Boolean(
targetPopulation?.targetingCriteria
?.flagExcludeIfOnSanctionList,
)}
label={t(
'Exclude People with an Active Sanction Screen Flag',
)}
/>
)}
{screenBeneficiary && isStandardDctType && (
<NoWrapCheckbox
disabled
control={
<Checkbox
name="flagExcludeIfOnSanctionList"
color="primary"
data-cy="checkbox-exclude-if-on-sanction-list"
/>
}
checked={Boolean(
targetPopulation?.targetingCriteria
?.flagExcludeIfOnSanctionList,
)}
label={t(
'Exclude Households with an Active Sanction Screen Flag',
)}
/>
)}
</Grid>
</Grid>
</Box>
) : (
<Box mt={3} p={3}>
<Grid container spacing={3}>
{isStandardDctType && (
<Grid item xs={6}>
<Field
name="flagExcludeIfActiveAdjudicationTicket"
label={t(
'Exclude Households with Active Adjudication Ticket',
)}
color="primary"
component={FormikCheckboxField}
data-cy="input-active-adjudication-ticket"
/>
</Grid>
)}
{isSocialDctType && (
<Grid item xs={6}>
<Field
name="flagExcludePeopleWithActiveAdjudicationTicket"
label={t(
'Exclude People with Active Adjudication Ticket',
)}
color="primary"
component={FormikCheckboxField}
data-cy="input-active-adjudication-ticket"
/>
</Grid>
)}
{screenBeneficiary && isStandardDctType && (
<Grid item xs={6}>
<Field
name="flagExcludeIfOnSanctionList"
label={t(
'Exclude Households with an Active Sanction Screen Flag',
)}
color="primary"
component={FormikCheckboxField}
data-cy="input-active-sanction-flag"
/>
</Grid>
)}
{screenBeneficiary && isSocialDctType && (
<Grid item xs={6}>
<Field
name="flagExcludeIfOnSanctionList"
label={t(
'Exclude People with an Active Sanction Screen Flag',
)}
color="primary"
component={FormikCheckboxField}
data-cy="input-active-sanction-flag"
/>
</Grid>
)}
</Grid>
</Box>
)}
</Box>
<ExcludeCheckboxes
isStandardDctType={isStandardDctType}
isSocialDctType={isSocialDctType}
screenBeneficiary={screenBeneficiary}
isDetailsPage={isDetailsPage}
targetPopulation={targetPopulation}
/>
</Box>
</ContentWrapper>
{targetPopulation && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export function Criteria({
))}
{collectorsFiltersBlocks.map((item, index) => (
<CriteriaSetBox key={index}>
{item.collectorsFiltersBlocks.map((filter, filterIndex) => (
{item.collectorBlockFilters.map((filter, filterIndex) => (
<CriteriaField
choicesDict={choicesDict}
key={filterIndex}
Expand Down
Loading

0 comments on commit a76f5dd

Please sign in to comment.