Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WCMS-20265: Enable Data Dictionary CSV Downloads with a prop #224

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/DatasetDataDictionaryTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import DatasetDictionaryTable from '../DatasetDictionaryTable';
import { Button, Spinner } from '@cmsgov/design-system';

const DataDictionary = (
{ datasetDictionaryEndpoint, datasetSitewideDictionary, title, pageSize = 20, additionalParams } :
{ datasetDictionaryEndpoint, datasetSitewideDictionary, title, pageSize = 20, additionalParams, csvDownload } :
{
datasetDictionaryEndpoint: string,
datasetSitewideDictionary: DatasetDictionaryItemType[]
title: string,
pageSize: number,
additionalParams: any,
csvDownload : boolean
}) => {

const {data, isPending, error} = useQuery({
Expand All @@ -36,10 +37,22 @@ const DataDictionary = (
<h2 className="ds-text-heading--2xl ds-u-margin-y--3">{title}</h2>
{datasetDictionary && (
<>
<div className="ds-u-margin-bottom--1 ds-u-display--flex ds-u-justify-content--end">
<div className="ds-u-margin-bottom--1 ds-u-display--flex ds-u-flex-wrap--wrap ds-u-justify-content--end">
<Button className="ds-l-col--12 ds-l-sm-col--6 ds-l-md-col--4" onClick={() => window.open(datasetDictionaryEndpoint)} type="button" >
<i className="fa fa-file-download ds-u-color--primary ds-u-padding-right--1"></i> View Dictionary JSON
</Button>
{csvDownload && (
<div className="ds-l-col--12 ds-l-sm-col--6 ds-l-md-col--4 ds-u-margin-top--2 ds-u-sm-margin-top--0 ds-u-padding--0 ds-u-sm-padding-left--2">
<a
href={datasetDictionaryEndpoint + "/csv"}
className="ds-c-button"
style={{width: '100%'}}
>
<i className="fa fa-file-download ds-u-color--primary ds-u-padding-right--1"></i>
Download Dictionary CSV
</a>
</div>
)}
</div>
<DatasetDictionaryTable datasetDictionary={datasetDictionary} pageSize={pageSize}/>
</>
Expand Down
11 changes: 9 additions & 2 deletions src/templates/Dataset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const Dataset = ({
apiPageUrl = "/api",
dataDictionaryUrl,
borderlessTabs = false,
defaultPageSize = 25
defaultPageSize = 25,
dataDictionaryCSV = false
} : DatasetPageType) => {
const options = location.search
? { ...qs.parse(location.search, { ignoreQueryPrefix: true }) }
Expand Down Expand Up @@ -197,7 +198,13 @@ const Dataset = ({
}
className={ borderlessTabs ? 'ds-u-border--0 ds-u-padding-x--0' : '' }
>
<DataDictionary datasetSitewideDictionary={datasetSitewideDictionary} datasetDictionaryEndpoint={distribution.data.describedBy} title={"Data Dictionary"} additionalParams={additionalParams} />
<DataDictionary
datasetSitewideDictionary={datasetSitewideDictionary}
datasetDictionaryEndpoint={distribution.data.describedBy}
title={"Data Dictionary"}
additionalParams={additionalParams}
csvDownload={dataDictionaryCSV}
/>
</TabPanel>
)
: null}
Expand Down
3 changes: 2 additions & 1 deletion src/types/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export type DatasetPageType = {
dataDictionaryUrl: string | undefined,
dataDictionaryACA: string | undefined,
borderlessTabs: boolean,
defaultPageSize: Number
defaultPageSize: Number,
dataDictionaryCSV: boolean,
}


Expand Down