Skip to content

Commit

Permalink
Merge pull request #55 from eea/develop
Browse files Browse the repository at this point in the history
Fix crash in dataset view
  • Loading branch information
kreafox committed Sep 13, 2023
2 parents c26a164 + 86e3d25 commit 388b0b8
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 80 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### [1.0.29](https://github.com/eea/volto-datahub/compare/1.0.28...1.0.29) - 13 September 2023

#### :hammer_and_wrench: Others

- Fix snapshot [kreafox - [`3e070c5`](https://github.com/eea/volto-datahub/commit/3e070c5973e314935d674c5d41a361882317937b)]
- Add test [kreafox - [`5683383`](https://github.com/eea/volto-datahub/commit/568338374247690706c4b5b1b766e1663602ace9)]
- Fix crash in dataset view [Tiberiu Ichim - [`f3a7310`](https://github.com/eea/volto-datahub/commit/f3a7310344b760bc8b4246bf69f47912068d6d90)]
### [1.0.28](https://github.com/eea/volto-datahub/compare/1.0.27...1.0.28) - 8 September 2023

#### :hammer_and_wrench: Others
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-datahub",
"version": "1.0.28",
"version": "1.0.29",
"description": "@eeacms/volto-datahub: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
30 changes: 15 additions & 15 deletions src/components/ItemView/Datasets/DatasetEsri.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ const ItemLink = ({ item }) => (
>
{item.protocol} {item.name || item.description}
</a>
{isInternalURL(item.url) && <SVGIcon name={lockSVG} size="20px" />}
{isInternalURL(item.url) ? (
<SVGIcon name={lockSVG} size="20px" />
) : null}
</div>
</List.Content>
</List.Item>
);

export default function DatasetEsri({ dataset }) {
return (
(dataset['ESRI:REST'] || dataset['OGC:WMS']) && (
<>
<h5>Services:</h5>
<List divided relaxed>
{[...(dataset['ESRI:REST'] || []), ...(dataset['OGC:WMS'] || [])].map(
(item, i) => (
<ItemLink item={item} key={item.id} />
),
)}
</List>
</>
)
);
return dataset['ESRI:REST'] || dataset['OGC:WMS'] ? (
<>
<h5>Services:</h5>
<List divided relaxed>
{[...(dataset['ESRI:REST'] || []), ...(dataset['OGC:WMS'] || [])].map(
(item, i) => (
<ItemLink item={item} key={item.id} />
),
)}
</List>
</>
) : null;
}
116 changes: 57 additions & 59 deletions src/components/ItemView/Datasets/DatasetHttpLinks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,61 @@ import { SVGIcon } from '../utils.js';
import lockSVG from 'remixicon/icons/System/lock-line.svg';

export default function DatasetHttpLinks({ dataset }) {
return (
(dataset['WWW:LINK-1.0-http--link'] || dataset['DOI']) && (
<>
<h5>Links:</h5>
<List divided relaxed>
{(dataset['WWW:LINK-1.0-http--link'] || []).map((item, i) => {
return (
<List.Item key={i}>
<List.Content>
<div className="dataset-item">
<Icon className="linkify" />
<a
href={item.url}
className="item-link"
target="_blank"
rel="noreferrer"
>
<span>{item.name || item.url}</span>
</a>
{isInternalURL(item.url) && (
<SVGIcon name={lockSVG} size="20px" />
)}
</div>
</List.Content>
{item.description && (
<span className="item-description">{item.description}</span>
)}
</List.Item>
);
})}
{(dataset['DOI'] || []).map((item, i) => {
return (
<List.Item key={i}>
<List.Content>
<div className="dataset-item">
<Icon className="info circle" />
<a
href={item.url}
className="item-link"
target="_blank"
rel="noreferrer"
>
<span>{item.name || item.url}</span>
</a>
{isInternalURL(item.url) && (
<SVGIcon name={lockSVG} size="20px" />
)}
</div>
</List.Content>
{item.description && (
<span className="item-description">{item.description}</span>
)}
</List.Item>
);
})}
</List>
</>
)
);
return dataset['WWW:LINK-1.0-http--link'] || dataset['DOI'] ? (
<>
<h5>Links:</h5>
<List divided relaxed>
{(dataset['WWW:LINK-1.0-http--link'] || []).map((item, i) => {
return (
<List.Item key={i}>
<List.Content>
<div className="dataset-item">
<Icon className="linkify" />
<a
href={item.url}
className="item-link"
target="_blank"
rel="noreferrer"
>
<span>{item.name || item.url}</span>
</a>
{isInternalURL(item.url) ? (
<SVGIcon name={lockSVG} size="20px" />
) : null}
</div>
</List.Content>
{item.description ? (
<span className="item-description">{item.description}</span>
) : null}
</List.Item>
);
})}
{(dataset['DOI'] || []).map((item, i) => {
return (
<List.Item key={i}>
<List.Content>
<div className="dataset-item">
<Icon className="info circle" />
<a
href={item.url}
className="item-link"
target="_blank"
rel="noreferrer"
>
<span>{item.name || item.url}</span>
</a>
{isInternalURL(item.url) ? (
<SVGIcon name={lockSVG} size="20px" />
) : null}
</div>
</List.Content>
{item.description ? (
<span className="item-description">{item.description}</span>
) : null}
</List.Item>
);
})}
</List>
</>
) : null;
}
13 changes: 8 additions & 5 deletions src/components/ItemView/Datasets/DatasetItemDownloadList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ import DatasetHttpLinks from './DatasetHttpLinks';
const DatasetItemDownloadList = (props) => {
const { link } = props;
const dataset = groupBy(link, 'protocol');
const showDownload = !!(
dataset['WWW:URL'] ||
dataset['WWW:LINK'] ||
dataset['EEA:FILEPATH'] ||
dataset['EEA:FOLDERPATH']
);

return (
<div>
{(dataset['WWW:URL'] ||
dataset['WWW:LINK'] ||
dataset['EEA:FILEPATH'] ||
dataset['EEA:FOLDERPATH']) && (
{showDownload ? (
<>
<h5>Download:</h5>
<List divided relaxed>
<DatasetUrls dataset={dataset} />
<DatasetLinks dataset={dataset} />
</List>
</>
)}
) : null}

<DatasetEsri dataset={dataset} />
<DatasetHttpLinks dataset={dataset} />
Expand Down
25 changes: 25 additions & 0 deletions src/components/ItemView/Datasets/DatasetUrls.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import renderer from 'react-test-renderer';

import DatasetUrls from './DatasetUrls';

jest.mock('@eeacms/search', () => ({
runRequest: jest.fn(),
}));

const dataset = {
'WWW:URL': [
{
url: 'https://example.org/1',
name: 'Direct download',
description: 'Download link description',
},
],
};

describe('DatasetUrl', () => {
it('renders correctly', () => {
const tree = renderer.create(<DatasetUrls dataset={dataset} />).toJSON();
expect(tree).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DatasetUrl renders correctly 1`] = `
<div
className="item"
onClick={[Function]}
role="listitem"
>
<div
className="content"
>
<div
className="dataset-item"
>
<i
aria-hidden="true"
className="icon download"
onClick={[Function]}
/>
<a
className="item-link"
href="https://example.org/1"
rel="noreferrer"
target="_blank"
>
<span>
Direct download
</span>
</a>
</div>
</div>
<span
className="item-description"
title="Download link description"
>
Download link description
</span>
</div>
`;

0 comments on commit 388b0b8

Please sign in to comment.