Skip to content

Commit

Permalink
Feat: build precomputed data screen in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienMattiussi committed Oct 13, 2023
1 parent 63909d7 commit 18227cc
Show file tree
Hide file tree
Showing 16 changed files with 1,911 additions and 555 deletions.
1,086 changes: 543 additions & 543 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions packages/transformers/.babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"presets": [
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings"
]
"presets": ["@babel/preset-env"],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-nullish-coalescing-operator",
"@babel/plugin-proposal-json-strings"
]
}
4 changes: 4 additions & 0 deletions src/app/custom/translations.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"column" "Column" "Colonne"
"for_row" "for row" "pour la ligne"
"enrichment" "Enrichment" "Enrichissement"
"precomputed" "Precomputed" "Précalculs"
"resource_share_export" "Share/Export" "Partager/Exporter"
"resource_ontology" "Ontology" "Ontologie"
"versions" "versions" "versions"
Expand Down Expand Up @@ -663,7 +664,9 @@
"internalName" "Internal name" "Nom interne"
"internalScope" "Field icon(s)" "Icône(s) du champ"
"advancedMode" "Advanced mode" "Mode avancé"
"name" "Name" "Nom"
"sourceColumn" "Source column" "Colonne de la source"
"sourceColumns" "Source column(s)" "Colonne(s) source(s)"
"subPath" "Sub-path" "Sous-chemin"
"subPathHelper" "Leave empty to directly send the column value" "Laisser vide pour utiliser directement la valeur de la colonne"
"imported_lines" "lines imported" "lignes importées"
Expand Down Expand Up @@ -912,6 +915,7 @@
"parsing_delete_row_error" "Error while deleting row" "Erreur lors de la suppression de la ligne"
"add_more_data" "Add more data" "Ajouter plus de données"
"add_more_enrichment" "Add more enrichments" "Ajouter plus d'enrichissements"
"add_more_precomputed" "Add more precomputed data" "Ajouter plus de données précalculées"
"add_more_subresource" "Add more subresources" "Ajouter plus de sous-ressources"
"density_tooltip" "Data density" "Choisir la densité de données"
"column_tooltip" "Column" "Choisir les colonnes"
Expand Down
7 changes: 6 additions & 1 deletion src/app/js/admin/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DataRoute } from './DataRoute';
import { DataAddRoute } from './DataAddRoute';
import RemovedResourcePage from './removedResources/RemovedResourcePage';
import { EnrichmentRoute } from './EnrichmentRoute';
import { PrecomputedRoute } from './PrecomputedRoute';

const DataComponent = () => {
let { path } = useRouteMatch();
Expand All @@ -27,10 +28,14 @@ const DataComponent = () => {
exact
component={() => <RemovedResourcePage />}
/>
<Route
<Route
path={`${path}/enrichment`}
component={() => <EnrichmentRoute />}
/>
<Route
path={`${path}/precomputed`}
component={() => <PrecomputedRoute />}
/>
<Route
path={path}
exact
Expand Down
32 changes: 32 additions & 0 deletions src/app/js/admin/PrecomputedRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';

import { compose } from 'recompose';
import translate from 'redux-polyglot/translate';
import withInitialData from './withInitialData';

import { Route, useRouteMatch, Switch } from 'react-router';
import PrecomputedListConnected from './precomputed/PrecomputedList';
import PrecomputedFormConnected from './precomputed/PrecomputedForm';

export const PrecomputedRouteComponent = () => {
let { path } = useRouteMatch();

return (
<Switch>
<Route exact path={`${path}`}>
<PrecomputedListConnected />
</Route>
<Route exact path={`${path}/add`}>
<PrecomputedFormConnected />
</Route>
<Route exact path={`${path}/:precomputedId`}>
<PrecomputedFormConnected />
</Route>
</Switch>
);
};

export const PrecomputedRoute = compose(
withInitialData,
translate,
)(PrecomputedRouteComponent);
9 changes: 9 additions & 0 deletions src/app/js/admin/Sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MenuList from '@mui/material/MenuList';
import Drawer from '@mui/material/Drawer';
import GridOnIcon from '@mui/icons-material/GridOn';
import PostAddIcon from '@mui/icons-material/PostAdd';
import MediationIcon from '@mui/icons-material/Mediation';
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
import HomeIcon from '@mui/icons-material/Home';
import EqualizerIcon from '@mui/icons-material/Equalizer';
Expand Down Expand Up @@ -57,6 +58,14 @@ const Sidebar = ({ p: polyglot, hasPublishedDataset }) => {
key="data-enrichment"
/>
),
matchDataRoute && (
<MenuItemLink
to="/data/precomputed"
primaryText={polyglot.t('precomputed')}
leftIcon={<MediationIcon />}
key="data-precomputed"
/>
),
matchDataRoute && hasPublishedDataset && (
<MenuItemLink
to="/data/removed"
Expand Down
4 changes: 2 additions & 2 deletions src/app/js/admin/enrichment/EnrichmentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export const EnrichmentForm = ({
};

// REDUX PART
const formSelector = formValueSelector('ENRICHMENT_FORM');
const formSelector = formValueSelector(ENRICHMENT_FORM);

const mapStateToProps = (state, { match }) => ({
formValues: formSelector(
Expand All @@ -572,7 +572,7 @@ const mapStateToProps = (state, { match }) => ({
});
const mapDispatchToProps = {
onChangeWebServiceUrl: value =>
change('ENRICHMENT_FORM', 'webServiceUrl', value),
change(ENRICHMENT_FORM, 'webServiceUrl', value),
onLaunchEnrichment: launchEnrichment,
onLoadEnrichments: loadEnrichments,
};
Expand Down
220 changes: 220 additions & 0 deletions src/app/js/admin/precomputed/EnrichmentCatalog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import translate from 'redux-polyglot/translate';
import compose from 'recompose/compose';
import { polyglot as polyglotPropTypes } from '../../propTypes';
import {
List,
ListItemText,
Dialog,
DialogContent,
DialogActions,
Button,
Typography,
Link,
ListItem,
Box,
Tooltip,
Grid,
} from '@mui/material';
import enrichers from '../../../custom/enrichers/enrichers-catalog.json';
import FilterIcon from '@mui/icons-material/FilterList';
import MenuBookIcon from '@mui/icons-material/MenuBook';
import SettingsEthernetIcon from '@mui/icons-material/SettingsEthernet';
import CancelButton from '../../lib/components/CancelButton';
import customTheme from '../../../custom/customTheme';

const styles = {
item: {
cursor: 'pointer',
'&:hover': {
backgroundColor: customTheme.palette.neutralDark.veryLight,
},
borderBottom: `1px solid ${customTheme.palette.neutralDark.light}`,
},
selectedItem: {
backgroundColor: customTheme.palette.primary.secondary,
'&:hover': {
backgroundColor: customTheme.palette.primary.main,
},
'& a': {
color: customTheme.palette.contrast.main,
},
},
};

const EnricherDescription = ({ enricher, polyglot }) => {
return (
<React.Fragment>
<Typography>
{polyglot.t(`ws_${enricher.id}_description`)}
</Typography>
<Box justifyContent="flex-end" display="flex">
{enricher.objectifTDM && (
<Tooltip title={polyglot.t(`tooltip_objectifTDM`)}>
<Link
href={enricher.objectifTDM}
target="_blank"
rel="noopener noreferrer"
style={{ marginRight: '1em' }}
onClick={e => e.stopPropagation()}
>
<MenuBookIcon />
</Link>
</Tooltip>
)}
{enricher.swagger && (
<Tooltip title={polyglot.t(`tooltip_swagger`)}>
<Link
href={enricher.swagger}
target="_blank"
rel="noopener noreferrer"
onClick={e => e.stopPropagation()}
>
<SettingsEthernetIcon />
</Link>
</Tooltip>
)}
</Box>
</React.Fragment>
);
};

export const EnrichmentCatalog = ({
p: polyglot,
isOpen,
handleClose,
onChange,
selectedWebServiceUrl,
}) => {
const filters = [
...new Set(enrichers.map(item => item.type)),
].sort((x, y) => polyglot.t(x).localeCompare(polyglot.t(y)));
filters.unshift('all');
filters.push(filters.splice(filters.indexOf('other'), 1)[0]);

const [filteredEnricher, setFilterEnricher] = useState(enrichers);
const [selectedFilter, setSelectedFilter] = useState('all');

useEffect(() => {
setFilterEnricher(
selectedFilter && selectedFilter !== 'all'
? enrichers.filter(item => item.type === selectedFilter)
: enrichers,
);
}, [selectedFilter]);

const handleValueChange = newValue => {
onChange(newValue);
handleClose();
};

const scrollTo = el => {
if (el) {
el.scrollIntoView({ inline: 'center', block: 'center' });
}
};

return (
<Dialog open={isOpen} onClose={handleClose} scroll="body" maxWidth="lg">
<DialogContent style={{ padding: 0, width: '1100px' }}>
<Grid
container={true}
direction="row"
style={{
width: '100%',
marginBottom: 25,
marginTop: 25,
padding: 10,
}}
justifyContent="space-around"
spacing={2}
>
<Box>
<FilterIcon
fontSize="large"
style={{ marginRight: 10 }}
/>
</Box>
{filters.map(filter => (
<Box key={filter}>
<Button
color="primary"
className="format-category"
onClick={() => setSelectedFilter(filter)}
variant={
filter === selectedFilter
? 'contained'
: 'outlined'
}
>
{polyglot.t(filter)}
</Button>
</Box>
))}
</Grid>
<List
component="nav"
aria-label="format list"
style={{ height: '70vh' }}
>
{filteredEnricher.map(enricher => (
<ListItem
key={enricher.id}
onClick={() => handleValueChange(enricher.url)}
sx={{
...styles.item,
...(selectedWebServiceUrl === enricher.url
? styles.selectedItem
: {}),
}}
ref={
selectedWebServiceUrl === enricher.url
? scrollTo
: null
}
>
<ListItemText
primary={polyglot.t(`ws_${enricher.id}_title`)}
primaryTypographyProps={{
style: { fontWeight: 'bold' },
}}
secondary={
<EnricherDescription
enricher={enricher}
polyglot={polyglot}
/>
}
/>
</ListItem>
))}
</List>
</DialogContent>
<DialogActions>
<CancelButton key="cancel" onClick={handleClose}>
{polyglot.t('cancel')}
</CancelButton>
</DialogActions>
</Dialog>
);
};

EnrichmentCatalog.propTypes = {
isOpen: PropTypes.bool.isRequired,
handleClose: PropTypes.func.isRequired,
p: polyglotPropTypes.isRequired,
onChange: PropTypes.func.isRequired,
selectedWebServiceUrl: PropTypes.string,
};

EnricherDescription.propTypes = {
enricher: PropTypes.shape({
id: PropTypes.string.isRequired,
doc: PropTypes.string,
swagger: PropTypes.string,
objectifTDM: PropTypes.string,
}).isRequired,
polyglot: polyglotPropTypes.isRequired,
};

export default compose(translate)(EnrichmentCatalog);
9 changes: 9 additions & 0 deletions src/app/js/admin/precomputed/EnrichmentContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

export const EnrichmentContext = React.createContext({
isEdit: false,
enrichment: null,
handleLaunchEnrichment: () => {},
handleDeleteEnrichment: () => {},
onLoadEnrichments: () => {},
});
Loading

0 comments on commit 18227cc

Please sign in to comment.