From 362043e4bd70e43c190f076b5298c2ac8c218a28 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 21 Jul 2023 11:18:51 -0400 Subject: [PATCH 1/8] Update downloads sidebar with dictionary and multiple resources --- .../DatasetDownloads/datasetdownloads.scss | 5 +++ src/components/DatasetDownloads/index.jsx | 37 ++++++++++++++++--- src/templates/Dataset/DatasetBody.jsx | 6 ++- 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 src/components/DatasetDownloads/datasetdownloads.scss diff --git a/src/components/DatasetDownloads/datasetdownloads.scss b/src/components/DatasetDownloads/datasetdownloads.scss new file mode 100644 index 00000000..cfd53a7d --- /dev/null +++ b/src/components/DatasetDownloads/datasetdownloads.scss @@ -0,0 +1,5 @@ +.dc-c-dataset-downloads { + ul { + list-style: none; + } +} \ No newline at end of file diff --git a/src/components/DatasetDownloads/index.jsx b/src/components/DatasetDownloads/index.jsx index 3488b763..3cb69b77 100644 --- a/src/components/DatasetDownloads/index.jsx +++ b/src/components/DatasetDownloads/index.jsx @@ -1,16 +1,41 @@ import React from 'react'; import PropTypes from 'prop-types'; +import './datasetdownloads.scss'; + +const DatasetDownloads = ({ dataDictionaryURL, dataDictionaryType, distributions }) => { + function trimDataDictionaryType() { + let splitDataDictionaryType = dataDictionaryType.split('/'); + let type = splitDataDictionaryType.length > 1 ? splitDataDictionaryType[1] : splitDataDictionaryType[0]; + return type.toUpperCase() + } -const DatasetDownloads = ({ downloadURL, type }) => { return ( -
+

Downloads

-

Resource

- - Download this resource ({type}) - + {(distributions.length || (dataDictionaryURL && dataDictionaryType)) && + + }
); }; diff --git a/src/templates/Dataset/DatasetBody.jsx b/src/templates/Dataset/DatasetBody.jsx index 0a267c8c..1936e475 100644 --- a/src/templates/Dataset/DatasetBody.jsx +++ b/src/templates/Dataset/DatasetBody.jsx @@ -148,7 +148,11 @@ const DatasetBody = ({
{Object.keys(distribution).length ? ( - + ) : ( '' )} From 3d590f8f5beb40196f8cc90bc33a3f915c3edf0e Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 21 Jul 2023 11:30:44 -0400 Subject: [PATCH 2/8] Fix data dictionary link and update tests --- .../datasetdownloads.test.jsx | 43 ++++++++++++++++--- src/components/DatasetDownloads/index.jsx | 2 +- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/components/DatasetDownloads/datasetdownloads.test.jsx b/src/components/DatasetDownloads/datasetdownloads.test.jsx index 22d71b33..0de36c8e 100644 --- a/src/components/DatasetDownloads/datasetdownloads.test.jsx +++ b/src/components/DatasetDownloads/datasetdownloads.test.jsx @@ -3,15 +3,48 @@ import { render, screen } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; import DatasetDownloads from './index'; +const dataDictionaryURLFixture = "https://test.com/file.pdf"; +const dataDictionaryTypeFixture = "application/pdf"; +const distributionsFixture = [ + {identifier: "1", data: {downloadURL: "https://test.com/file.csv", format: "csv"}}, + {identifier: "2", data: {downloadURL: "https://test.com/file.xlsx", format: "xlsx"}}, +]; + + describe('', () => { test('Renders a download URL link and title', () => { - render(); + render( + + ); + expect(screen.getByRole('heading', { name: 'Downloads' })).toBeTruthy(); + expect(screen.getByRole('link', { name: 'CSV Resource File' })).toBeTruthy(); + expect(screen.getByRole('link', { name: 'CSV Resource File' })).toHaveAttribute( + 'href', + 'https://test.com/file.csv' + ); + expect(screen.getByRole('link', { name: 'XLSX Resource File' })).toBeTruthy(); + expect(screen.getByRole('link', { name: 'XLSX Resource File' })).toHaveAttribute( + 'href', + 'https://test.com/file.xlsx' + ); + }); + test('Renders a data dictionary link', () => { + render( + + ); expect(screen.getByRole('heading', { name: 'Downloads' })).toBeTruthy(); - //expect(screen.getByText('Dataset')).toBeTruthy(); - expect(screen.getByRole('link', { name: 'Download this resource (csv)' })).toBeTruthy(); - expect(screen.getByRole('link', { name: 'Download this resource (csv)' })).toHaveAttribute( + expect(screen.getByRole('link', { name: 'Data Dictionary (PDF)' })).toBeTruthy(); + expect(screen.getByRole('link', { name: 'Data Dictionary (PDF)' })).toHaveAttribute( 'href', - 'http://dkan.com/download.csv' + 'https://test.com/file.pdf' ); }); }); diff --git a/src/components/DatasetDownloads/index.jsx b/src/components/DatasetDownloads/index.jsx index 3cb69b77..caebc78f 100644 --- a/src/components/DatasetDownloads/index.jsx +++ b/src/components/DatasetDownloads/index.jsx @@ -29,7 +29,7 @@ const DatasetDownloads = ({ dataDictionaryURL, dataDictionaryType, distributions } {(dataDictionaryURL && dataDictionaryType) &&
  • - + Data Dictionary ({trimDataDictionaryType()})
  • From f307d3d381b282e0703d4ba02462c2575d84e691 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 21 Jul 2023 11:34:14 -0400 Subject: [PATCH 3/8] Bump to 2.1.0-alpha.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index eb935092..e28d6932 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@civicactions/cmsds-open-data-components", - "version": "2.0.7", + "version": "2.1.0-alpha.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@civicactions/cmsds-open-data-components", - "version": "2.0.7", + "version": "2.1.0-alpha.1", "license": "GPL-3.0", "dependencies": { "@popperjs/core": "^2.11.6", diff --git a/package.json b/package.json index a41235d9..a5f56f75 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@civicactions/cmsds-open-data-components", - "version": "2.0.7", + "version": "2.1.0-alpha.1", "description": "Components for the open data catalog frontend using CMS Design System", "main": "dist/main.js", "source": "src/index.ts", From a604060b318ab8a94963e4fa888857ea05560d02 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 25 Jul 2023 10:44:28 -0400 Subject: [PATCH 4/8] Swap to design system list classes --- src/components/DatasetDownloads/datasetdownloads.scss | 5 ----- src/components/DatasetDownloads/index.jsx | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 src/components/DatasetDownloads/datasetdownloads.scss diff --git a/src/components/DatasetDownloads/datasetdownloads.scss b/src/components/DatasetDownloads/datasetdownloads.scss deleted file mode 100644 index cfd53a7d..00000000 --- a/src/components/DatasetDownloads/datasetdownloads.scss +++ /dev/null @@ -1,5 +0,0 @@ -.dc-c-dataset-downloads { - ul { - list-style: none; - } -} \ No newline at end of file diff --git a/src/components/DatasetDownloads/index.jsx b/src/components/DatasetDownloads/index.jsx index caebc78f..fa55c123 100644 --- a/src/components/DatasetDownloads/index.jsx +++ b/src/components/DatasetDownloads/index.jsx @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import './datasetdownloads.scss'; const DatasetDownloads = ({ dataDictionaryURL, dataDictionaryType, distributions }) => { function trimDataDictionaryType() { @@ -15,7 +14,7 @@ const DatasetDownloads = ({ dataDictionaryURL, dataDictionaryType, distributions Downloads {(distributions.length || (dataDictionaryURL && dataDictionaryType)) && -
      +
        { distributions.map((dist) => (
      • From 08947fe316c2b3ad87ed84cdbb12446ed1f61e72 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 25 Jul 2023 10:46:00 -0400 Subject: [PATCH 5/8] Bump to alpha 2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e28d6932..2b46dd80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.1", + "version": "2.1.0-alpha.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.1", + "version": "2.1.0-alpha.2", "license": "GPL-3.0", "dependencies": { "@popperjs/core": "^2.11.6", diff --git a/package.json b/package.json index a5f56f75..e3077020 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.1", + "version": "2.1.0-alpha.2", "description": "Components for the open data catalog frontend using CMS Design System", "main": "dist/main.js", "source": "src/index.ts", From 7e559c932aac72f0e845ad92a9e30bcc814543d5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 2 Aug 2023 10:11:27 -0400 Subject: [PATCH 6/8] Build format type from mime if format missing --- src/components/DatasetDownloads/index.jsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/DatasetDownloads/index.jsx b/src/components/DatasetDownloads/index.jsx index fa55c123..0863b665 100644 --- a/src/components/DatasetDownloads/index.jsx +++ b/src/components/DatasetDownloads/index.jsx @@ -8,6 +8,19 @@ const DatasetDownloads = ({ dataDictionaryURL, dataDictionaryType, distributions return type.toUpperCase() } + function getFormatType(dist) { + if(dist.data.format) { + return dist.data.format.toUpperCase() + } else if (dist.data.mediaType) { + const mediaType = dist.data.mediaType.split('/'); + if (mediaType.length && mediaType[1]) { + return mediaType[1].toUpperCase(); + } + } else { + return ''; + } + } + return (

        @@ -19,7 +32,7 @@ const DatasetDownloads = ({ dataDictionaryURL, dataDictionaryType, distributions distributions.map((dist) => (
      • - {dist.data.format.toUpperCase()} + {getFormatType(dist)} {' '} Resource File From 24e298468a48b4ccb7be02c3b95a865c113c90ff Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 3 Aug 2023 10:20:14 -0400 Subject: [PATCH 7/8] Bump to 2.1.0-alpha.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2b46dd80..a23c6c82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.2", + "version": "2.1.0-alpha.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.2", + "version": "2.1.0-alpha.3", "license": "GPL-3.0", "dependencies": { "@popperjs/core": "^2.11.6", diff --git a/package.json b/package.json index e3077020..c3d92430 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.2", + "version": "2.1.0-alpha.3", "description": "Components for the open data catalog frontend using CMS Design System", "main": "dist/main.js", "source": "src/index.ts", From 9bb84d4cfd503708f8d62a449cea7680ed187ce6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 3 Aug 2023 12:00:29 -0400 Subject: [PATCH 8/8] Fix proptype and key bugs --- package-lock.json | 4 ++-- package.json | 2 +- src/components/DatasetDownloads/index.jsx | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index a23c6c82..ff128e1f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.3", + "version": "2.1.0-alpha.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.3", + "version": "2.1.0-alpha.4", "license": "GPL-3.0", "dependencies": { "@popperjs/core": "^2.11.6", diff --git a/package.json b/package.json index c3d92430..6f8f5232 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@civicactions/cmsds-open-data-components", - "version": "2.1.0-alpha.3", + "version": "2.1.0-alpha.4", "description": "Components for the open data catalog frontend using CMS Design System", "main": "dist/main.js", "source": "src/index.ts", diff --git a/src/components/DatasetDownloads/index.jsx b/src/components/DatasetDownloads/index.jsx index 0863b665..ecceac15 100644 --- a/src/components/DatasetDownloads/index.jsx +++ b/src/components/DatasetDownloads/index.jsx @@ -11,14 +11,22 @@ const DatasetDownloads = ({ dataDictionaryURL, dataDictionaryType, distributions function getFormatType(dist) { if(dist.data.format) { return dist.data.format.toUpperCase() - } else if (dist.data.mediaType) { + } + if(dist.data.mediaType) { const mediaType = dist.data.mediaType.split('/'); if (mediaType.length && mediaType[1]) { return mediaType[1].toUpperCase(); } - } else { - return ''; } + if(dist.data["%Ref:downloadURL"].length && dist.data["%Ref:downloadURL"][0].data) { + if(dist.data["%Ref:downloadURL"][0].data.mimeType) { + const mimeType = dist.data["%Ref:downloadURL"][0].data.mimeType.split("/"); + if (mimeType.length && mimeType[1]) { + return mimeType[1].toUpperCase(); + } + } + } + return ''; } return ( @@ -30,8 +38,8 @@ const DatasetDownloads = ({ dataDictionaryURL, dataDictionaryType, distributions