From 181fb8cf3fe0ad30baa98cdc069ba8614412e834 Mon Sep 17 00:00:00 2001 From: Bethany Dunfield Date: Fri, 19 Jul 2024 09:40:59 -0600 Subject: [PATCH] WCMS-21486: Add data dictionary info banner when data dictionaries are enabled and prop is passed (#230) --- .../DatasetTableTab/DatasetTableTab.test.jsx | 21 ++++++++++++++ src/components/DatasetTableTab/index.tsx | 29 +++++++++++++++++-- src/templates/Dataset/index.tsx | 19 ++++++++---- src/types/dataset.ts | 1 + 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/components/DatasetTableTab/DatasetTableTab.test.jsx b/src/components/DatasetTableTab/DatasetTableTab.test.jsx index 9e3ed3d9..75bbdb7f 100644 --- a/src/components/DatasetTableTab/DatasetTableTab.test.jsx +++ b/src/components/DatasetTableTab/DatasetTableTab.test.jsx @@ -19,4 +19,25 @@ describe('', () => { expect(screen.getByRole("table")).toBeInTheDocument(); expect(screen.getByRole("navigation")).toHaveClass("ds-c-pagination"); }); + test("Renders data dictionary info banner if prop is provided", () => { + resource.setSort = jest.fn(); + render( + ) + expect(screen.getByText('Click on the "Data Dictionary" tab above for full column definitions')).toBeInTheDocument(); + }); + test("Does not render data dictionary info banner if prop is not provided", () => { + resource.setSort = jest.fn(); + render( + ) + expect(screen.queryByText('Click on the "Data Dictionary" tab above for full column definitions')).not.toBeInTheDocument(); + }); }); \ No newline at end of file diff --git a/src/components/DatasetTableTab/index.tsx b/src/components/DatasetTableTab/index.tsx index fea587dc..1c6afa47 100644 --- a/src/components/DatasetTableTab/index.tsx +++ b/src/components/DatasetTableTab/index.tsx @@ -3,7 +3,7 @@ import qs from 'qs'; import DataTable from '../Datatable/Datatable'; import { transformTableSortToQuerySort } from '../../services/useDatastore/transformSorts'; import { buildCustomColHeaders } from '../../templates/FilteredResource/functions'; -import { Pagination, Dropdown, Spinner } from '@cmsgov/design-system'; +import { Pagination, Dropdown, Spinner, Alert } from '@cmsgov/design-system'; import DataTableHeader from '../DatatableHeader'; import QueryBuilder from '../QueryBuilder'; import { DistributionType, ColumnType, ResourceType } from '../../types/dataset'; @@ -16,8 +16,26 @@ export function prepareColumns(columns : any, schema : any) { })); } -const DatasetTable = ({ id, distribution, resource, rootUrl, customColumns = [], jsonUrl = undefined } - : {id: string, distribution: DistributionType, resource: ResourceType, rootUrl: string, customColumns: Array, jsonUrl?: string} +type DatasetTableTabProps = { + id: string, + distribution: DistributionType, + resource: ResourceType, + rootUrl: string, + customColumns: Array, + jsonUrl?: string, + dataDictionaryBanner: boolean, +} + +const DatasetTable = ({ + id, + distribution, + resource, + rootUrl, + customColumns = [], + jsonUrl = undefined, + dataDictionaryBanner + } + : DatasetTableTabProps ) => { const defaultPage = 1; const defaultPageSize = 10; @@ -51,6 +69,11 @@ const DatasetTable = ({ id, distribution, resource, rootUrl, customColumns = [], return ( <> + {dataDictionaryBanner && ( +
+ Click on the "Data Dictionary" tab above for full column definitions +
+ )} { }
{ const options = location.search ? { ...qs.parse(location.search, { ignoreQueryPrefix: true }) } @@ -132,6 +133,8 @@ const Dataset = ({ else if (window.location.hash.substring(1) != selectedTab) setSelectedTab(window.location.hash.substring(1)) }, [distribution, window.location.hash]) + + const displayDataDictionaryTab = ((distribution.data && distribution.data.describedBy && distribution.data.describedByType === 'application/vnd.tableschema+json') || (datasetSitewideDictionary && datasetSitewideDictionary.length > 0)) as boolean; return ( <> @@ -172,7 +175,14 @@ const Dataset = ({ } className={ borderlessTabs ? 'ds-u-border--0 ds-u-padding-x--0' : '' } > - + )} - {(distribution.data && distribution.data.describedBy && distribution.data.describedByType === 'application/vnd.tableschema+json') || (datasetSitewideDictionary && datasetSitewideDictionary.length) ? ( + {displayDataDictionaryTab && ( - ) - : null} + )} { distribution && distribution.data && (