From 9a64ddca920944e813a6041649c35573ab62e940 Mon Sep 17 00:00:00 2001 From: Timo Tuominen Date: Mon, 25 Sep 2023 22:17:02 +0300 Subject: [PATCH 1/2] Allow hiding indicator list page insights with page settings --- common/__generated__/graphql.ts | 3 ++- components/indicators/IndicatorList.tsx | 5 +++-- pages/indicators/index.js | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/common/__generated__/graphql.ts b/common/__generated__/graphql.ts index 18e6be65..da3b6370 100644 --- a/common/__generated__/graphql.ts +++ b/common/__generated__/graphql.ts @@ -2166,6 +2166,7 @@ export type IndicatorListPage = PageInterface & { contentType: Scalars['String']; depth?: Maybe; descendants: Array; + displayInsights?: Maybe; draftTitle: Scalars['String']; expireAt?: Maybe; expired: Scalars['Boolean']; @@ -10560,7 +10561,7 @@ export type GetPlanPageIndicatorListQuery = ( { id?: string | null, slug: string, title: string, lastPublishedAt?: any | null } & { __typename: 'AccessibilityStatementPage' | 'ActionListPage' | 'CategoryPage' | 'CategoryTypePage' | 'EmptyPage' | 'ImpactGroupPage' | 'Page' | 'PlanRootPage' | 'PrivacyPolicyPage' | 'StaticPage' } ) | ( - { leadContent?: string | null, id?: string | null, slug: string, title: string, lastPublishedAt?: any | null } + { leadContent?: string | null, displayInsights?: boolean | null, id?: string | null, slug: string, title: string, lastPublishedAt?: any | null } & { __typename: 'IndicatorListPage' } ) | null } & { __typename?: 'Query' } diff --git a/components/indicators/IndicatorList.tsx b/components/indicators/IndicatorList.tsx index 12b39ac0..5e00f3f3 100644 --- a/components/indicators/IndicatorList.tsx +++ b/components/indicators/IndicatorList.tsx @@ -210,9 +210,10 @@ const getFirstUsableCategoryType = (categoryTypes, indicators) => interface Props { title: string; leadContent: IndicatorListPage['leadContent']; + displayInsights: boolean; } -const IndicatorList = ({ title, leadContent }: Props) => { +const IndicatorList = ({ title, leadContent, displayInsights }: Props) => { const plan = usePlan(); const { t } = useTranslation('common'); const router = useRouter(); @@ -332,7 +333,7 @@ const IndicatorList = ({ title, leadContent }: Props) => { const indicatorListProps = getIndicatorListProps(data); const hierarchy = processCommonIndicatorHierarchy(data?.planIndicators); - const showInsights = hasInsights(data); + const showInsights = displayInsights && hasInsights(data); const categoryType = getFirstUsableCategoryType( data?.plan?.categoryTypes, diff --git a/pages/indicators/index.js b/pages/indicators/index.js index bd7d22f8..c68affed 100644 --- a/pages/indicators/index.js +++ b/pages/indicators/index.js @@ -15,6 +15,7 @@ const GET_PLAN_PAGE = gql` title ... on IndicatorListPage { leadContent + displayInsights } lastPublishedAt } @@ -39,6 +40,7 @@ function IndicatorsPage() { ); From 71122a2b54c67d745fbc2f8e40419f816a330572 Mon Sep 17 00:00:00 2001 From: Timo Tuominen Date: Tue, 26 Sep 2023 09:06:56 +0300 Subject: [PATCH 2/2] Handle undefined case for displayInsights --- components/indicators/IndicatorList.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/indicators/IndicatorList.tsx b/components/indicators/IndicatorList.tsx index 5e00f3f3..ee24ebd7 100644 --- a/components/indicators/IndicatorList.tsx +++ b/components/indicators/IndicatorList.tsx @@ -210,7 +210,7 @@ const getFirstUsableCategoryType = (categoryTypes, indicators) => interface Props { title: string; leadContent: IndicatorListPage['leadContent']; - displayInsights: boolean; + displayInsights: IndicatorListPage['displayInsights']; } const IndicatorList = ({ title, leadContent, displayInsights }: Props) => { @@ -333,7 +333,7 @@ const IndicatorList = ({ title, leadContent, displayInsights }: Props) => { const indicatorListProps = getIndicatorListProps(data); const hierarchy = processCommonIndicatorHierarchy(data?.planIndicators); - const showInsights = displayInsights && hasInsights(data); + const showInsights = (displayInsights ?? true) && hasInsights(data); const categoryType = getFirstUsableCategoryType( data?.plan?.categoryTypes,