Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit ddb58ae

Browse files
authored
feat: generate config on lifecycle events (#244)
1 parent 2b964b6 commit ddb58ae

3 files changed

Lines changed: 47 additions & 17 deletions

File tree

src/components/menus/definitions/InspectorDefinitionMenu.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ const getDependencies = (
6464
*/
6565
const InspectorDefinitionMenu = (props: InspectorDefinitionProps) => {
6666
const definitions = useStoreState((state) => state.definitions);
67-
const generateConfig = useStoreActions((actions) => actions.generateConfig);
6867
const navigateBack = useStoreActions((actions) => actions.navigateBack);
6968
const setGuideStep = useStoreActions((actions) => actions.setGuideStep);
7069
const guideStep = useStoreState((state) => state.guideStep);
@@ -195,7 +194,6 @@ const InspectorDefinitionMenu = (props: InspectorDefinitionProps) => {
195194
}
196195
},
197196
});
198-
generateConfig();
199197
}}
200198
>
201199
{(formikProps) => (

src/state/DefinitionStore.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Action,
66
action,
77
ActionCreator,
8+
Actions,
89
TargetResolver,
910
ThunkOn,
1011
thunkOn,
@@ -473,6 +474,29 @@ export const createObservableThunks = <
473474
};
474475
};
475476

477+
export const generateLifeCycleMatrix = (actions: Actions<StoreActions>) => {
478+
const lifeCycles = ['define', 'update', 'cleanup'];
479+
const types: DefinitionType[] = [
480+
'parameters',
481+
'commands',
482+
'jobs',
483+
'executors',
484+
'workflows',
485+
];
486+
487+
const matrix: ActionCreator<any>[] = [];
488+
489+
lifeCycles.forEach((lifecycle) => {
490+
matrix.push(
491+
...types.map(
492+
(type) => actions[`${lifecycle}_${type}` as keyof AllDefinitionActions],
493+
),
494+
);
495+
});
496+
497+
return matrix;
498+
};
499+
476500
export const createDefinitionStore = (): AllDefinitionActions => {
477501
return {
478502
// actions - lifecycle for each definition

src/state/Store.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
DefinitionStore,
3737
DefinitionSubscriptions,
3838
DefinitionType,
39+
generateLifeCycleMatrix,
3940
NamedGenerable,
4041
} from './DefinitionStore';
4142

@@ -167,11 +168,11 @@ export type StoreActions = AllDefinitionActions & {
167168
updateConnecting: Action<
168169
StoreModel,
169170
| {
170-
ref?: MutableRefObject<any>;
171-
id: SetConnectionId;
172-
pos?: XYPosition;
173-
name?: string;
174-
}
171+
ref?: MutableRefObject<any>;
172+
id: SetConnectionId;
173+
pos?: XYPosition;
174+
name?: string;
175+
}
175176
| undefined
176177
>;
177178

@@ -200,7 +201,7 @@ export type StoreActions = AllDefinitionActions & {
200201
triggerToast: Action<StoreModel, ToastModel | undefined | void>;
201202
triggerConfirmation: Action<StoreModel, ConfirmationModalModel | undefined>;
202203
triggerConfigRefresh: ThunkOn<StoreActions, void>;
203-
204+
204205
updateTooltip: Action<StoreModel, InfoToolTip | undefined>;
205206
};
206207

@@ -257,12 +258,12 @@ const Actions: StoreActions = {
257258
payload.origin && root
258259
? root
259260
: {
260-
...curNav,
261-
props: {
262-
...curNav.props,
263-
values: payload.values,
261+
...curNav,
262+
props: {
263+
...curNav.props,
264+
values: payload.values,
265+
},
264266
},
265-
},
266267
};
267268
}),
268269

@@ -694,8 +695,8 @@ const Actions: StoreActions = {
694695
const parameterList =
695696
pipelineParameters.length > 0
696697
? new parameters.CustomParametersList<PipelineParameterLiteral>(
697-
pipelineParameters,
698-
)
698+
pipelineParameters,
699+
)
699700
: undefined;
700701

701702
const config = new Config(
@@ -723,12 +724,19 @@ const Actions: StoreActions = {
723724
state.toast = payload ?? undefined;
724725
}),
725726
// this is just to trigger the set toast action
726-
triggerToast: action((_, __) => { }),
727+
triggerToast: action((_, __) => {}),
727728
triggerConfirmation: action((state, payload) => {
728729
state.confirm = payload;
729730
}),
730731
triggerConfigRefresh: thunkOn(
731-
(actions) => actions.importOrb,
732+
(actions) => [
733+
actions.importOrb,
734+
...generateLifeCycleMatrix(actions),
735+
actions.addWorkflowElement,
736+
actions.setWorkflowElements,
737+
actions.removeWorkflowElement,
738+
actions.updateWorkflowElement,
739+
],
732740
(actions) => {
733741
actions.generateConfig();
734742
},

0 commit comments

Comments
 (0)