Skip to content

Commit

Permalink
chore: comments
Browse files Browse the repository at this point in the history
Signed-off-by: Carina Ursu <[email protected]>
  • Loading branch information
ursucarina committed Apr 11, 2022
1 parent 6b0839f commit c6f0d53
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/components/Project/test/ProjectWorkflows.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ describe('ProjectWorkflows', () => {
await waitFor(() => expect(getByText('MyWorkflow')));
fireEvent.click(checkboxes[0]);
// when user selects checkbox, table should have no workflows to display
await waitFor(() => expect(queryByText('MyWorkflow')).toBeNull());
await waitFor(() => expect(queryByText('MyWorkflow')).not.toBeInTheDocument());
});
});
178 changes: 87 additions & 91 deletions src/components/Workflow/SearchableWorkflowNameList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ const useStyles = makeStyles((theme: Theme) => ({
alignItems: 'center',
marginRight: 24,
},
confirmationBox: {
height: '100%',
[`& > button`]: {
height: '100%',
},
},
confirmationButton: {
borderRadius: 0,
minWidth: '100px',
Expand Down Expand Up @@ -170,97 +164,99 @@ const padExecutionPaths = (items: WorkflowExecutionIdentifier[]) => {
const getArchiveIcon = (isArchived: boolean) =>
isArchived ? <UnarchiveOutline /> : <ArchiveOutlined />;

const SearchableWorkflowNameItemActions: React.FC<SearchableWorkflowNameItemActionsProps> =
React.memo(({ item, setHideItem }) => {
const styles = useStyles();
const { enqueueSnackbar } = useSnackbar();
const { id } = item;
const isArchived = isWorkflowArchived(item);
const [isUpdating, setIsUpdating] = useState<boolean>(false);
const [showConfirmation, setShowConfirmation] = useState<boolean>(false);
const SearchableWorkflowNameItemActions: React.FC<SearchableWorkflowNameItemActionsProps> = ({
item,
setHideItem,
}) => {
const styles = useStyles();
const { enqueueSnackbar } = useSnackbar();
const { id } = item;
const isArchived = isWorkflowArchived(item);
const [isUpdating, setIsUpdating] = useState<boolean>(false);
const [showConfirmation, setShowConfirmation] = useState<boolean>(false);

const mutation = useMutation(
(newState: WorkflowExecutionState) => updateWorkflowState(id, newState),
{
onMutate: () => setIsUpdating(true),
onSuccess: () => {
enqueueSnackbar(t('archiveSuccess', !isArchived), {
variant: 'success',
});
setHideItem(true);
},
onError: () => {
enqueueSnackbar(`${mutation.error ?? t('archiveError', !isArchived)}`, {
variant: 'error',
});
},
onSettled: () => {
setShowConfirmation(false);
setIsUpdating(false);
},
const mutation = useMutation(
(newState: WorkflowExecutionState) => updateWorkflowState(id, newState),
{
onMutate: () => setIsUpdating(true),
onSuccess: () => {
enqueueSnackbar(t('archiveSuccess', !isArchived), {
variant: 'success',
});
setHideItem(true);
},
);
onError: () => {
enqueueSnackbar(`${mutation.error ?? t('archiveError', !isArchived)}`, {
variant: 'error',
});
},
onSettled: () => {
setShowConfirmation(false);
setIsUpdating(false);
},
},
);

const onArchiveClick = (event: React.MouseEvent) => {
event.stopPropagation();
event.preventDefault();
setShowConfirmation(true);
};
const onArchiveClick = (event: React.MouseEvent) => {
event.stopPropagation();
event.preventDefault();
setShowConfirmation(true);
};

const onConfirmArchiveClick = (event: React.MouseEvent) => {
event.stopPropagation();
event.preventDefault();
mutation.mutate(
isWorkflowArchived(item)
? WorkflowExecutionState.NAMED_ENTITY_ACTIVE
: WorkflowExecutionState.NAMED_ENTITY_ARCHIVED,
);
};
const onConfirmArchiveClick = (event: React.MouseEvent) => {
event.stopPropagation();
event.preventDefault();
mutation.mutate(
isWorkflowArchived(item)
? WorkflowExecutionState.NAMED_ENTITY_ACTIVE
: WorkflowExecutionState.NAMED_ENTITY_ARCHIVED,
);
};

const onCancelClick = (event: React.MouseEvent) => {
event.stopPropagation();
event.preventDefault();
setShowConfirmation(false);
};
const onCancelClick = (event: React.MouseEvent) => {
event.stopPropagation();
event.preventDefault();
setShowConfirmation(false);
};

const singleItemStyle = isUpdating || !showConfirmation ? styles.centeredChild : '';
return (
<div className={classNames(styles.actionContainer, showOnHoverClass, singleItemStyle)}>
{isUpdating ? (
<IconButton size="small">
<CircularProgress size={24} />
</IconButton>
) : showConfirmation ? (
<div className={styles.confirmationBox}>
<Button
size="medium"
variant="contained"
color="primary"
className={styles.confirmationButton}
disableElevation
onClick={onConfirmArchiveClick}
>
{t('archiveAction', isArchived)}
</Button>
<Button
size="medium"
variant="contained"
color="inherit"
className={styles.confirmationButton}
disableElevation
onClick={onCancelClick}
>
{t('cancelAction')}
</Button>
</div>
) : (
<IconButton size="small" title={t('archiveAction', isArchived)} onClick={onArchiveClick}>
{getArchiveIcon(isArchived)}
</IconButton>
)}
</div>
);
});
const singleItemStyle = isUpdating || !showConfirmation ? styles.centeredChild : '';
return (
<div className={classNames(styles.actionContainer, showOnHoverClass, singleItemStyle)}>
{isUpdating ? (
<IconButton size="small">
<CircularProgress size={24} />
</IconButton>
) : showConfirmation ? (
<>
<Button
size="medium"
variant="contained"
color="primary"
className={styles.confirmationButton}
disableElevation
onClick={onConfirmArchiveClick}
>
{t('archiveAction', isArchived)}
</Button>
<Button
size="medium"
variant="contained"
color="inherit"
className={styles.confirmationButton}
disableElevation
onClick={onCancelClick}
>
{t('cancelAction')}
</Button>
</>
) : (
<IconButton size="small" title={t('archiveAction', isArchived)} onClick={onArchiveClick}>
{getArchiveIcon(isArchived)}
</IconButton>
)}
</div>
);
};

/**
* Renders individual searchable workflow item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ interface ArchiveFilterState {
export function useWorkflowShowArchivedState(): ArchiveFilterState {
const [showArchived, setShowArchived] = useState(false);

// By default all values are returned with NAMED_ENTITY_ACTIVE state,
// so filter need to be applied only for ARCHIVED executions
// By default all values are returned with NAMED_ENTITY_ACTIVE state
const getFilter = (): FilterOperation => {
return {
key: 'state',
Expand Down
1 change: 1 addition & 0 deletions src/components/Workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function isWorkflowStateArchive(workflow: WorkflowListStructureItem): boolean {
const state = workflow?.state ?? null;
return !!state && state === WorkflowExecutionState.NAMED_ENTITY_ARCHIVED;
}

export function isWorkflowArchived(workflow: WorkflowListStructureItem): boolean {
return isWorkflowStateArchive(workflow);
}

0 comments on commit c6f0d53

Please sign in to comment.