Skip to content

Commit

Permalink
Merge pull request #1791 from Inist-CNRS/feat/enrichment-quick-launch
Browse files Browse the repository at this point in the history
Feat(enrichment): Add run button to List
  • Loading branch information
arimet authored Nov 22, 2023
2 parents cd99a9d + 695b37b commit 8b5d477
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 18 deletions.
41 changes: 26 additions & 15 deletions src/app/js/admin/enrichment/EnrichmentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ export const renderStatus = (status, polyglot) => {
);
};

export const renderRunButton = (
handleLaunchEnrichment,
enrichmentStatus,
polyglot,
variant,
) => (
<Button
color="primary"
variant={variant || 'contained'}
sx={{ height: '100%' }}
startIcon={<PlayArrowIcon />}
onClick={handleLaunchEnrichment}
disabled={
enrichmentStatus === IN_PROGRESS || enrichmentStatus === PENDING
}
>
{polyglot.t('run')}
</Button>
);

// COMPONENT PART
export const EnrichmentForm = ({
datasetFields,
Expand Down Expand Up @@ -349,21 +369,12 @@ export const EnrichmentForm = ({
component={renderTextField}
label={polyglot.t('fieldName')}
/>
{isEditMode && (
<Button
color="primary"
variant="contained"
sx={{ height: '100%' }}
startIcon={<PlayArrowIcon />}
onClick={handleLaunchEnrichment}
disabled={
enrichmentStatus === IN_PROGRESS ||
enrichmentStatus === PENDING
}
>
{polyglot.t('run')}
</Button>
)}
{isEditMode &&
renderRunButton(
handleLaunchEnrichment,
enrichmentStatus,
polyglot,
)}
</Box>
{isEditMode && (
<Box
Expand Down
45 changes: 42 additions & 3 deletions src/app/js/admin/enrichment/EnrichmentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,37 @@ import {
import { Link } from 'react-router-dom';
import { useHistory } from 'react-router';
import { polyglot as polyglotPropTypes } from '../../propTypes';
import { renderStatus } from './EnrichmentForm';
import { renderRunButton, renderStatus } from './EnrichmentForm';
import { FINISHED, IN_PROGRESS } from '../../../../common/taskStatus';
import { launchEnrichment } from '.';
import { toast } from '../../../../common/tools/toast';

export const EnrichmentList = ({ enrichments, p: polyglot }) => {
export const EnrichmentList = ({
enrichments,
p: polyglot,
onLaunchEnrichment,
}) => {
const history = useHistory();
const isEnrichingRunning = enrichments.some(
enrichment => enrichment.status === IN_PROGRESS,
);
const handleRowClick = params => {
history.push(`/data/enrichment/${params.row._id}`);
};

const handleLaunchPrecomputed = params => event => {
event.stopPropagation();
if (isEnrichingRunning) {
toast(polyglot.t('pending_enrichment'), {
type: toast.TYPE.INFO,
});
}
onLaunchEnrichment({
id: params._id,
action: params.status === FINISHED ? 'relaunch' : 'launch',
});
};

const CustomToolbar = () => {
return (
<GridToolbarContainer>
Expand Down Expand Up @@ -95,6 +118,19 @@ export const EnrichmentList = ({ enrichments, p: polyglot }) => {
renderCell: params =>
renderStatus(params.value, polyglot),
},
{
field: 'run',
headerName: polyglot.t('run'),
flex: 1,
renderCell: params => {
return renderRunButton(
handleLaunchPrecomputed(params.row),
params.row.status,
polyglot,
'text',
);
},
},
]}
rows={enrichments}
getRowId={row => row._id}
Expand All @@ -117,13 +153,16 @@ export const EnrichmentList = ({ enrichments, p: polyglot }) => {
EnrichmentList.propTypes = {
enrichments: PropTypes.array.isRequired,
p: polyglotPropTypes.isRequired,
onLaunchEnrichment: PropTypes.func.isRequired,
};

const mapStateToProps = state => ({
enrichments: state.enrichment.enrichments,
});

const mapDispatchToProps = {};
const mapDispatchToProps = {
onLaunchEnrichment: launchEnrichment,
};

export default compose(
translate,
Expand Down

0 comments on commit 8b5d477

Please sign in to comment.