@dovetail-v2/refine 0.3.14-alpha.2 → 0.3.15-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/EditMetadataForm/index.d.ts +1 -0
- package/dist/components/Form/YamlForm.d.ts +1 -0
- package/dist/components/Form/useReactHookForm.d.ts +4 -1
- package/dist/components/Form/useRefineForm.d.ts +2 -0
- package/dist/components/Form/useYamlForm.d.ts +4 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/i18n.d.ts +2 -0
- package/dist/locales/en-US/index.d.ts +1 -0
- package/dist/locales/zh-CN/index.d.ts +1 -0
- package/dist/refine.cjs +119 -15
- package/dist/refine.js +119 -15
- package/dist/types/resource.d.ts +7 -0
- package/package.json +1 -1
|
@@ -23,6 +23,7 @@ export interface YamlFormProps<Model extends ResourceModel = ResourceModel> {
|
|
|
23
23
|
rules?: YamlFormRule[];
|
|
24
24
|
transformInitValues?: (values: Record<string, unknown>) => Record<string, unknown>;
|
|
25
25
|
transformApplyValues?: (values: Unstructured) => Unstructured;
|
|
26
|
+
beforeSubmit?: (values: Unstructured, setErrors: (errors: string[]) => void) => Promise<Unstructured>;
|
|
26
27
|
onSaveButtonPropsChange?: (saveButtonProps: {
|
|
27
28
|
disabled?: boolean;
|
|
28
29
|
onClick: () => void;
|
|
@@ -9,6 +9,7 @@ export type UseFormReturnType<TQueryFnData extends BaseRecord = BaseRecord, TErr
|
|
|
9
9
|
disabled: boolean;
|
|
10
10
|
onClick: (e: React.BaseSyntheticEvent) => void;
|
|
11
11
|
};
|
|
12
|
+
beforeSubmitErrors: string[];
|
|
12
13
|
};
|
|
13
14
|
export type UseFormProps<TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TVariables extends FieldValues = FieldValues, TContext extends object = object, TData extends BaseRecord = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError> = {
|
|
14
15
|
/**
|
|
@@ -29,5 +30,7 @@ export type UseFormProps<TQueryFnData extends BaseRecord = BaseRecord, TError ex
|
|
|
29
30
|
disableServerSideValidation?: boolean;
|
|
30
31
|
transformApplyValues?: (values: TVariables) => TVariables;
|
|
31
32
|
transformInitValues?: (values: Record<string, unknown>) => DefaultValues<TVariables>;
|
|
33
|
+
beforeSubmit?: (values: TVariables, setErrors: (errors: string[]) => void) => Promise<TVariables>;
|
|
34
|
+
onBeforeSubmitError?: (errors: string[]) => void;
|
|
32
35
|
} & UseHookFormProps<TVariables, TContext>;
|
|
33
|
-
export declare const useForm: <TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TVariables extends FieldValues = FieldValues, TContext extends object = object, TData extends BaseRecord = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError>({ refineCoreProps, warnWhenUnsavedChanges: warnWhenUnsavedChangesProp, disableServerSideValidation: disableServerSideValidationProp, transformApplyValues, transformInitValues, ...rest }?: UseFormProps<TQueryFnData, TError, TVariables, TContext, TData, TResponse, TResponseError>) => UseFormReturnType<TQueryFnData, TError, TVariables, TContext, TData, TResponse, TResponseError>;
|
|
36
|
+
export declare const useForm: <TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TVariables extends FieldValues = FieldValues, TContext extends object = object, TData extends BaseRecord = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError>({ refineCoreProps, warnWhenUnsavedChanges: warnWhenUnsavedChangesProp, disableServerSideValidation: disableServerSideValidationProp, transformApplyValues, transformInitValues, beforeSubmit, onBeforeSubmitError, ...rest }?: UseFormProps<TQueryFnData, TError, TVariables, TContext, TData, TResponse, TResponseError>) => UseFormReturnType<TQueryFnData, TError, TVariables, TContext, TData, TResponse, TResponseError>;
|
|
@@ -2,6 +2,7 @@ import { CommonFormConfig, RefineFormConfig, ResourceConfig } from '../../types'
|
|
|
2
2
|
import { UseFormProps } from './useReactHookForm';
|
|
3
3
|
interface UseRefineFormOptions {
|
|
4
4
|
initialValues?: Record<string, unknown>;
|
|
5
|
+
onBeforeSubmitError?: (errors: string[]) => void;
|
|
5
6
|
}
|
|
6
7
|
export declare const useRefineForm: (props: {
|
|
7
8
|
formConfig?: RefineFormConfig & CommonFormConfig;
|
|
@@ -14,5 +15,6 @@ export declare const useRefineForm: (props: {
|
|
|
14
15
|
[x: string]: any;
|
|
15
16
|
}, {}, import("@refinedev/core").BaseRecord, import("@refinedev/core").BaseRecord, import("@refinedev/core").HttpError>;
|
|
16
17
|
responseErrorMsgs: string[];
|
|
18
|
+
beforeSubmitErrors: string[];
|
|
17
19
|
};
|
|
18
20
|
export {};
|
|
@@ -27,6 +27,8 @@ export type UseFormProps<TQueryFnData extends BaseRecord = BaseRecord, TError ex
|
|
|
27
27
|
initialValuesForEdit?: Record<string, unknown>;
|
|
28
28
|
transformInitValues?: (values: Record<string, unknown>) => Record<string, unknown>;
|
|
29
29
|
transformApplyValues?: (values: Unstructured) => Unstructured;
|
|
30
|
+
beforeSubmit?: (values: Unstructured, setErrors: (errors: string[]) => void) => Promise<Unstructured>;
|
|
31
|
+
onBeforeSubmitError?: (errors: string[]) => void;
|
|
30
32
|
rules?: YamlFormRule[];
|
|
31
33
|
};
|
|
32
34
|
export type UseFormReturnType<TQueryFnData extends BaseRecord = BaseRecord, TError extends HttpError = HttpError, TVariables extends object = object, TData extends BaseRecord = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError> = UseFormReturnTypeCore<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError> & {
|
|
@@ -43,6 +45,7 @@ export type UseFormReturnType<TQueryFnData extends BaseRecord = BaseRecord, TErr
|
|
|
43
45
|
loadSchemaError: Error | null;
|
|
44
46
|
fetchSchema: () => void;
|
|
45
47
|
errorResponseBody?: Record<string, unknown> | null;
|
|
48
|
+
beforeSubmitErrors: string[];
|
|
46
49
|
};
|
|
47
50
|
declare const useYamlForm: <TQueryFnData extends Unstructured = Unstructured & {
|
|
48
51
|
id: string;
|
|
@@ -50,5 +53,5 @@ declare const useYamlForm: <TQueryFnData extends Unstructured = Unstructured & {
|
|
|
50
53
|
[prop: string]: unknown;
|
|
51
54
|
} = {
|
|
52
55
|
[prop: string]: unknown;
|
|
53
|
-
}, TData extends Unstructured = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError>({ action: actionFromProps, resource, onMutationSuccess: onMutationSuccessProp, onMutationError, submitOnEnter, warnWhenUnsavedChanges: warnWhenUnsavedChangesProp, redirect, successNotification, errorNotification, meta, metaData, queryMeta, mutationMeta, liveMode, liveParams, mutationMode, dataProviderName, onLiveEvent, invalidates, undoableTimeout, queryOptions, createMutationOptions, updateMutationOptions, id: idFromProps, overtimeOptions, editorOptions, initialValuesForCreate, initialValuesForEdit, transformInitValues, transformApplyValues, rules, }?: UseFormProps<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>) => UseFormReturnType<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>;
|
|
56
|
+
}, TData extends Unstructured = TQueryFnData, TResponse extends BaseRecord = TData, TResponseError extends HttpError = TError>({ action: actionFromProps, resource, onMutationSuccess: onMutationSuccessProp, onMutationError, submitOnEnter, warnWhenUnsavedChanges: warnWhenUnsavedChangesProp, redirect, successNotification, errorNotification, meta, metaData, queryMeta, mutationMeta, liveMode, liveParams, mutationMode, dataProviderName, onLiveEvent, invalidates, undoableTimeout, queryOptions, createMutationOptions, updateMutationOptions, id: idFromProps, overtimeOptions, editorOptions, initialValuesForCreate, initialValuesForEdit, transformInitValues, transformApplyValues, beforeSubmit, onBeforeSubmitError, rules, }?: UseFormProps<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>) => UseFormReturnType<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>;
|
|
54
57
|
export default useYamlForm;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export * from './useDownloadYAML';
|
|
|
6
6
|
export * from './useEdit';
|
|
7
7
|
export * from './useGlobalStore';
|
|
8
8
|
export * from './useOpenForm';
|
|
9
|
+
export * from './useSubmitForm';
|
|
9
10
|
export { default as useNamespaceRefineFilter } from './useNamespaceRefineFilter';
|
|
10
11
|
export * from './useRefineFilters';
|
package/dist/i18n.d.ts
CHANGED
|
@@ -204,6 +204,7 @@ export declare const resources: {
|
|
|
204
204
|
edit_distribute_storage: string;
|
|
205
205
|
edit_distribute_storage_success_toast: string;
|
|
206
206
|
edit_distribute_storage_failed_toast: string;
|
|
207
|
+
edit_taint: string;
|
|
207
208
|
edit_node_taint: string;
|
|
208
209
|
edit_node_taint_success_toast: string;
|
|
209
210
|
node_taint_NoSchedule: string;
|
|
@@ -455,6 +456,7 @@ export declare const resources: {
|
|
|
455
456
|
edit_distribute_storage: string;
|
|
456
457
|
edit_distribute_storage_success_toast: string;
|
|
457
458
|
edit_distribute_storage_failed_toast: string;
|
|
459
|
+
edit_taint: string;
|
|
458
460
|
edit_node_taint: string;
|
|
459
461
|
edit_node_taint_success_toast: string;
|
|
460
462
|
node_taint_NoSchedule: string;
|
|
@@ -201,6 +201,7 @@ declare const _default: {
|
|
|
201
201
|
edit_distribute_storage: string;
|
|
202
202
|
edit_distribute_storage_success_toast: string;
|
|
203
203
|
edit_distribute_storage_failed_toast: string;
|
|
204
|
+
edit_taint: string;
|
|
204
205
|
edit_node_taint: string;
|
|
205
206
|
edit_node_taint_success_toast: string;
|
|
206
207
|
node_taint_NoSchedule: string;
|
|
@@ -199,6 +199,7 @@ declare const _default: {
|
|
|
199
199
|
edit_distribute_storage: string;
|
|
200
200
|
edit_distribute_storage_success_toast: string;
|
|
201
201
|
edit_distribute_storage_failed_toast: string;
|
|
202
|
+
edit_taint: string;
|
|
202
203
|
edit_node_taint: string;
|
|
203
204
|
edit_node_taint_success_toast: string;
|
|
204
205
|
node_taint_NoSchedule: string;
|
package/dist/refine.cjs
CHANGED
|
@@ -658,6 +658,7 @@ const allow_expand$1 = "Volume expansion";
|
|
|
658
658
|
const edit_distribute_storage$1 = "Edit capacity allocation";
|
|
659
659
|
const edit_distribute_storage_success_toast$1 = "Successfully edited the capacity allocation";
|
|
660
660
|
const edit_distribute_storage_failed_toast$1 = "Failed to edit the capacity allocation";
|
|
661
|
+
const edit_taint$1 = "Edit taint";
|
|
661
662
|
const edit_node_taint$1 = "Edit taint";
|
|
662
663
|
const edit_node_taint_success_toast$1 = "Successfully edited the taint for the node {{name}}";
|
|
663
664
|
const node_taint_NoSchedule$1 = "NoSchedule";
|
|
@@ -675,7 +676,7 @@ const taint_effect_empty_text$1 = "Please select an effect.";
|
|
|
675
676
|
const add_label$1 = "Add label";
|
|
676
677
|
const add_annotation$1 = "Add annotation";
|
|
677
678
|
const add_taint$1 = "Add taint";
|
|
678
|
-
const look_format_requirement$1 = "View
|
|
679
|
+
const look_format_requirement$1 = "View format requirements";
|
|
679
680
|
const yes$1 = "Yes";
|
|
680
681
|
const no$1 = "No";
|
|
681
682
|
const contains$1 = "Contains";
|
|
@@ -908,6 +909,7 @@ const dovetail$1 = {
|
|
|
908
909
|
edit_distribute_storage: edit_distribute_storage$1,
|
|
909
910
|
edit_distribute_storage_success_toast: edit_distribute_storage_success_toast$1,
|
|
910
911
|
edit_distribute_storage_failed_toast: edit_distribute_storage_failed_toast$1,
|
|
912
|
+
edit_taint: edit_taint$1,
|
|
911
913
|
edit_node_taint: edit_node_taint$1,
|
|
912
914
|
edit_node_taint_success_toast: edit_node_taint_success_toast$1,
|
|
913
915
|
node_taint_NoSchedule: node_taint_NoSchedule$1,
|
|
@@ -1156,6 +1158,7 @@ const allow_expand = "卷扩容";
|
|
|
1156
1158
|
const edit_distribute_storage = "编辑分配量";
|
|
1157
1159
|
const edit_distribute_storage_success_toast = "编辑分配量成功";
|
|
1158
1160
|
const edit_distribute_storage_failed_toast = "编辑分配量失败";
|
|
1161
|
+
const edit_taint = "编辑污点";
|
|
1159
1162
|
const edit_node_taint = "编辑污点";
|
|
1160
1163
|
const edit_node_taint_success_toast = "编辑节点 {{name}} 的污点成功";
|
|
1161
1164
|
const node_taint_NoSchedule = "仅阻止调度";
|
|
@@ -1427,6 +1430,7 @@ const dovetail = {
|
|
|
1427
1430
|
edit_distribute_storage,
|
|
1428
1431
|
edit_distribute_storage_success_toast,
|
|
1429
1432
|
edit_distribute_storage_failed_toast,
|
|
1433
|
+
edit_taint,
|
|
1430
1434
|
edit_node_taint,
|
|
1431
1435
|
edit_node_taint_success_toast,
|
|
1432
1436
|
node_taint_NoSchedule,
|
|
@@ -15486,6 +15490,8 @@ const useForm = ({
|
|
|
15486
15490
|
disableServerSideValidation: disableServerSideValidationProp = false,
|
|
15487
15491
|
transformApplyValues,
|
|
15488
15492
|
transformInitValues,
|
|
15493
|
+
beforeSubmit,
|
|
15494
|
+
onBeforeSubmitError,
|
|
15489
15495
|
...rest
|
|
15490
15496
|
} = {}) => {
|
|
15491
15497
|
const { options } = core.useRefineContext();
|
|
@@ -15498,6 +15504,8 @@ const useForm = ({
|
|
|
15498
15504
|
defaultValues: transformInitValues && typeof rest.defaultValues === "object" ? transformInitValues(rest.defaultValues) : rest.defaultValues
|
|
15499
15505
|
});
|
|
15500
15506
|
const [transformedInitValues, setTransformedInitValues] = React.useState(useHookFormResult.getValues());
|
|
15507
|
+
const [beforeSubmitErrors, setBeforeSubmitErrors] = React.useState([]);
|
|
15508
|
+
const [isBeforeSubmitLoading, setIsBeforeSubmitLoading] = React.useState(false);
|
|
15501
15509
|
const {
|
|
15502
15510
|
watch,
|
|
15503
15511
|
setValue,
|
|
@@ -15601,20 +15609,55 @@ const useForm = ({
|
|
|
15601
15609
|
const saveButtonProps = React.useMemo(() => {
|
|
15602
15610
|
return {
|
|
15603
15611
|
disabled: formLoading,
|
|
15604
|
-
|
|
15612
|
+
loading: formLoading || isBeforeSubmitLoading,
|
|
15613
|
+
onClick: async (e2) => {
|
|
15614
|
+
setBeforeSubmitErrors([]);
|
|
15605
15615
|
handleSubmit(
|
|
15606
|
-
(v) =>
|
|
15616
|
+
async (v) => {
|
|
15617
|
+
let finalValues = transformApplyValues ? transformApplyValues(v) : v;
|
|
15618
|
+
if (beforeSubmit) {
|
|
15619
|
+
try {
|
|
15620
|
+
setIsBeforeSubmitLoading(true);
|
|
15621
|
+
let hasErrors = false;
|
|
15622
|
+
const result = await beforeSubmit(finalValues, (errors) => {
|
|
15623
|
+
if (errors && errors.length > 0) {
|
|
15624
|
+
setBeforeSubmitErrors(errors);
|
|
15625
|
+
onBeforeSubmitError == null ? void 0 : onBeforeSubmitError(errors);
|
|
15626
|
+
hasErrors = true;
|
|
15627
|
+
}
|
|
15628
|
+
});
|
|
15629
|
+
if (hasErrors) {
|
|
15630
|
+
return;
|
|
15631
|
+
}
|
|
15632
|
+
if (result !== void 0) {
|
|
15633
|
+
finalValues = result;
|
|
15634
|
+
}
|
|
15635
|
+
} finally {
|
|
15636
|
+
setIsBeforeSubmitLoading(false);
|
|
15637
|
+
}
|
|
15638
|
+
}
|
|
15639
|
+
return onFinish(finalValues);
|
|
15640
|
+
},
|
|
15607
15641
|
() => false
|
|
15608
15642
|
)(e2);
|
|
15609
15643
|
}
|
|
15610
15644
|
};
|
|
15611
|
-
}, [
|
|
15645
|
+
}, [
|
|
15646
|
+
formLoading,
|
|
15647
|
+
isBeforeSubmitLoading,
|
|
15648
|
+
handleSubmit,
|
|
15649
|
+
onFinish,
|
|
15650
|
+
transformApplyValues,
|
|
15651
|
+
beforeSubmit,
|
|
15652
|
+
onBeforeSubmitError
|
|
15653
|
+
]);
|
|
15612
15654
|
return {
|
|
15613
15655
|
...useHookFormResult,
|
|
15614
15656
|
transformedInitValues,
|
|
15615
15657
|
handleSubmit,
|
|
15616
15658
|
refineCore: useFormCoreResult,
|
|
15617
|
-
saveButtonProps
|
|
15659
|
+
saveButtonProps,
|
|
15660
|
+
beforeSubmitErrors
|
|
15618
15661
|
};
|
|
15619
15662
|
};
|
|
15620
15663
|
const useRefineForm = (props) => {
|
|
@@ -15656,6 +15699,8 @@ const useRefineForm = (props) => {
|
|
|
15656
15699
|
defaultValues: (options == null ? void 0 : options.initialValues) || (config == null ? void 0 : config.initValue),
|
|
15657
15700
|
transformApplyValues,
|
|
15658
15701
|
transformInitValues,
|
|
15702
|
+
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
15703
|
+
onBeforeSubmitError: options == null ? void 0 : options.onBeforeSubmitError,
|
|
15659
15704
|
...formConfig == null ? void 0 : formConfig.useFormProps
|
|
15660
15705
|
});
|
|
15661
15706
|
React.useEffect(() => {
|
|
@@ -15668,7 +15713,7 @@ const useRefineForm = (props) => {
|
|
|
15668
15713
|
});
|
|
15669
15714
|
}
|
|
15670
15715
|
}, [formConfig, result, i18n2]);
|
|
15671
|
-
return { formResult: result, responseErrorMsgs };
|
|
15716
|
+
return { formResult: result, responseErrorMsgs, beforeSubmitErrors: result.beforeSubmitErrors };
|
|
15672
15717
|
};
|
|
15673
15718
|
const index_2ivb33 = "";
|
|
15674
15719
|
const Style = "s1bsn3us";
|
|
@@ -16087,6 +16132,8 @@ const useYamlForm = ({
|
|
|
16087
16132
|
initialValuesForEdit,
|
|
16088
16133
|
transformInitValues,
|
|
16089
16134
|
transformApplyValues,
|
|
16135
|
+
beforeSubmit,
|
|
16136
|
+
onBeforeSubmitError,
|
|
16090
16137
|
rules
|
|
16091
16138
|
} = {}) => {
|
|
16092
16139
|
var _a;
|
|
@@ -16096,6 +16143,8 @@ const useYamlForm = ({
|
|
|
16096
16143
|
const [isSchemaValid, setIsSchemaValid] = React.useState(true);
|
|
16097
16144
|
const [editorErrors, setEditorErrors] = React.useState([]);
|
|
16098
16145
|
const [rulesErrors, setRulesErrors] = React.useState([]);
|
|
16146
|
+
const [isBeforeSubmitLoading, setIsBeforeSubmitLoading] = React.useState(false);
|
|
16147
|
+
const [beforeSubmitErrors, setBeforeSubmitErrors] = React.useState([]);
|
|
16099
16148
|
const [errorResponseBody, setErrorResponseBody] = React.useState(null);
|
|
16100
16149
|
const useResourceResult = core.useResource();
|
|
16101
16150
|
const globalStore = useGlobalStore();
|
|
@@ -16171,12 +16220,12 @@ const useYamlForm = ({
|
|
|
16171
16220
|
}, [schema]);
|
|
16172
16221
|
const saveButtonProps = React.useMemo(
|
|
16173
16222
|
() => ({
|
|
16174
|
-
loading: formLoading,
|
|
16223
|
+
loading: formLoading || isBeforeSubmitLoading,
|
|
16175
16224
|
onClick: () => {
|
|
16176
16225
|
form2.submit();
|
|
16177
16226
|
}
|
|
16178
16227
|
}),
|
|
16179
|
-
[formLoading, form2]
|
|
16228
|
+
[formLoading, form2, isBeforeSubmitLoading]
|
|
16180
16229
|
);
|
|
16181
16230
|
const emptySchemas = React.useMemo(() => {
|
|
16182
16231
|
return [];
|
|
@@ -16253,6 +16302,7 @@ const useYamlForm = ({
|
|
|
16253
16302
|
...formSF.formProps,
|
|
16254
16303
|
onFinish: async (values) => {
|
|
16255
16304
|
var _a2, _b;
|
|
16305
|
+
setBeforeSubmitErrors([]);
|
|
16256
16306
|
const errors = [
|
|
16257
16307
|
!isYamlValid ? t2("dovetail.yaml_format_wrong") : "",
|
|
16258
16308
|
!isSchemaValid ? t2("dovetail.yaml_value_wrong") : ""
|
|
@@ -16269,7 +16319,28 @@ const useYamlForm = ({
|
|
|
16269
16319
|
}
|
|
16270
16320
|
try {
|
|
16271
16321
|
const objectValues = editor.current ? yaml$2.load(((_b = editor.current) == null ? void 0 : _b.getEditorValue()) || "") : values;
|
|
16272
|
-
|
|
16322
|
+
let finalValues = (transformApplyValues == null ? void 0 : transformApplyValues(objectValues)) || objectValues;
|
|
16323
|
+
if (beforeSubmit) {
|
|
16324
|
+
try {
|
|
16325
|
+
let hasErrors = false;
|
|
16326
|
+
setIsBeforeSubmitLoading(true);
|
|
16327
|
+
const result = await beforeSubmit(finalValues, (errors2) => {
|
|
16328
|
+
if (errors2 && errors2.length > 0) {
|
|
16329
|
+
setBeforeSubmitErrors(errors2);
|
|
16330
|
+
onBeforeSubmitError == null ? void 0 : onBeforeSubmitError(errors2);
|
|
16331
|
+
hasErrors = true;
|
|
16332
|
+
}
|
|
16333
|
+
});
|
|
16334
|
+
if (hasErrors) {
|
|
16335
|
+
return;
|
|
16336
|
+
}
|
|
16337
|
+
if (result !== void 0) {
|
|
16338
|
+
finalValues = result;
|
|
16339
|
+
}
|
|
16340
|
+
} finally {
|
|
16341
|
+
setIsBeforeSubmitLoading(false);
|
|
16342
|
+
}
|
|
16343
|
+
}
|
|
16273
16344
|
return onFinish(finalValues);
|
|
16274
16345
|
} catch (error) {
|
|
16275
16346
|
if (error instanceof Error) {
|
|
@@ -16289,6 +16360,7 @@ const useYamlForm = ({
|
|
|
16289
16360
|
saveButtonProps,
|
|
16290
16361
|
...useFormCoreResult,
|
|
16291
16362
|
errorResponseBody,
|
|
16363
|
+
beforeSubmitErrors,
|
|
16292
16364
|
editorProps,
|
|
16293
16365
|
schemas: schema ? [schema] : [],
|
|
16294
16366
|
isLoadingSchema,
|
|
@@ -16316,6 +16388,7 @@ function YamlForm(props) {
|
|
|
16316
16388
|
config,
|
|
16317
16389
|
transformInitValues,
|
|
16318
16390
|
transformApplyValues,
|
|
16391
|
+
beforeSubmit,
|
|
16319
16392
|
onSaveButtonPropsChange,
|
|
16320
16393
|
onErrorsChange,
|
|
16321
16394
|
rules
|
|
@@ -16336,6 +16409,7 @@ function YamlForm(props) {
|
|
|
16336
16409
|
saveButtonProps,
|
|
16337
16410
|
editorProps,
|
|
16338
16411
|
errorResponseBody,
|
|
16412
|
+
beforeSubmitErrors,
|
|
16339
16413
|
mutationResult,
|
|
16340
16414
|
isLoadingSchema,
|
|
16341
16415
|
queryResult,
|
|
@@ -16352,6 +16426,7 @@ function YamlForm(props) {
|
|
|
16352
16426
|
initialValuesForCreate: props.initialValuesForCreate ?? BASE_INIT_VALUE,
|
|
16353
16427
|
initialValuesForEdit: props.initialValuesForEdit,
|
|
16354
16428
|
rules,
|
|
16429
|
+
beforeSubmit,
|
|
16355
16430
|
successNotification(data2) {
|
|
16356
16431
|
var _a;
|
|
16357
16432
|
const displayName = config.displayName || ((_a = resource == null ? void 0 : resource.meta) == null ? void 0 : _a.kind);
|
|
@@ -16379,6 +16454,18 @@ function YamlForm(props) {
|
|
|
16379
16454
|
saveButtonProps
|
|
16380
16455
|
} : {};
|
|
16381
16456
|
const responseErrors = React.useMemo(() => errorResponseBody ? getCommonErrors(errorResponseBody, i18n2) : [], [errorResponseBody, i18n2]);
|
|
16457
|
+
const finalErrors = React.useMemo(() => {
|
|
16458
|
+
if (beforeSubmitErrors.length) {
|
|
16459
|
+
return beforeSubmitErrors;
|
|
16460
|
+
}
|
|
16461
|
+
if (mutationResult.error) {
|
|
16462
|
+
if (responseErrors.length) {
|
|
16463
|
+
return responseErrors;
|
|
16464
|
+
}
|
|
16465
|
+
return [mutationResult.error.message];
|
|
16466
|
+
}
|
|
16467
|
+
return [];
|
|
16468
|
+
}, [responseErrors, beforeSubmitErrors, mutationResult.error]);
|
|
16382
16469
|
const onFinish = React.useCallback(async (store) => {
|
|
16383
16470
|
var _a, _b;
|
|
16384
16471
|
try {
|
|
@@ -16398,8 +16485,8 @@ function YamlForm(props) {
|
|
|
16398
16485
|
onSaveButtonPropsChange == null ? void 0 : onSaveButtonPropsChange(saveButtonProps);
|
|
16399
16486
|
}, [saveButtonProps, onSaveButtonPropsChange]);
|
|
16400
16487
|
React.useEffect(() => {
|
|
16401
|
-
onErrorsChange == null ? void 0 : onErrorsChange(
|
|
16402
|
-
}, [
|
|
16488
|
+
onErrorsChange == null ? void 0 : onErrorsChange(finalErrors);
|
|
16489
|
+
}, [finalErrors, onErrorsChange]);
|
|
16403
16490
|
return /* @__PURE__ */ common.jsxRuntimeExports.jsx(FormWrapper, {
|
|
16404
16491
|
...formWrapperProps,
|
|
16405
16492
|
children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(eagle.Form, {
|
|
@@ -16423,8 +16510,8 @@ function YamlForm(props) {
|
|
|
16423
16510
|
collapsable: false
|
|
16424
16511
|
})
|
|
16425
16512
|
}), /* @__PURE__ */ common.jsxRuntimeExports.jsx(eagle.Form.Item, {
|
|
16426
|
-
children:
|
|
16427
|
-
errorMsgs:
|
|
16513
|
+
children: finalErrors.length > 0 && /* @__PURE__ */ common.jsxRuntimeExports.jsx(FormErrorAlert, {
|
|
16514
|
+
errorMsgs: finalErrors,
|
|
16428
16515
|
style: {
|
|
16429
16516
|
marginBottom: 16
|
|
16430
16517
|
},
|
|
@@ -16470,7 +16557,14 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16470
16557
|
...formConfig == null ? void 0 : formConfig.refineCoreProps
|
|
16471
16558
|
},
|
|
16472
16559
|
formConfig,
|
|
16473
|
-
options
|
|
16560
|
+
options: {
|
|
16561
|
+
...options,
|
|
16562
|
+
onBeforeSubmitError: (errors) => {
|
|
16563
|
+
if (errors.length) {
|
|
16564
|
+
onError == null ? void 0 : onError();
|
|
16565
|
+
}
|
|
16566
|
+
}
|
|
16567
|
+
}
|
|
16474
16568
|
});
|
|
16475
16569
|
const fieldsConfig = useFieldsConfig(
|
|
16476
16570
|
config,
|
|
@@ -16512,6 +16606,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16512
16606
|
validators: "validators" in config2 ? config2.validators : void 0
|
|
16513
16607
|
})),
|
|
16514
16608
|
onSaveButtonPropsChange,
|
|
16609
|
+
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16515
16610
|
onErrorsChange(errors) {
|
|
16516
16611
|
if (errors.length) {
|
|
16517
16612
|
onError == null ? void 0 : onError();
|
|
@@ -16531,6 +16626,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16531
16626
|
config,
|
|
16532
16627
|
id,
|
|
16533
16628
|
refineFormResult,
|
|
16629
|
+
formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16534
16630
|
transformApplyValues,
|
|
16535
16631
|
onSaveButtonPropsChange,
|
|
16536
16632
|
onSuccess,
|
|
@@ -16572,7 +16668,10 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16572
16668
|
config,
|
|
16573
16669
|
step,
|
|
16574
16670
|
formConfig,
|
|
16575
|
-
errorMsgs:
|
|
16671
|
+
errorMsgs: [
|
|
16672
|
+
...refineFormResult.responseErrorMsgs,
|
|
16673
|
+
...refineFormResult.beforeSubmitErrors
|
|
16674
|
+
],
|
|
16576
16675
|
resourceId: id,
|
|
16577
16676
|
transformedInitValues: refineFormResult.formResult.transformedInitValues,
|
|
16578
16677
|
customOptions: options == null ? void 0 : options.customOptions
|
|
@@ -16602,6 +16701,7 @@ function YamlFormContainer({
|
|
|
16602
16701
|
config,
|
|
16603
16702
|
transformInitValues,
|
|
16604
16703
|
transformApplyValues,
|
|
16704
|
+
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16605
16705
|
initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(config),
|
|
16606
16706
|
initialValuesForEdit: void 0,
|
|
16607
16707
|
id,
|
|
@@ -16624,6 +16724,7 @@ function YamlFormContainer({
|
|
|
16624
16724
|
action,
|
|
16625
16725
|
customYamlFormProps,
|
|
16626
16726
|
config,
|
|
16727
|
+
formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16627
16728
|
transformInitValues,
|
|
16628
16729
|
transformApplyValues,
|
|
16629
16730
|
onSuccess,
|
|
@@ -19959,6 +20060,7 @@ exports.EditFieldModal = EditFieldModal;
|
|
|
19959
20060
|
exports.EditLabelDropdownMenuItem = EditLabelDropdownMenuItem;
|
|
19960
20061
|
exports.EditLabelForm = EditLabelForm;
|
|
19961
20062
|
exports.EditNodeTaintDropdownMenuItem = EditNodeTaintDropdownMenuItem;
|
|
20063
|
+
exports.EditNodeTaintForm = EditNodeTaintForm;
|
|
19962
20064
|
exports.ErrorContent = WidgetErrorContent;
|
|
19963
20065
|
exports.ErrorContentType = ErrorContentType;
|
|
19964
20066
|
exports.ErrorWrapper = ErrorWrapper;
|
|
@@ -20158,6 +20260,7 @@ exports.StorageClassPvGroup = StorageClassPvGroup;
|
|
|
20158
20260
|
exports.Table = Table;
|
|
20159
20261
|
exports.Tabs = Tabs;
|
|
20160
20262
|
exports.Tags = Tags;
|
|
20263
|
+
exports.TaintEffectTooltip = TaintEffectTooltip;
|
|
20161
20264
|
exports.TextTags = TextTags;
|
|
20162
20265
|
exports.Time = Time;
|
|
20163
20266
|
exports.ValidateRfc1035Name = ValidateRfc1035Name;
|
|
@@ -20205,6 +20308,7 @@ exports.useOpenForm = useOpenForm;
|
|
|
20205
20308
|
exports.useRefineFilters = useRefineFilters;
|
|
20206
20309
|
exports.useRefineForm = useRefineForm;
|
|
20207
20310
|
exports.useSchema = useSchema;
|
|
20311
|
+
exports.useSubmitForm = useSubmitForm;
|
|
20208
20312
|
exports.validateDataKey = validateDataKey;
|
|
20209
20313
|
exports.validateDnsSubdomainName = validateDnsSubdomainName;
|
|
20210
20314
|
exports.validateLabelKey = validateLabelKey;
|
package/dist/refine.js
CHANGED
|
@@ -639,6 +639,7 @@ const allow_expand$1 = "Volume expansion";
|
|
|
639
639
|
const edit_distribute_storage$1 = "Edit capacity allocation";
|
|
640
640
|
const edit_distribute_storage_success_toast$1 = "Successfully edited the capacity allocation";
|
|
641
641
|
const edit_distribute_storage_failed_toast$1 = "Failed to edit the capacity allocation";
|
|
642
|
+
const edit_taint$1 = "Edit taint";
|
|
642
643
|
const edit_node_taint$1 = "Edit taint";
|
|
643
644
|
const edit_node_taint_success_toast$1 = "Successfully edited the taint for the node {{name}}";
|
|
644
645
|
const node_taint_NoSchedule$1 = "NoSchedule";
|
|
@@ -656,7 +657,7 @@ const taint_effect_empty_text$1 = "Please select an effect.";
|
|
|
656
657
|
const add_label$1 = "Add label";
|
|
657
658
|
const add_annotation$1 = "Add annotation";
|
|
658
659
|
const add_taint$1 = "Add taint";
|
|
659
|
-
const look_format_requirement$1 = "View
|
|
660
|
+
const look_format_requirement$1 = "View format requirements";
|
|
660
661
|
const yes$1 = "Yes";
|
|
661
662
|
const no$1 = "No";
|
|
662
663
|
const contains$1 = "Contains";
|
|
@@ -889,6 +890,7 @@ const dovetail$1 = {
|
|
|
889
890
|
edit_distribute_storage: edit_distribute_storage$1,
|
|
890
891
|
edit_distribute_storage_success_toast: edit_distribute_storage_success_toast$1,
|
|
891
892
|
edit_distribute_storage_failed_toast: edit_distribute_storage_failed_toast$1,
|
|
893
|
+
edit_taint: edit_taint$1,
|
|
892
894
|
edit_node_taint: edit_node_taint$1,
|
|
893
895
|
edit_node_taint_success_toast: edit_node_taint_success_toast$1,
|
|
894
896
|
node_taint_NoSchedule: node_taint_NoSchedule$1,
|
|
@@ -1137,6 +1139,7 @@ const allow_expand = "卷扩容";
|
|
|
1137
1139
|
const edit_distribute_storage = "编辑分配量";
|
|
1138
1140
|
const edit_distribute_storage_success_toast = "编辑分配量成功";
|
|
1139
1141
|
const edit_distribute_storage_failed_toast = "编辑分配量失败";
|
|
1142
|
+
const edit_taint = "编辑污点";
|
|
1140
1143
|
const edit_node_taint = "编辑污点";
|
|
1141
1144
|
const edit_node_taint_success_toast = "编辑节点 {{name}} 的污点成功";
|
|
1142
1145
|
const node_taint_NoSchedule = "仅阻止调度";
|
|
@@ -1408,6 +1411,7 @@ const dovetail = {
|
|
|
1408
1411
|
edit_distribute_storage,
|
|
1409
1412
|
edit_distribute_storage_success_toast,
|
|
1410
1413
|
edit_distribute_storage_failed_toast,
|
|
1414
|
+
edit_taint,
|
|
1411
1415
|
edit_node_taint,
|
|
1412
1416
|
edit_node_taint_success_toast,
|
|
1413
1417
|
node_taint_NoSchedule,
|
|
@@ -15467,6 +15471,8 @@ const useForm = ({
|
|
|
15467
15471
|
disableServerSideValidation: disableServerSideValidationProp = false,
|
|
15468
15472
|
transformApplyValues,
|
|
15469
15473
|
transformInitValues,
|
|
15474
|
+
beforeSubmit,
|
|
15475
|
+
onBeforeSubmitError,
|
|
15470
15476
|
...rest
|
|
15471
15477
|
} = {}) => {
|
|
15472
15478
|
const { options } = useRefineContext();
|
|
@@ -15479,6 +15485,8 @@ const useForm = ({
|
|
|
15479
15485
|
defaultValues: transformInitValues && typeof rest.defaultValues === "object" ? transformInitValues(rest.defaultValues) : rest.defaultValues
|
|
15480
15486
|
});
|
|
15481
15487
|
const [transformedInitValues, setTransformedInitValues] = useState(useHookFormResult.getValues());
|
|
15488
|
+
const [beforeSubmitErrors, setBeforeSubmitErrors] = useState([]);
|
|
15489
|
+
const [isBeforeSubmitLoading, setIsBeforeSubmitLoading] = useState(false);
|
|
15482
15490
|
const {
|
|
15483
15491
|
watch,
|
|
15484
15492
|
setValue,
|
|
@@ -15582,20 +15590,55 @@ const useForm = ({
|
|
|
15582
15590
|
const saveButtonProps = useMemo(() => {
|
|
15583
15591
|
return {
|
|
15584
15592
|
disabled: formLoading,
|
|
15585
|
-
|
|
15593
|
+
loading: formLoading || isBeforeSubmitLoading,
|
|
15594
|
+
onClick: async (e2) => {
|
|
15595
|
+
setBeforeSubmitErrors([]);
|
|
15586
15596
|
handleSubmit(
|
|
15587
|
-
(v) =>
|
|
15597
|
+
async (v) => {
|
|
15598
|
+
let finalValues = transformApplyValues ? transformApplyValues(v) : v;
|
|
15599
|
+
if (beforeSubmit) {
|
|
15600
|
+
try {
|
|
15601
|
+
setIsBeforeSubmitLoading(true);
|
|
15602
|
+
let hasErrors = false;
|
|
15603
|
+
const result = await beforeSubmit(finalValues, (errors) => {
|
|
15604
|
+
if (errors && errors.length > 0) {
|
|
15605
|
+
setBeforeSubmitErrors(errors);
|
|
15606
|
+
onBeforeSubmitError == null ? void 0 : onBeforeSubmitError(errors);
|
|
15607
|
+
hasErrors = true;
|
|
15608
|
+
}
|
|
15609
|
+
});
|
|
15610
|
+
if (hasErrors) {
|
|
15611
|
+
return;
|
|
15612
|
+
}
|
|
15613
|
+
if (result !== void 0) {
|
|
15614
|
+
finalValues = result;
|
|
15615
|
+
}
|
|
15616
|
+
} finally {
|
|
15617
|
+
setIsBeforeSubmitLoading(false);
|
|
15618
|
+
}
|
|
15619
|
+
}
|
|
15620
|
+
return onFinish(finalValues);
|
|
15621
|
+
},
|
|
15588
15622
|
() => false
|
|
15589
15623
|
)(e2);
|
|
15590
15624
|
}
|
|
15591
15625
|
};
|
|
15592
|
-
}, [
|
|
15626
|
+
}, [
|
|
15627
|
+
formLoading,
|
|
15628
|
+
isBeforeSubmitLoading,
|
|
15629
|
+
handleSubmit,
|
|
15630
|
+
onFinish,
|
|
15631
|
+
transformApplyValues,
|
|
15632
|
+
beforeSubmit,
|
|
15633
|
+
onBeforeSubmitError
|
|
15634
|
+
]);
|
|
15593
15635
|
return {
|
|
15594
15636
|
...useHookFormResult,
|
|
15595
15637
|
transformedInitValues,
|
|
15596
15638
|
handleSubmit,
|
|
15597
15639
|
refineCore: useFormCoreResult,
|
|
15598
|
-
saveButtonProps
|
|
15640
|
+
saveButtonProps,
|
|
15641
|
+
beforeSubmitErrors
|
|
15599
15642
|
};
|
|
15600
15643
|
};
|
|
15601
15644
|
const useRefineForm = (props) => {
|
|
@@ -15637,6 +15680,8 @@ const useRefineForm = (props) => {
|
|
|
15637
15680
|
defaultValues: (options == null ? void 0 : options.initialValues) || (config == null ? void 0 : config.initValue),
|
|
15638
15681
|
transformApplyValues,
|
|
15639
15682
|
transformInitValues,
|
|
15683
|
+
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
15684
|
+
onBeforeSubmitError: options == null ? void 0 : options.onBeforeSubmitError,
|
|
15640
15685
|
...formConfig == null ? void 0 : formConfig.useFormProps
|
|
15641
15686
|
});
|
|
15642
15687
|
useEffect(() => {
|
|
@@ -15649,7 +15694,7 @@ const useRefineForm = (props) => {
|
|
|
15649
15694
|
});
|
|
15650
15695
|
}
|
|
15651
15696
|
}, [formConfig, result, i18n2]);
|
|
15652
|
-
return { formResult: result, responseErrorMsgs };
|
|
15697
|
+
return { formResult: result, responseErrorMsgs, beforeSubmitErrors: result.beforeSubmitErrors };
|
|
15653
15698
|
};
|
|
15654
15699
|
const index_2ivb33 = "";
|
|
15655
15700
|
const Style = "s1bsn3us";
|
|
@@ -16068,6 +16113,8 @@ const useYamlForm = ({
|
|
|
16068
16113
|
initialValuesForEdit,
|
|
16069
16114
|
transformInitValues,
|
|
16070
16115
|
transformApplyValues,
|
|
16116
|
+
beforeSubmit,
|
|
16117
|
+
onBeforeSubmitError,
|
|
16071
16118
|
rules
|
|
16072
16119
|
} = {}) => {
|
|
16073
16120
|
var _a;
|
|
@@ -16077,6 +16124,8 @@ const useYamlForm = ({
|
|
|
16077
16124
|
const [isSchemaValid, setIsSchemaValid] = useState(true);
|
|
16078
16125
|
const [editorErrors, setEditorErrors] = useState([]);
|
|
16079
16126
|
const [rulesErrors, setRulesErrors] = useState([]);
|
|
16127
|
+
const [isBeforeSubmitLoading, setIsBeforeSubmitLoading] = useState(false);
|
|
16128
|
+
const [beforeSubmitErrors, setBeforeSubmitErrors] = useState([]);
|
|
16080
16129
|
const [errorResponseBody, setErrorResponseBody] = useState(null);
|
|
16081
16130
|
const useResourceResult = useResource();
|
|
16082
16131
|
const globalStore = useGlobalStore();
|
|
@@ -16152,12 +16201,12 @@ const useYamlForm = ({
|
|
|
16152
16201
|
}, [schema]);
|
|
16153
16202
|
const saveButtonProps = useMemo(
|
|
16154
16203
|
() => ({
|
|
16155
|
-
loading: formLoading,
|
|
16204
|
+
loading: formLoading || isBeforeSubmitLoading,
|
|
16156
16205
|
onClick: () => {
|
|
16157
16206
|
form2.submit();
|
|
16158
16207
|
}
|
|
16159
16208
|
}),
|
|
16160
|
-
[formLoading, form2]
|
|
16209
|
+
[formLoading, form2, isBeforeSubmitLoading]
|
|
16161
16210
|
);
|
|
16162
16211
|
const emptySchemas = useMemo(() => {
|
|
16163
16212
|
return [];
|
|
@@ -16234,6 +16283,7 @@ const useYamlForm = ({
|
|
|
16234
16283
|
...formSF.formProps,
|
|
16235
16284
|
onFinish: async (values) => {
|
|
16236
16285
|
var _a2, _b;
|
|
16286
|
+
setBeforeSubmitErrors([]);
|
|
16237
16287
|
const errors = [
|
|
16238
16288
|
!isYamlValid ? t2("dovetail.yaml_format_wrong") : "",
|
|
16239
16289
|
!isSchemaValid ? t2("dovetail.yaml_value_wrong") : ""
|
|
@@ -16250,7 +16300,28 @@ const useYamlForm = ({
|
|
|
16250
16300
|
}
|
|
16251
16301
|
try {
|
|
16252
16302
|
const objectValues = editor.current ? yaml$2.load(((_b = editor.current) == null ? void 0 : _b.getEditorValue()) || "") : values;
|
|
16253
|
-
|
|
16303
|
+
let finalValues = (transformApplyValues == null ? void 0 : transformApplyValues(objectValues)) || objectValues;
|
|
16304
|
+
if (beforeSubmit) {
|
|
16305
|
+
try {
|
|
16306
|
+
let hasErrors = false;
|
|
16307
|
+
setIsBeforeSubmitLoading(true);
|
|
16308
|
+
const result = await beforeSubmit(finalValues, (errors2) => {
|
|
16309
|
+
if (errors2 && errors2.length > 0) {
|
|
16310
|
+
setBeforeSubmitErrors(errors2);
|
|
16311
|
+
onBeforeSubmitError == null ? void 0 : onBeforeSubmitError(errors2);
|
|
16312
|
+
hasErrors = true;
|
|
16313
|
+
}
|
|
16314
|
+
});
|
|
16315
|
+
if (hasErrors) {
|
|
16316
|
+
return;
|
|
16317
|
+
}
|
|
16318
|
+
if (result !== void 0) {
|
|
16319
|
+
finalValues = result;
|
|
16320
|
+
}
|
|
16321
|
+
} finally {
|
|
16322
|
+
setIsBeforeSubmitLoading(false);
|
|
16323
|
+
}
|
|
16324
|
+
}
|
|
16254
16325
|
return onFinish(finalValues);
|
|
16255
16326
|
} catch (error) {
|
|
16256
16327
|
if (error instanceof Error) {
|
|
@@ -16270,6 +16341,7 @@ const useYamlForm = ({
|
|
|
16270
16341
|
saveButtonProps,
|
|
16271
16342
|
...useFormCoreResult,
|
|
16272
16343
|
errorResponseBody,
|
|
16344
|
+
beforeSubmitErrors,
|
|
16273
16345
|
editorProps,
|
|
16274
16346
|
schemas: schema ? [schema] : [],
|
|
16275
16347
|
isLoadingSchema,
|
|
@@ -16297,6 +16369,7 @@ function YamlForm(props) {
|
|
|
16297
16369
|
config,
|
|
16298
16370
|
transformInitValues,
|
|
16299
16371
|
transformApplyValues,
|
|
16372
|
+
beforeSubmit,
|
|
16300
16373
|
onSaveButtonPropsChange,
|
|
16301
16374
|
onErrorsChange,
|
|
16302
16375
|
rules
|
|
@@ -16317,6 +16390,7 @@ function YamlForm(props) {
|
|
|
16317
16390
|
saveButtonProps,
|
|
16318
16391
|
editorProps,
|
|
16319
16392
|
errorResponseBody,
|
|
16393
|
+
beforeSubmitErrors,
|
|
16320
16394
|
mutationResult,
|
|
16321
16395
|
isLoadingSchema,
|
|
16322
16396
|
queryResult,
|
|
@@ -16333,6 +16407,7 @@ function YamlForm(props) {
|
|
|
16333
16407
|
initialValuesForCreate: props.initialValuesForCreate ?? BASE_INIT_VALUE,
|
|
16334
16408
|
initialValuesForEdit: props.initialValuesForEdit,
|
|
16335
16409
|
rules,
|
|
16410
|
+
beforeSubmit,
|
|
16336
16411
|
successNotification(data2) {
|
|
16337
16412
|
var _a;
|
|
16338
16413
|
const displayName = config.displayName || ((_a = resource == null ? void 0 : resource.meta) == null ? void 0 : _a.kind);
|
|
@@ -16360,6 +16435,18 @@ function YamlForm(props) {
|
|
|
16360
16435
|
saveButtonProps
|
|
16361
16436
|
} : {};
|
|
16362
16437
|
const responseErrors = useMemo(() => errorResponseBody ? getCommonErrors(errorResponseBody, i18n2) : [], [errorResponseBody, i18n2]);
|
|
16438
|
+
const finalErrors = useMemo(() => {
|
|
16439
|
+
if (beforeSubmitErrors.length) {
|
|
16440
|
+
return beforeSubmitErrors;
|
|
16441
|
+
}
|
|
16442
|
+
if (mutationResult.error) {
|
|
16443
|
+
if (responseErrors.length) {
|
|
16444
|
+
return responseErrors;
|
|
16445
|
+
}
|
|
16446
|
+
return [mutationResult.error.message];
|
|
16447
|
+
}
|
|
16448
|
+
return [];
|
|
16449
|
+
}, [responseErrors, beforeSubmitErrors, mutationResult.error]);
|
|
16363
16450
|
const onFinish = useCallback(async (store) => {
|
|
16364
16451
|
var _a, _b;
|
|
16365
16452
|
try {
|
|
@@ -16379,8 +16466,8 @@ function YamlForm(props) {
|
|
|
16379
16466
|
onSaveButtonPropsChange == null ? void 0 : onSaveButtonPropsChange(saveButtonProps);
|
|
16380
16467
|
}, [saveButtonProps, onSaveButtonPropsChange]);
|
|
16381
16468
|
useEffect(() => {
|
|
16382
|
-
onErrorsChange == null ? void 0 : onErrorsChange(
|
|
16383
|
-
}, [
|
|
16469
|
+
onErrorsChange == null ? void 0 : onErrorsChange(finalErrors);
|
|
16470
|
+
}, [finalErrors, onErrorsChange]);
|
|
16384
16471
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(FormWrapper, {
|
|
16385
16472
|
...formWrapperProps,
|
|
16386
16473
|
children: /* @__PURE__ */ jsxRuntimeExports.jsx(Form, {
|
|
@@ -16404,8 +16491,8 @@ function YamlForm(props) {
|
|
|
16404
16491
|
collapsable: false
|
|
16405
16492
|
})
|
|
16406
16493
|
}), /* @__PURE__ */ jsxRuntimeExports.jsx(Form.Item, {
|
|
16407
|
-
children:
|
|
16408
|
-
errorMsgs:
|
|
16494
|
+
children: finalErrors.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(FormErrorAlert, {
|
|
16495
|
+
errorMsgs: finalErrors,
|
|
16409
16496
|
style: {
|
|
16410
16497
|
marginBottom: 16
|
|
16411
16498
|
},
|
|
@@ -16451,7 +16538,14 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16451
16538
|
...formConfig == null ? void 0 : formConfig.refineCoreProps
|
|
16452
16539
|
},
|
|
16453
16540
|
formConfig,
|
|
16454
|
-
options
|
|
16541
|
+
options: {
|
|
16542
|
+
...options,
|
|
16543
|
+
onBeforeSubmitError: (errors) => {
|
|
16544
|
+
if (errors.length) {
|
|
16545
|
+
onError == null ? void 0 : onError();
|
|
16546
|
+
}
|
|
16547
|
+
}
|
|
16548
|
+
}
|
|
16455
16549
|
});
|
|
16456
16550
|
const fieldsConfig = useFieldsConfig(
|
|
16457
16551
|
config,
|
|
@@ -16493,6 +16587,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16493
16587
|
validators: "validators" in config2 ? config2.validators : void 0
|
|
16494
16588
|
})),
|
|
16495
16589
|
onSaveButtonPropsChange,
|
|
16590
|
+
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16496
16591
|
onErrorsChange(errors) {
|
|
16497
16592
|
if (errors.length) {
|
|
16498
16593
|
onError == null ? void 0 : onError();
|
|
@@ -16512,6 +16607,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16512
16607
|
config,
|
|
16513
16608
|
id,
|
|
16514
16609
|
refineFormResult,
|
|
16610
|
+
formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16515
16611
|
transformApplyValues,
|
|
16516
16612
|
onSaveButtonPropsChange,
|
|
16517
16613
|
onSuccess,
|
|
@@ -16553,7 +16649,10 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16553
16649
|
config,
|
|
16554
16650
|
step,
|
|
16555
16651
|
formConfig,
|
|
16556
|
-
errorMsgs:
|
|
16652
|
+
errorMsgs: [
|
|
16653
|
+
...refineFormResult.responseErrorMsgs,
|
|
16654
|
+
...refineFormResult.beforeSubmitErrors
|
|
16655
|
+
],
|
|
16557
16656
|
resourceId: id,
|
|
16558
16657
|
transformedInitValues: refineFormResult.formResult.transformedInitValues,
|
|
16559
16658
|
customOptions: options == null ? void 0 : options.customOptions
|
|
@@ -16583,6 +16682,7 @@ function YamlFormContainer({
|
|
|
16583
16682
|
config,
|
|
16584
16683
|
transformInitValues,
|
|
16585
16684
|
transformApplyValues,
|
|
16685
|
+
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16586
16686
|
initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(config),
|
|
16587
16687
|
initialValuesForEdit: void 0,
|
|
16588
16688
|
id,
|
|
@@ -16605,6 +16705,7 @@ function YamlFormContainer({
|
|
|
16605
16705
|
action,
|
|
16606
16706
|
customYamlFormProps,
|
|
16607
16707
|
config,
|
|
16708
|
+
formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16608
16709
|
transformInitValues,
|
|
16609
16710
|
transformApplyValues,
|
|
16610
16711
|
onSuccess,
|
|
@@ -19941,6 +20042,7 @@ export {
|
|
|
19941
20042
|
EditLabelDropdownMenuItem,
|
|
19942
20043
|
EditLabelForm,
|
|
19943
20044
|
EditNodeTaintDropdownMenuItem,
|
|
20045
|
+
EditNodeTaintForm,
|
|
19944
20046
|
WidgetErrorContent as ErrorContent,
|
|
19945
20047
|
ErrorContentType,
|
|
19946
20048
|
ErrorWrapper,
|
|
@@ -20140,6 +20242,7 @@ export {
|
|
|
20140
20242
|
Table,
|
|
20141
20243
|
Tabs,
|
|
20142
20244
|
Tags,
|
|
20245
|
+
TaintEffectTooltip,
|
|
20143
20246
|
TextTags,
|
|
20144
20247
|
Time,
|
|
20145
20248
|
ValidateRfc1035Name,
|
|
@@ -20187,6 +20290,7 @@ export {
|
|
|
20187
20290
|
useRefineFilters,
|
|
20188
20291
|
useRefineForm,
|
|
20189
20292
|
useSchema,
|
|
20293
|
+
useSubmitForm,
|
|
20190
20294
|
validateDataKey,
|
|
20191
20295
|
validateDnsSubdomainName,
|
|
20192
20296
|
validateLabelKey,
|
package/dist/types/resource.d.ts
CHANGED
|
@@ -111,6 +111,13 @@ export type CommonFormConfig<Model extends ResourceModel = ResourceModel> = {
|
|
|
111
111
|
* @returns YAML格式的数据
|
|
112
112
|
*/
|
|
113
113
|
transformApplyValues?: (values: Record<string, unknown>) => Model['_rawYaml'];
|
|
114
|
+
/**
|
|
115
|
+
* 提交前回调函数
|
|
116
|
+
* @param values 表单值
|
|
117
|
+
* @param setErrors 设置错误信息的函数,如果调用此函数并传入错误信息,将阻止提交
|
|
118
|
+
* @returns 可选的处理后的值,如果返回值存在,将使用返回值替代原始值进行提交
|
|
119
|
+
*/
|
|
120
|
+
beforeSubmit?: (values: Record<string, unknown>, setErrors: (errors: string[]) => void) => Promise<Model['_rawYaml']>;
|
|
114
121
|
/** 表单容器类型:页面形式或模态框形式
|
|
115
122
|
* PAGE 或者 MODAL
|
|
116
123
|
*/
|