From 1ff1189c8d38577dcfaee74fa6f6109f32be729c Mon Sep 17 00:00:00 2001 From: Amy Benson Date: Wed, 29 May 2024 11:50:28 +0100 Subject: [PATCH] EES-4995 only show type filter is there are api data sets --- .../data-catalogue/DataCataloguePage.tsx | 14 ++++- .../data-catalogue/DataCataloguePageNew.tsx | 8 ++- .../data-catalogue/components/Filters.tsx | 59 +++++++++++-------- .../components/__tests__/Filters.test.tsx | 13 ++++ 4 files changed, 67 insertions(+), 27 deletions(-) diff --git a/src/explore-education-statistics-frontend/src/modules/data-catalogue/DataCataloguePage.tsx b/src/explore-education-statistics-frontend/src/modules/data-catalogue/DataCataloguePage.tsx index b8824656d86..ee670a776e1 100644 --- a/src/explore-education-statistics-frontend/src/modules/data-catalogue/DataCataloguePage.tsx +++ b/src/explore-education-statistics-frontend/src/modules/data-catalogue/DataCataloguePage.tsx @@ -16,6 +16,7 @@ import { QueryClient, dehydrate } from '@tanstack/react-query'; import publicationQueries from '@frontend/queries/publicationQueries'; interface Props { + showTypeFilter?: boolean; releases?: ReleaseSummary[]; selectedPublication?: PublicationTreeSummary; selectedRelease?: ReleaseSummary; @@ -25,6 +26,7 @@ interface Props { } const DataCataloguePage: NextPage = ({ + showTypeFilter, releases = [], selectedPublication, selectedRelease, @@ -34,7 +36,7 @@ const DataCataloguePage: NextPage = ({ }) => { // TO DO EES-4781 - remove old version if (newDesign) { - return ; + return ; } return ( = async context => { newDesign, } = context.query as Dictionary; + let showTypeFilter = context.query.dataSetType === 'api'; + const queryClient = new QueryClient(); if (newDesign) { @@ -63,6 +67,13 @@ export const getServerSideProps: GetServerSideProps = async context => { publicationFilter: 'DataCatalogue', }), ); + + if (!showTypeFilter) { + const apiDataSets = await queryClient.fetchQuery( + dataSetFileQueries.list({ dataSetType: 'api' }), + ); + showTypeFilter = !!apiDataSets.results.length; + } } const themes = newDesign @@ -99,6 +110,7 @@ export const getServerSideProps: GetServerSideProps = async context => { } const props: Props = { + showTypeFilter, releases, subjects, themes, diff --git a/src/explore-education-statistics-frontend/src/modules/data-catalogue/DataCataloguePageNew.tsx b/src/explore-education-statistics-frontend/src/modules/data-catalogue/DataCataloguePageNew.tsx index 6b9dd647643..5baf58f797e 100644 --- a/src/explore-education-statistics-frontend/src/modules/data-catalogue/DataCataloguePageNew.tsx +++ b/src/explore-education-statistics-frontend/src/modules/data-catalogue/DataCataloguePageNew.tsx @@ -55,7 +55,11 @@ export interface DataCataloguePageQuery { themeId?: string; } -export default function DataCataloguePageNew() { +interface Props { + showTypeFilter?: boolean; +} + +export default function DataCataloguePageNew({ showTypeFilter }: Props) { const router = useRouter(); const queryClient = useQueryClient(); const { isMedia: isMobileMedia } = useMobileMedia(); @@ -318,6 +322,7 @@ export default function DataCataloguePageNew() { releaseId={releaseId} releases={releases} showClearFiltersButton={!isMobileMedia && isFiltered} + showTypeFilter={showTypeFilter} themeId={themeId} themes={themes} onChange={handleChangeFilter} @@ -420,6 +425,7 @@ export default function DataCataloguePageNew() { publications={publications} releaseId={releaseId} releases={releases} + showTypeFilter={showTypeFilter} themeId={themeId} themes={themes} onChange={handleChangeFilter} diff --git a/src/explore-education-statistics-frontend/src/modules/data-catalogue/components/Filters.tsx b/src/explore-education-statistics-frontend/src/modules/data-catalogue/components/Filters.tsx index 5b58c81c37d..783b767ad0a 100644 --- a/src/explore-education-statistics-frontend/src/modules/data-catalogue/components/Filters.tsx +++ b/src/explore-education-statistics-frontend/src/modules/data-catalogue/components/Filters.tsx @@ -1,3 +1,4 @@ +import ButtonText from '@common/components/ButtonText'; import { PublicationTreeSummary, ReleaseSummary, @@ -16,7 +17,7 @@ import { } from '@frontend/services/dataSetFileService'; import styles from '@frontend/modules/data-catalogue/components/Filters.module.scss'; import React from 'react'; -import ButtonText from '@common/components/ButtonText'; +import classNames from 'classnames'; const formId = 'filters-form'; @@ -28,6 +29,7 @@ interface Props { releaseId?: string; releases?: ReleaseSummary[]; showClearFiltersButton?: boolean; + showTypeFilter?: boolean; themeId?: string; themes: Theme[]; onChange: ({ @@ -48,6 +50,7 @@ export default function Filters({ releaseId, releases = [], showClearFiltersButton, + showTypeFilter, themeId, themes, onChange, @@ -135,31 +138,37 @@ export default function Filters({ {showClearFiltersButton && ( - Clear filters + + Clear filters + + )} + {showTypeFilter && ( + + formGroupClass="dfe-border-top govuk-!-padding-top-4 govuk-!-margin-top-2" + id={`${formId}-dataSetType`} + legend="Type of data" + legendSize="s" + name="dataSetType" + options={[ + { label: 'All data', value: 'all' }, + { + label: 'API data sets only', + value: 'api', + }, + ]} + small + value={dataSetType} + onChange={e => { + onChange({ + filterType: 'dataSetType', + nextValue: e.target.value, + }); + }} + /> )} - - - formGroupClass="dfe-border-top govuk-!-padding-top-4 govuk-!-margin-top-2" - id={`${formId}-dataSetType`} - legend="Type of data" - legendSize="s" - name="dataSetType" - options={[ - { label: 'All data', value: 'all' }, - { - label: 'API data sets only', - value: 'api', - }, - ]} - small - value={dataSetType} - onChange={e => { - onChange({ - filterType: 'dataSetType', - nextValue: e.target.value, - }); - }} - />