Skip to content

Commit

Permalink
includeRelatedPlans to indicatorlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavatu committed Oct 17, 2024
1 parent af915ab commit 125336c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default async function ActionsPage({ params }: Props) {
<IndicatorList
leadContent={data.planPage.leadContent}
displayInsights={data.planPage.displayInsights}
includeRelatedPlans={data.planPage?.includeRelatedPlans}
/>
);
}
3 changes: 2 additions & 1 deletion common/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 16 additions & 13 deletions components/indicators/IndicatorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ const collectCommonCategories = (indicators) => {
}));
};

const includeRelatedPlanIndicators = true;

const getFilterConfig = (categoryType, indicators, commonCategories) => ({
mainFilters: [
...(includeRelatedPlanIndicators
...(commonCategories
? commonCategories.map(({ typeIdentifier, categories, type }) => ({
__typename: 'CategoryTypeFilterBlock',
field: 'category',
Expand Down Expand Up @@ -291,6 +289,7 @@ interface Filters {
const filterIndicators = (
indicators,
filters: Filters,
includeRelatedPlans: boolean,
categoryIdentifier?: string
) => {
const filterByCategory = (indicator) => {
Expand Down Expand Up @@ -336,7 +335,7 @@ const filterIndicators = (
const commonCategoryResult = filterByCommonCategory(indicator);
const searchResult = filterBySearch(indicator);
return (
(!includeRelatedPlanIndicators ? categoryResult : commonCategoryResult) &&
(!includeRelatedPlans ? categoryResult : commonCategoryResult) &&
searchResult
);
});
Expand All @@ -352,9 +351,14 @@ const getFirstUsableCategoryType = (categoryTypes, indicators) =>
interface Props {
leadContent: IndicatorListPage['leadContent'];
displayInsights: IndicatorListPage['displayInsights'];
includeRelatedPlans: IndicatorListPage['includeRelatedPlans'];
}

const IndicatorList = ({ leadContent, displayInsights }: Props) => {
const IndicatorList = ({
leadContent,
displayInsights,
includeRelatedPlans,
}: Props) => {
const plan = usePlan();
const t = useTranslations();
const searchParams = useSearchParams();
Expand All @@ -364,7 +368,7 @@ const IndicatorList = ({ leadContent, displayInsights }: Props) => {
{
variables: {
plan: plan.identifier,
relatedPlanIndicators: includeRelatedPlanIndicators,
relatedPlanIndicators: includeRelatedPlans,
},
}
);
Expand Down Expand Up @@ -413,9 +417,7 @@ const IndicatorList = ({ leadContent, displayInsights }: Props) => {
leadContent: generalContent.indicatorListLeadContent,
displayMunicipality,
displayNormalizedValues,
relatedPlanIndicators: includeRelatedPlanIndicators
? relatedPlanIndicators
: [],
relatedPlanIndicators: includeRelatedPlans ? relatedPlanIndicators : [],
};
};

Expand All @@ -424,13 +426,13 @@ const IndicatorList = ({ leadContent, displayInsights }: Props) => {

const indicatorListProps = getIndicatorListProps(data);

const indicators = includeRelatedPlanIndicators
const indicators = includeRelatedPlans
? indicatorListProps.relatedPlanIndicators
: indicatorListProps.indicators;

const commonCategories = collectCommonCategories(indicators);
const hierarchy = processCommonIndicatorHierarchy(
includeRelatedPlanIndicators
includeRelatedPlans
? indicatorListProps.relatedPlanIndicators
: data?.planIndicators
);
Expand All @@ -445,7 +447,7 @@ const IndicatorList = ({ leadContent, displayInsights }: Props) => {
? getFilterConfig(
categoryType,
indicators,
includeRelatedPlanIndicators ? commonCategories : []
includeRelatedPlans ? commonCategories : []
)
: {};

Expand All @@ -462,6 +464,7 @@ const IndicatorList = ({ leadContent, displayInsights }: Props) => {
const filteredIndicators = filterIndicators(
indicators,
filters,
includeRelatedPlans,
categoryType?.identifier
);

Expand Down Expand Up @@ -490,7 +493,7 @@ const IndicatorList = ({ leadContent, displayInsights }: Props) => {
shouldDisplayCategory={(category: Category) =>
category.type.id === categoryType?.id
}
includePlanRelatedIndicators={includeRelatedPlanIndicators}
includePlanRelatedIndicators={includeRelatedPlans}
commonCategories={commonCategories}
/>
</Container>
Expand Down
1 change: 1 addition & 0 deletions queries/get-indicator-list-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const GET_INDICATOR_LIST_PAGE = gql`
... on IndicatorListPage {
leadContent
displayInsights
includeRelatedPlans
}
lastPublishedAt
}
Expand Down

0 comments on commit 125336c

Please sign in to comment.