@orchestrator-ui/orchestrator-ui-components 6.8.0 → 7.0.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.
Files changed (101) hide show
  1. package/.turbo/turbo-build.log +8 -8
  2. package/.turbo/turbo-lint.log +5 -2
  3. package/.turbo/turbo-test.log +9 -10
  4. package/CHANGELOG.md +19 -0
  5. package/dist/index.d.ts +164 -4306
  6. package/dist/index.js +1739 -5747
  7. package/dist/index.js.map +1 -1
  8. package/package.json +4 -8
  9. package/src/components/WfoPydanticForm/Footer.tsx +33 -6
  10. package/src/components/WfoPydanticForm/RenderFormErrors.tsx +2 -1
  11. package/src/components/WfoPydanticForm/Row.tsx +3 -1
  12. package/src/components/WfoPydanticForm/fields/WfoInteger.tsx +5 -1
  13. package/src/components/WfoPydanticForm/fields/WfoSummary.tsx +3 -5
  14. package/src/components/WfoPydanticForm/fields/styles.ts +72 -0
  15. package/src/components/WfoSearchPage/WfoSearch/WfoSearch.tsx +42 -54
  16. package/src/components/WfoSearchPage/utils.ts +9 -1
  17. package/src/components/WfoWorkflowSteps/WfoStep/WfoStep.tsx +10 -27
  18. package/src/components/WfoWorkflowSteps/WfoStep/WfoStepForm.tsx +1 -1
  19. package/src/components/index.ts +0 -1
  20. package/src/configuration/version.ts +1 -1
  21. package/src/contexts/OrchestratorConfigContext.tsx +0 -1
  22. package/src/hooks/useSearch.ts +12 -2
  23. package/src/hooks/useSearchPagination.ts +4 -0
  24. package/src/messages/en-GB.json +5 -3
  25. package/src/pages/processes/WfoStartProcessPage.tsx +5 -107
  26. package/src/rtk/endpoints/index.ts +0 -2
  27. package/src/rtk/endpoints/search.ts +13 -4
  28. package/src/types/index.ts +0 -1
  29. package/src/types/search.ts +7 -0
  30. package/src/types/types.ts +0 -1
  31. package/src/components/WfoForms/AutoFieldLoader.tsx +0 -118
  32. package/src/components/WfoForms/AutoFields.tsx +0 -49
  33. package/src/components/WfoForms/CreateForm.tsx +0 -75
  34. package/src/components/WfoForms/UserInputForm.tsx +0 -697
  35. package/src/components/WfoForms/UserInputFormStyling.ts +0 -80
  36. package/src/components/WfoForms/UserInputFormWizard.tsx +0 -127
  37. package/src/components/WfoForms/formFields/AcceptField.tsx +0 -243
  38. package/src/components/WfoForms/formFields/AcceptFieldStyling.ts +0 -35
  39. package/src/components/WfoForms/formFields/BoolField.tsx +0 -77
  40. package/src/components/WfoForms/formFields/BoolFieldStyling.ts +0 -64
  41. package/src/components/WfoForms/formFields/ConnectedSelectField.tsx +0 -19
  42. package/src/components/WfoForms/formFields/CustomerField.tsx +0 -77
  43. package/src/components/WfoForms/formFields/DateField.tsx +0 -72
  44. package/src/components/WfoForms/formFields/DividerField.tsx +0 -29
  45. package/src/components/WfoForms/formFields/ErrorField.tsx +0 -40
  46. package/src/components/WfoForms/formFields/ErrorsField.tsx +0 -34
  47. package/src/components/WfoForms/formFields/LabelField.tsx +0 -43
  48. package/src/components/WfoForms/formFields/ListAddField.tsx +0 -95
  49. package/src/components/WfoForms/formFields/ListDelField.tsx +0 -95
  50. package/src/components/WfoForms/formFields/ListField.tsx +0 -117
  51. package/src/components/WfoForms/formFields/ListItemField.tsx +0 -40
  52. package/src/components/WfoForms/formFields/ListSelectField.tsx +0 -95
  53. package/src/components/WfoForms/formFields/LocationCodeField.tsx +0 -60
  54. package/src/components/WfoForms/formFields/LongTextField.tsx +0 -68
  55. package/src/components/WfoForms/formFields/NestField.tsx +0 -107
  56. package/src/components/WfoForms/formFields/NumField.tsx +0 -85
  57. package/src/components/WfoForms/formFields/OptGroupField.tsx +0 -74
  58. package/src/components/WfoForms/formFields/RadioField.tsx +0 -87
  59. package/src/components/WfoForms/formFields/SelectField/SelectField.tsx +0 -177
  60. package/src/components/WfoForms/formFields/SelectField/index.ts +0 -1
  61. package/src/components/WfoForms/formFields/SelectField/styles.ts +0 -52
  62. package/src/components/WfoForms/formFields/SubmitField.tsx +0 -50
  63. package/src/components/WfoForms/formFields/SubscriptionSummaryField.tsx +0 -74
  64. package/src/components/WfoForms/formFields/SummaryField.tsx +0 -104
  65. package/src/components/WfoForms/formFields/SummaryFieldStyling.ts +0 -44
  66. package/src/components/WfoForms/formFields/TextField.tsx +0 -81
  67. package/src/components/WfoForms/formFields/commonStyles.ts +0 -32
  68. package/src/components/WfoForms/formFields/deprecated/ContactPersonAutocomplete.tsx +0 -99
  69. package/src/components/WfoForms/formFields/deprecated/ContactPersonAutocompleteStyles.ts +0 -41
  70. package/src/components/WfoForms/formFields/deprecated/ContactPersonNameField.tsx +0 -263
  71. package/src/components/WfoForms/formFields/deprecated/FileUploadField.tsx +0 -151
  72. package/src/components/WfoForms/formFields/deprecated/ImsNodeIdField.tsx +0 -109
  73. package/src/components/WfoForms/formFields/deprecated/ImsPortIdField.tsx +0 -233
  74. package/src/components/WfoForms/formFields/deprecated/ImsPortIdFieldStyling.ts +0 -17
  75. package/src/components/WfoForms/formFields/deprecated/IpNetworkField.tsx +0 -105
  76. package/src/components/WfoForms/formFields/deprecated/IpPrefixTableField.tsx +0 -390
  77. package/src/components/WfoForms/formFields/deprecated/IpPrefixTableFieldStyling.ts +0 -117
  78. package/src/components/WfoForms/formFields/deprecated/SplitPrefix.tsx +0 -138
  79. package/src/components/WfoForms/formFields/deprecated/SplitPrefixStyling.ts +0 -11
  80. package/src/components/WfoForms/formFields/deprecated/SubscriptionField.tsx +0 -263
  81. package/src/components/WfoForms/formFields/deprecated/SubscriptionFieldStyling.ts +0 -33
  82. package/src/components/WfoForms/formFields/deprecated/TimestampField.tsx +0 -110
  83. package/src/components/WfoForms/formFields/deprecated/VlanField.tsx +0 -300
  84. package/src/components/WfoForms/formFields/deprecated/index.ts +0 -15
  85. package/src/components/WfoForms/formFields/deprecated/types.ts +0 -74
  86. package/src/components/WfoForms/formFields/deprecated/utils.ts +0 -1
  87. package/src/components/WfoForms/formFields/index.ts +0 -30
  88. package/src/components/WfoForms/formFields/listFieldStyling.ts +0 -86
  89. package/src/components/WfoForms/formFields/types.ts +0 -41
  90. package/src/components/WfoForms/formFields/utils.spec.ts +0 -296
  91. package/src/components/WfoForms/formFields/utils.ts +0 -69
  92. package/src/components/WfoForms/index.ts +0 -5
  93. package/src/components/WfoWorkflowSteps/WfoStep/WfoStepFormOld.tsx +0 -67
  94. package/src/hooks/deprecated/useGetSurfSubcriptionDropdownOptions.ts +0 -37
  95. package/src/hooks/deprecated/useIsTaggedPort.ts +0 -25
  96. package/src/rtk/endpoints/deprecated/index.ts +0 -1
  97. package/src/rtk/endpoints/deprecated/surfSubscriptionDropdownOptions.ts +0 -53
  98. package/src/rtk/endpoints/formFields.ts +0 -131
  99. package/src/rtk/endpoints/ipam.ts +0 -54
  100. package/src/types/deprecated/SurfSubscriptionDropdownOptionsFilterParams.ts +0 -10
  101. package/src/types/deprecated/index.ts +0 -1
@@ -1,95 +0,0 @@
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
-
16
- /* NOTE: This component is only needed to avoid the circular import that started to be a problem
17
- after the upgrade to react-script 5.0. The original SelectField would import itself to handle the list:
18
- that seems to be impossible with the new webpack.
19
- */
20
- import React from 'react';
21
-
22
- import { get } from 'lodash';
23
- import { joinName, useField, useForm } from 'uniforms';
24
-
25
- import { ListField, ListFieldProps } from './ListField';
26
- import { ListItemField } from './ListItemField';
27
- // Avoid circular deps
28
- import { UnconnectedSelectField } from './SelectField';
29
- import { FieldProps } from './types';
30
-
31
- export type ListSelectFieldProps = FieldProps<
32
- string | string[],
33
- { allowedValues?: string[]; transform?(value: string): string }
34
- >;
35
-
36
- export function ListSelectField({
37
- allowedValues = [],
38
- fieldType,
39
- name,
40
- transform,
41
- ...props
42
- }: ListSelectFieldProps) {
43
- const nameArray = joinName(null, name);
44
- let parentName = joinName(nameArray.slice(0, -1));
45
-
46
- // We can't call useField conditionally so we call it for ourselves if there is no parent
47
- if (parentName === '') {
48
- parentName = name;
49
- }
50
- const parent = useField(parentName, {}, { absoluteName: true })[0];
51
- const { model } = useForm();
52
-
53
- if (parentName !== name) {
54
- if (
55
- parent.fieldType === Array &&
56
- (parent as ListFieldProps).uniqueItems
57
- ) {
58
- const allValues: string[] = get(model, parentName, []);
59
- const chosenValues = allValues.filter(
60
- (_item, index) =>
61
- index.toString() !== nameArray[nameArray.length - 1],
62
- );
63
-
64
- allowedValues = allowedValues.filter(
65
- (value) => !chosenValues.includes(value),
66
- );
67
- }
68
- }
69
-
70
- if (fieldType === Array) {
71
- return (
72
- <ListField name={name}>
73
- <ListItemField name="$">
74
- <UnconnectedSelectField
75
- name=""
76
- transform={transform}
77
- allowedValues={allowedValues}
78
- fieldType={fieldType}
79
- {...props}
80
- />
81
- </ListItemField>
82
- </ListField>
83
- );
84
- } else {
85
- return (
86
- <UnconnectedSelectField
87
- name=""
88
- transform={transform}
89
- allowedValues={allowedValues}
90
- fieldType={fieldType}
91
- {...props}
92
- />
93
- );
94
- }
95
- }
@@ -1,60 +0,0 @@
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 { useTranslations } from 'next-intl';
18
- import { connectField, filterDOMProps } from 'uniforms';
19
-
20
- import { SelectFieldProps, UnconnectedSelectField } from '@/components';
21
- import { useLocationCodesQuery } from '@/rtk/endpoints/formFields';
22
-
23
- export type LocationCodeFieldProps = { locationCodes?: string[] } & Omit<
24
- SelectFieldProps,
25
- 'placeholder' | 'allowedValues'
26
- >;
27
-
28
- declare module 'uniforms' {
29
- interface FilterDOMProps {
30
- locationCodes: never;
31
- }
32
- }
33
-
34
- filterDOMProps.register('locationCodes');
35
-
36
- function LocationCode({ locationCodes, ...props }: LocationCodeFieldProps) {
37
- const t = useTranslations('pydanticForms');
38
- const [codes, setCodes] = useState<string[]>(locationCodes ?? []);
39
- const { data, error } = useLocationCodesQuery();
40
-
41
- useEffect(() => {
42
- if (data) {
43
- setCodes(data);
44
- }
45
- if (error) {
46
- console.error(error);
47
- setCodes([]);
48
- }
49
- }, [data, error]);
50
-
51
- return (
52
- <UnconnectedSelectField
53
- {...props}
54
- allowedValues={codes}
55
- placeholder={t('widgets.locationCode.placeholder')}
56
- />
57
- );
58
- }
59
-
60
- export const LocationCodeField = connectField(LocationCode, { kind: 'leaf' });
@@ -1,68 +0,0 @@
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 from 'react';
16
-
17
- import { connectField, filterDOMProps } from 'uniforms';
18
-
19
- import { EuiFormRow, EuiText, EuiTextArea } from '@elastic/eui';
20
-
21
- import { FieldProps } from '@/components';
22
-
23
- export type LongTextFieldProps = FieldProps<
24
- string,
25
- object,
26
- HTMLTextAreaElement
27
- >;
28
-
29
- function LongText({
30
- disabled,
31
- id,
32
- label,
33
- description,
34
- name,
35
- onChange,
36
- placeholder,
37
- readOnly,
38
- value,
39
- error,
40
- errorMessage,
41
- ...props
42
- }: LongTextFieldProps) {
43
- return (
44
- <section {...filterDOMProps(props)}>
45
- <EuiFormRow
46
- label={label}
47
- labelAppend={<EuiText size="m">{description}</EuiText>}
48
- error={errorMessage}
49
- isInvalid={error}
50
- id={id}
51
- fullWidth
52
- >
53
- <EuiTextArea
54
- disabled={disabled}
55
- name={name}
56
- isInvalid={error}
57
- onChange={(event) => onChange(event.target.value)}
58
- placeholder={placeholder}
59
- readOnly={readOnly}
60
- value={value ?? ''}
61
- fullWidth
62
- />
63
- </EuiFormRow>
64
- </section>
65
- );
66
- }
67
-
68
- export const LongTextField = connectField(LongText, { kind: 'leaf' });
@@ -1,107 +0,0 @@
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 from 'react';
16
-
17
- import { connectField, filterDOMProps, joinName } from 'uniforms';
18
- import { AutoField } from 'uniforms-unstyled';
19
-
20
- import {
21
- EuiDescribedFormGroup,
22
- EuiFlexGroup,
23
- EuiFlexItem,
24
- EuiText,
25
- } from '@elastic/eui';
26
-
27
- import { FieldProps } from './types';
28
-
29
- export type NestFieldProps = FieldProps<
30
- null,
31
- { fields?: unknown[]; itemProps?: object }
32
- >;
33
-
34
- declare module 'uniforms' {
35
- interface FilterDOMProps {
36
- properties: never;
37
- wrap: never;
38
- ref: never;
39
- }
40
- }
41
- filterDOMProps.register('properties', 'wrap');
42
-
43
- function Nest({
44
- children,
45
- fields,
46
- itemProps,
47
- label,
48
- description,
49
- name,
50
- className = '',
51
- ...props
52
- }: NestFieldProps) {
53
- const nameArray = joinName(null, name);
54
- const lastNamePart = nameArray[nameArray.length - 1];
55
- const isInList = !isNaN(parseInt(lastNamePart));
56
- const itemIndex = isInList ? parseInt(lastNamePart) : 0;
57
-
58
- if (isInList) {
59
- return (
60
- <EuiFlexGroup
61
- {...filterDOMProps(props)}
62
- className={`${className} nest-field`}
63
- >
64
- {label && (
65
- <>
66
- <label className="euiFormLabel euiFormRow__label">
67
- {label}
68
- </label>
69
- <EuiText size="m">{description}</EuiText>
70
- </>
71
- )}
72
-
73
- {children ||
74
- fields?.map((field) => (
75
- <EuiFlexItem key={field}>
76
- <AutoField
77
- name={field}
78
- {...itemProps}
79
- label={itemIndex === 0 ? undefined : false}
80
- />
81
- </EuiFlexItem>
82
- ))}
83
- </EuiFlexGroup>
84
- );
85
- } else {
86
- return (
87
- <EuiDescribedFormGroup
88
- {...filterDOMProps(props)}
89
- title={<span>{label}</span>}
90
- description={description}
91
- className={`${className} nest-field`}
92
- >
93
- {children ||
94
- fields?.map((field) => (
95
- <AutoField
96
- key={field}
97
- name={field}
98
- {...itemProps}
99
- label={itemIndex === 0 ? undefined : false}
100
- />
101
- ))}
102
- </EuiDescribedFormGroup>
103
- );
104
- }
105
- }
106
-
107
- export const NestField = connectField(Nest);
@@ -1,85 +0,0 @@
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 from 'react';
16
-
17
- import { connectField, filterDOMProps } from 'uniforms';
18
-
19
- import { EuiFieldNumber, EuiFormRow, EuiText } from '@elastic/eui';
20
-
21
- import { FieldProps } from '@/components';
22
- import { getCommonFormFieldStyles } from '@/components/WfoForms/formFields/commonStyles';
23
- import { useWithOrchestratorTheme } from '@/hooks';
24
- import { getFormFieldsBaseStyle } from '@/theme';
25
-
26
- export type NumFieldProps = FieldProps<
27
- number,
28
- { max?: number; min?: number; precision?: number; step?: number }
29
- // Todo: not sure what this did
30
- // NumericInput
31
- >;
32
-
33
- function Num({
34
- disabled,
35
- id,
36
- label,
37
- description,
38
- max,
39
- min,
40
- name,
41
- onChange,
42
- placeholder,
43
- readOnly,
44
- step,
45
- value,
46
- error,
47
- showInlineError,
48
- errorMessage,
49
- ...props
50
- }: NumFieldProps) {
51
- const { formRowStyle } = useWithOrchestratorTheme(getCommonFormFieldStyles);
52
- const { formFieldBaseStyle } = useWithOrchestratorTheme(
53
- getFormFieldsBaseStyle,
54
- );
55
-
56
- return (
57
- <div {...filterDOMProps(props)}>
58
- <EuiFormRow
59
- css={formRowStyle}
60
- label={label}
61
- labelAppend={<EuiText size="m">{description}</EuiText>}
62
- error={showInlineError ? errorMessage : false}
63
- isInvalid={error}
64
- id={id}
65
- fullWidth
66
- >
67
- <EuiFieldNumber
68
- css={formFieldBaseStyle}
69
- name={name}
70
- isInvalid={error}
71
- placeholder={placeholder}
72
- readOnly={readOnly}
73
- onChange={(event) => onChange(parseInt(event.target.value))}
74
- min={min}
75
- max={max}
76
- step={step ?? 1}
77
- value={value ?? ''}
78
- disabled={disabled}
79
- />
80
- </EuiFormRow>
81
- </div>
82
- );
83
- }
84
-
85
- export const NumField = connectField(Num, { kind: 'leaf' });
@@ -1,74 +0,0 @@
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 from 'react';
16
-
17
- import { useTranslations } from 'next-intl';
18
- import { connectField, filterDOMProps, useField } from 'uniforms';
19
- import { AutoField } from 'uniforms-unstyled';
20
-
21
- import { EuiDescribedFormGroup, EuiFlexItem, EuiFormRow } from '@elastic/eui';
22
-
23
- import { BoolField } from './BoolField';
24
- import { FieldProps } from './types';
25
-
26
- export type OptGroupFieldProps = FieldProps<
27
- null,
28
- { fields?: unknown[]; itemProps?: object }
29
- >;
30
-
31
- filterDOMProps.register('properties');
32
-
33
- function OptGroup({
34
- fields,
35
- itemProps,
36
- name,
37
- readOnly,
38
- className = '',
39
- ...props
40
- }: OptGroupFieldProps) {
41
- const t = useTranslations('pydanticForms.backendTranslations');
42
- const enabled = useField('enabled', {})[0].value;
43
-
44
- return (
45
- <EuiDescribedFormGroup
46
- {...filterDOMProps(props)}
47
- title={<span>{t(`${name}.title`)}</span>}
48
- description={t(`${name}.description`)}
49
- className={`${className} optgroup-field`}
50
- >
51
- <>
52
- <EuiFlexItem>
53
- <EuiFormRow
54
- error={false}
55
- isInvalid={false}
56
- id={name} // Not sure if this is always unique...
57
- >
58
- <BoolField name="enabled" readOnly={readOnly} />
59
- </EuiFormRow>
60
- </EuiFlexItem>
61
- {enabled &&
62
- fields
63
- ?.filter((field) => field !== 'enabled')
64
- .map((field) => (
65
- <EuiFlexItem key={field}>
66
- <AutoField name={field} {...itemProps} />
67
- </EuiFlexItem>
68
- ))}
69
- </>
70
- </EuiDescribedFormGroup>
71
- );
72
- }
73
-
74
- export const OptGroupField = connectField(OptGroup);
@@ -1,87 +0,0 @@
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 from 'react';
16
-
17
- import { omit } from 'lodash';
18
- import { connectField, filterDOMProps } from 'uniforms';
19
-
20
- import { EuiFormRow, EuiRadio, EuiText } from '@elastic/eui';
21
-
22
- import { FieldProps } from '@/components';
23
-
24
- const base64 =
25
- typeof btoa !== 'undefined'
26
- ? btoa
27
- : (x: string) => Buffer.from(x).toString('base64');
28
- const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, '');
29
-
30
- export type RadioFieldProps = FieldProps<
31
- string,
32
- {
33
- allowedValues?: string[];
34
- checkboxes?: boolean;
35
- transform?(value: string): string;
36
- }
37
- >;
38
-
39
- function Radio({
40
- allowedValues,
41
- disabled,
42
- id,
43
- label,
44
- description,
45
- name,
46
- onChange,
47
- readOnly,
48
- transform,
49
- value,
50
- error,
51
- showInlineError,
52
- errorMessage,
53
- ...props
54
- }: RadioFieldProps) {
55
- return (
56
- <div {...omit(filterDOMProps(props), ['checkboxes'])}>
57
- <EuiFormRow
58
- label={label}
59
- labelAppend={<EuiText size="m">{description}</EuiText>}
60
- error={showInlineError ? errorMessage : false}
61
- isInvalid={error}
62
- id={id}
63
- fullWidth
64
- >
65
- <>
66
- {allowedValues?.map((item) => (
67
- <EuiRadio
68
- key={item}
69
- id={`${id}-${escape(item)}`}
70
- label={transform ? transform(item) : item}
71
- disabled={disabled}
72
- name={name}
73
- checked={item === value}
74
- onChange={() => {
75
- if (!readOnly) {
76
- onChange(item);
77
- }
78
- }}
79
- />
80
- ))}
81
- </>
82
- </EuiFormRow>
83
- </div>
84
- );
85
- }
86
-
87
- export const RadioField = connectField(Radio, { kind: 'leaf' });