Skip to content

Commit fd6edf1

Browse files
Add tooltips to Workflow Actions to explain why they are disabled (#862)
Expand WorkflowActionsEnabledConfig to return an enum (enabled, ...list of disabled reasons) instead of a boolean Create WorkflowActionsRunnableStatus enum to similarly define if a workflow action can be run (if enabled in config) Change getIsRunnable in WorkflowActionsConfig to getRunnableStatus Add StatefulTooltip to disabled workflow action menu items, to show a disabled reason on hover
1 parent c054660 commit fd6edf1

15 files changed

+245
-52
lines changed

src/config/dynamic/resolvers/schemas/resolver-schemas.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { z } from 'zod';
22

33
import { type ResolverSchemas } from '../../../../utils/config/config.types';
4+
import WORKFLOW_ACTIONS_DISABLED_VALUES_CONFIG from '../workflow-actions-disabled-values.config';
5+
6+
const workflowActionsEnabledValueSchema = z.enum([
7+
'ENABLED',
8+
...WORKFLOW_ACTIONS_DISABLED_VALUES_CONFIG,
9+
]);
410

511
const resolverSchemas: ResolverSchemas = {
612
CLUSTERS: {
@@ -30,9 +36,9 @@ const resolverSchemas: ResolverSchemas = {
3036
domain: z.string(),
3137
}),
3238
returnType: z.object({
33-
cancel: z.boolean(),
34-
terminate: z.boolean(),
35-
restart: z.boolean(),
39+
cancel: workflowActionsEnabledValueSchema,
40+
terminate: workflowActionsEnabledValueSchema,
41+
restart: workflowActionsEnabledValueSchema,
3642
}),
3743
},
3844
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const WORKFLOW_ACTIONS_DISABLED_VALUES_CONFIG = [
2+
'DISABLED_DEFAULT',
3+
'DISABLED_UNAUTHORIZED',
4+
] as const satisfies Array<`DISABLED_${string}`>;
5+
6+
export default WORKFLOW_ACTIONS_DISABLED_VALUES_CONFIG;

src/config/dynamic/resolvers/workflow-actions-enabled.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export default async function workflowActionsEnabled(
1111
_: WorkflowActionsEnabledResolverParams
1212
): Promise<WorkflowActionsEnabledConfig> {
1313
return {
14-
terminate: true,
15-
cancel: true,
16-
restart: true,
14+
terminate: 'ENABLED',
15+
cancel: 'ENABLED',
16+
restart: 'ENABLED',
1717
};
1818
}
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
import { type WorkflowActionID } from '@/views/workflow-actions/workflow-actions.types';
1+
import type WORKFLOW_ACTIONS_DISABLED_VALUES_CONFIG from './workflow-actions-disabled-values.config';
2+
3+
export type WorkflowActionID = 'cancel' | 'terminate' | 'restart';
24

35
export type WorkflowActionsEnabledResolverParams = {
46
domain: string;
57
cluster: string;
68
};
79

8-
export type WorkflowActionsEnabledConfig = Record<WorkflowActionID, boolean>;
10+
export type WorkflowActionDisabledValue =
11+
(typeof WORKFLOW_ACTIONS_DISABLED_VALUES_CONFIG)[number];
12+
13+
export type WorkflowActionEnabledConfigValue =
14+
| 'ENABLED'
15+
| WorkflowActionDisabledValue;
16+
17+
export type WorkflowActionsEnabledConfig = Record<
18+
WorkflowActionID,
19+
WorkflowActionEnabledConfigValue
20+
>;

src/utils/config/__fixtures__/resolved-config-values.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const mockResolvedConfigValues: LoadedConfigResolvedValues = {
2828
},
2929
],
3030
WORKFLOW_ACTIONS_ENABLED: {
31-
terminate: true,
32-
cancel: true,
33-
restart: true,
31+
terminate: 'ENABLED',
32+
cancel: 'ENABLED',
33+
restart: 'ENABLED',
3434
},
3535
};
3636
export default mockResolvedConfigValues;

src/views/workflow-actions/__fixtures__/workflow-actions-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const mockWorkflowActionsConfig: [
2121
},
2222
},
2323
icon: MdHighlightOff,
24-
getIsRunnable: () => true,
24+
getRunnableStatus: () => 'RUNNABLE',
2525
apiRoute: 'cancel',
2626
renderSuccessMessage: () => 'Mock cancel notification',
2727
},
@@ -37,7 +37,7 @@ export const mockWorkflowActionsConfig: [
3737
},
3838
},
3939
icon: MdPowerSettingsNew,
40-
getIsRunnable: () => false,
40+
getRunnableStatus: () => 'RUNNABLE',
4141
apiRoute: 'terminate',
4242
renderSuccessMessage: () => 'Mock terminate notification',
4343
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { type WorkflowActionDisabledValue } from '@/config/dynamic/resolvers/workflow-actions-enabled.types';
2+
3+
const WORKFLOW_ACTIONS_DISABLED_REASONS_CONFIG = {
4+
DISABLED_DEFAULT: 'Workflow action has been disabled',
5+
DISABLED_UNAUTHORIZED: 'Not authorized to perform this action',
6+
} as const satisfies Record<WorkflowActionDisabledValue, string>;
7+
8+
export default WORKFLOW_ACTIONS_DISABLED_REASONS_CONFIG;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { type WorkflowActionNonRunnableStatus } from '../workflow-actions.types';
2+
3+
const WORKFLOW_ACTIONS_NON_RUNNABLE_REASONS_CONFIG = {
4+
NOT_RUNNABLE_WORKFLOW_CLOSED: 'Workflow is already closed',
5+
} as const satisfies Record<WorkflowActionNonRunnableStatus, string>;
6+
7+
export default WORKFLOW_ACTIONS_NON_RUNNABLE_REASONS_CONFIG;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const WORKFLOW_ACTIONS_NON_RUNNABLE_STATUSES_CONFIG = [
2+
'NOT_RUNNABLE_WORKFLOW_CLOSED',
3+
] as const satisfies Array<`NOT_RUNNABLE_${string}`>;
4+
5+
export default WORKFLOW_ACTIONS_NON_RUNNABLE_STATUSES_CONFIG;

src/views/workflow-actions/config/workflow-actions.config.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ const workflowActionsConfig: [
3131
},
3232
},
3333
icon: MdHighlightOff,
34-
getIsRunnable: (workflow) =>
35-
!getWorkflowIsCompleted(
34+
getRunnableStatus: (workflow) =>
35+
getWorkflowIsCompleted(
3636
workflow.workflowExecutionInfo?.closeEvent?.attributes ?? ''
37-
),
37+
)
38+
? 'NOT_RUNNABLE_WORKFLOW_CLOSED'
39+
: 'RUNNABLE',
3840
apiRoute: 'cancel',
3941
renderSuccessMessage: () => 'Workflow cancellation has been requested.',
4042
},
@@ -50,10 +52,12 @@ const workflowActionsConfig: [
5052
},
5153
},
5254
icon: MdPowerSettingsNew,
53-
getIsRunnable: (workflow) =>
54-
!getWorkflowIsCompleted(
55+
getRunnableStatus: (workflow) =>
56+
getWorkflowIsCompleted(
5557
workflow.workflowExecutionInfo?.closeEvent?.attributes ?? ''
56-
),
58+
)
59+
? 'NOT_RUNNABLE_WORKFLOW_CLOSED'
60+
: 'RUNNABLE',
5761
apiRoute: 'terminate',
5862
renderSuccessMessage: () => 'Workflow has been terminated.',
5963
},
@@ -68,7 +72,7 @@ const workflowActionsConfig: [
6872
],
6973
},
7074
icon: MdOutlineRestartAlt,
71-
getIsRunnable: () => true,
75+
getRunnableStatus: () => 'RUNNABLE',
7276
apiRoute: 'restart',
7377
renderSuccessMessage: (props) =>
7478
createElement(WorkflowActionRestartSuccessMsg, props),

0 commit comments

Comments
 (0)