@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.
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-lint.log +5 -2
- package/.turbo/turbo-test.log +9 -10
- package/CHANGELOG.md +19 -0
- package/dist/index.d.ts +164 -4306
- package/dist/index.js +1739 -5747
- package/dist/index.js.map +1 -1
- package/package.json +4 -8
- package/src/components/WfoPydanticForm/Footer.tsx +33 -6
- package/src/components/WfoPydanticForm/RenderFormErrors.tsx +2 -1
- package/src/components/WfoPydanticForm/Row.tsx +3 -1
- package/src/components/WfoPydanticForm/fields/WfoInteger.tsx +5 -1
- package/src/components/WfoPydanticForm/fields/WfoSummary.tsx +3 -5
- package/src/components/WfoPydanticForm/fields/styles.ts +72 -0
- package/src/components/WfoSearchPage/WfoSearch/WfoSearch.tsx +42 -54
- package/src/components/WfoSearchPage/utils.ts +9 -1
- package/src/components/WfoWorkflowSteps/WfoStep/WfoStep.tsx +10 -27
- package/src/components/WfoWorkflowSteps/WfoStep/WfoStepForm.tsx +1 -1
- package/src/components/index.ts +0 -1
- package/src/configuration/version.ts +1 -1
- package/src/contexts/OrchestratorConfigContext.tsx +0 -1
- package/src/hooks/useSearch.ts +12 -2
- package/src/hooks/useSearchPagination.ts +4 -0
- package/src/messages/en-GB.json +5 -3
- package/src/pages/processes/WfoStartProcessPage.tsx +5 -107
- package/src/rtk/endpoints/index.ts +0 -2
- package/src/rtk/endpoints/search.ts +13 -4
- package/src/types/index.ts +0 -1
- package/src/types/search.ts +7 -0
- package/src/types/types.ts +0 -1
- package/src/components/WfoForms/AutoFieldLoader.tsx +0 -118
- package/src/components/WfoForms/AutoFields.tsx +0 -49
- package/src/components/WfoForms/CreateForm.tsx +0 -75
- package/src/components/WfoForms/UserInputForm.tsx +0 -697
- package/src/components/WfoForms/UserInputFormStyling.ts +0 -80
- package/src/components/WfoForms/UserInputFormWizard.tsx +0 -127
- package/src/components/WfoForms/formFields/AcceptField.tsx +0 -243
- package/src/components/WfoForms/formFields/AcceptFieldStyling.ts +0 -35
- package/src/components/WfoForms/formFields/BoolField.tsx +0 -77
- package/src/components/WfoForms/formFields/BoolFieldStyling.ts +0 -64
- package/src/components/WfoForms/formFields/ConnectedSelectField.tsx +0 -19
- package/src/components/WfoForms/formFields/CustomerField.tsx +0 -77
- package/src/components/WfoForms/formFields/DateField.tsx +0 -72
- package/src/components/WfoForms/formFields/DividerField.tsx +0 -29
- package/src/components/WfoForms/formFields/ErrorField.tsx +0 -40
- package/src/components/WfoForms/formFields/ErrorsField.tsx +0 -34
- package/src/components/WfoForms/formFields/LabelField.tsx +0 -43
- package/src/components/WfoForms/formFields/ListAddField.tsx +0 -95
- package/src/components/WfoForms/formFields/ListDelField.tsx +0 -95
- package/src/components/WfoForms/formFields/ListField.tsx +0 -117
- package/src/components/WfoForms/formFields/ListItemField.tsx +0 -40
- package/src/components/WfoForms/formFields/ListSelectField.tsx +0 -95
- package/src/components/WfoForms/formFields/LocationCodeField.tsx +0 -60
- package/src/components/WfoForms/formFields/LongTextField.tsx +0 -68
- package/src/components/WfoForms/formFields/NestField.tsx +0 -107
- package/src/components/WfoForms/formFields/NumField.tsx +0 -85
- package/src/components/WfoForms/formFields/OptGroupField.tsx +0 -74
- package/src/components/WfoForms/formFields/RadioField.tsx +0 -87
- package/src/components/WfoForms/formFields/SelectField/SelectField.tsx +0 -177
- package/src/components/WfoForms/formFields/SelectField/index.ts +0 -1
- package/src/components/WfoForms/formFields/SelectField/styles.ts +0 -52
- package/src/components/WfoForms/formFields/SubmitField.tsx +0 -50
- package/src/components/WfoForms/formFields/SubscriptionSummaryField.tsx +0 -74
- package/src/components/WfoForms/formFields/SummaryField.tsx +0 -104
- package/src/components/WfoForms/formFields/SummaryFieldStyling.ts +0 -44
- package/src/components/WfoForms/formFields/TextField.tsx +0 -81
- package/src/components/WfoForms/formFields/commonStyles.ts +0 -32
- package/src/components/WfoForms/formFields/deprecated/ContactPersonAutocomplete.tsx +0 -99
- package/src/components/WfoForms/formFields/deprecated/ContactPersonAutocompleteStyles.ts +0 -41
- package/src/components/WfoForms/formFields/deprecated/ContactPersonNameField.tsx +0 -263
- package/src/components/WfoForms/formFields/deprecated/FileUploadField.tsx +0 -151
- package/src/components/WfoForms/formFields/deprecated/ImsNodeIdField.tsx +0 -109
- package/src/components/WfoForms/formFields/deprecated/ImsPortIdField.tsx +0 -233
- package/src/components/WfoForms/formFields/deprecated/ImsPortIdFieldStyling.ts +0 -17
- package/src/components/WfoForms/formFields/deprecated/IpNetworkField.tsx +0 -105
- package/src/components/WfoForms/formFields/deprecated/IpPrefixTableField.tsx +0 -390
- package/src/components/WfoForms/formFields/deprecated/IpPrefixTableFieldStyling.ts +0 -117
- package/src/components/WfoForms/formFields/deprecated/SplitPrefix.tsx +0 -138
- package/src/components/WfoForms/formFields/deprecated/SplitPrefixStyling.ts +0 -11
- package/src/components/WfoForms/formFields/deprecated/SubscriptionField.tsx +0 -263
- package/src/components/WfoForms/formFields/deprecated/SubscriptionFieldStyling.ts +0 -33
- package/src/components/WfoForms/formFields/deprecated/TimestampField.tsx +0 -110
- package/src/components/WfoForms/formFields/deprecated/VlanField.tsx +0 -300
- package/src/components/WfoForms/formFields/deprecated/index.ts +0 -15
- package/src/components/WfoForms/formFields/deprecated/types.ts +0 -74
- package/src/components/WfoForms/formFields/deprecated/utils.ts +0 -1
- package/src/components/WfoForms/formFields/index.ts +0 -30
- package/src/components/WfoForms/formFields/listFieldStyling.ts +0 -86
- package/src/components/WfoForms/formFields/types.ts +0 -41
- package/src/components/WfoForms/formFields/utils.spec.ts +0 -296
- package/src/components/WfoForms/formFields/utils.ts +0 -69
- package/src/components/WfoForms/index.ts +0 -5
- package/src/components/WfoWorkflowSteps/WfoStep/WfoStepFormOld.tsx +0 -67
- package/src/hooks/deprecated/useGetSurfSubcriptionDropdownOptions.ts +0 -37
- package/src/hooks/deprecated/useIsTaggedPort.ts +0 -25
- package/src/rtk/endpoints/deprecated/index.ts +0 -1
- package/src/rtk/endpoints/deprecated/surfSubscriptionDropdownOptions.ts +0 -53
- package/src/rtk/endpoints/formFields.ts +0 -131
- package/src/rtk/endpoints/ipam.ts +0 -54
- package/src/types/deprecated/SurfSubscriptionDropdownOptionsFilterParams.ts +0 -10
- package/src/types/deprecated/index.ts +0 -1
|
@@ -1,77 +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 _ from 'lodash';
|
|
18
|
-
import { useTranslations } from 'next-intl';
|
|
19
|
-
import { connectField, useField } from 'uniforms';
|
|
20
|
-
|
|
21
|
-
import { useGetCustomersQuery } from '@/rtk/endpoints';
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
SelectFieldProps,
|
|
25
|
-
UnconnectedSelectField,
|
|
26
|
-
} from './SelectField/SelectField';
|
|
27
|
-
|
|
28
|
-
export type CustomerFieldProps = Omit<
|
|
29
|
-
SelectFieldProps,
|
|
30
|
-
'placeholder' | 'transform' | 'allowedValues'
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
function Customer({ ...props }: CustomerFieldProps) {
|
|
34
|
-
const t = useTranslations('pydanticForms');
|
|
35
|
-
const [, context] = useField(props.name, {}, { absoluteName: true });
|
|
36
|
-
|
|
37
|
-
const { data: customers, isLoading } = useGetCustomersQuery();
|
|
38
|
-
|
|
39
|
-
const uuidCustomerNameMap = new Map<string, string>();
|
|
40
|
-
|
|
41
|
-
if (!isLoading && customers) {
|
|
42
|
-
customers?.map((customer) => {
|
|
43
|
-
uuidCustomerNameMap.set(
|
|
44
|
-
customer.customerId,
|
|
45
|
-
`${customer.shortcode} - ${customer.fullname}`,
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const genericFieldName = props.name.split('.').shift();
|
|
51
|
-
const valueFromContext =
|
|
52
|
-
genericFieldName && context.model[genericFieldName];
|
|
53
|
-
|
|
54
|
-
// RVL:19-89-24 This is the only way I found to make sure the value is set to undefined when the value
|
|
55
|
-
// is removed from the form (i.e. when the user clicks the "-" button in the form) for the last list item.
|
|
56
|
-
const value =
|
|
57
|
-
Array.isArray(valueFromContext) && _.isEmpty(valueFromContext)
|
|
58
|
-
? ''
|
|
59
|
-
: props.value;
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<UnconnectedSelectField
|
|
63
|
-
{...props}
|
|
64
|
-
allowedValues={Array.from(uuidCustomerNameMap.keys())}
|
|
65
|
-
transform={(uuid: string) => uuidCustomerNameMap.get(uuid) || uuid}
|
|
66
|
-
disabled={isLoading || props.disabled}
|
|
67
|
-
value={value}
|
|
68
|
-
placeholder={
|
|
69
|
-
!isLoading
|
|
70
|
-
? t('widgets.customer.placeholder')
|
|
71
|
-
: t('widgets.customer.loading')
|
|
72
|
-
}
|
|
73
|
-
/>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const CustomerField = connectField(Customer, { kind: 'leaf' });
|
|
@@ -1,72 +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 { FieldProps } from './types';
|
|
20
|
-
|
|
21
|
-
const DateConstructor = (typeof global === 'object' ? global : window).Date;
|
|
22
|
-
const dateFormat = (value?: Date) => {
|
|
23
|
-
return value?.toISOString().slice(0, -8);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type DateFieldProps = FieldProps<Date, { max?: Date; min?: Date }>;
|
|
27
|
-
|
|
28
|
-
function Date({
|
|
29
|
-
disabled,
|
|
30
|
-
id,
|
|
31
|
-
inputRef,
|
|
32
|
-
label,
|
|
33
|
-
max,
|
|
34
|
-
min,
|
|
35
|
-
name,
|
|
36
|
-
onChange,
|
|
37
|
-
readOnly,
|
|
38
|
-
placeholder,
|
|
39
|
-
value,
|
|
40
|
-
...props
|
|
41
|
-
}: DateFieldProps) {
|
|
42
|
-
return (
|
|
43
|
-
<div {...filterDOMProps(props)}>
|
|
44
|
-
{label && <label htmlFor={id}>{label}</label>}
|
|
45
|
-
|
|
46
|
-
<input
|
|
47
|
-
disabled={disabled}
|
|
48
|
-
id={id}
|
|
49
|
-
max={dateFormat(max)}
|
|
50
|
-
min={dateFormat(min)}
|
|
51
|
-
name={name}
|
|
52
|
-
onChange={(event) => {
|
|
53
|
-
const date = new DateConstructor(
|
|
54
|
-
event.target.valueAsNumber,
|
|
55
|
-
);
|
|
56
|
-
if (date.getFullYear() < 10000) {
|
|
57
|
-
onChange(date);
|
|
58
|
-
} else if (isNaN(event.target.valueAsNumber)) {
|
|
59
|
-
onChange(undefined);
|
|
60
|
-
}
|
|
61
|
-
}}
|
|
62
|
-
placeholder={placeholder}
|
|
63
|
-
readOnly={readOnly}
|
|
64
|
-
ref={inputRef}
|
|
65
|
-
type="datetime-local"
|
|
66
|
-
value={dateFormat(value) ?? ''}
|
|
67
|
-
/>
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const DateField = connectField(Date, { kind: 'leaf' });
|
|
@@ -1,29 +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 } from 'uniforms';
|
|
18
|
-
|
|
19
|
-
import { EuiHorizontalRule } from '@elastic/eui';
|
|
20
|
-
|
|
21
|
-
import { FieldProps } from '@/components';
|
|
22
|
-
|
|
23
|
-
export type DividerFieldProps = FieldProps<null, object, null, HTMLDivElement>;
|
|
24
|
-
|
|
25
|
-
function Divider({ id }: DividerFieldProps) {
|
|
26
|
-
return <EuiHorizontalRule style={{ marginTop: '-30px' }} id={id} />;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const DividerField = connectField(Divider, { kind: 'leaf' });
|
|
@@ -1,40 +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 { FieldProps } from '@/components';
|
|
20
|
-
|
|
21
|
-
export type ErrorFieldProps = FieldProps<null>;
|
|
22
|
-
|
|
23
|
-
// onChange not used on purpose
|
|
24
|
-
function Error({
|
|
25
|
-
children,
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
27
|
-
onChange,
|
|
28
|
-
error,
|
|
29
|
-
errorMessage,
|
|
30
|
-
...props
|
|
31
|
-
}: ErrorFieldProps) {
|
|
32
|
-
return !error ? null : (
|
|
33
|
-
<div {...filterDOMProps(props)}>{children || errorMessage}</div>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const ErrorField = connectField(Error, {
|
|
38
|
-
initialValue: false,
|
|
39
|
-
kind: 'leaf',
|
|
40
|
-
});
|
|
@@ -1,34 +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, { HTMLProps } from 'react';
|
|
16
|
-
|
|
17
|
-
import { filterDOMProps, useForm } from 'uniforms';
|
|
18
|
-
|
|
19
|
-
export type ErrorsFieldProps = HTMLProps<HTMLDivElement>;
|
|
20
|
-
|
|
21
|
-
export const ErrorsField = (props: ErrorsFieldProps) => {
|
|
22
|
-
const { error, schema } = useForm();
|
|
23
|
-
return !error && !props.children ? null : (
|
|
24
|
-
<div {...filterDOMProps(props)}>
|
|
25
|
-
{props.children}
|
|
26
|
-
|
|
27
|
-
<ul>
|
|
28
|
-
{schema.getErrorMessages(error).map((message, index) => (
|
|
29
|
-
<li key={index}>{message}</li>
|
|
30
|
-
))}
|
|
31
|
-
</ul>
|
|
32
|
-
</div>
|
|
33
|
-
);
|
|
34
|
-
};
|
|
@@ -1,43 +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 { FieldProps } from '@/components';
|
|
20
|
-
import { useOrchestratorTheme } from '@/hooks';
|
|
21
|
-
|
|
22
|
-
export type LabelFieldProps = FieldProps<null, object, null, HTMLDivElement>;
|
|
23
|
-
|
|
24
|
-
// onChange not used on purpose
|
|
25
|
-
function Label({ id, value, label, ...props }: LabelFieldProps) {
|
|
26
|
-
const { theme } = useOrchestratorTheme();
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<section {...filterDOMProps(props)}>
|
|
30
|
-
<label
|
|
31
|
-
css={{ color: theme.colors.text }}
|
|
32
|
-
id={id}
|
|
33
|
-
className={`euiFormLabel euiFormRow__label${
|
|
34
|
-
value ? '__large' : ''
|
|
35
|
-
}`}
|
|
36
|
-
>
|
|
37
|
-
{value ? value : label}
|
|
38
|
-
</label>
|
|
39
|
-
</section>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const LabelField = connectField(Label, { kind: 'leaf' });
|
|
@@ -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
|
-
import React from 'react';
|
|
16
|
-
|
|
17
|
-
import cloneDeep from 'lodash/cloneDeep';
|
|
18
|
-
import { useTranslations } from 'next-intl';
|
|
19
|
-
import { connectField, filterDOMProps, joinName, useField } from 'uniforms';
|
|
20
|
-
|
|
21
|
-
import { EuiIcon, EuiText } from '@elastic/eui';
|
|
22
|
-
|
|
23
|
-
import { useOrchestratorTheme } from '@/hooks';
|
|
24
|
-
|
|
25
|
-
import { FieldProps } from './types';
|
|
26
|
-
|
|
27
|
-
export type ListAddFieldProps = FieldProps<
|
|
28
|
-
string,
|
|
29
|
-
{ initialCount?: number; outerList?: boolean }
|
|
30
|
-
>;
|
|
31
|
-
|
|
32
|
-
// onChange not used on purpose
|
|
33
|
-
function ListAdd({
|
|
34
|
-
disabled,
|
|
35
|
-
initialCount,
|
|
36
|
-
name,
|
|
37
|
-
readOnly,
|
|
38
|
-
value,
|
|
39
|
-
outerList = false,
|
|
40
|
-
...props
|
|
41
|
-
}: ListAddFieldProps) {
|
|
42
|
-
const { theme } = useOrchestratorTheme();
|
|
43
|
-
const t = useTranslations('pydanticForms.backendTranslations');
|
|
44
|
-
|
|
45
|
-
const nameParts = joinName(null, name);
|
|
46
|
-
const parentName = joinName(nameParts.slice(0, -1));
|
|
47
|
-
const parent = useField<
|
|
48
|
-
{ initialCount?: number; maxCount?: number },
|
|
49
|
-
unknown[]
|
|
50
|
-
>(parentName, { initialCount }, { absoluteName: true })[0];
|
|
51
|
-
const parentValueCount = parent.value?.length ?? 0;
|
|
52
|
-
const limitNotReached =
|
|
53
|
-
!disabled && (!parent.maxCount || parent.maxCount > parentValueCount);
|
|
54
|
-
const count = 1 + Math.max((initialCount ?? 0) - parentValueCount, 0);
|
|
55
|
-
|
|
56
|
-
function onAction(event: React.KeyboardEvent | React.MouseEvent) {
|
|
57
|
-
if (
|
|
58
|
-
limitNotReached &&
|
|
59
|
-
!readOnly &&
|
|
60
|
-
(!('key' in event) || event.key === 'Enter')
|
|
61
|
-
) {
|
|
62
|
-
const newRowsValue = Array(count).fill(cloneDeep(value));
|
|
63
|
-
parent.onChange(parent.value!.concat(newRowsValue));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<div
|
|
69
|
-
className="add-item"
|
|
70
|
-
{...filterDOMProps(props)}
|
|
71
|
-
onClick={onAction}
|
|
72
|
-
onKeyDown={onAction}
|
|
73
|
-
role="button"
|
|
74
|
-
tabIndex={0}
|
|
75
|
-
>
|
|
76
|
-
<EuiIcon
|
|
77
|
-
type="plus"
|
|
78
|
-
size="xxl"
|
|
79
|
-
color={
|
|
80
|
-
!limitNotReached || disabled
|
|
81
|
-
? theme.colors.disabled
|
|
82
|
-
: theme.colors.success
|
|
83
|
-
}
|
|
84
|
-
/>
|
|
85
|
-
<label>
|
|
86
|
-
{outerList && <EuiText>{t(`${parentName}_add`)}</EuiText>}
|
|
87
|
-
</label>
|
|
88
|
-
</div>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const ListAddField = connectField(ListAdd, {
|
|
93
|
-
initialValue: false,
|
|
94
|
-
kind: 'leaf',
|
|
95
|
-
});
|
|
@@ -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
|
-
import React from 'react';
|
|
16
|
-
|
|
17
|
-
import { useTranslations } from 'next-intl';
|
|
18
|
-
import { connectField, filterDOMProps, joinName, useField } from 'uniforms';
|
|
19
|
-
|
|
20
|
-
import { EuiIcon, EuiText } from '@elastic/eui';
|
|
21
|
-
|
|
22
|
-
import { useOrchestratorTheme } from '@/hooks';
|
|
23
|
-
|
|
24
|
-
import { FieldProps } from './types';
|
|
25
|
-
|
|
26
|
-
export type ListDelFieldProps = FieldProps<
|
|
27
|
-
null,
|
|
28
|
-
{ initialCount?: number; itemProps?: object; outerList?: boolean }
|
|
29
|
-
>;
|
|
30
|
-
|
|
31
|
-
// onChange prop not used on purpose
|
|
32
|
-
function ListDel({
|
|
33
|
-
disabled,
|
|
34
|
-
name,
|
|
35
|
-
readOnly,
|
|
36
|
-
id,
|
|
37
|
-
outerList = false,
|
|
38
|
-
...props
|
|
39
|
-
}: ListDelFieldProps) {
|
|
40
|
-
const { theme } = useOrchestratorTheme();
|
|
41
|
-
const t = useTranslations('pydanticForms.backendTranslations');
|
|
42
|
-
|
|
43
|
-
const nameParts = joinName(null, name);
|
|
44
|
-
const nameIndex = +nameParts[nameParts.length - 1];
|
|
45
|
-
const parentName = joinName(nameParts.slice(0, -1));
|
|
46
|
-
const parent = useField<{ minCount?: number }, unknown[]>(
|
|
47
|
-
parentName,
|
|
48
|
-
{},
|
|
49
|
-
{ absoluteName: true },
|
|
50
|
-
)[0];
|
|
51
|
-
|
|
52
|
-
const parentValueCount = parent.value?.length ?? 0;
|
|
53
|
-
|
|
54
|
-
// Make a row deletable only if its:
|
|
55
|
-
const isDeletable: boolean =
|
|
56
|
-
!disabled &&
|
|
57
|
-
!readOnly &&
|
|
58
|
-
(!parent.minCount || parentValueCount > parent.minCount);
|
|
59
|
-
|
|
60
|
-
function onAction(event: React.KeyboardEvent | React.MouseEvent) {
|
|
61
|
-
if (isDeletable && (!('key' in event) || event.key === 'Enter')) {
|
|
62
|
-
const value = parent?.value!.slice();
|
|
63
|
-
value.splice(nameIndex, 1);
|
|
64
|
-
parent.onChange(value);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<div
|
|
70
|
-
{...filterDOMProps(props)}
|
|
71
|
-
className="del-item"
|
|
72
|
-
id={`${id}.remove`}
|
|
73
|
-
onClick={onAction}
|
|
74
|
-
onKeyDown={onAction}
|
|
75
|
-
role="button"
|
|
76
|
-
tabIndex={0}
|
|
77
|
-
>
|
|
78
|
-
<EuiIcon
|
|
79
|
-
type="minus"
|
|
80
|
-
size="xxl"
|
|
81
|
-
color={
|
|
82
|
-
isDeletable ? theme.colors.danger : theme.colors.disabled
|
|
83
|
-
}
|
|
84
|
-
/>
|
|
85
|
-
<label>
|
|
86
|
-
{outerList && <EuiText>{t(`${parentName}_del`)}</EuiText>}
|
|
87
|
-
</label>
|
|
88
|
-
</div>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const ListDelField = connectField(ListDel, {
|
|
93
|
-
initialValue: false,
|
|
94
|
-
kind: 'leaf',
|
|
95
|
-
});
|
|
@@ -1,117 +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, { Children, cloneElement, isValidElement } from 'react';
|
|
16
|
-
|
|
17
|
-
import range from 'lodash/range';
|
|
18
|
-
import { connectField, filterDOMProps, joinName, useField } from 'uniforms';
|
|
19
|
-
|
|
20
|
-
import { EuiFlexItem, EuiFormRow, EuiText } from '@elastic/eui';
|
|
21
|
-
|
|
22
|
-
import { getCommonFormFieldStyles } from '@/components/WfoForms/formFields/commonStyles';
|
|
23
|
-
import { useWithOrchestratorTheme } from '@/hooks';
|
|
24
|
-
|
|
25
|
-
import { ListAddField } from './ListAddField';
|
|
26
|
-
import { ListItemField } from './ListItemField';
|
|
27
|
-
import { listFieldStyling } from './listFieldStyling';
|
|
28
|
-
import { FieldProps } from './types';
|
|
29
|
-
|
|
30
|
-
declare module 'uniforms' {
|
|
31
|
-
interface FilterDOMProps {
|
|
32
|
-
items: never;
|
|
33
|
-
uniqueItems: never;
|
|
34
|
-
outerList: never;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
filterDOMProps.register('minCount');
|
|
38
|
-
filterDOMProps.register('maxCount');
|
|
39
|
-
filterDOMProps.register('items');
|
|
40
|
-
filterDOMProps.register('uniqueItems');
|
|
41
|
-
filterDOMProps.register('outerList');
|
|
42
|
-
|
|
43
|
-
export type ListFieldProps = FieldProps<
|
|
44
|
-
unknown[],
|
|
45
|
-
{ initialCount?: number; itemProps?: object; uniqueItems?: boolean },
|
|
46
|
-
null,
|
|
47
|
-
HTMLUListElement
|
|
48
|
-
>;
|
|
49
|
-
|
|
50
|
-
function List({
|
|
51
|
-
disabled,
|
|
52
|
-
children = <ListItemField name="$" disabled={disabled} outerList={false} />,
|
|
53
|
-
initialCount = 1,
|
|
54
|
-
itemProps,
|
|
55
|
-
label,
|
|
56
|
-
description,
|
|
57
|
-
name,
|
|
58
|
-
value,
|
|
59
|
-
error,
|
|
60
|
-
showInlineError,
|
|
61
|
-
errorMessage,
|
|
62
|
-
...props
|
|
63
|
-
}: ListFieldProps) {
|
|
64
|
-
const { formRowStyle } = useWithOrchestratorTheme(getCommonFormFieldStyles);
|
|
65
|
-
|
|
66
|
-
const child = useField(joinName(name, '$'), {}, { absoluteName: true })[0];
|
|
67
|
-
const hasListAsChild = child.fieldType === Array;
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<EuiFlexItem css={listFieldStyling}>
|
|
71
|
-
<section
|
|
72
|
-
{...filterDOMProps(props)}
|
|
73
|
-
className={`list-field${hasListAsChild ? ' outer-list' : ''}`}
|
|
74
|
-
>
|
|
75
|
-
<EuiFormRow
|
|
76
|
-
css={formRowStyle}
|
|
77
|
-
label={label}
|
|
78
|
-
labelAppend={<EuiText size="m">{description}</EuiText>}
|
|
79
|
-
error={showInlineError ? errorMessage : false}
|
|
80
|
-
isInvalid={error}
|
|
81
|
-
id={`formrow-${name}`}
|
|
82
|
-
fullWidth
|
|
83
|
-
>
|
|
84
|
-
<></>
|
|
85
|
-
</EuiFormRow>
|
|
86
|
-
<ul>
|
|
87
|
-
{range(Math.max(value?.length ?? 0, initialCount ?? 0)).map(
|
|
88
|
-
(itemIndex) =>
|
|
89
|
-
Children.map(children, (child, childIndex) =>
|
|
90
|
-
isValidElement(child)
|
|
91
|
-
? cloneElement(child, {
|
|
92
|
-
key: `${itemIndex}-${childIndex}`,
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
94
|
-
// @ts-ignore
|
|
95
|
-
name: child.props.name?.replace(
|
|
96
|
-
'$',
|
|
97
|
-
itemIndex.toString(),
|
|
98
|
-
),
|
|
99
|
-
outerList: hasListAsChild,
|
|
100
|
-
...itemProps,
|
|
101
|
-
})
|
|
102
|
-
: child,
|
|
103
|
-
),
|
|
104
|
-
)}
|
|
105
|
-
<ListAddField
|
|
106
|
-
initialCount={initialCount}
|
|
107
|
-
name="$"
|
|
108
|
-
disabled={disabled}
|
|
109
|
-
outerList={hasListAsChild}
|
|
110
|
-
/>
|
|
111
|
-
</ul>
|
|
112
|
-
</section>
|
|
113
|
-
</EuiFlexItem>
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export const ListField = connectField(List);
|
|
@@ -1,40 +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, { ReactNode } from 'react';
|
|
16
|
-
|
|
17
|
-
import { connectField } from 'uniforms';
|
|
18
|
-
import { AutoField } from 'uniforms-unstyled';
|
|
19
|
-
|
|
20
|
-
import { ListDelField } from './ListDelField';
|
|
21
|
-
|
|
22
|
-
export type ListItemFieldProps = {
|
|
23
|
-
children?: ReactNode;
|
|
24
|
-
name: string;
|
|
25
|
-
outerList?: boolean;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function ListItem({
|
|
29
|
-
children = <AutoField label={null} name="" />,
|
|
30
|
-
outerList = false,
|
|
31
|
-
}: ListItemFieldProps) {
|
|
32
|
-
return (
|
|
33
|
-
<li>
|
|
34
|
-
{children}
|
|
35
|
-
<ListDelField name="" outerList={outerList} />
|
|
36
|
-
</li>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const ListItemField = connectField(ListItem, { initialValue: false });
|