From 3ee805ceb5effc3d6ac4f320589d02aec3bd0391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20M=C3=BCller?= Date: Tue, 5 Jul 2022 15:14:25 +0200 Subject: [PATCH] Fixed undefined task input types access in NodeExecutionActions Issue occurred due to race condition while loading data, indentical fix applies as for #506 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nick Müller --- .../Tables/NodeExecutionActions.tsx | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/zapp/console/src/components/Executions/Tables/NodeExecutionActions.tsx b/packages/zapp/console/src/components/Executions/Tables/NodeExecutionActions.tsx index 62ef88c35..430f82704 100644 --- a/packages/zapp/console/src/components/Executions/Tables/NodeExecutionActions.tsx +++ b/packages/zapp/console/src/components/Executions/Tables/NodeExecutionActions.tsx @@ -3,7 +3,7 @@ import { NodeExecution } from 'models/Execution/types'; import * as React from 'react'; import InputsAndOutputsIcon from '@material-ui/icons/Tv'; import { RerunIcon } from '@flyteconsole/ui-atoms'; -import { Identifier, ResourceIdentifier, Variable } from 'models/Common/types'; +import { Identifier, ResourceIdentifier } from 'models/Common/types'; import { LaunchFormDialog } from 'components/Launch/LaunchForm/LaunchFormDialog'; import { getTask } from 'models/Task/api'; import { useNodeExecutionData } from 'components/hooks/useNodeExecution'; @@ -27,13 +27,12 @@ export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Elem const [nodeExecutionDetails, setNodeExecutionDetails] = React.useState< NodeExecutionDetails | undefined >(); - const [taskInputsTypes, setTaskInputsTypes] = React.useState< - Record | undefined - >(); + const [initialParameters, setInitialParameters] = React.useState< + TaskInitialLaunchParameters | undefined + >(undefined); const executionData = useNodeExecutionData(execution.id); - const literals = executionData.value.fullInputs?.literals; - const id = nodeExecutionDetails?.taskTemplate?.id as ResourceIdentifier; + const id = nodeExecutionDetails?.taskTemplate?.id; React.useEffect(() => { detailsContext.getNodeExecutionDetails(execution).then((res) => { @@ -42,11 +41,23 @@ export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Elem }); React.useEffect(() => { - const fetchTask = async () => { + if (!id) { + return; + } + + (async () => { const task = await getTask(id as Identifier); - setTaskInputsTypes(task.closure.compiledTask.template?.interface?.inputs?.variables); - }; - if (id) fetchTask(); + + const literals = executionData.value.fullInputs?.literals; + const taskInputsTypes = task.closure.compiledTask.template?.interface?.inputs?.variables; + + const tempInitialParameters: TaskInitialLaunchParameters = { + values: literals && taskInputsTypes && literalsToLiteralValueMap(literals, taskInputsTypes), + taskId: id as Identifier | undefined, + }; + + setInitialParameters(tempInitialParameters); + })(); }, [id]); // open the side panel for selected execution's detail @@ -63,14 +74,10 @@ export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Elem }; const renderRerunAction = () => { - if (!id) { + if (!id || !initialParameters) { return <>; } - const initialParameters: TaskInitialLaunchParameters = { - values: literals && taskInputsTypes && literalsToLiteralValueMap(literals, taskInputsTypes), - taskId: id as Identifier | undefined, - }; return ( <> @@ -79,7 +86,7 @@ export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Elem