Skip to content

Commit

Permalink
fix(orchestrator): improve error handling for incorrect nextWorkflow …
Browse files Browse the repository at this point in the history
…IDs (#2288)

Improve error handling for incorrect nextWorkflow IDs

Fixes: FLPATH-1748
  • Loading branch information
mareklibra authored Oct 4, 2024
1 parent c8e4de6 commit 37fcd06
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 21 deletions.
51 changes: 40 additions & 11 deletions plugins/orchestrator/src/components/WorkflowDescriptionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { WorkflowOverviewDTO } from '@janus-idp/backstage-plugin-orchestrator-co

export type WorkflowDescriptionModalProps = {
workflow: WorkflowOverviewDTO;
workflowError?: {
itemId: string;
error: any;
};
runWorkflowLink: string;
open: boolean;
onClose?: () => void;
Expand All @@ -37,7 +41,13 @@ export const RefForwardingWorkflowDescriptionModal: ForwardRefRenderFunction<
ParentComponentRef,
WorkflowDescriptionModalProps
> = (props, forwardedRef): JSX.Element | null => {
const { workflow, open = false, onClose, runWorkflowLink } = props;
const {
workflow,
open = false,
onClose,
runWorkflowLink,
workflowError,
} = props;
const classes = useStyles();
const navigate = useNavigate();

Expand All @@ -47,6 +57,27 @@ export const RefForwardingWorkflowDescriptionModal: ForwardRefRenderFunction<
}
};

let content;
if (workflowError) {
content = (
<Box>
<p>
Failed to load details for the workflow ID:
{workflowError.itemId}
</p>
{workflowError.error.message && <p>{workflowError.error.message}</p>}
</Box>
);
} else if (workflow.description) {
content = <Box>{workflow.description}</Box>;
} else {
content = (
<Box>
<p>Are you sure you want to run this workflow?</p>
</Box>
);
}

return (
<Dialog
onClose={_ => onClose}
Expand All @@ -67,17 +98,15 @@ export const RefForwardingWorkflowDescriptionModal: ForwardRefRenderFunction<
</IconButton>
</Box>
</DialogTitle>
<DialogContent>
{workflow.description ? (
<Box>{workflow.description}</Box>
) : (
<Box>
<p>Are you sure you want to run this workflow?</p>
</Box>
)}
</DialogContent>

<DialogContent>{content}</DialogContent>
<DialogActions>
<Button onClick={handleRunWorkflow} color="primary" variant="contained">
<Button
onClick={handleRunWorkflow}
color="primary"
variant="contained"
disabled={!!workflowError}
>
Run workflow
</Button>
<Button onClick={onClose} color="primary" variant="outlined">
Expand Down
21 changes: 11 additions & 10 deletions plugins/orchestrator/src/components/WorkflowResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import { orchestratorApiRef } from '../api';
import { VALUE_UNAVAILABLE } from '../constants';
import { executeWorkflowRouteRef } from '../routes';
import { buildUrl } from '../utils/UrlUtils';
import { WorkflowDescriptionModal } from './WorkflowDescriptionModal';
import {
WorkflowDescriptionModal,
WorkflowDescriptionModalProps,
} from './WorkflowDescriptionModal';

const useStyles = makeStyles(theme => ({
outputGrid: {
Expand Down Expand Up @@ -126,6 +129,8 @@ const NextWorkflows = ({
const [currentWorkflow, setCurrentWorkflow] = React.useState(
{} as WorkflowOverviewDTO,
);
const [workflowError, setWorkflowError] =
React.useState<WorkflowDescriptionModalProps['workflowError']>();

const runWorkflowLink = React.useMemo(
() =>
Expand All @@ -145,16 +150,11 @@ const NextWorkflows = ({
if (itemId) {
orchestratorApi
.getWorkflowOverview(itemId)
.then(
workflow => {
setCurrentWorkflow(workflow.data);
},
error => {
throw new Error(error);
},
)
.then(workflow => {
setCurrentWorkflow(workflow.data);
})
.catch(error => {
throw new Error(error);
setWorkflowError({ itemId, error });
});
setCurrentOpenedWorkflowDescriptionModalID(itemId);
}
Expand Down Expand Up @@ -197,6 +197,7 @@ const NextWorkflows = ({
</AboutField>
<WorkflowDescriptionModal
workflow={currentWorkflow}
workflowError={workflowError}
runWorkflowLink={runWorkflowLink}
open={!!currentOpenedWorkflowDescriptionModalID}
onClose={closeWorkflowDescriptionModal}
Expand Down

0 comments on commit 37fcd06

Please sign in to comment.