Skip to content

Commit 4bd9869

Browse files
authored
Allow Create LIR prefixes workflow to start with pre-filled variables (#1640)
* Allow Create LIR prefixes workflow to start with pre-filled variables * Changed order of if-else block
1 parent e345617 commit 4bd9869

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed

.changeset/curly-squids-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@orchestrator-ui/orchestrator-ui-components': patch
3+
---
4+
5+
1146 Allow workflow to start with additional prefilled variables - LIR prefixes page

packages/orchestrator-ui-components/src/components/WfoForms/UserInputForm.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import React, { useContext, useState } from 'react';
1818

1919
import invariant from 'invariant';
2020
import { JSONSchema6 } from 'json-schema';
21+
import { isObject } from 'lodash';
2122
import cloneDeep from 'lodash/cloneDeep';
2223
import get from 'lodash/get';
2324
import { useTranslations } from 'next-intl';
@@ -393,17 +394,30 @@ function fillPreselection(form: JSONSchema6, router: NextRouter) {
393394
// ipvany preselect
394395
if (queryParams.prefix && queryParams.prefixlen) {
395396
if (form && form.properties.ip_prefix) {
396-
const ipPrefixInput = form.properties
397-
.ip_prefix as UniformJSONSchemaProperty;
397+
const ipPrefix = isObject(form.properties.ip_prefix)
398+
? form.properties.ip_prefix
399+
: {};
400+
const ipPrefixInput = {
401+
...ipPrefix,
402+
uniforms: { prefixMin: 0 },
403+
default: {},
404+
} as UniformJSONSchemaProperty;
398405
if (!ipPrefixInput.uniforms) {
399-
ipPrefixInput.uniforms = {};
406+
ipPrefixInput.uniforms = { prefixMin: 0 };
400407
}
401408
ipPrefixInput.default = `${queryParams.prefix}/${queryParams.prefixlen}`;
402409
ipPrefixInput.uniforms.prefixMin = parseInt(
403410
(queryParams.prefix_min as string) ??
404411
(queryParams.prefixlen as string),
405412
10,
406413
);
414+
return {
415+
...form,
416+
properties: {
417+
...form.properties,
418+
ip_prefix: ipPrefixInput,
419+
},
420+
};
407421
}
408422
}
409423
}

packages/orchestrator-ui-components/src/pages/processes/WfoStartProcessPage.tsx

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ import { FormNotCompleteResponse } from '@/types/forms';
3535

3636
import { WfoProcessDetail } from './WfoProcessDetail';
3737

38+
type PreselectedInput = {
39+
prefix?: string;
40+
prefixlen?: string;
41+
prefix_min?: string;
42+
};
43+
3844
type StartCreateWorkflowPayload = {
3945
product: string;
40-
};
46+
} & PreselectedInput;
47+
4148
type StartModifyWorkflowPayload = {
4249
subscription_id: string;
4350
};
@@ -46,10 +53,10 @@ type StartWorkflowPayload =
4653
| StartCreateWorkflowPayload
4754
| StartModifyWorkflowPayload;
4855

49-
interface StartProcessPageQuery {
56+
type StartProcessPageQuery = {
5057
productId?: string;
5158
subscriptionId?: string;
52-
}
59+
} & PreselectedInput;
5360

5461
interface WfoStartProcessPageProps {
5562
processName: string;
@@ -64,15 +71,24 @@ export interface UserInputForm {
6471
const getInitialProcessPayload = ({
6572
productId,
6673
subscriptionId,
74+
prefix,
75+
prefixlen,
76+
prefix_min,
6777
}: StartProcessPageQuery): StartWorkflowPayload | undefined => {
68-
if (productId) {
78+
if (subscriptionId) {
79+
return {
80+
subscription_id: subscriptionId,
81+
};
82+
} else if (productId && prefix && prefixlen && prefix_min) {
6983
return {
7084
product: productId,
85+
prefix: prefix,
86+
prefixlen: prefixlen,
87+
prefix_min: prefix_min,
7188
};
72-
}
73-
if (subscriptionId) {
89+
} else if (productId) {
7490
return {
75-
subscription_id: subscriptionId,
91+
product: productId,
7692
};
7793
}
7894
return undefined;
@@ -87,7 +103,8 @@ export const WfoStartProcessPage = ({
87103
const [hasError, setHasError] = useState<boolean>(false);
88104
const { theme } = useOrchestratorTheme();
89105
const [form, setForm] = useState<UserInputForm>({});
90-
const { productId, subscriptionId } = router.query as StartProcessPageQuery;
106+
const { productId, subscriptionId, prefix, prefixlen, prefix_min } =
107+
router.query as StartProcessPageQuery;
91108

92109
const {
93110
data: subscriptionDetail,
@@ -108,8 +125,15 @@ export const WfoStartProcessPage = ({
108125
const [startProcess] = useStartProcessMutation();
109126

110127
const startProcessPayload = useMemo(
111-
() => getInitialProcessPayload({ productId, subscriptionId }),
112-
[productId, subscriptionId],
128+
() =>
129+
getInitialProcessPayload({
130+
productId,
131+
subscriptionId,
132+
prefix,
133+
prefixlen,
134+
prefix_min,
135+
}),
136+
[productId, subscriptionId, prefix, prefixlen, prefix_min],
113137
);
114138

115139
const { stepUserInput, hasNext } = form;

0 commit comments

Comments
 (0)