-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rerun task action in execution page (#488)
* feat: task rerun done Signed-off-by: Eugene Jahn <[email protected]> * feat: fix initialParameters Signed-off-by: Eugene Jahn <[email protected]> * fix: remove a file Signed-off-by: Eugene Jahn <[email protected]> * feat: rerun task done Signed-off-by: Eugene Jahn <[email protected]> * feat: rerun fix literal type Signed-off-by: Eugene Jahn <[email protected]> * feat: small typo fixed Signed-off-by: Eugene Jahn <[email protected]> * feat: small typo fixed Signed-off-by: Eugene Jahn <[email protected]> * feat: fix test coverage Signed-off-by: Eugene Jahn <[email protected]>
- Loading branch information
1 parent
271cb65
commit 9c453eb
Showing
10 changed files
with
303 additions
and
3 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/composites/ui-atoms/src/Icons/RerunIcon/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from 'react'; | ||
|
||
interface IconProps { | ||
size?: number; | ||
className?: string; | ||
onClick?: () => void; | ||
} | ||
|
||
export const RerunIcon = (props: IconProps): JSX.Element => { | ||
const { size = 18, className, onClick } = props; | ||
return ( | ||
<svg | ||
className={className} | ||
width={size} | ||
height={size} | ||
viewBox="0 0 13 11" | ||
fill="none" | ||
onClick={onClick} | ||
> | ||
<path | ||
d="M4.8 1.4H8.8V0L12.6 2.2L8.8 4.4V3H4.8C3.04 3 1.6 4.44 1.6 6.2C1.6 7.96 3.04 9.4 4.8 9.4H8.8V11H4.8C2.16 11 0 8.84 0 6.2C0 3.56 2.16 1.4 4.8 1.4Z" | ||
fill="#666666" | ||
/> | ||
</svg> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { FlyteLogo } from './FlyteLogo'; | ||
export { InfoIcon } from './InfoIcon'; | ||
export { RerunIcon } from './RerunIcon'; |
70 changes: 70 additions & 0 deletions
70
packages/zapp/console/src/components/Executions/ExecutionDetails/ExecutionDetailsActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Button } from '@material-ui/core'; | ||
import * as React from 'react'; | ||
import { ResourceIdentifier, Identifier, Variable } from 'models/Common/types'; | ||
import { getTask } from 'models/Task/api'; | ||
import { LaunchFormDialog } from 'components/Launch/LaunchForm/LaunchFormDialog'; | ||
import { NodeExecutionIdentifier } from 'models/Execution/types'; | ||
import { useNodeExecutionData } from 'components/hooks/useNodeExecution'; | ||
import { literalsToLiteralValueMap } from 'components/Launch/LaunchForm/utils'; | ||
import { TaskInitialLaunchParameters } from 'components/Launch/LaunchForm/types'; | ||
import { NodeExecutionDetails } from '../types'; | ||
import t from './strings'; | ||
|
||
interface ExecutionDetailsActionsProps { | ||
className?: string; | ||
details: NodeExecutionDetails; | ||
nodeExecutionId: NodeExecutionIdentifier; | ||
} | ||
|
||
export const ExecutionDetailsActions = (props: ExecutionDetailsActionsProps): JSX.Element => { | ||
const { className, details, nodeExecutionId } = props; | ||
|
||
const [showLaunchForm, setShowLaunchForm] = React.useState<boolean>(false); | ||
const [taskInputsTypes, setTaskInputsTypes] = React.useState< | ||
Record<string, Variable> | undefined | ||
>(); | ||
|
||
const executionData = useNodeExecutionData(nodeExecutionId); | ||
|
||
const id = details.taskTemplate?.id as ResourceIdentifier | undefined; | ||
|
||
React.useEffect(() => { | ||
const fetchTask = async () => { | ||
const task = await getTask(id as Identifier); | ||
setTaskInputsTypes(task.closure.compiledTask.template?.interface?.inputs?.variables); | ||
}; | ||
if (id) fetchTask(); | ||
}, [id]); | ||
|
||
if (!id) { | ||
return <></>; | ||
} | ||
|
||
const literals = executionData.value.fullInputs?.literals; | ||
|
||
const initialParameters: TaskInitialLaunchParameters = { | ||
values: literals && taskInputsTypes && literalsToLiteralValueMap(literals, taskInputsTypes), | ||
taskId: id as Identifier | undefined, | ||
}; | ||
|
||
const rerunOnClick = (e: React.MouseEvent<HTMLElement>) => { | ||
e.stopPropagation(); | ||
setShowLaunchForm(true); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className={className}> | ||
<Button variant="outlined" color="primary" onClick={rerunOnClick}> | ||
{t('rerun')} | ||
</Button> | ||
</div> | ||
<LaunchFormDialog | ||
id={id} | ||
initialParameters={initialParameters} | ||
showLaunchForm={showLaunchForm} | ||
setShowLaunchForm={setShowLaunchForm} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/zapp/console/src/components/Executions/ExecutionDetails/strings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { createLocalizedString } from '@flyteconsole/locale'; | ||
|
||
const str = { | ||
rerun: 'RERUN', | ||
}; | ||
|
||
export { patternKey } from '@flyteconsole/locale'; | ||
export default createLocalizedString(str); |
101 changes: 101 additions & 0 deletions
101
packages/zapp/console/src/components/Executions/Tables/NodeExecutionActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { IconButton, Tooltip } from '@material-ui/core'; | ||
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 { LaunchFormDialog } from 'components/Launch/LaunchForm/LaunchFormDialog'; | ||
import { getTask } from 'models/Task/api'; | ||
import { useNodeExecutionData } from 'components/hooks/useNodeExecution'; | ||
import { TaskInitialLaunchParameters } from 'components/Launch/LaunchForm/types'; | ||
import { literalsToLiteralValueMap } from 'components/Launch/LaunchForm/utils'; | ||
import { NodeExecutionsTableState } from './types'; | ||
import { useNodeExecutionContext } from '../contextProvider/NodeExecutionDetails'; | ||
import { NodeExecutionDetails } from '../types'; | ||
import t from './strings'; | ||
|
||
interface NodeExecutionActionsProps { | ||
execution: NodeExecution; | ||
state: NodeExecutionsTableState; | ||
} | ||
|
||
export const NodeExecutionActions = (props: NodeExecutionActionsProps): JSX.Element => { | ||
const { execution, state } = props; | ||
|
||
const detailsContext = useNodeExecutionContext(); | ||
const [showLaunchForm, setShowLaunchForm] = React.useState<boolean>(false); | ||
const [nodeExecutionDetails, setNodeExecutionDetails] = React.useState< | ||
NodeExecutionDetails | undefined | ||
>(); | ||
const [taskInputsTypes, setTaskInputsTypes] = React.useState< | ||
Record<string, Variable> | undefined | ||
>(); | ||
|
||
const executionData = useNodeExecutionData(execution.id); | ||
const literals = executionData.value.fullInputs?.literals; | ||
const id = nodeExecutionDetails?.taskTemplate?.id as ResourceIdentifier; | ||
|
||
React.useEffect(() => { | ||
detailsContext.getNodeExecutionDetails(execution).then((res) => { | ||
setNodeExecutionDetails(res); | ||
}); | ||
}); | ||
|
||
React.useEffect(() => { | ||
const fetchTask = async () => { | ||
const task = await getTask(id as Identifier); | ||
setTaskInputsTypes(task.closure.compiledTask.template?.interface?.inputs?.variables); | ||
}; | ||
if (id) fetchTask(); | ||
}, [id]); | ||
|
||
// open the side panel for selected execution's detail | ||
const inputsAndOutputsIconOnClick = (e: React.MouseEvent<HTMLElement>) => { | ||
// prevent the parent row body onClick event trigger | ||
e.stopPropagation(); | ||
// use null in case if there is no execution provided - when it is null will close panel | ||
state.setSelectedExecution(execution?.id ?? null); | ||
}; | ||
|
||
const rerunIconOnClick = (e: React.MouseEvent<HTMLElement>) => { | ||
e.stopPropagation(); | ||
setShowLaunchForm(true); | ||
}; | ||
|
||
const renderRerunAction = () => { | ||
if (!id) { | ||
return <></>; | ||
} | ||
|
||
const initialParameters: TaskInitialLaunchParameters = { | ||
values: literals && taskInputsTypes && literalsToLiteralValueMap(literals, taskInputsTypes), | ||
taskId: id as Identifier | undefined, | ||
}; | ||
return ( | ||
<> | ||
<Tooltip title={t('rerunTooltip')}> | ||
<IconButton onClick={rerunIconOnClick}> | ||
<RerunIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
<LaunchFormDialog | ||
id={id} | ||
initialParameters={initialParameters} | ||
showLaunchForm={showLaunchForm} | ||
setShowLaunchForm={setShowLaunchForm} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Tooltip title={t('inputsAndOutputsTooltip')}> | ||
<IconButton onClick={inputsAndOutputsIconOnClick}> | ||
<InputsAndOutputsIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
{renderRerunAction()} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/zapp/console/src/components/Executions/Tables/strings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createLocalizedString } from '@flyteconsole/locale'; | ||
|
||
const str = { | ||
inputsAndOutputsTooltip: 'View Inputs & Outpus', | ||
rerunTooltip: 'Rerun', | ||
}; | ||
|
||
export { patternKey } from '@flyteconsole/locale'; | ||
export default createLocalizedString(str); |
51 changes: 51 additions & 0 deletions
51
packages/zapp/console/src/components/Launch/LaunchForm/LaunchFormDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Dialog } from '@material-ui/core'; | ||
import * as React from 'react'; | ||
import { LaunchForm } from 'components/Launch/LaunchForm/LaunchForm'; | ||
import { ResourceIdentifier, ResourceType } from 'models/Common/types'; | ||
import { | ||
TaskInitialLaunchParameters, | ||
WorkflowInitialLaunchParameters, | ||
} from 'components/Launch/LaunchForm/types'; | ||
|
||
interface LaunchFormDialogProps { | ||
id: ResourceIdentifier; | ||
initialParameters: TaskInitialLaunchParameters | WorkflowInitialLaunchParameters; | ||
showLaunchForm: boolean; | ||
setShowLaunchForm: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
function getLaunchProps(id: ResourceIdentifier) { | ||
if (id.resourceType === ResourceType.TASK) { | ||
return { taskId: id }; | ||
} else if (id.resourceType === ResourceType.WORKFLOW) { | ||
return { workflowId: id }; | ||
} | ||
throw new Error('Unknown Resource Type'); | ||
} | ||
|
||
export const LaunchFormDialog = (props: LaunchFormDialogProps): JSX.Element => { | ||
const { id, initialParameters, showLaunchForm, setShowLaunchForm } = props; | ||
|
||
const onCancelLaunch = () => setShowLaunchForm(false); | ||
|
||
// prevent child onclick event in the dialog triggers parent onclick event | ||
const dialogOnClick = (e: React.MouseEvent<HTMLElement>) => { | ||
e.stopPropagation(); | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
scroll="paper" | ||
maxWidth="sm" | ||
fullWidth={true} | ||
open={showLaunchForm} | ||
onClick={dialogOnClick} | ||
> | ||
<LaunchForm | ||
initialParameters={initialParameters} | ||
onClose={onCancelLaunch} | ||
{...getLaunchProps(id)} | ||
/> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters