@dovetail-v2/refine 0.3.34 → 0.3.35
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/hooks/use409Retry.d.ts +20 -0
- package/dist/refine.cjs +51 -34
- package/dist/refine.js +51 -34
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Unstructured } from 'k8s-api-provider';
|
|
2
|
+
import { MutableRefObject, ReactNode } from 'react';
|
|
2
3
|
export type Retry409MetaOptions = {
|
|
3
4
|
/** 编辑表单打开时捕获的初始版本;通常由本 hook 自动捕获,外部一般不需要手动传入。 */
|
|
4
5
|
initialResource?: Unstructured;
|
|
@@ -25,6 +26,25 @@ type Use409RetryResult = {
|
|
|
25
26
|
/** 已合并 409 重试参数的 mutationMeta,应直接传给 refine useFormCore。 */
|
|
26
27
|
mutationMeta: Record<string, unknown>;
|
|
27
28
|
};
|
|
29
|
+
type InitialResourceRef = MutableRefObject<Unstructured | undefined>;
|
|
30
|
+
type Retry409ProviderProps = {
|
|
31
|
+
/** 需要共享同一份初始版本的表单内容,例如同一个编辑弹窗内的 FORM 和 YAML 模式。 */
|
|
32
|
+
children?: ReactNode;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* 为同一个编辑弹窗内的多个表单模式共享 409 重试初始版本。
|
|
36
|
+
*
|
|
37
|
+
* 背景:FORM 模式保存失败后,如果用户切换到 YAML 模式,YAML 表单会重新挂载。
|
|
38
|
+
* 如果每个模式都维护自己的初始版本,YAML 可能捕获到已经变化的服务端版本,
|
|
39
|
+
* 导致 provider 误以为初始版本和服务端版本一致,从而允许覆盖保存。
|
|
40
|
+
*
|
|
41
|
+
* 用法:在表单弹窗层包裹一次,内部所有 `use409Retry` 会共用同一个 ref。
|
|
42
|
+
*
|
|
43
|
+
* @param props - Provider 属性。
|
|
44
|
+
* @param props.children - 需要共享初始版本的子节点。
|
|
45
|
+
* @returns 包裹后的 React 节点。
|
|
46
|
+
*/
|
|
47
|
+
export declare function Retry409Provider({ children, }: Retry409ProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<InitialResourceRef | null>>;
|
|
28
48
|
/**
|
|
29
49
|
* 为 D2 编辑表单接入 Kubernetes PUT 409 自动恢复能力。
|
|
30
50
|
*
|
package/dist/refine.cjs
CHANGED
|
@@ -11053,6 +11053,19 @@ const useGlobalStore = (name2 = "default") => {
|
|
|
11053
11053
|
const globalStores = React.useContext(GlobalStoreContext);
|
|
11054
11054
|
return globalStores[name2];
|
|
11055
11055
|
};
|
|
11056
|
+
const ResourceVersionConflictRetryContext = React.createContext(null);
|
|
11057
|
+
function Retry409Provider({
|
|
11058
|
+
children
|
|
11059
|
+
}) {
|
|
11060
|
+
const initialResourceRef = React.useRef();
|
|
11061
|
+
return React.createElement(
|
|
11062
|
+
ResourceVersionConflictRetryContext.Provider,
|
|
11063
|
+
{
|
|
11064
|
+
value: initialResourceRef
|
|
11065
|
+
},
|
|
11066
|
+
children
|
|
11067
|
+
);
|
|
11068
|
+
}
|
|
11056
11069
|
function use409Retry({
|
|
11057
11070
|
action,
|
|
11058
11071
|
dataProviderName,
|
|
@@ -11061,7 +11074,9 @@ function use409Retry({
|
|
|
11061
11074
|
}) {
|
|
11062
11075
|
const { t: t2 } = common.useTranslation();
|
|
11063
11076
|
const globalStore = useGlobalStore(dataProviderName);
|
|
11064
|
-
const
|
|
11077
|
+
const sharedInitialResourceRef = React.useContext(ResourceVersionConflictRetryContext);
|
|
11078
|
+
const localInitialResourceRef = React.useRef();
|
|
11079
|
+
const initialResourceRef = sharedInitialResourceRef || localInitialResourceRef;
|
|
11065
11080
|
const isEditAction = action === "edit" || !!id;
|
|
11066
11081
|
const captureInitialResource = React.useCallback((resource) => {
|
|
11067
11082
|
var _a;
|
|
@@ -11073,7 +11088,7 @@ function use409Retry({
|
|
|
11073
11088
|
return;
|
|
11074
11089
|
}
|
|
11075
11090
|
initialResourceRef.current = lodashEs.cloneDeep(rawResource);
|
|
11076
|
-
}, [globalStore, isEditAction]);
|
|
11091
|
+
}, [globalStore, initialResourceRef, isEditAction]);
|
|
11077
11092
|
const retryMutationMeta = React.useMemo(() => {
|
|
11078
11093
|
const restMutationMeta = lodashEs.omit(mutationMeta, "resourceVersionConflictRetry");
|
|
11079
11094
|
if (!isEditAction) {
|
|
@@ -11089,7 +11104,7 @@ function use409Retry({
|
|
|
11089
11104
|
conflictMessage: t2("dovetail.resource_version_conflict")
|
|
11090
11105
|
}
|
|
11091
11106
|
};
|
|
11092
|
-
}, [isEditAction, mutationMeta, t2]);
|
|
11107
|
+
}, [initialResourceRef, isEditAction, mutationMeta, t2]);
|
|
11093
11108
|
return {
|
|
11094
11109
|
captureInitialResource,
|
|
11095
11110
|
mutationMeta: retryMutationMeta
|
|
@@ -17451,37 +17466,39 @@ function FormModal(props) {
|
|
|
17451
17466
|
setStep(nextStep);
|
|
17452
17467
|
}
|
|
17453
17468
|
}, [step]);
|
|
17454
|
-
return /* @__PURE__ */ common.jsxRuntimeExports.
|
|
17455
|
-
|
|
17456
|
-
|
|
17457
|
-
|
|
17458
|
-
|
|
17459
|
-
|
|
17460
|
-
|
|
17461
|
-
children:
|
|
17462
|
-
|
|
17463
|
-
formConfig:
|
|
17464
|
-
|
|
17465
|
-
|
|
17466
|
-
|
|
17467
|
-
|
|
17468
|
-
|
|
17469
|
-
|
|
17470
|
-
|
|
17471
|
-
|
|
17472
|
-
|
|
17473
|
-
|
|
17474
|
-
|
|
17475
|
-
|
|
17476
|
-
|
|
17477
|
-
|
|
17478
|
-
|
|
17479
|
-
|
|
17480
|
-
|
|
17481
|
-
|
|
17482
|
-
|
|
17483
|
-
|
|
17484
|
-
|
|
17469
|
+
return /* @__PURE__ */ common.jsxRuntimeExports.jsx(Retry409Provider, {
|
|
17470
|
+
children: /* @__PURE__ */ common.jsxRuntimeExports.jsxs(eagle.WizardDialog, {
|
|
17471
|
+
style: {
|
|
17472
|
+
"--max-modal-width": isYamlForm || !isDisabledChangeMode ? "1024px" : "648px"
|
|
17473
|
+
},
|
|
17474
|
+
title: /* @__PURE__ */ common.jsxRuntimeExports.jsxs("div", {
|
|
17475
|
+
className: TitleWrapperStyle,
|
|
17476
|
+
children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx("span", {
|
|
17477
|
+
children: title
|
|
17478
|
+
}), ((_b = resourceConfig.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ common.jsxRuntimeExports.jsx(FormModeSegmentControl, {
|
|
17479
|
+
formConfig: resourceConfig.formConfig,
|
|
17480
|
+
mode,
|
|
17481
|
+
onChangeMode
|
|
17482
|
+
}) : null]
|
|
17483
|
+
}),
|
|
17484
|
+
error: errorText,
|
|
17485
|
+
steps,
|
|
17486
|
+
step,
|
|
17487
|
+
onStepChange: handleStepChange,
|
|
17488
|
+
onOk,
|
|
17489
|
+
okButtonProps: {
|
|
17490
|
+
...lodashEs.omit(saveButtonProps, "onClick"),
|
|
17491
|
+
children: (_c = resourceConfig.formConfig) == null ? void 0 : _c.saveButtonText
|
|
17492
|
+
},
|
|
17493
|
+
okText: ((_d = resourceConfig.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
|
|
17494
|
+
destroyOnClose: true,
|
|
17495
|
+
destroyOtherStep: true,
|
|
17496
|
+
...modalProps,
|
|
17497
|
+
children: [desc ? /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", {
|
|
17498
|
+
className: FormDescStyle,
|
|
17499
|
+
children: desc
|
|
17500
|
+
}) : void 0, formEle]
|
|
17501
|
+
})
|
|
17485
17502
|
});
|
|
17486
17503
|
}
|
|
17487
17504
|
const RefineFormPage_1v0fhor = "";
|
package/dist/refine.js
CHANGED
|
@@ -11034,6 +11034,19 @@ const useGlobalStore = (name2 = "default") => {
|
|
|
11034
11034
|
const globalStores = useContext(GlobalStoreContext);
|
|
11035
11035
|
return globalStores[name2];
|
|
11036
11036
|
};
|
|
11037
|
+
const ResourceVersionConflictRetryContext = createContext(null);
|
|
11038
|
+
function Retry409Provider({
|
|
11039
|
+
children
|
|
11040
|
+
}) {
|
|
11041
|
+
const initialResourceRef = useRef();
|
|
11042
|
+
return createElement(
|
|
11043
|
+
ResourceVersionConflictRetryContext.Provider,
|
|
11044
|
+
{
|
|
11045
|
+
value: initialResourceRef
|
|
11046
|
+
},
|
|
11047
|
+
children
|
|
11048
|
+
);
|
|
11049
|
+
}
|
|
11037
11050
|
function use409Retry({
|
|
11038
11051
|
action,
|
|
11039
11052
|
dataProviderName,
|
|
@@ -11042,7 +11055,9 @@ function use409Retry({
|
|
|
11042
11055
|
}) {
|
|
11043
11056
|
const { t: t2 } = useTranslation();
|
|
11044
11057
|
const globalStore = useGlobalStore(dataProviderName);
|
|
11045
|
-
const
|
|
11058
|
+
const sharedInitialResourceRef = useContext(ResourceVersionConflictRetryContext);
|
|
11059
|
+
const localInitialResourceRef = useRef();
|
|
11060
|
+
const initialResourceRef = sharedInitialResourceRef || localInitialResourceRef;
|
|
11046
11061
|
const isEditAction = action === "edit" || !!id;
|
|
11047
11062
|
const captureInitialResource = useCallback((resource) => {
|
|
11048
11063
|
var _a;
|
|
@@ -11054,7 +11069,7 @@ function use409Retry({
|
|
|
11054
11069
|
return;
|
|
11055
11070
|
}
|
|
11056
11071
|
initialResourceRef.current = cloneDeep(rawResource);
|
|
11057
|
-
}, [globalStore, isEditAction]);
|
|
11072
|
+
}, [globalStore, initialResourceRef, isEditAction]);
|
|
11058
11073
|
const retryMutationMeta = useMemo(() => {
|
|
11059
11074
|
const restMutationMeta = omit$1(mutationMeta, "resourceVersionConflictRetry");
|
|
11060
11075
|
if (!isEditAction) {
|
|
@@ -11070,7 +11085,7 @@ function use409Retry({
|
|
|
11070
11085
|
conflictMessage: t2("dovetail.resource_version_conflict")
|
|
11071
11086
|
}
|
|
11072
11087
|
};
|
|
11073
|
-
}, [isEditAction, mutationMeta, t2]);
|
|
11088
|
+
}, [initialResourceRef, isEditAction, mutationMeta, t2]);
|
|
11074
11089
|
return {
|
|
11075
11090
|
captureInitialResource,
|
|
11076
11091
|
mutationMeta: retryMutationMeta
|
|
@@ -17432,37 +17447,39 @@ function FormModal(props) {
|
|
|
17432
17447
|
setStep(nextStep);
|
|
17433
17448
|
}
|
|
17434
17449
|
}, [step]);
|
|
17435
|
-
return /* @__PURE__ */ jsxRuntimeExports.
|
|
17436
|
-
|
|
17437
|
-
|
|
17438
|
-
|
|
17439
|
-
|
|
17440
|
-
|
|
17441
|
-
|
|
17442
|
-
children:
|
|
17443
|
-
|
|
17444
|
-
formConfig:
|
|
17445
|
-
|
|
17446
|
-
|
|
17447
|
-
|
|
17448
|
-
|
|
17449
|
-
|
|
17450
|
-
|
|
17451
|
-
|
|
17452
|
-
|
|
17453
|
-
|
|
17454
|
-
|
|
17455
|
-
|
|
17456
|
-
|
|
17457
|
-
|
|
17458
|
-
|
|
17459
|
-
|
|
17460
|
-
|
|
17461
|
-
|
|
17462
|
-
|
|
17463
|
-
|
|
17464
|
-
|
|
17465
|
-
|
|
17450
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Retry409Provider, {
|
|
17451
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsxs(WizardDialog, {
|
|
17452
|
+
style: {
|
|
17453
|
+
"--max-modal-width": isYamlForm || !isDisabledChangeMode ? "1024px" : "648px"
|
|
17454
|
+
},
|
|
17455
|
+
title: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", {
|
|
17456
|
+
className: TitleWrapperStyle,
|
|
17457
|
+
children: [/* @__PURE__ */ jsxRuntimeExports.jsx("span", {
|
|
17458
|
+
children: title
|
|
17459
|
+
}), ((_b = resourceConfig.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ jsxRuntimeExports.jsx(FormModeSegmentControl, {
|
|
17460
|
+
formConfig: resourceConfig.formConfig,
|
|
17461
|
+
mode,
|
|
17462
|
+
onChangeMode
|
|
17463
|
+
}) : null]
|
|
17464
|
+
}),
|
|
17465
|
+
error: errorText,
|
|
17466
|
+
steps,
|
|
17467
|
+
step,
|
|
17468
|
+
onStepChange: handleStepChange,
|
|
17469
|
+
onOk,
|
|
17470
|
+
okButtonProps: {
|
|
17471
|
+
...omit$1(saveButtonProps, "onClick"),
|
|
17472
|
+
children: (_c = resourceConfig.formConfig) == null ? void 0 : _c.saveButtonText
|
|
17473
|
+
},
|
|
17474
|
+
okText: ((_d = resourceConfig.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
|
|
17475
|
+
destroyOnClose: true,
|
|
17476
|
+
destroyOtherStep: true,
|
|
17477
|
+
...modalProps,
|
|
17478
|
+
children: [desc ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", {
|
|
17479
|
+
className: FormDescStyle,
|
|
17480
|
+
children: desc
|
|
17481
|
+
}) : void 0, formEle]
|
|
17482
|
+
})
|
|
17466
17483
|
});
|
|
17467
17484
|
}
|
|
17468
17485
|
const RefineFormPage_1v0fhor = "";
|