Skip to content

Commit

Permalink
fix(export): Add button dropdown for multiple formats
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Jan 31, 2024
1 parent 74b9277 commit 4d0d7d4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 65 deletions.
50 changes: 50 additions & 0 deletions client/src/components/button-dropdown/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// https://www.w3schools.com/css/css_dropdowns.asp
import PropTypes from 'prop-types';

import Button from '../button';
import { export2Csv, export2FosmCsv, export2jsonl } from '../../utils/file';

import './index.scss';

export default function ButtonDropdown({ data, label }) {
return (
<div className={`dropdown ${data.length > 0 ? 'enabled' : 'disabled'}`}>
<Button
disabled={!data.length}
icon="ri-save-line"
size="sm"
>
Export
{' '}
{label}
</Button>
<div className="dropdown-content">
<Button
onClick={() => export2Csv({ data, label })}
size="sm"
>
Export in CSV (minimal data)
</Button>
<Button
onClick={() => export2jsonl({ data, label })}
size="sm"
>
Export in JSONL (complete data)
</Button>
{label === 'publications' && (
<Button
onClick={() => export2FosmCsv(data)}
size="sm"
>
Custom export for French OSM
</Button>
)}
</div>
</div>
);
}

ButtonDropdown.propTypes = {
data: PropTypes.array.isRequired,
label: PropTypes.string.isRequired,
};
15 changes: 15 additions & 0 deletions client/src/components/button-dropdown/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.dropdown {
display: inline-block;
position: relative;

.dropdown-content {
display: none;
min-width: 160px;
position: absolute;
z-index: 1;
}
}

.dropdown:hover .dropdown-content {
display: block;
}
69 changes: 4 additions & 65 deletions client/src/pages/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { useSearchParams } from 'react-router-dom';
import { Tooltip } from 'react-tooltip';

import Button from '../components/button';
import { export2Csv, export2FosmCsv, export2json, export2jsonl, importJson } from '../utils/file';
import ButtonDropdown from '../components/button-dropdown';
import { export2json, importJson } from '../utils/file';
import { status } from '../config';

export default function Actions({
Expand Down Expand Up @@ -50,70 +51,8 @@ export default function Actions({
<Tooltip id="restore-affiliations-button">
Restore affiliations from saved file
</Tooltip>
<Button
data-tooltip-id="export-datasets-csv-button"
disabled={!allDatasets.length}
icon="ri-save-line"
onClick={() => export2Csv({ data: allDatasets, label: 'datasets' })}
size="sm"
>
Export datasets (minimal data)
</Button>
<Tooltip id="export-datasets-csv-button" hidden={!allDatasets.length}>
Export all datasets in CSV
</Tooltip>
<Button
data-tooltip-id="export-datasets-jsonl-button"
disabled={!allDatasets.length}
icon="ri-save-line"
onClick={() => export2jsonl({ data: allDatasets, label: 'datasets' })}
size="sm"
>
Export datasets (complete data)
</Button>
<Tooltip id="export-datasets-jsonl-button" hidden={!allDatasets.length}>
Export all datasets in JSONL
</Tooltip>
<Button
data-tooltip-id="export-publications-csv-button"
disabled={!allPublications.length}
icon="ri-save-line"
onClick={() => export2Csv({ data: allPublications, label: 'publications' })}
size="sm"
>
Export publications (minimal data)
</Button>
<Tooltip id="export-publications-csv-button" hidden={!allPublications.length}>
Export all publications in CSV
</Tooltip>
<Button
data-tooltip-id="export-publications-jsonl-button"
disabled={!allPublications.length}
icon="ri-save-line"
onClick={() => export2jsonl({ data: allPublications, label: 'publications' })}
size="sm"
>
Export publications (complete data)
</Button>
<Tooltip id="export-publications-jsonl-button" hidden={!allPublications.length}>
Export all publications in JSONL
</Tooltip>
<Button
data-tooltip-id="export-fosm-button"
disabled={!allPublications.length}
icon="ri-save-line"
onClick={() => export2FosmCsv(allPublications)}
size="sm"
>
Custom export for French OSM
</Button>
<Tooltip id="export-fosm-button" hidden={!allPublications.length}>
Export the
{' '}
<b>validated</b>
{' '}
publications in the format needed to build a local French OSM in CSV
</Tooltip>
<ButtonDropdown data={allDatasets} label="datasets" />
<ButtonDropdown data={allPublications} label="publications" />
</Col>
</Row>
{displayFileUpload && (
Expand Down

0 comments on commit 4d0d7d4

Please sign in to comment.