@scm-manager/ui-forms 2.42.3 → 2.42.4-20230213-150253
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 +7 -7
- package/build/index.d.ts +105 -38
- package/build/index.js +447 -207
- package/build/index.mjs +435 -195
- package/package.json +8 -6
- package/src/AddListEntryForm.tsx +123 -0
- package/src/Form.stories.tsx +295 -0
- package/src/Form.tsx +39 -49
- package/src/FormPathContext.tsx +73 -0
- package/src/FormRow.tsx +15 -2
- package/src/ScmFormContext.tsx +1 -0
- package/src/ScmFormListContext.tsx +65 -0
- package/src/base/help/Help.tsx +4 -6
- package/src/checkbox/ControlledCheckboxField.tsx +11 -8
- package/src/helpers.ts +27 -0
- package/src/index.ts +28 -1
- package/src/input/ControlledInputField.tsx +16 -9
- package/src/input/ControlledSecretConfirmationField.tsx +28 -17
- package/src/list/ControlledList.tsx +88 -0
- package/src/select/ControlledSelectField.tsx +16 -9
- package/src/select/Select.tsx +18 -8
- package/src/table/ControlledColumn.tsx +49 -0
- package/src/table/ControlledTable.tsx +100 -0
- package/src/Form.stories.mdx +0 -160
package/build/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
27
27
|
var src_exports = {};
|
|
28
28
|
__export(src_exports, {
|
|
29
29
|
ConfigurationForm: () => ConfigurationForm_default,
|
|
30
|
-
Form: () =>
|
|
30
|
+
Form: () => Form2,
|
|
31
31
|
useCreateResource: () => useCreateResource,
|
|
32
32
|
useDeleteResource: () => useDeleteResource,
|
|
33
33
|
useUpdateResource: () => useUpdateResource
|
|
@@ -35,9 +35,9 @@ __export(src_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
37
|
// src/Form.tsx
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
38
|
+
var import_react2 = __toESM(require("react"));
|
|
39
|
+
var import_react_hook_form = require("react-hook-form");
|
|
40
|
+
var import_ui_components = require("@scm-manager/ui-components");
|
|
41
41
|
|
|
42
42
|
// src/ScmFormContext.tsx
|
|
43
43
|
var import_react = __toESM(require("react"));
|
|
@@ -54,161 +54,292 @@ function useScmFormContext() {
|
|
|
54
54
|
// src/Form.tsx
|
|
55
55
|
var import_react_i18next = require("react-i18next");
|
|
56
56
|
var import_ui_buttons = require("@scm-manager/ui-buttons");
|
|
57
|
+
var SuccessNotification = ({ label, hide }) => {
|
|
58
|
+
if (!label) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
62
|
+
className: "notification is-success"
|
|
63
|
+
}, /* @__PURE__ */ import_react2.default.createElement("button", {
|
|
64
|
+
className: "delete",
|
|
65
|
+
onClick: hide
|
|
66
|
+
}), label);
|
|
67
|
+
};
|
|
68
|
+
function Form({
|
|
69
|
+
children,
|
|
70
|
+
onSubmit,
|
|
71
|
+
defaultValues,
|
|
72
|
+
translationPath,
|
|
73
|
+
readOnly,
|
|
74
|
+
submitButtonTestId
|
|
75
|
+
}) {
|
|
76
|
+
const form = (0, import_react_hook_form.useForm)({
|
|
77
|
+
mode: "onChange",
|
|
78
|
+
defaultValues
|
|
79
|
+
});
|
|
80
|
+
const { formState, handleSubmit, reset } = form;
|
|
81
|
+
const [ns, prefix] = translationPath;
|
|
82
|
+
const { t } = (0, import_react_i18next.useTranslation)(ns, { keyPrefix: prefix });
|
|
83
|
+
const [defaultTranslate] = (0, import_react_i18next.useTranslation)("commons", { keyPrefix: "form" });
|
|
84
|
+
const translateWithFallback = (0, import_react2.useCallback)(
|
|
85
|
+
(key, ...args) => {
|
|
86
|
+
const translation = t(key, ...args);
|
|
87
|
+
if (translation === `${prefix}.${key}`) {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
return translation;
|
|
91
|
+
},
|
|
92
|
+
[prefix, t]
|
|
93
|
+
);
|
|
94
|
+
const { isDirty, isValid, isSubmitting, isSubmitSuccessful } = formState;
|
|
95
|
+
const [error, setError] = (0, import_react2.useState)();
|
|
96
|
+
const [showSuccessNotification, setShowSuccessNotification] = (0, import_react2.useState)(false);
|
|
97
|
+
const submitButtonLabel = t("submit", { defaultValue: defaultTranslate("submit") });
|
|
98
|
+
const successNotification = translateWithFallback("submit-success-notification", {
|
|
99
|
+
defaultValue: defaultTranslate("submit-success-notification")
|
|
100
|
+
});
|
|
101
|
+
(0, import_react2.useEffect)(() => {
|
|
102
|
+
if (isSubmitSuccessful) {
|
|
103
|
+
setShowSuccessNotification(true);
|
|
104
|
+
}
|
|
105
|
+
}, [isSubmitSuccessful]);
|
|
106
|
+
(0, import_react2.useEffect)(() => reset(defaultValues), [defaultValues, reset]);
|
|
107
|
+
(0, import_react2.useEffect)(() => {
|
|
108
|
+
if (isDirty) {
|
|
109
|
+
setShowSuccessNotification(false);
|
|
110
|
+
}
|
|
111
|
+
}, [isDirty]);
|
|
112
|
+
const submit = (0, import_react2.useCallback)(
|
|
113
|
+
async (data) => {
|
|
114
|
+
setError(null);
|
|
115
|
+
try {
|
|
116
|
+
return await onSubmit(data);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
if (e instanceof Error) {
|
|
119
|
+
setError(e);
|
|
120
|
+
} else {
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
[onSubmit]
|
|
126
|
+
);
|
|
127
|
+
return /* @__PURE__ */ import_react2.default.createElement(ScmFormContextProvider, {
|
|
128
|
+
...form,
|
|
129
|
+
readOnly: isSubmitting || readOnly,
|
|
130
|
+
t: translateWithFallback,
|
|
131
|
+
formId: prefix
|
|
132
|
+
}, /* @__PURE__ */ import_react2.default.createElement("form", {
|
|
133
|
+
onSubmit: handleSubmit(submit),
|
|
134
|
+
id: prefix
|
|
135
|
+
}), showSuccessNotification ? /* @__PURE__ */ import_react2.default.createElement(SuccessNotification, {
|
|
136
|
+
label: successNotification,
|
|
137
|
+
hide: () => setShowSuccessNotification(false)
|
|
138
|
+
}) : null, typeof children === "function" ? children(form) : children, error ? /* @__PURE__ */ import_react2.default.createElement(import_ui_components.ErrorNotification, {
|
|
139
|
+
error
|
|
140
|
+
}) : null, !readOnly ? /* @__PURE__ */ import_react2.default.createElement(import_ui_components.Level, {
|
|
141
|
+
right: /* @__PURE__ */ import_react2.default.createElement(import_ui_buttons.Button, {
|
|
142
|
+
type: "submit",
|
|
143
|
+
variant: "primary",
|
|
144
|
+
testId: submitButtonTestId ?? "submit-button",
|
|
145
|
+
disabled: !isDirty || !isValid,
|
|
146
|
+
isLoading: isSubmitting,
|
|
147
|
+
form: prefix
|
|
148
|
+
}, submitButtonLabel)
|
|
149
|
+
}) : null);
|
|
150
|
+
}
|
|
151
|
+
var Form_default = Form;
|
|
57
152
|
|
|
58
153
|
// src/FormRow.tsx
|
|
59
|
-
var
|
|
154
|
+
var import_react3 = __toESM(require("react"));
|
|
60
155
|
var import_classnames = __toESM(require("classnames"));
|
|
61
|
-
var
|
|
62
|
-
|
|
156
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
157
|
+
var FormRowDiv = import_styled_components.default.div`
|
|
158
|
+
.field {
|
|
159
|
+
margin-left: 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
gap: 1rem;
|
|
163
|
+
|
|
164
|
+
&:not(:last-child) {
|
|
165
|
+
margin-bottom: 1rem;
|
|
166
|
+
}
|
|
167
|
+
`;
|
|
168
|
+
var FormRow = import_react3.default.forwardRef(
|
|
169
|
+
({ className, children, hidden, ...rest }, ref) => hidden ? null : /* @__PURE__ */ import_react3.default.createElement(FormRowDiv, {
|
|
63
170
|
ref,
|
|
64
|
-
className: (0, import_classnames.default)("
|
|
171
|
+
className: (0, import_classnames.default)("is-flex is-flex-wrap-wrap", className),
|
|
65
172
|
...rest
|
|
66
173
|
}, children)
|
|
67
174
|
);
|
|
68
175
|
var FormRow_default = FormRow;
|
|
69
176
|
|
|
70
177
|
// src/input/ControlledInputField.tsx
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var import_classnames8 = __toESM(require("classnames"));
|
|
178
|
+
var import_react12 = __toESM(require("react"));
|
|
179
|
+
var import_react_hook_form2 = require("react-hook-form");
|
|
74
180
|
|
|
75
181
|
// src/input/InputField.tsx
|
|
76
|
-
var
|
|
182
|
+
var import_react10 = __toESM(require("react"));
|
|
77
183
|
|
|
78
184
|
// src/base/Field.tsx
|
|
79
|
-
var
|
|
185
|
+
var import_react4 = __toESM(require("react"));
|
|
80
186
|
var import_classnames2 = __toESM(require("classnames"));
|
|
81
|
-
var Field = ({ className, children, ...rest }) => /* @__PURE__ */
|
|
187
|
+
var Field = ({ className, children, ...rest }) => /* @__PURE__ */ import_react4.default.createElement("div", {
|
|
82
188
|
className: (0, import_classnames2.default)("field", className),
|
|
83
189
|
...rest
|
|
84
190
|
}, children);
|
|
85
191
|
var Field_default = Field;
|
|
86
192
|
|
|
87
193
|
// src/base/Control.tsx
|
|
88
|
-
var
|
|
194
|
+
var import_react5 = __toESM(require("react"));
|
|
89
195
|
var import_classnames3 = __toESM(require("classnames"));
|
|
90
|
-
var Control = ({ className, children, ...rest }) => /* @__PURE__ */
|
|
196
|
+
var Control = ({ className, children, ...rest }) => /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
91
197
|
className: (0, import_classnames3.default)("control", className),
|
|
92
198
|
...rest
|
|
93
199
|
}, children);
|
|
94
200
|
var Control_default = Control;
|
|
95
201
|
|
|
96
202
|
// src/base/label/Label.tsx
|
|
97
|
-
var
|
|
203
|
+
var import_react6 = __toESM(require("react"));
|
|
98
204
|
var import_classnames4 = __toESM(require("classnames"));
|
|
99
|
-
var Label = ({ className, children, ...rest }) => /* @__PURE__ */
|
|
205
|
+
var Label = ({ className, children, ...rest }) => /* @__PURE__ */ import_react6.default.createElement("label", {
|
|
100
206
|
className: (0, import_classnames4.default)("label", className),
|
|
101
207
|
...rest
|
|
102
208
|
}, children);
|
|
103
209
|
var Label_default = Label;
|
|
104
210
|
|
|
105
211
|
// src/base/field-message/FieldMessage.tsx
|
|
106
|
-
var
|
|
212
|
+
var import_react7 = __toESM(require("react"));
|
|
107
213
|
var import_classnames5 = __toESM(require("classnames"));
|
|
108
214
|
|
|
109
215
|
// src/variants.ts
|
|
110
216
|
var createVariantClass = (variant) => variant ? `is-${variant}` : void 0;
|
|
111
217
|
|
|
112
218
|
// src/base/field-message/FieldMessage.tsx
|
|
113
|
-
var FieldMessage = ({ variant, className, children }) => /* @__PURE__ */
|
|
219
|
+
var FieldMessage = ({ variant, className, children }) => /* @__PURE__ */ import_react7.default.createElement("p", {
|
|
114
220
|
className: (0, import_classnames5.default)("help", createVariantClass(variant), className)
|
|
115
221
|
}, children);
|
|
116
222
|
var FieldMessage_default = FieldMessage;
|
|
117
223
|
|
|
118
224
|
// src/input/Input.tsx
|
|
119
|
-
var
|
|
225
|
+
var import_react8 = __toESM(require("react"));
|
|
120
226
|
var import_classnames6 = __toESM(require("classnames"));
|
|
121
|
-
var
|
|
122
|
-
var Input =
|
|
123
|
-
return /* @__PURE__ */
|
|
227
|
+
var import_ui_components2 = require("@scm-manager/ui-components");
|
|
228
|
+
var Input = import_react8.default.forwardRef(({ variant, className, testId, ...props }, ref) => {
|
|
229
|
+
return /* @__PURE__ */ import_react8.default.createElement("input", {
|
|
124
230
|
ref,
|
|
125
231
|
className: (0, import_classnames6.default)("input", createVariantClass(variant), className),
|
|
126
232
|
...props,
|
|
127
|
-
...(0,
|
|
233
|
+
...(0, import_ui_components2.createAttributesForTesting)(testId)
|
|
128
234
|
});
|
|
129
235
|
});
|
|
130
236
|
var Input_default = Input;
|
|
131
237
|
|
|
132
238
|
// src/base/help/Help.tsx
|
|
133
|
-
var
|
|
134
|
-
var
|
|
135
|
-
var Help = ({ text, className }) => /* @__PURE__ */
|
|
136
|
-
className
|
|
137
|
-
|
|
138
|
-
}
|
|
239
|
+
var import_react9 = __toESM(require("react"));
|
|
240
|
+
var import_ui_overlays = require("@scm-manager/ui-overlays");
|
|
241
|
+
var Help = ({ text, className }) => /* @__PURE__ */ import_react9.default.createElement(import_ui_overlays.Tooltip, {
|
|
242
|
+
className,
|
|
243
|
+
message: text
|
|
244
|
+
}, /* @__PURE__ */ import_react9.default.createElement("i", {
|
|
245
|
+
className: "fas fa-fw fa-question-circle has-text-blue-light"
|
|
246
|
+
}));
|
|
139
247
|
var Help_default = Help;
|
|
140
248
|
|
|
141
249
|
// src/input/InputField.tsx
|
|
142
|
-
var InputField =
|
|
250
|
+
var InputField = import_react10.default.forwardRef(
|
|
143
251
|
({ label, helpText, error, className, ...props }, ref) => {
|
|
144
252
|
const variant = error ? "danger" : void 0;
|
|
145
|
-
return /* @__PURE__ */
|
|
253
|
+
return /* @__PURE__ */ import_react10.default.createElement(Field_default, {
|
|
146
254
|
className
|
|
147
|
-
}, /* @__PURE__ */
|
|
255
|
+
}, /* @__PURE__ */ import_react10.default.createElement(Label_default, null, label, helpText ? /* @__PURE__ */ import_react10.default.createElement(Help_default, {
|
|
148
256
|
className: "ml-1",
|
|
149
257
|
text: helpText
|
|
150
|
-
}) : null), /* @__PURE__ */
|
|
258
|
+
}) : null), /* @__PURE__ */ import_react10.default.createElement(Control_default, null, /* @__PURE__ */ import_react10.default.createElement(Input_default, {
|
|
151
259
|
variant,
|
|
152
260
|
ref,
|
|
153
261
|
...props
|
|
154
|
-
})), error ? /* @__PURE__ */
|
|
262
|
+
})), error ? /* @__PURE__ */ import_react10.default.createElement(FieldMessage_default, {
|
|
155
263
|
variant
|
|
156
264
|
}, error) : null);
|
|
157
265
|
}
|
|
158
266
|
);
|
|
159
267
|
var InputField_default = InputField;
|
|
160
268
|
|
|
269
|
+
// src/FormPathContext.tsx
|
|
270
|
+
var import_react11 = __toESM(require("react"));
|
|
271
|
+
var ScmFormPathContext = import_react11.default.createContext("");
|
|
272
|
+
function useScmFormPathContext() {
|
|
273
|
+
return (0, import_react11.useContext)(ScmFormPathContext);
|
|
274
|
+
}
|
|
275
|
+
var ScmFormPathContextProvider = ({ children, path }) => /* @__PURE__ */ import_react11.default.createElement(ScmFormPathContext.Provider, {
|
|
276
|
+
value: path
|
|
277
|
+
}, children);
|
|
278
|
+
var ScmNestedFormPathContextProvider = ({ children, path }) => {
|
|
279
|
+
const prefix = useScmFormPathContext();
|
|
280
|
+
const pathWithPrefix = (0, import_react11.useMemo)(() => prefix ? `${prefix}.${path}` : path, [path, prefix]);
|
|
281
|
+
return /* @__PURE__ */ import_react11.default.createElement(ScmFormPathContext.Provider, {
|
|
282
|
+
value: pathWithPrefix
|
|
283
|
+
}, children);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/helpers.ts
|
|
287
|
+
function prefixWithoutIndices(path) {
|
|
288
|
+
return path.replace(/(\.\d+)/g, "");
|
|
289
|
+
}
|
|
290
|
+
|
|
161
291
|
// src/input/ControlledInputField.tsx
|
|
162
292
|
function ControlledInputField({
|
|
163
293
|
name,
|
|
164
294
|
label,
|
|
165
295
|
helpText,
|
|
166
296
|
rules,
|
|
167
|
-
className,
|
|
168
297
|
testId,
|
|
169
298
|
defaultValue,
|
|
170
299
|
readOnly,
|
|
171
300
|
...props
|
|
172
301
|
}) {
|
|
173
|
-
const { control, t, readOnly: formReadonly } = useScmFormContext();
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
302
|
+
const { control, t, readOnly: formReadonly, formId } = useScmFormContext();
|
|
303
|
+
const formPathPrefix = useScmFormPathContext();
|
|
304
|
+
const nameWithPrefix = formPathPrefix ? `${formPathPrefix}.${name}` : name;
|
|
305
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
306
|
+
const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
|
|
307
|
+
const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
|
|
308
|
+
return /* @__PURE__ */ import_react12.default.createElement(import_react_hook_form2.Controller, {
|
|
177
309
|
control,
|
|
178
|
-
name,
|
|
310
|
+
name: nameWithPrefix,
|
|
179
311
|
rules,
|
|
180
312
|
defaultValue,
|
|
181
|
-
render: ({ field, fieldState }) => /* @__PURE__ */
|
|
182
|
-
className: (0, import_classnames8.default)("column", className),
|
|
313
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ import_react12.default.createElement(InputField_default, {
|
|
183
314
|
readOnly: readOnly ?? formReadonly,
|
|
184
315
|
required: rules == null ? void 0 : rules.required,
|
|
185
316
|
...props,
|
|
186
317
|
...field,
|
|
318
|
+
form: formId,
|
|
187
319
|
label: labelTranslation,
|
|
188
320
|
helpText: helpTextTranslation,
|
|
189
|
-
error: fieldState.error ? fieldState.error.message || t(`${
|
|
190
|
-
testId: testId ?? `input-${
|
|
321
|
+
error: fieldState.error ? fieldState.error.message || t(`${prefixedNameWithoutIndices}.error.${fieldState.error.type}`) : void 0,
|
|
322
|
+
testId: testId ?? `input-${nameWithPrefix}`
|
|
191
323
|
})
|
|
192
324
|
});
|
|
193
325
|
}
|
|
194
326
|
var ControlledInputField_default = ControlledInputField;
|
|
195
327
|
|
|
196
328
|
// src/checkbox/ControlledCheckboxField.tsx
|
|
197
|
-
var
|
|
198
|
-
var
|
|
199
|
-
var import_classnames9 = __toESM(require("classnames"));
|
|
329
|
+
var import_react15 = __toESM(require("react"));
|
|
330
|
+
var import_react_hook_form3 = require("react-hook-form");
|
|
200
331
|
|
|
201
332
|
// src/checkbox/CheckboxField.tsx
|
|
202
|
-
var
|
|
333
|
+
var import_react14 = __toESM(require("react"));
|
|
203
334
|
|
|
204
335
|
// src/checkbox/Checkbox.tsx
|
|
205
|
-
var
|
|
206
|
-
var
|
|
207
|
-
var Checkbox =
|
|
208
|
-
({ readOnly, label, value, name, checked, defaultChecked, defaultValue, testId, helpText, ...props }, ref) => /* @__PURE__ */
|
|
336
|
+
var import_react13 = __toESM(require("react"));
|
|
337
|
+
var import_ui_components3 = require("@scm-manager/ui-components");
|
|
338
|
+
var Checkbox = import_react13.default.forwardRef(
|
|
339
|
+
({ readOnly, label, value, name, checked, defaultChecked, defaultValue, testId, helpText, ...props }, ref) => /* @__PURE__ */ import_react13.default.createElement("label", {
|
|
209
340
|
className: "checkbox",
|
|
210
341
|
disabled: readOnly || props.disabled
|
|
211
|
-
}, readOnly ? /* @__PURE__ */
|
|
342
|
+
}, readOnly ? /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, /* @__PURE__ */ import_react13.default.createElement("input", {
|
|
212
343
|
type: "hidden",
|
|
213
344
|
name,
|
|
214
345
|
value,
|
|
@@ -216,7 +347,7 @@ var Checkbox = import_react11.default.forwardRef(
|
|
|
216
347
|
checked,
|
|
217
348
|
defaultChecked,
|
|
218
349
|
readOnly: true
|
|
219
|
-
}), /* @__PURE__ */
|
|
350
|
+
}), /* @__PURE__ */ import_react13.default.createElement("input", {
|
|
220
351
|
type: "checkbox",
|
|
221
352
|
className: "mr-1",
|
|
222
353
|
ref,
|
|
@@ -225,9 +356,9 @@ var Checkbox = import_react11.default.forwardRef(
|
|
|
225
356
|
checked,
|
|
226
357
|
defaultChecked,
|
|
227
358
|
...props,
|
|
228
|
-
...(0,
|
|
359
|
+
...(0, import_ui_components3.createAttributesForTesting)(testId),
|
|
229
360
|
disabled: true
|
|
230
|
-
})) : /* @__PURE__ */
|
|
361
|
+
})) : /* @__PURE__ */ import_react13.default.createElement("input", {
|
|
231
362
|
type: "checkbox",
|
|
232
363
|
className: "mr-1",
|
|
233
364
|
ref,
|
|
@@ -237,8 +368,8 @@ var Checkbox = import_react11.default.forwardRef(
|
|
|
237
368
|
checked,
|
|
238
369
|
defaultChecked,
|
|
239
370
|
...props,
|
|
240
|
-
...(0,
|
|
241
|
-
}), label, helpText ? /* @__PURE__ */
|
|
371
|
+
...(0, import_ui_components3.createAttributesForTesting)(testId)
|
|
372
|
+
}), label, helpText ? /* @__PURE__ */ import_react13.default.createElement(Help_default, {
|
|
242
373
|
className: "ml-1",
|
|
243
374
|
text: helpText
|
|
244
375
|
}) : null)
|
|
@@ -246,9 +377,9 @@ var Checkbox = import_react11.default.forwardRef(
|
|
|
246
377
|
var Checkbox_default = Checkbox;
|
|
247
378
|
|
|
248
379
|
// src/checkbox/CheckboxField.tsx
|
|
249
|
-
var CheckboxField =
|
|
380
|
+
var CheckboxField = import_react14.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ import_react14.default.createElement(Field_default, {
|
|
250
381
|
className
|
|
251
|
-
}, /* @__PURE__ */
|
|
382
|
+
}, /* @__PURE__ */ import_react14.default.createElement(Control_default, null, /* @__PURE__ */ import_react14.default.createElement(Checkbox_default, {
|
|
252
383
|
ref,
|
|
253
384
|
...props
|
|
254
385
|
}))));
|
|
@@ -260,38 +391,39 @@ function ControlledInputField2({
|
|
|
260
391
|
label,
|
|
261
392
|
helpText,
|
|
262
393
|
rules,
|
|
263
|
-
className,
|
|
264
394
|
testId,
|
|
265
395
|
defaultChecked,
|
|
266
396
|
readOnly,
|
|
267
397
|
...props
|
|
268
398
|
}) {
|
|
269
|
-
const { control, t, readOnly: formReadonly } = useScmFormContext();
|
|
270
|
-
const
|
|
271
|
-
const
|
|
272
|
-
|
|
399
|
+
const { control, t, readOnly: formReadonly, formId } = useScmFormContext();
|
|
400
|
+
const formPathPrefix = useScmFormPathContext();
|
|
401
|
+
const nameWithPrefix = formPathPrefix ? `${formPathPrefix}.${name}` : name;
|
|
402
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
403
|
+
const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
|
|
404
|
+
const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
|
|
405
|
+
return /* @__PURE__ */ import_react15.default.createElement(import_react_hook_form3.Controller, {
|
|
273
406
|
control,
|
|
274
|
-
name,
|
|
407
|
+
name: nameWithPrefix,
|
|
275
408
|
rules,
|
|
276
409
|
defaultValue: defaultChecked,
|
|
277
|
-
render: ({ field }) => /* @__PURE__ */
|
|
278
|
-
|
|
410
|
+
render: ({ field }) => /* @__PURE__ */ import_react15.default.createElement(CheckboxField_default, {
|
|
411
|
+
form: formId,
|
|
279
412
|
readOnly: readOnly ?? formReadonly,
|
|
280
413
|
defaultChecked: field.value,
|
|
281
414
|
...props,
|
|
282
415
|
...field,
|
|
283
416
|
label: labelTranslation,
|
|
284
417
|
helpText: helpTextTranslation,
|
|
285
|
-
testId: testId ?? `checkbox-${
|
|
418
|
+
testId: testId ?? `checkbox-${nameWithPrefix}`
|
|
286
419
|
})
|
|
287
420
|
});
|
|
288
421
|
}
|
|
289
422
|
var ControlledCheckboxField_default = ControlledInputField2;
|
|
290
423
|
|
|
291
424
|
// src/input/ControlledSecretConfirmationField.tsx
|
|
292
|
-
var
|
|
293
|
-
var
|
|
294
|
-
var import_classnames10 = __toESM(require("classnames"));
|
|
425
|
+
var import_react16 = __toESM(require("react"));
|
|
426
|
+
var import_react_hook_form4 = require("react-hook-form");
|
|
295
427
|
function ControlledSecretConfirmationField({
|
|
296
428
|
name,
|
|
297
429
|
label,
|
|
@@ -307,47 +439,52 @@ function ControlledSecretConfirmationField({
|
|
|
307
439
|
readOnly,
|
|
308
440
|
...props
|
|
309
441
|
}) {
|
|
310
|
-
const { control, watch, t, readOnly: formReadonly } = useScmFormContext();
|
|
311
|
-
const
|
|
312
|
-
const
|
|
313
|
-
const
|
|
314
|
-
const
|
|
315
|
-
const
|
|
316
|
-
const
|
|
317
|
-
|
|
442
|
+
const { control, watch, t, readOnly: formReadonly, formId } = useScmFormContext();
|
|
443
|
+
const formPathPrefix = useScmFormPathContext();
|
|
444
|
+
const nameWithPrefix = formPathPrefix ? `${formPathPrefix}.${name}` : name;
|
|
445
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
446
|
+
const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
|
|
447
|
+
const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
|
|
448
|
+
const confirmationLabelTranslation = confirmationLabel || t(`${prefixedNameWithoutIndices}.confirmation.label`) || "";
|
|
449
|
+
const confirmationHelpTextTranslation = confirmationHelpText || t(`${prefixedNameWithoutIndices}.confirmation.helpText`);
|
|
450
|
+
const confirmationErrorMessageTranslation = confirmationErrorMessage || t(`${prefixedNameWithoutIndices}.confirmation.errorMessage`);
|
|
451
|
+
const secretValue = watch(nameWithPrefix);
|
|
452
|
+
return /* @__PURE__ */ import_react16.default.createElement(import_react16.default.Fragment, null, /* @__PURE__ */ import_react16.default.createElement(import_react_hook_form4.Controller, {
|
|
318
453
|
control,
|
|
319
|
-
name,
|
|
454
|
+
name: nameWithPrefix,
|
|
320
455
|
defaultValue,
|
|
321
456
|
rules: {
|
|
322
457
|
...rules,
|
|
323
|
-
deps: [`${
|
|
458
|
+
deps: [`${nameWithPrefix}Confirmation`]
|
|
324
459
|
},
|
|
325
|
-
render: ({ field, fieldState }) => /* @__PURE__ */
|
|
326
|
-
className
|
|
460
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ import_react16.default.createElement(InputField_default, {
|
|
461
|
+
className,
|
|
327
462
|
readOnly: readOnly ?? formReadonly,
|
|
328
463
|
...props,
|
|
329
464
|
...field,
|
|
465
|
+
form: formId,
|
|
330
466
|
required: rules == null ? void 0 : rules.required,
|
|
331
467
|
type: "password",
|
|
332
468
|
label: labelTranslation,
|
|
333
469
|
helpText: helpTextTranslation,
|
|
334
|
-
error: fieldState.error ? fieldState.error.message || t(`${
|
|
335
|
-
testId: testId ?? `input-${
|
|
470
|
+
error: fieldState.error ? fieldState.error.message || t(`${prefixedNameWithoutIndices}.error.${fieldState.error.type}`) : void 0,
|
|
471
|
+
testId: testId ?? `input-${nameWithPrefix}`
|
|
336
472
|
})
|
|
337
|
-
}), /* @__PURE__ */
|
|
473
|
+
}), /* @__PURE__ */ import_react16.default.createElement(import_react_hook_form4.Controller, {
|
|
338
474
|
control,
|
|
339
|
-
name: `${
|
|
475
|
+
name: `${nameWithPrefix}Confirmation`,
|
|
340
476
|
defaultValue,
|
|
341
|
-
render: ({ field, fieldState }) => /* @__PURE__ */
|
|
342
|
-
className
|
|
477
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ import_react16.default.createElement(InputField_default, {
|
|
478
|
+
className,
|
|
343
479
|
type: "password",
|
|
344
480
|
readOnly: readOnly ?? formReadonly,
|
|
345
481
|
disabled: props.disabled,
|
|
346
482
|
...field,
|
|
483
|
+
form: formId,
|
|
347
484
|
label: confirmationLabelTranslation,
|
|
348
485
|
helpText: confirmationHelpTextTranslation,
|
|
349
|
-
error: fieldState.error ? fieldState.error.message || t(`${
|
|
350
|
-
testId: confirmationTestId ?? `input-${
|
|
486
|
+
error: fieldState.error ? fieldState.error.message || t(`${prefixedNameWithoutIndices}.confirmation.error.${fieldState.error.type}`) : void 0,
|
|
487
|
+
testId: confirmationTestId ?? `input-${nameWithPrefix}-confirmation`
|
|
351
488
|
}),
|
|
352
489
|
rules: {
|
|
353
490
|
validate: (value) => secretValue === value || confirmationErrorMessageTranslation
|
|
@@ -356,40 +493,44 @@ function ControlledSecretConfirmationField({
|
|
|
356
493
|
}
|
|
357
494
|
|
|
358
495
|
// src/select/ControlledSelectField.tsx
|
|
359
|
-
var
|
|
360
|
-
var
|
|
361
|
-
var import_classnames12 = __toESM(require("classnames"));
|
|
496
|
+
var import_react19 = __toESM(require("react"));
|
|
497
|
+
var import_react_hook_form5 = require("react-hook-form");
|
|
362
498
|
|
|
363
499
|
// src/select/SelectField.tsx
|
|
364
|
-
var
|
|
500
|
+
var import_react18 = __toESM(require("react"));
|
|
365
501
|
|
|
366
502
|
// src/select/Select.tsx
|
|
367
|
-
var
|
|
368
|
-
var
|
|
369
|
-
var
|
|
370
|
-
var Select =
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
503
|
+
var import_react17 = __toESM(require("react"));
|
|
504
|
+
var import_classnames7 = __toESM(require("classnames"));
|
|
505
|
+
var import_ui_components4 = require("@scm-manager/ui-components");
|
|
506
|
+
var Select = import_react17.default.forwardRef(
|
|
507
|
+
({ variant, children, className, options, testId, ...props }, ref) => /* @__PURE__ */ import_react17.default.createElement("div", {
|
|
508
|
+
className: (0, import_classnames7.default)("select", { "is-multiple": props.multiple }, createVariantClass(variant), className)
|
|
509
|
+
}, /* @__PURE__ */ import_react17.default.createElement("select", {
|
|
510
|
+
ref,
|
|
511
|
+
...props,
|
|
512
|
+
...(0, import_ui_components4.createAttributesForTesting)(testId)
|
|
513
|
+
}, options ? options.map((option) => /* @__PURE__ */ import_react17.default.createElement("option", {
|
|
514
|
+
...option,
|
|
515
|
+
key: option.value
|
|
516
|
+
}, option.label, option.children)) : children))
|
|
517
|
+
);
|
|
377
518
|
var Select_default = Select;
|
|
378
519
|
|
|
379
520
|
// src/select/SelectField.tsx
|
|
380
|
-
var SelectField =
|
|
521
|
+
var SelectField = import_react18.default.forwardRef(
|
|
381
522
|
({ label, helpText, error, className, ...props }, ref) => {
|
|
382
523
|
const variant = error ? "danger" : void 0;
|
|
383
|
-
return /* @__PURE__ */
|
|
524
|
+
return /* @__PURE__ */ import_react18.default.createElement(Field_default, {
|
|
384
525
|
className
|
|
385
|
-
}, /* @__PURE__ */
|
|
526
|
+
}, /* @__PURE__ */ import_react18.default.createElement(Label_default, null, label, helpText ? /* @__PURE__ */ import_react18.default.createElement(Help_default, {
|
|
386
527
|
className: "ml-1",
|
|
387
528
|
text: helpText
|
|
388
|
-
}) : null), /* @__PURE__ */
|
|
529
|
+
}) : null), /* @__PURE__ */ import_react18.default.createElement(Control_default, null, /* @__PURE__ */ import_react18.default.createElement(Select_default, {
|
|
389
530
|
variant,
|
|
390
531
|
ref,
|
|
391
532
|
...props
|
|
392
|
-
})), error ? /* @__PURE__ */
|
|
533
|
+
})), error ? /* @__PURE__ */ import_react18.default.createElement(FieldMessage_default, {
|
|
393
534
|
variant
|
|
394
535
|
}, error) : null);
|
|
395
536
|
}
|
|
@@ -402,140 +543,223 @@ function ControlledSelectField({
|
|
|
402
543
|
label,
|
|
403
544
|
helpText,
|
|
404
545
|
rules,
|
|
405
|
-
className,
|
|
406
546
|
testId,
|
|
407
547
|
defaultValue,
|
|
408
548
|
readOnly,
|
|
409
549
|
...props
|
|
410
550
|
}) {
|
|
411
|
-
const { control, t, readOnly: formReadonly } = useScmFormContext();
|
|
412
|
-
const
|
|
413
|
-
const
|
|
414
|
-
|
|
551
|
+
const { control, t, readOnly: formReadonly, formId } = useScmFormContext();
|
|
552
|
+
const formPathPrefix = useScmFormPathContext();
|
|
553
|
+
const nameWithPrefix = formPathPrefix ? `${formPathPrefix}.${name}` : name;
|
|
554
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
555
|
+
const labelTranslation = label || t(`${prefixedNameWithoutIndices}.label`) || "";
|
|
556
|
+
const helpTextTranslation = helpText || t(`${prefixedNameWithoutIndices}.helpText`);
|
|
557
|
+
return /* @__PURE__ */ import_react19.default.createElement(import_react_hook_form5.Controller, {
|
|
415
558
|
control,
|
|
416
|
-
name,
|
|
559
|
+
name: nameWithPrefix,
|
|
417
560
|
rules,
|
|
418
561
|
defaultValue,
|
|
419
|
-
render: ({ field, fieldState }) => /* @__PURE__ */
|
|
420
|
-
|
|
562
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ import_react19.default.createElement(SelectField_default, {
|
|
563
|
+
form: formId,
|
|
421
564
|
readOnly: readOnly ?? formReadonly,
|
|
422
565
|
required: rules == null ? void 0 : rules.required,
|
|
423
566
|
...props,
|
|
424
567
|
...field,
|
|
425
568
|
label: labelTranslation,
|
|
426
569
|
helpText: helpTextTranslation,
|
|
427
|
-
error: fieldState.error ? fieldState.error.message || t(`${
|
|
428
|
-
testId: testId ?? `select-${
|
|
570
|
+
error: fieldState.error ? fieldState.error.message || t(`${prefixedNameWithoutIndices}.error.${fieldState.error.type}`) : void 0,
|
|
571
|
+
testId: testId ?? `select-${nameWithPrefix}`
|
|
429
572
|
})
|
|
430
573
|
});
|
|
431
574
|
}
|
|
432
575
|
var ControlledSelectField_default = ControlledSelectField;
|
|
433
576
|
|
|
434
|
-
// src/
|
|
435
|
-
var
|
|
436
|
-
|
|
577
|
+
// src/ScmFormListContext.tsx
|
|
578
|
+
var import_react20 = __toESM(require("react"));
|
|
579
|
+
var import_react_hook_form6 = require("react-hook-form");
|
|
580
|
+
var ScmFormListContext = import_react20.default.createContext(null);
|
|
581
|
+
var ScmFormListContextProvider = ({ name, children }) => {
|
|
582
|
+
const { control } = useScmFormContext();
|
|
583
|
+
const prefix = useScmFormPathContext();
|
|
584
|
+
const parentForm = useScmFormListContext();
|
|
585
|
+
const nameWithPrefix = (0, import_react20.useMemo)(() => prefix ? `${prefix}.${name}` : name, [name, prefix]);
|
|
586
|
+
const fieldArray = (0, import_react_hook_form6.useFieldArray)({
|
|
587
|
+
control,
|
|
588
|
+
name: nameWithPrefix
|
|
589
|
+
});
|
|
590
|
+
const value = (0, import_react20.useMemo)(() => ({ ...fieldArray, isNested: !!parentForm }), [fieldArray, parentForm]);
|
|
591
|
+
return /* @__PURE__ */ import_react20.default.createElement(ScmFormPathContextProvider, {
|
|
592
|
+
path: nameWithPrefix
|
|
593
|
+
}, /* @__PURE__ */ import_react20.default.createElement(ScmFormListContext.Provider, {
|
|
594
|
+
value
|
|
595
|
+
}, children));
|
|
596
|
+
};
|
|
597
|
+
function useScmFormListContext() {
|
|
598
|
+
return (0, import_react20.useContext)(ScmFormListContext);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// src/list/ControlledList.tsx
|
|
602
|
+
var import_react21 = __toESM(require("react"));
|
|
603
|
+
var import_ui_buttons2 = require("@scm-manager/ui-buttons");
|
|
604
|
+
var import_react_i18next2 = require("react-i18next");
|
|
605
|
+
function ControlledList({
|
|
606
|
+
withDelete,
|
|
607
|
+
children
|
|
608
|
+
}) {
|
|
609
|
+
const [defaultTranslate] = (0, import_react_i18next2.useTranslation)("commons", { keyPrefix: "form" });
|
|
610
|
+
const { readOnly, t } = useScmFormContext();
|
|
611
|
+
const nameWithPrefix = useScmFormPathContext();
|
|
612
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
613
|
+
const { fields, remove } = useScmFormListContext();
|
|
614
|
+
const deleteButtonTranslation = t(`${prefixedNameWithoutIndices}.delete`, {
|
|
615
|
+
defaultValue: defaultTranslate("list.delete.label", {
|
|
616
|
+
entity: t(`${prefixedNameWithoutIndices}.entity`)
|
|
617
|
+
})
|
|
618
|
+
});
|
|
619
|
+
return /* @__PURE__ */ import_react21.default.createElement(import_react21.default.Fragment, null, fields.map((value, index) => /* @__PURE__ */ import_react21.default.createElement(ScmFormPathContextProvider, {
|
|
620
|
+
key: value.id,
|
|
621
|
+
path: `${nameWithPrefix}.${index}`
|
|
622
|
+
}, typeof children === "function" ? children({ value, index, remove: () => remove(index) }) : children, withDelete && !readOnly ? /* @__PURE__ */ import_react21.default.createElement("div", {
|
|
623
|
+
className: "level-right"
|
|
624
|
+
}, /* @__PURE__ */ import_react21.default.createElement(import_ui_buttons2.Button, {
|
|
625
|
+
variant: "signal",
|
|
626
|
+
onClick: () => remove(index)
|
|
627
|
+
}, deleteButtonTranslation)) : null, /* @__PURE__ */ import_react21.default.createElement("hr", null))));
|
|
628
|
+
}
|
|
629
|
+
var ControlledList_default = ControlledList;
|
|
630
|
+
|
|
631
|
+
// src/table/ControlledTable.tsx
|
|
632
|
+
var import_react22 = __toESM(require("react"));
|
|
633
|
+
var import_ui_buttons3 = require("@scm-manager/ui-buttons");
|
|
634
|
+
var import_classnames8 = __toESM(require("classnames"));
|
|
635
|
+
var import_react_i18next3 = require("react-i18next");
|
|
636
|
+
function ControlledTable({
|
|
637
|
+
withDelete,
|
|
638
|
+
children,
|
|
639
|
+
className
|
|
640
|
+
}) {
|
|
641
|
+
const [defaultTranslate] = (0, import_react_i18next3.useTranslation)("commons", { keyPrefix: "form.table" });
|
|
642
|
+
const { readOnly, t } = useScmFormContext();
|
|
643
|
+
const nameWithPrefix = useScmFormPathContext();
|
|
644
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
645
|
+
const { fields, remove } = useScmFormListContext();
|
|
646
|
+
const deleteLabel = t(`${prefixedNameWithoutIndices}.delete`) || defaultTranslate("delete.label");
|
|
647
|
+
const actionHeaderLabel = t(`${prefixedNameWithoutIndices}.action.label`) || defaultTranslate("headers.action.label");
|
|
648
|
+
if (!fields.length) {
|
|
437
649
|
return null;
|
|
438
650
|
}
|
|
439
|
-
return /* @__PURE__ */
|
|
440
|
-
className: "
|
|
441
|
-
}, /* @__PURE__ */
|
|
442
|
-
className: "
|
|
443
|
-
|
|
444
|
-
|
|
651
|
+
return /* @__PURE__ */ import_react22.default.createElement("table", {
|
|
652
|
+
className: (0, import_classnames8.default)("table content is-hoverable", className)
|
|
653
|
+
}, /* @__PURE__ */ import_react22.default.createElement("thead", null, /* @__PURE__ */ import_react22.default.createElement("tr", null, import_react22.default.Children.map(children, (child) => /* @__PURE__ */ import_react22.default.createElement("th", null, t(`${prefixedNameWithoutIndices}.${child.props.name}.label`))), withDelete && !readOnly ? /* @__PURE__ */ import_react22.default.createElement("th", {
|
|
654
|
+
className: "has-text-right"
|
|
655
|
+
}, actionHeaderLabel) : null)), /* @__PURE__ */ import_react22.default.createElement("tbody", null, fields.map((value, index) => /* @__PURE__ */ import_react22.default.createElement(ScmFormPathContextProvider, {
|
|
656
|
+
key: value.id,
|
|
657
|
+
path: `${nameWithPrefix}.${index}`
|
|
658
|
+
}, /* @__PURE__ */ import_react22.default.createElement("tr", null, children, withDelete && !readOnly ? /* @__PURE__ */ import_react22.default.createElement("td", {
|
|
659
|
+
className: "has-text-right"
|
|
660
|
+
}, /* @__PURE__ */ import_react22.default.createElement(import_ui_buttons3.Button, {
|
|
661
|
+
className: "px-4",
|
|
662
|
+
onClick: () => remove(index),
|
|
663
|
+
"aria-label": deleteLabel
|
|
664
|
+
}, /* @__PURE__ */ import_react22.default.createElement("span", {
|
|
665
|
+
className: "icon is-small"
|
|
666
|
+
}, /* @__PURE__ */ import_react22.default.createElement("i", {
|
|
667
|
+
className: "fas fa-trash"
|
|
668
|
+
})))) : null)))));
|
|
669
|
+
}
|
|
670
|
+
var ControlledTable_default = ControlledTable;
|
|
671
|
+
|
|
672
|
+
// src/table/ControlledColumn.tsx
|
|
673
|
+
var import_react23 = __toESM(require("react"));
|
|
674
|
+
var import_react_hook_form7 = require("react-hook-form");
|
|
675
|
+
var ControlledColumn = ({ name, children, ...props }) => {
|
|
676
|
+
const { control } = useScmFormContext();
|
|
677
|
+
const formPathPrefix = useScmFormPathContext();
|
|
678
|
+
const nameWithPrefix = (0, import_react23.useMemo)(() => formPathPrefix ? `${formPathPrefix}.${name}` : name, [formPathPrefix, name]);
|
|
679
|
+
const value = (0, import_react_hook_form7.useWatch)({ control, name: nameWithPrefix, disabled: typeof children === "function" });
|
|
680
|
+
const allValues = (0, import_react_hook_form7.useWatch)({ control, name: formPathPrefix, disabled: typeof children !== "function" });
|
|
681
|
+
return /* @__PURE__ */ import_react23.default.createElement("td", {
|
|
682
|
+
...props
|
|
683
|
+
}, typeof children === "function" ? children(allValues) : value);
|
|
445
684
|
};
|
|
446
|
-
|
|
685
|
+
var ControlledColumn_default = ControlledColumn;
|
|
686
|
+
|
|
687
|
+
// src/AddListEntryForm.tsx
|
|
688
|
+
var import_react24 = __toESM(require("react"));
|
|
689
|
+
var import_react_hook_form8 = require("react-hook-form");
|
|
690
|
+
var import_ui_buttons4 = require("@scm-manager/ui-buttons");
|
|
691
|
+
var import_react_i18next4 = require("react-i18next");
|
|
692
|
+
var import_styled_components2 = __toESM(require("styled-components"));
|
|
693
|
+
var StyledHr = import_styled_components2.default.hr`
|
|
694
|
+
&:last-child {
|
|
695
|
+
display: none;
|
|
696
|
+
}
|
|
697
|
+
`;
|
|
698
|
+
function AddListEntryForm({
|
|
447
699
|
children,
|
|
448
|
-
onSubmit,
|
|
449
700
|
defaultValues,
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
submitButtonTestId
|
|
701
|
+
submit,
|
|
702
|
+
disableSubmitWhenDirty = true
|
|
453
703
|
}) {
|
|
454
|
-
const
|
|
704
|
+
const [defaultTranslate] = (0, import_react_i18next4.useTranslation)("commons", { keyPrefix: "form" });
|
|
705
|
+
const { readOnly, t } = useScmFormContext();
|
|
706
|
+
const nameWithPrefix = useScmFormPathContext();
|
|
707
|
+
const prefixedNameWithoutIndices = prefixWithoutIndices(nameWithPrefix);
|
|
708
|
+
const { append, isNested } = useScmFormListContext();
|
|
709
|
+
const form = (0, import_react_hook_form8.useForm)({
|
|
455
710
|
mode: "onChange",
|
|
456
711
|
defaultValues
|
|
457
712
|
});
|
|
458
|
-
const {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
713
|
+
const {
|
|
714
|
+
reset,
|
|
715
|
+
formState: { isSubmitSuccessful, isDirty, isValid }
|
|
716
|
+
} = form;
|
|
717
|
+
const translateWithExtraPrefix = (0, import_react24.useCallback)(
|
|
718
|
+
(key, ...args) => t(`${prefixedNameWithoutIndices}.${key}`, ...args),
|
|
719
|
+
[prefixedNameWithoutIndices, t]
|
|
720
|
+
);
|
|
721
|
+
const onSubmit = (0, import_react24.useCallback)((data) => submit ? submit(data, append) : append(data), [append, submit]);
|
|
722
|
+
const submitButtonLabel = translateWithExtraPrefix("add", {
|
|
723
|
+
defaultValue: defaultTranslate("list.add.label", { entity: translateWithExtraPrefix("entity") })
|
|
724
|
+
});
|
|
725
|
+
(0, import_react24.useEffect)(() => {
|
|
465
726
|
if (isSubmitSuccessful) {
|
|
466
|
-
|
|
727
|
+
reset(defaultValues);
|
|
467
728
|
}
|
|
468
|
-
}, [isSubmitSuccessful]);
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
}, [isDirty]);
|
|
475
|
-
const translateWithFallback = (0, import_react18.useCallback)(
|
|
476
|
-
(key, ...args) => {
|
|
477
|
-
const translation = t(key, ...args);
|
|
478
|
-
if (translation === `${prefix}.${key}`) {
|
|
479
|
-
return "";
|
|
480
|
-
}
|
|
481
|
-
return translation;
|
|
482
|
-
},
|
|
483
|
-
[prefix, t]
|
|
484
|
-
);
|
|
485
|
-
const submit = (0, import_react18.useCallback)(
|
|
486
|
-
async (data) => {
|
|
487
|
-
setError(null);
|
|
488
|
-
try {
|
|
489
|
-
return await onSubmit(data);
|
|
490
|
-
} catch (e) {
|
|
491
|
-
if (e instanceof Error) {
|
|
492
|
-
setError(e);
|
|
493
|
-
} else {
|
|
494
|
-
throw e;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
},
|
|
498
|
-
[onSubmit]
|
|
499
|
-
);
|
|
500
|
-
return /* @__PURE__ */ import_react18.default.createElement(ScmFormContextProvider, {
|
|
729
|
+
}, [defaultValues, isSubmitSuccessful, reset]);
|
|
730
|
+
if (readOnly) {
|
|
731
|
+
return null;
|
|
732
|
+
}
|
|
733
|
+
return /* @__PURE__ */ import_react24.default.createElement(ScmFormContextProvider, {
|
|
501
734
|
...form,
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}, /* @__PURE__ */
|
|
505
|
-
|
|
506
|
-
},
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
})
|
|
510
|
-
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
isLoading: isSubmitting
|
|
518
|
-
}, t("submit"))
|
|
519
|
-
}) : null));
|
|
735
|
+
t: translateWithExtraPrefix,
|
|
736
|
+
formId: nameWithPrefix
|
|
737
|
+
}, /* @__PURE__ */ import_react24.default.createElement(ScmFormPathContextProvider, {
|
|
738
|
+
path: ""
|
|
739
|
+
}, /* @__PURE__ */ import_react24.default.createElement("form", {
|
|
740
|
+
id: nameWithPrefix,
|
|
741
|
+
onSubmit: form.handleSubmit(onSubmit)
|
|
742
|
+
}), typeof children === "function" ? children(form) : children, /* @__PURE__ */ import_react24.default.createElement("div", {
|
|
743
|
+
className: "level-right"
|
|
744
|
+
}, /* @__PURE__ */ import_react24.default.createElement(import_ui_buttons4.Button, {
|
|
745
|
+
form: nameWithPrefix,
|
|
746
|
+
type: "submit",
|
|
747
|
+
variant: isNested ? void 0 : "secondary",
|
|
748
|
+
disabled: disableSubmitWhenDirty && !isDirty || !isValid
|
|
749
|
+
}, submitButtonLabel)), /* @__PURE__ */ import_react24.default.createElement(StyledHr, null)));
|
|
520
750
|
}
|
|
521
|
-
var
|
|
522
|
-
Row: FormRow_default,
|
|
523
|
-
Input: ControlledInputField_default,
|
|
524
|
-
Checkbox: ControlledCheckboxField_default,
|
|
525
|
-
SecretConfirmation: ControlledSecretConfirmationField,
|
|
526
|
-
Select: ControlledSelectField_default
|
|
527
|
-
});
|
|
751
|
+
var AddListEntryForm_default = AddListEntryForm;
|
|
528
752
|
|
|
529
753
|
// src/ConfigurationForm.tsx
|
|
530
754
|
var import_ui_api = require("@scm-manager/ui-api");
|
|
531
755
|
var import_ui_components5 = require("@scm-manager/ui-components");
|
|
532
|
-
var
|
|
756
|
+
var import_react25 = __toESM(require("react"));
|
|
533
757
|
function ConfigurationForm({ link, translationPath, children }) {
|
|
534
758
|
const { initialConfiguration, isReadOnly, update, isLoading } = (0, import_ui_api.useConfigLink)(link);
|
|
535
759
|
if (isLoading || !initialConfiguration) {
|
|
536
|
-
return /* @__PURE__ */
|
|
760
|
+
return /* @__PURE__ */ import_react25.default.createElement(import_ui_components5.Loading, null);
|
|
537
761
|
}
|
|
538
|
-
return /* @__PURE__ */
|
|
762
|
+
return /* @__PURE__ */ import_react25.default.createElement(Form_default, {
|
|
539
763
|
onSubmit: update,
|
|
540
764
|
translationPath,
|
|
541
765
|
defaultValues: initialConfiguration,
|
|
@@ -629,6 +853,22 @@ var useDeleteResource = (idFactory, { collectionName: [entityQueryKey, collectio
|
|
|
629
853
|
submissionResult: data
|
|
630
854
|
};
|
|
631
855
|
};
|
|
856
|
+
|
|
857
|
+
// src/index.ts
|
|
858
|
+
var Form2 = Object.assign(Form_default, {
|
|
859
|
+
Row: FormRow_default,
|
|
860
|
+
Input: ControlledInputField_default,
|
|
861
|
+
Checkbox: ControlledCheckboxField_default,
|
|
862
|
+
SecretConfirmation: ControlledSecretConfirmationField,
|
|
863
|
+
Select: ControlledSelectField_default,
|
|
864
|
+
PathContext: ScmNestedFormPathContextProvider,
|
|
865
|
+
ListContext: ScmFormListContextProvider,
|
|
866
|
+
List: ControlledList_default,
|
|
867
|
+
AddListEntryForm: AddListEntryForm_default,
|
|
868
|
+
Table: Object.assign(ControlledTable_default, {
|
|
869
|
+
Column: ControlledColumn_default
|
|
870
|
+
})
|
|
871
|
+
});
|
|
632
872
|
// Annotate the CommonJS export names for ESM import in node:
|
|
633
873
|
0 && (module.exports = {
|
|
634
874
|
ConfigurationForm,
|