@dovetail-v2/refine 0.4.2-beta.0 → 0.4.3
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/LabelFormatPopover.d.ts +0 -1
- package/dist/components/Form/ExtraSubmitFooter.d.ts +23 -0
- package/dist/components/Form/FormModal.d.ts +1 -1
- package/dist/components/Form/RawYamlFormModal.d.ts +1 -1
- package/dist/components/Form/RefineFormContainer.d.ts +1 -1
- package/dist/components/Form/useReactHookForm.d.ts +1 -2
- package/dist/components/Form/useRefineForm.d.ts +1 -1
- package/dist/components/KeyValueTableForm/FormatRulePopover.d.ts +7 -0
- package/dist/components/KeyValueTableForm/index.d.ts +3 -1
- package/dist/hooks/use409Retry.d.ts +68 -0
- package/dist/hooks/useOpenForm.d.ts +1 -1
- package/dist/i18n.d.ts +6 -0
- package/dist/locales/en-US/index.d.ts +3 -0
- package/dist/locales/zh-CN/index.d.ts +3 -0
- package/dist/refine.cjs +389 -252
- package/dist/refine.js +392 -255
- package/dist/style.css +148 -130
- package/dist/types/resource.d.ts +24 -0
- package/package.json +2 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RefineFormConfig } from 'src/types';
|
|
3
|
+
import { type SaveButtonProps } from './FormModal';
|
|
4
|
+
interface UseExtraSubmitFooterOptions {
|
|
5
|
+
action: 'create' | 'edit';
|
|
6
|
+
cancelText: React.ReactNode;
|
|
7
|
+
defaultSubmitText: React.ReactNode;
|
|
8
|
+
errorText: React.ReactNode;
|
|
9
|
+
extraSubmitButton?: RefineFormConfig['extraSubmitButton'];
|
|
10
|
+
fallbackFooter?: React.ReactNode;
|
|
11
|
+
isYamlMode: boolean;
|
|
12
|
+
nextStepText: React.ReactNode;
|
|
13
|
+
prevStepText: React.ReactNode;
|
|
14
|
+
saveButtonProps: SaveButtonProps;
|
|
15
|
+
step: number;
|
|
16
|
+
stepCount: number;
|
|
17
|
+
onCancel: () => void;
|
|
18
|
+
onNextStep: () => void;
|
|
19
|
+
onPrevStep: () => void;
|
|
20
|
+
onSubmit: (e: React.BaseSyntheticEvent) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare function useExtraSubmitFooter({ action, cancelText, defaultSubmitText, errorText, extraSubmitButton, fallbackFooter, isYamlMode, nextStepText, prevStepText, saveButtonProps, step, stepCount, onCancel, onNextStep, onPrevStep, onSubmit, }: UseExtraSubmitFooterOptions): React.ReactNode;
|
|
23
|
+
export {};
|
|
@@ -17,7 +17,7 @@ export interface ConfirmModalProps {
|
|
|
17
17
|
}
|
|
18
18
|
export type FormModalProps = {
|
|
19
19
|
id?: string;
|
|
20
|
-
resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig'>;
|
|
20
|
+
resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig' | 'dataProviderName'>;
|
|
21
21
|
yamlFormProps?: YamlFormProps;
|
|
22
22
|
options?: {
|
|
23
23
|
initialValues?: Record<string, unknown>;
|
|
@@ -4,7 +4,7 @@ import { ResourceConfig } from 'src/types';
|
|
|
4
4
|
import { YamlFormProps } from './YamlForm';
|
|
5
5
|
type RawYamlFormModalProps = {
|
|
6
6
|
id?: string;
|
|
7
|
-
resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig'>;
|
|
7
|
+
resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig' | 'dataProviderName'>;
|
|
8
8
|
yamlFormProps?: YamlFormProps;
|
|
9
9
|
onSuccess?: (data: UpdateResponse<BaseRecord> | CreateResponse<BaseRecord>) => void;
|
|
10
10
|
};
|
|
@@ -7,7 +7,7 @@ import { YamlFormProps } from './YamlForm';
|
|
|
7
7
|
interface RefineFormContainerProps {
|
|
8
8
|
id: string;
|
|
9
9
|
isYamlMode: boolean;
|
|
10
|
-
resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'basePath' | 'formConfig'>;
|
|
10
|
+
resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'basePath' | 'formConfig' | 'dataProviderName'>;
|
|
11
11
|
step: number;
|
|
12
12
|
formConfig: (RefineFormConfig & CommonFormConfig) | undefined;
|
|
13
13
|
customYamlFormProps?: YamlFormProps;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BaseRecord, HttpError, UseFormProps as UseFormCoreProps, UseFormReturnType as UseFormReturnTypeCore } from '@refinedev/core';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { DefaultValues } from 'react-hook-form';
|
|
4
|
-
import { UseFormProps as UseHookFormProps, UseFormReturn, FieldValues } from 'react-hook-form';
|
|
3
|
+
import { DefaultValues, UseFormProps as UseHookFormProps, UseFormReturn, FieldValues } from 'react-hook-form';
|
|
5
4
|
export type UseFormReturnType<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> = UseFormReturn<TVariables, TContext> & {
|
|
6
5
|
transformedInitValues: TVariables | undefined;
|
|
7
6
|
refineCore: UseFormReturnTypeCore<TQueryFnData, TError, TVariables, TData, TResponse, TResponseError>;
|
|
@@ -9,7 +9,7 @@ interface UseRefineFormOptions {
|
|
|
9
9
|
export declare const useRefineForm: (props: {
|
|
10
10
|
formConfig?: RefineFormConfig & CommonFormConfig;
|
|
11
11
|
id?: string;
|
|
12
|
-
resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'formConfig'>;
|
|
12
|
+
resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'formConfig' | 'dataProviderName'>;
|
|
13
13
|
refineProps?: UseFormProps['refineCoreProps'];
|
|
14
14
|
options?: UseRefineFormOptions;
|
|
15
15
|
}) => {
|
|
@@ -31,6 +31,7 @@ interface KeyValueTableFormProps<T extends KeyValuePair> {
|
|
|
31
31
|
};
|
|
32
32
|
onSubmit?: (value: T[]) => Promise<unknown> | undefined;
|
|
33
33
|
keyTitle?: string;
|
|
34
|
+
formatPopover?: React.ReactNode;
|
|
34
35
|
}
|
|
35
36
|
export type KeyValueTableFormHandle<T extends KeyValuePair = KeyValuePair> = {
|
|
36
37
|
validate: () => Promise<boolean>;
|
|
@@ -38,4 +39,5 @@ export type KeyValueTableFormHandle<T extends KeyValuePair = KeyValuePair> = {
|
|
|
38
39
|
setValue: (value: T[]) => void;
|
|
39
40
|
};
|
|
40
41
|
export declare const KeyValueTableForm: React.ForwardRefExoticComponent<KeyValueTableFormProps<KeyValuePair> & React.RefAttributes<KeyValueTableFormHandle<KeyValuePair>>>;
|
|
41
|
-
export {};
|
|
42
|
+
export { FormatRulePopover } from './FormatRulePopover';
|
|
43
|
+
export type { FormatRulePopoverProps } from './FormatRulePopover';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Unstructured } from 'k8s-api-provider';
|
|
2
|
+
import { MutableRefObject, ReactNode } from 'react';
|
|
3
|
+
export type Retry409MetaOptions = {
|
|
4
|
+
/** 编辑表单打开时捕获的初始版本;通常由本 hook 自动捕获,外部一般不需要手动传入。 */
|
|
5
|
+
initialResource?: Unstructured;
|
|
6
|
+
/** provider 判断无法安全重试时抛出的本地化错误文案。 */
|
|
7
|
+
conflictMessage?: string;
|
|
8
|
+
};
|
|
9
|
+
type MutationMetaWith409Retry = Record<string, unknown> & {
|
|
10
|
+
/** 传给 k8s-api-provider 的 409 恢复内部参数。 */
|
|
11
|
+
resourceVersionConflictRetry?: Retry409MetaOptions;
|
|
12
|
+
};
|
|
13
|
+
type Use409RetryOptions = {
|
|
14
|
+
/** 当前表单动作;只有 edit 动作会启用 409 重试,create 会自动移除重试 meta。 */
|
|
15
|
+
action?: string;
|
|
16
|
+
/** 当前表单使用的数据源名称,用于找到对应 GlobalStore 并还原 raw YAML。 */
|
|
17
|
+
dataProviderName?: string;
|
|
18
|
+
/** 当前编辑资源的 id;部分调用链 action 不稳定时,用 id 作为 edit 场景的兜底判断。 */
|
|
19
|
+
id?: unknown;
|
|
20
|
+
/** 调用方原本要传给 refine useFormCore 的 mutationMeta,本 hook 会保留其它字段并覆盖内部 409 重试参数。 */
|
|
21
|
+
mutationMeta?: MutationMetaWith409Retry;
|
|
22
|
+
};
|
|
23
|
+
type Use409RetryResult = {
|
|
24
|
+
/** queryResult 拿到资源后调用,用来捕获打开编辑表单时的初始版本。 */
|
|
25
|
+
captureInitialResource: (resource?: Unstructured) => void;
|
|
26
|
+
/** 已合并 409 重试参数的 mutationMeta,应直接传给 refine useFormCore。 */
|
|
27
|
+
mutationMeta: Record<string, unknown>;
|
|
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>>;
|
|
48
|
+
/**
|
|
49
|
+
* 为 D2 编辑表单接入 Kubernetes PUT 409 自动恢复能力。
|
|
50
|
+
*
|
|
51
|
+
* 背景:Kubernetes PUT 保存要求用户保存版本里的 `metadata.resourceVersion`
|
|
52
|
+
* 与服务端版本一致。如果用户编辑期间只有 status、managedFields 等运行时字段发生变化,
|
|
53
|
+
* D2 可以把打开表单时的初始版本交给 k8s-api-provider,由 provider 拉取服务端版本、
|
|
54
|
+
* 判断是否安全,并在安全时替换用户保存版本的 resourceVersion 后重试一次。
|
|
55
|
+
*
|
|
56
|
+
* 用法:FORM/YAML 表单在创建 refine useFormCore 前调用本 hook,把返回的 `mutationMeta`
|
|
57
|
+
* 传给 useFormCore;queryResult 首次拿到资源后调用 `captureInitialResource(data)`。
|
|
58
|
+
* D2 只负责捕获初始版本和传递本地化错误文案,比较、拉取服务端版本和重试都内聚在 provider。
|
|
59
|
+
*
|
|
60
|
+
* @param options - 409 重试接入配置。
|
|
61
|
+
* @param options.action - 当前表单动作;只有 edit 动作会启用 409 重试。
|
|
62
|
+
* @param options.dataProviderName - 当前表单使用的数据源名称,用于选择对应 GlobalStore。
|
|
63
|
+
* @param options.id - 当前编辑资源的 id,用作 edit 场景的兜底判断。
|
|
64
|
+
* @param options.mutationMeta - 调用方原本的 mutationMeta,本 hook 会保留其它字段并覆盖内部 409 重试参数。
|
|
65
|
+
* @returns 用于捕获初始版本的方法,以及应传给 useFormCore 的 mutationMeta。
|
|
66
|
+
*/
|
|
67
|
+
export declare function use409Retry({ action, dataProviderName, id, mutationMeta, }: Use409RetryOptions): Use409RetryResult;
|
|
68
|
+
export {};
|
|
@@ -2,7 +2,7 @@ import { CreateResponse, UpdateResponse, BaseRecord } from '@refinedev/core';
|
|
|
2
2
|
import { ResourceConfig } from 'src/types';
|
|
3
3
|
interface OpenFormOptions {
|
|
4
4
|
id?: string;
|
|
5
|
-
resourceConfig?: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig'>;
|
|
5
|
+
resourceConfig?: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig' | 'dataProviderName'>;
|
|
6
6
|
resourceName?: string;
|
|
7
7
|
initialValues?: Record<string, unknown>;
|
|
8
8
|
customOptions?: Record<string, unknown>;
|
package/dist/i18n.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export declare const resources: {
|
|
|
22
22
|
name: string;
|
|
23
23
|
pod: string;
|
|
24
24
|
cancel: string;
|
|
25
|
+
prev_step: string;
|
|
26
|
+
next_step: string;
|
|
25
27
|
delete: string;
|
|
26
28
|
create: string;
|
|
27
29
|
confirm_delete_text: string;
|
|
@@ -187,6 +189,7 @@ export declare const resources: {
|
|
|
187
189
|
data_expired: string;
|
|
188
190
|
data_expired_body: string;
|
|
189
191
|
data_expired_note: string;
|
|
192
|
+
resource_version_conflict: string;
|
|
190
193
|
abandon_edit: string;
|
|
191
194
|
exit_yaml_tip: string;
|
|
192
195
|
value_optional: string;
|
|
@@ -298,6 +301,8 @@ export declare const resources: {
|
|
|
298
301
|
copied: string;
|
|
299
302
|
already_reset: string;
|
|
300
303
|
cancel: string;
|
|
304
|
+
prev_step: string;
|
|
305
|
+
next_step: string;
|
|
301
306
|
delete: string;
|
|
302
307
|
create: string;
|
|
303
308
|
delete_resource: string;
|
|
@@ -473,6 +478,7 @@ export declare const resources: {
|
|
|
473
478
|
data_expired: string;
|
|
474
479
|
data_expired_body: string;
|
|
475
480
|
data_expired_note: string;
|
|
481
|
+
resource_version_conflict: string;
|
|
476
482
|
abandon_edit: string;
|
|
477
483
|
exit_yaml_tip: string;
|
|
478
484
|
form: string;
|
|
@@ -19,6 +19,8 @@ declare const _default: {
|
|
|
19
19
|
name: string;
|
|
20
20
|
pod: string;
|
|
21
21
|
cancel: string;
|
|
22
|
+
prev_step: string;
|
|
23
|
+
next_step: string;
|
|
22
24
|
delete: string;
|
|
23
25
|
create: string;
|
|
24
26
|
confirm_delete_text: string;
|
|
@@ -184,6 +186,7 @@ declare const _default: {
|
|
|
184
186
|
data_expired: string;
|
|
185
187
|
data_expired_body: string;
|
|
186
188
|
data_expired_note: string;
|
|
189
|
+
resource_version_conflict: string;
|
|
187
190
|
abandon_edit: string;
|
|
188
191
|
exit_yaml_tip: string;
|
|
189
192
|
value_optional: string;
|
|
@@ -11,6 +11,8 @@ declare const _default: {
|
|
|
11
11
|
copied: string;
|
|
12
12
|
already_reset: string;
|
|
13
13
|
cancel: string;
|
|
14
|
+
prev_step: string;
|
|
15
|
+
next_step: string;
|
|
14
16
|
delete: string;
|
|
15
17
|
create: string;
|
|
16
18
|
delete_resource: string;
|
|
@@ -186,6 +188,7 @@ declare const _default: {
|
|
|
186
188
|
data_expired: string;
|
|
187
189
|
data_expired_body: string;
|
|
188
190
|
data_expired_note: string;
|
|
191
|
+
resource_version_conflict: string;
|
|
189
192
|
abandon_edit: string;
|
|
190
193
|
exit_yaml_tip: string;
|
|
191
194
|
form: string;
|