@orchestrator-ui/orchestrator-ui-components 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orchestrator-ui/orchestrator-ui-components",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Library of UI Components used to display the workflow orchestrator frontend",
6
6
  "author": {
@@ -16,7 +16,7 @@ import React, { useCallback, useEffect, useState } from 'react';
16
16
 
17
17
  import { Form, FormNotCompleteResponse } from '@/types/forms';
18
18
 
19
- import UserInputFormWizard from './UserInputFormWizard';
19
+ import UserInputFormWizardDeprecated from './UserInputFormWizardDeprecated';
20
20
  import { useAxiosApiClient } from './useAxiosApiClient';
21
21
 
22
22
  interface IProps {
@@ -60,7 +60,7 @@ export function CreateForm(props: IProps) {
60
60
  return (
61
61
  <div>
62
62
  {stepUserInput && (
63
- <UserInputFormWizard
63
+ <UserInputFormWizardDeprecated
64
64
  stepUserInput={stepUserInput}
65
65
  validSubmit={submit}
66
66
  cancel={handleCancel}
@@ -18,10 +18,10 @@ import { useRouter } from 'next/router';
18
18
  import hash from 'object-hash';
19
19
 
20
20
  import { ConfirmDialogActions } from '@/contexts';
21
+ import { HttpStatus, handlePromiseErrorWithCallback } from '@/rtk';
21
22
  import { FormNotCompleteResponse, InputForm } from '@/types/forms';
22
23
 
23
24
  import UserInputForm from './UserInputForm';
24
- import { useAxiosApiClient } from './useAxiosApiClient';
25
25
 
26
26
  interface Form {
27
27
  form: InputForm;
@@ -30,7 +30,7 @@ interface Form {
30
30
 
31
31
  interface UserInputFormWizardProps {
32
32
  stepUserInput: InputForm;
33
- validSubmit: (processInput: object[]) => Promise<unknown>;
33
+ stepSubmit: (processInput: object[]) => Promise<unknown>;
34
34
  cancel?: () => void;
35
35
  isTask: boolean;
36
36
  hasNext?: boolean;
@@ -47,13 +47,12 @@ function stop(e: React.SyntheticEvent) {
47
47
  export function UserInputFormWizard({
48
48
  hasNext = false,
49
49
  stepUserInput,
50
- validSubmit,
50
+ stepSubmit,
51
51
  cancel,
52
52
  isTask,
53
53
  isResuming = false,
54
54
  }: UserInputFormWizardProps) {
55
55
  const router = useRouter();
56
- const apiClient = useAxiosApiClient();
57
56
  const [forms, setForms] = useState<Form[]>([
58
57
  { form: stepUserInput, hasNext: hasNext },
59
58
  ]);
@@ -75,20 +74,17 @@ export function UserInputFormWizard({
75
74
  const newUserInputs = userInputs.slice(0, forms.length - 1);
76
75
  newUserInputs.push(currentFormData);
77
76
 
78
- const result = validSubmit(newUserInputs);
79
- return apiClient.catchErrorStatus<FormNotCompleteResponse>(
80
- result,
81
- 510,
82
- (json) => {
83
- // Scroll to top when navigating to next screen of wizard
84
- window.scrollTo(0, 0);
85
- // setFlash(intl.formatMessage({ id: "process.flash.wizard_next_step" }));
86
- setForms([
87
- ...forms,
88
- { form: json.form, hasNext: json.hasNext },
89
- ]);
90
- setUserInputs(newUserInputs);
91
- },
77
+ const promise = stepSubmit(newUserInputs);
78
+ const callback = (data: FormNotCompleteResponse) => {
79
+ window.scrollTo(0, 0);
80
+ setForms([...forms, { form: data.form, hasNext: data.hasNext }]);
81
+ setUserInputs(newUserInputs);
82
+ };
83
+
84
+ return handlePromiseErrorWithCallback<FormNotCompleteResponse>(
85
+ promise,
86
+ HttpStatus.FormNotComplete,
87
+ callback,
92
88
  );
93
89
  };
94
90
 
@@ -0,0 +1,125 @@
1
+ /*
2
+ * Copyright 2019-2023 SURF.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software
9
+ * distributed under the License is distributed on an "AS IS" BASIS,
10
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the License for the specific language governing permissions and
12
+ * limitations under the License.
13
+ *
14
+ */
15
+ import React, { useEffect, useState } from 'react';
16
+
17
+ import { useRouter } from 'next/router';
18
+ import hash from 'object-hash';
19
+
20
+ import { ConfirmDialogActions } from '@/contexts';
21
+ import { FormNotCompleteResponse, InputForm } from '@/types/forms';
22
+
23
+ import UserInputForm from './UserInputForm';
24
+ import { useAxiosApiClient } from './useAxiosApiClient';
25
+
26
+ interface Form {
27
+ form: InputForm;
28
+ hasNext?: boolean;
29
+ }
30
+
31
+ interface UserInputFormWizardProps {
32
+ stepUserInput: InputForm;
33
+ validSubmit: (processInput: object[]) => Promise<unknown>;
34
+ cancel?: () => void;
35
+ isTask: boolean;
36
+ hasNext?: boolean;
37
+ isResuming?: boolean;
38
+ }
39
+
40
+ function stop(e: React.SyntheticEvent) {
41
+ if (e !== undefined && e !== null) {
42
+ e.preventDefault();
43
+ e.stopPropagation();
44
+ }
45
+ }
46
+
47
+ export function UserInputFormWizardDeprecated({
48
+ hasNext = false,
49
+ stepUserInput,
50
+ validSubmit,
51
+ cancel,
52
+ isTask,
53
+ isResuming = false,
54
+ }: UserInputFormWizardProps) {
55
+ const router = useRouter();
56
+ const apiClient = useAxiosApiClient();
57
+ const [forms, setForms] = useState<Form[]>([
58
+ { form: stepUserInput, hasNext: hasNext },
59
+ ]);
60
+ const [userInputs, setUserInputs] = useState<object[]>([]);
61
+
62
+ useEffect(() => {
63
+ setForms([{ form: stepUserInput, hasNext: hasNext }]);
64
+ }, [hasNext, stepUserInput]);
65
+
66
+ const previous: ConfirmDialogActions['closeConfirmDialog'] = (e) => {
67
+ if (e) {
68
+ stop(e);
69
+ }
70
+ const current = forms.pop();
71
+ setForms(forms.filter((item) => item !== current));
72
+ };
73
+
74
+ const submit = (currentFormData: object) => {
75
+ const newUserInputs = userInputs.slice(0, forms.length - 1);
76
+ newUserInputs.push(currentFormData);
77
+
78
+ const result = validSubmit(newUserInputs);
79
+ return apiClient.catchErrorStatus<FormNotCompleteResponse>(
80
+ result,
81
+ 510,
82
+ (json) => {
83
+ window.scrollTo(0, 0);
84
+ setForms([
85
+ ...forms,
86
+ { form: json.form, hasNext: json.hasNext },
87
+ ]);
88
+ setUserInputs(newUserInputs);
89
+ },
90
+ );
91
+ };
92
+
93
+ const currentForm = forms[forms.length - 1];
94
+ const currentUserInput = userInputs[forms.length - 1];
95
+ if (!currentForm || !currentForm.form.properties) {
96
+ return null;
97
+ }
98
+
99
+ /* Generate a key based on input widget names that results in a new
100
+ * clean instance + rerender of UserInputForm if the form changes. Without this, state of previous,
101
+ * wizard step can cause wrong/weird default values for forms inputs.
102
+ *
103
+ * Note: to ensure a new form for multiple form wizard steps with exactly the same fields and labels on
104
+ * the form the hash is calculated on the form object itself + length, which generates a unique hash as it
105
+ * has a changing ".length" attribute.
106
+ * */
107
+ const key = hash.sha1({ form: currentForm.form, length: forms.length });
108
+ return (
109
+ <UserInputForm
110
+ key={key}
111
+ router={router}
112
+ stepUserInput={currentForm.form}
113
+ validSubmit={submit}
114
+ previous={previous}
115
+ hasNext={currentForm.hasNext}
116
+ hasPrev={forms.length > 1}
117
+ cancel={cancel}
118
+ userInput={currentUserInput}
119
+ isTask={isTask}
120
+ isResuming={isResuming}
121
+ />
122
+ );
123
+ }
124
+
125
+ export default UserInputFormWizardDeprecated;
@@ -1,5 +1,6 @@
1
1
  export * from './AutoFields';
2
2
  export * from './UserInputForm';
3
3
  export * from './UserInputFormWizard';
4
+ export * from './UserInputFormWizardDeprecated';
4
5
  export * from './formFields';
5
6
  export * from './CreateForm';
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
2
2
 
3
3
  import { EuiFlexItem } from '@elastic/eui';
4
4
 
5
- import { UserInputFormWizard, WfoLoading } from '@/components';
5
+ import { UserInputFormWizardDeprecated, WfoLoading } from '@/components';
6
6
  import { useAxiosApiClient } from '@/components/WfoForms/useAxiosApiClient';
7
7
  import { useOrchestratorTheme } from '@/hooks';
8
8
  import { InputForm } from '@/types/forms';
@@ -35,7 +35,7 @@ export const WfoStepForm = ({
35
35
  return (
36
36
  <EuiFlexItem css={{ margin: theme.size.m }}>
37
37
  {(isProcessing && <WfoLoading />) || (
38
- <UserInputFormWizard
38
+ <UserInputFormWizardDeprecated
39
39
  stepUserInput={userInputForm}
40
40
  validSubmit={submitForm}
41
41
  hasNext={false}
@@ -42,6 +42,10 @@ export const filterDataByCriteria = <Type>(
42
42
  });
43
43
  };
44
44
 
45
+ /**
46
+ * @deprecated
47
+ * Currently not in use in the SURF app - switched to RTK Query
48
+ */
45
49
  export const useFilterQueryWithRest = <Type>(
46
50
  url: string,
47
51
  queryKey: string[],
@@ -28,7 +28,7 @@ import {
28
28
  } from '@/types';
29
29
  import { FormNotCompleteResponse } from '@/types/forms';
30
30
 
31
- import UserInputFormWizard from '../../components/WfoForms/UserInputFormWizard';
31
+ import UserInputFormWizardDeprecated from '../../components/WfoForms/UserInputFormWizardDeprecated';
32
32
  import { WfoProcessDetail } from './WfoProcessDetail';
33
33
 
34
34
  type StartCreateWorkflowPayload = {
@@ -215,7 +215,7 @@ export const WfoStartProcessPage = ({
215
215
  <EuiHorizontalRule />
216
216
  {(hasError && <WfoError />) ||
217
217
  (stepUserInput && (
218
- <UserInputFormWizard
218
+ <UserInputFormWizardDeprecated
219
219
  stepUserInput={stepUserInput}
220
220
  validSubmit={submit}
221
221
  cancel={() =>
package/src/rtk/api.ts CHANGED
@@ -21,6 +21,12 @@ export enum CacheTags {
21
21
  subscriptionList = 'subscriptionList',
22
22
  }
23
23
 
24
+ export enum HttpStatus {
25
+ FormNotComplete = 510,
26
+ BadGateway = 502,
27
+ BadRequest = 400,
28
+ }
29
+
24
30
  type ExtraOptions = {
25
31
  baseQueryType?: BaseQueryTypes;
26
32
  apiName?: string;
@@ -34,6 +40,20 @@ export const prepareHeaders = async (headers: Headers) => {
34
40
  return headers;
35
41
  };
36
42
 
43
+ export const handlePromiseErrorWithCallback = <T>(
44
+ promise: Promise<unknown>,
45
+ status: number,
46
+ callbackAction: (json: T) => void,
47
+ ) => {
48
+ return promise.catch((err) => {
49
+ if (err.data && err.status === status) {
50
+ callbackAction(err.data);
51
+ } else {
52
+ throw err;
53
+ }
54
+ });
55
+ };
56
+
37
57
  export const orchestratorApi = createApi({
38
58
  reducerPath: 'orchestratorApi',
39
59
  baseQuery: (args, api, extraOptions: ExtraOptions) => {