@orchestrator-ui/orchestrator-ui-components 5.8.0 → 5.8.1

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": "5.8.0",
3
+ "version": "5.8.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Library of UI Components used to display the workflow orchestrator frontend",
6
6
  "author": {
@@ -48,7 +48,7 @@
48
48
  "next-query-params": "^5.0.0",
49
49
  "object-hash": "^3.0.0",
50
50
  "prism-themes": "^1.9.0",
51
- "pydantic-forms": "^0.9.1",
51
+ "pydantic-forms": "^0.9.2",
52
52
  "react-diff-view": "^3.2.0",
53
53
  "react-draggable": "^4.4.6",
54
54
  "react-redux": "^9.1.2",
@@ -1,5 +1,6 @@
1
1
  import React, { useCallback, useMemo } from 'react';
2
2
 
3
+ import _ from 'lodash';
3
4
  import { AbstractIntlMessages, useMessages, useTranslations } from 'next-intl';
4
5
  import { useRouter } from 'next/router';
5
6
  import type {
@@ -168,7 +169,7 @@ export const useWfoPydanticFormConfig = () => {
168
169
  // We are not using a radio button component to maintain being able to deselect options
169
170
  return (
170
171
  field.type === PydanticFormFieldType.STRING &&
171
- Array.isArray(field.options) &&
172
+ _.isArray(field.options) &&
172
173
  field.options.length > 0
173
174
  );
174
175
  },
@@ -193,6 +194,7 @@ export const useWfoPydanticFormConfig = () => {
193
194
  matcher(field) {
194
195
  return (
195
196
  field.type === PydanticFormFieldType.ARRAY &&
197
+ _.isArray(field.options) &&
196
198
  field.options?.length > 0 &&
197
199
  field.options?.length <= 5
198
200
  );
@@ -9,14 +9,14 @@ export const WfoDropdown: PydanticFormControlledElement = ({
9
9
  pydanticFormField,
10
10
  value,
11
11
  }) => {
12
- const dropDownOptions = pydanticFormField.options.map((option) => ({
12
+ const dropDownOptions = pydanticFormField.options?.map((option) => ({
13
13
  value: option.value,
14
14
  label: option.label,
15
15
  }));
16
16
 
17
17
  return (
18
18
  <WfoReactSelect
19
- options={dropDownOptions}
19
+ options={dropDownOptions || []}
20
20
  onChange={onChange}
21
21
  id={pydanticFormField.id}
22
22
  value={value}
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
 
3
+ import _ from 'lodash';
3
4
  import type { PydanticFormControlledElement } from 'pydantic-forms';
5
+ import { getFormFieldIdWithPath } from 'pydantic-forms';
4
6
 
5
7
  import { EuiFieldNumber } from '@elastic/eui';
6
8
  import { css } from '@emotion/react';
@@ -32,13 +34,21 @@ export const WfoInteger: PydanticFormControlledElement = ({
32
34
  getFormFieldsBaseStyle,
33
35
  );
34
36
 
37
+ // If the field is part of an array the value is passed in as an object with the field name as key
38
+ // this is imposed by react-hook-form. We try to detect this and extract the actual value
39
+ const fieldName = getFormFieldIdWithPath(pydanticFormField.id);
40
+ const fieldValue =
41
+ _.isObject(value) && _.has(value, fieldName)
42
+ ? _.get(value, fieldName)
43
+ : value;
44
+
35
45
  return (
36
46
  <EuiFieldNumber
37
47
  data-testid={pydanticFormField.id}
38
48
  css={formFieldBaseStyle}
39
49
  name={pydanticFormField.id}
40
50
  onChange={(event) => onChange(parseInt(event.target.value))}
41
- value={value}
51
+ value={fieldValue}
42
52
  disabled={disabled}
43
53
  />
44
54
  );
@@ -35,7 +35,7 @@ export const WfoMultiCheckboxField: PydanticFormControlledElement = ({
35
35
 
36
36
  const { options, id } = pydanticFormField;
37
37
 
38
- const checkboxes = options.map((option, index) => ({
38
+ const checkboxes = options?.map((option, index) => ({
39
39
  label: option.label,
40
40
  id: option.value,
41
41
  'data-test-id': `${id}-${index}`,
@@ -59,7 +59,7 @@ export const WfoMultiCheckboxField: PydanticFormControlledElement = ({
59
59
 
60
60
  return (
61
61
  <EuiCheckboxGroup
62
- options={checkboxes}
62
+ options={checkboxes || []}
63
63
  idToSelectedMap={checkboxIdToSelectedMap}
64
64
  onChange={(id) => handleCheckboxChange(id)}
65
65
  data-testid={id}
@@ -10,7 +10,7 @@ export const WfoRadio: PydanticFormControlledElement = ({
10
10
  value,
11
11
  disabled,
12
12
  }) => {
13
- const radioOptions = pydanticFormField.options.map((option) => ({
13
+ const radioOptions = pydanticFormField.options?.map((option) => ({
14
14
  id: option.value,
15
15
  label: option.label,
16
16
  }));
@@ -18,7 +18,7 @@ export const WfoRadio: PydanticFormControlledElement = ({
18
18
  return (
19
19
  <EuiRadioGroup
20
20
  data-testid={pydanticFormField.id}
21
- options={radioOptions}
21
+ options={radioOptions || []}
22
22
  idSelected={value}
23
23
  onChange={(id) => onChange(id)}
24
24
  name={pydanticFormField.id}
@@ -1,4 +1,4 @@
1
- import React, { useEffect } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import ReactSelect, { components } from 'react-select';
3
3
  import type { GroupBase, InputProps } from 'react-select';
4
4
 
@@ -13,7 +13,7 @@ import { getWfoReactSelectStyles } from './styles';
13
13
  interface WfoReactSelectProps<ValueType> {
14
14
  options: Option<ValueType>[];
15
15
  id: string;
16
- onChange: (value: ValueType | undefined) => void;
16
+ onChange: (value: ValueType | undefined | null) => void;
17
17
  value: ValueType;
18
18
  disabled?: boolean;
19
19
  isLoading?: boolean;
@@ -33,19 +33,21 @@ export const WfoReactSelect = <ValueType,>({
33
33
  hasError = false,
34
34
  refetch,
35
35
  }: WfoReactSelectProps<ValueType>) => {
36
- useEffect(() => {
37
- const selectedValue = options.find(
38
- (option: Option<ValueType>) => option.value === value,
39
- );
40
- setSelectedValue(selectedValue || null);
41
- }, [options, value]);
42
-
43
36
  const initialValue = options.find(
44
37
  (option: Option<ValueType>) => option.value === value,
45
38
  );
46
39
 
47
40
  const [selectedValue, setSelectedValue] =
48
- React.useState<Option<ValueType> | null>(initialValue || null);
41
+ useState<Option<ValueType> | null>(initialValue || null);
42
+
43
+ useEffect(() => {
44
+ const preSelectedValue = options.find(
45
+ (option: Option<ValueType>) => option.value === value,
46
+ );
47
+ if (preSelectedValue !== selectedValue) {
48
+ setSelectedValue(preSelectedValue || null);
49
+ }
50
+ }, [options, selectedValue, value]);
49
51
 
50
52
  // React select allows callbacks to supply style for innercomponents: https://react-select.com/styles#inner-components
51
53
  const {
@@ -89,12 +91,12 @@ export const WfoReactSelect = <ValueType,>({
89
91
  id={id}
90
92
  inputId={`${id}.search`}
91
93
  onChange={(option) => {
94
+ // By default reactSelect reverts to the initial option when cleared.
95
+ // This is to make sure we can also deselect the value after it is
96
+ // initialized from error state that sets it to the latest value.
92
97
  if (option === null) {
93
- // By default reactSelect reverts to the initial option when cleared
94
- // this is to make sure we can also deselect the value after it is
95
- // initialized from error state for example.
96
98
  setSelectedValue(null);
97
- onChange(undefined);
99
+ onChange(null);
98
100
  } else {
99
101
  const selectedValue = option?.value;
100
102
  setSelectedValue(option);
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
 
3
+ import _ from 'lodash';
3
4
  import type { PydanticFormControlledElement } from 'pydantic-forms';
5
+ import { getFormFieldIdWithPath } from 'pydantic-forms';
4
6
 
5
7
  import { EuiFieldText } from '@elastic/eui';
6
8
 
@@ -16,14 +18,20 @@ export const WfoText: PydanticFormControlledElement = ({
16
18
  const { formFieldBaseStyle } = useWithOrchestratorTheme(
17
19
  getFormFieldsBaseStyle,
18
20
  );
19
-
21
+ // If the field is part of an array the value is passed in as an object with the field name as key
22
+ // this is imposed by react-hook-form. We try to detect this and extract the actual value
23
+ const fieldName = getFormFieldIdWithPath(pydanticFormField.id);
24
+ const fieldValue =
25
+ _.isObject(value) && _.has(value, fieldName)
26
+ ? _.get(value, fieldName)
27
+ : value;
20
28
  return (
21
29
  <EuiFieldText
22
30
  data-testid={pydanticFormField.id}
23
31
  css={formFieldBaseStyle}
24
32
  disabled={disabled}
25
33
  onChange={(event) => onChange(event.target.value)}
26
- value={value ?? ''}
34
+ value={fieldValue}
27
35
  fullWidth
28
36
  />
29
37
  );
@@ -1 +1 @@
1
- export const ORCHESTRATOR_UI_LIBRARY_VERSION = '5.8.0';
1
+ export const ORCHESTRATOR_UI_LIBRARY_VERSION = '5.8.1';