Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(enrichment): Add run button to List #1791

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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