@dovetail-v2/refine 0.1.32 → 0.2.0-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/style.css CHANGED
@@ -4230,14 +4230,6 @@
4230
4230
  }
4231
4231
 
4232
4232
  .c1c9j4da {
4233
- width: 100%;
4234
- }
4235
-
4236
- .cjxv8cf {
4237
- color: rgba(44, 56, 82, 0.6);
4238
- }
4239
-
4240
- .c1xsnuvk {
4241
4233
  flex-basis: 58%;
4242
4234
  width: 100%;
4243
4235
  margin: 0 auto;
@@ -1,12 +1,20 @@
1
1
  import React from 'react';
2
2
  import { YamlFormProps } from './YamlForm';
3
+ export type SaveButtonProps = {
4
+ disabled: boolean;
5
+ onClick: (e: React.BaseSyntheticEvent) => void;
6
+ } | {
7
+ loading?: boolean | {
8
+ delay?: number | undefined;
9
+ } | undefined;
10
+ onClick?: (() => void) | undefined;
11
+ };
3
12
  export interface ConfirmModalProps {
4
13
  onOk?: () => void;
5
14
  }
6
15
  export type FormModalProps = {
7
16
  resource?: string;
8
17
  id?: string;
9
- formProps?: YamlFormProps;
10
- renderForm?: (props: YamlFormProps) => React.ReactNode;
18
+ yamlFormProps?: YamlFormProps;
11
19
  };
12
20
  export declare function FormModal(props: FormModalProps): JSX.Element;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { CommonFormConfig, RefineFormConfig, FormMode } from 'src/types';
3
+ interface FormModeSegmentControlProps {
4
+ formConfig: CommonFormConfig & RefineFormConfig;
5
+ mode: FormMode;
6
+ onChangeMode: (mode: FormMode) => void;
7
+ }
8
+ declare function FormModeSegmentControl({ formConfig, mode, onChangeMode, }: FormModeSegmentControlProps): JSX.Element | null;
9
+ export default FormModeSegmentControl;
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { type SaveButtonProps } from 'src/components/Form/FormModal';
3
+ import { ResourceConfig } from 'src/types';
4
+ import { CommonFormConfig, RefineFormConfig } from 'src/types';
5
+ import { YamlFormProps } from './YamlForm';
6
+ interface RefineFormContainerProps {
7
+ id: string;
8
+ isYamlMode: boolean;
9
+ config: ResourceConfig;
10
+ formConfig: (RefineFormConfig & CommonFormConfig) | undefined;
11
+ customYamlFormProps?: YamlFormProps;
12
+ onSaveButtonPropsChange?: (props: SaveButtonProps) => void;
13
+ onError?: () => void;
14
+ onSuccess?: () => void;
15
+ }
16
+ declare function RefineFormContainer({ id, config, customYamlFormProps, formConfig, isYamlMode, onSuccess, onError, onSaveButtonPropsChange, }: RefineFormContainerProps): JSX.Element;
17
+ export default RefineFormContainer;
@@ -1,12 +1,15 @@
1
1
  /// <reference types="react" />
2
2
  import { UseFormReturnType } from '@refinedev/react-hook-form';
3
+ import { RefineFormFieldRenderProps } from 'src/components/Form/type';
3
4
  import { ResourceModel } from 'src/models';
4
- import { ResourceConfig } from 'src/types';
5
+ import { CommonFormConfig, RefineFormConfig, ResourceConfig } from 'src/types';
5
6
  type Props<Model extends ResourceModel> = {
6
7
  config?: ResourceConfig<Model>;
8
+ formConfig?: CommonFormConfig & RefineFormConfig;
7
9
  formResult: UseFormReturnType;
8
10
  errorMsgs?: string[];
9
11
  resourceId?: string;
10
12
  };
13
+ export declare function renderCommonFormFiled(props: RefineFormFieldRenderProps): JSX.Element;
11
14
  export declare const RefineFormContent: <Model extends ResourceModel<import("k8s-api-provider").Unstructured>>(props: Props<Model>) => JSX.Element;
12
15
  export {};
@@ -1,6 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { FormAction } from '@refinedev/core';
3
3
  import { Unstructured } from 'k8s-api-provider';
4
+ import { ResourceModel } from 'src/models';
5
+ import { ResourceConfig } from 'src/types';
4
6
  import useYamlForm from './useYamlForm';
5
7
  import { YamlFormRule } from './useYamlForm';
6
8
  export declare enum SchemaStrategy {
@@ -8,9 +10,10 @@ export declare enum SchemaStrategy {
8
10
  Optional = "Optional",
9
11
  None = "None"
10
12
  }
11
- export interface YamlFormProps {
13
+ export interface YamlFormProps<Model extends ResourceModel = ResourceModel> {
12
14
  id?: string;
13
15
  action?: FormAction;
16
+ config: ResourceConfig<Model>;
14
17
  initialValuesForCreate?: Record<string, unknown>;
15
18
  initialValuesForEdit?: Record<string, unknown>;
16
19
  schemaStrategy?: SchemaStrategy;
@@ -29,4 +32,4 @@ export interface YamlFormProps {
29
32
  onErrorsChange?: (errors: string[]) => void;
30
33
  onFinish?: () => void;
31
34
  }
32
- export declare function YamlForm(props: YamlFormProps): JSX.Element;
35
+ export declare function YamlForm<Model extends ResourceModel = ResourceModel>(props: YamlFormProps<Model>): JSX.Element;
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { type SaveButtonProps } from 'src/components/Form/FormModal';
3
+ import { ResourceConfig } from 'src/types';
4
+ import { CommonFormConfig } from 'src/types';
5
+ import { YamlFormConfig } from 'src/types';
6
+ import { YamlFormProps } from './YamlForm';
7
+ interface YamlFormContainerProps {
8
+ id: string;
9
+ config: ResourceConfig;
10
+ customYamlFormProps?: YamlFormProps;
11
+ formConfig?: YamlFormConfig & CommonFormConfig;
12
+ onSuccess?: () => void;
13
+ onError?: () => void;
14
+ onSaveButtonPropsChange?: (props: SaveButtonProps) => void;
15
+ }
16
+ declare function YamlFormContainer({ id, customYamlFormProps, config, formConfig, onSuccess, onError, onSaveButtonPropsChange }: YamlFormContainerProps): JSX.Element;
17
+ export default YamlFormContainer;
@@ -1,9 +1,17 @@
1
1
  import React from 'react';
2
- import { Control } from 'react-hook-form';
3
- export type RefineFormValidator = (value: unknown, formValue: unknown) => {
2
+ import { Control, UseFormTrigger, FieldValues, ControllerRenderProps } from 'react-hook-form';
3
+ import { FormType } from 'src/types/resource';
4
+ export type RefineFormValidator = (value: unknown, formValue: unknown, formMode: FormType) => {
4
5
  isValid: boolean;
5
6
  errorMsg: string;
6
7
  };
8
+ export type RefineFormFieldRenderProps = {
9
+ field: ControllerRenderProps<FieldValues, string>;
10
+ fieldConfig: RefineFormField;
11
+ action: 'edit' | 'create';
12
+ control: Control;
13
+ trigger: UseFormTrigger<FieldValues>;
14
+ };
7
15
  export type RefineFormField = {
8
16
  path: string[];
9
17
  key: string;
@@ -13,5 +21,11 @@ export type RefineFormField = {
13
21
  type?: 'number';
14
22
  validators?: RefineFormValidator[];
15
23
  disabledWhenEdit?: boolean;
16
- render?: (value: unknown, onChange: (event: unknown) => void, formValue: unknown, onBlur: () => void, action: 'edit' | 'create', control: Control) => React.ReactElement;
24
+ render?: (props: RefineFormFieldRenderProps) => React.ReactElement;
25
+ /**
26
+ * 表单项条件渲染函数
27
+ * @param formValue 表单值
28
+ * @returns 是否渲染
29
+ */
30
+ condition?: (formValue: Record<string, unknown>, value: unknown) => boolean;
17
31
  };
@@ -1,4 +1,4 @@
1
1
  import { ResourceModel } from 'src/models';
2
- import { ResourceConfig } from 'src/types';
3
- declare function useFieldsConfig<Model extends ResourceModel>(config?: ResourceConfig<Model>, resourceId?: string): import("./type").RefineFormField[] | undefined;
2
+ import { CommonFormConfig, RefineFormConfig, ResourceConfig } from 'src/types';
3
+ declare function useFieldsConfig<Model extends ResourceModel>(config?: ResourceConfig<Model>, formConfig?: CommonFormConfig & RefineFormConfig, resourceId?: string): import("./type").RefineFormField[] | undefined;
4
4
  export default useFieldsConfig;
@@ -1,8 +1,9 @@
1
- import { ResourceConfig } from '../../types';
1
+ import { CommonFormConfig, RefineFormConfig, ResourceConfig } from '../../types';
2
2
  import { UseFormProps } from './useReactHookForm';
3
3
  export declare const useRefineForm: (props: {
4
- config: ResourceConfig;
4
+ formConfig?: RefineFormConfig & CommonFormConfig;
5
5
  id?: string;
6
+ config: ResourceConfig;
6
7
  refineProps?: UseFormProps['refineCoreProps'];
7
8
  useFormProps?: UseFormProps;
8
9
  }) => {
@@ -1,6 +1,6 @@
1
1
  import { TableProps as BaseTableProps, RequiredColumnProps } from '@cloudtower/eagle';
2
2
  import React from 'react';
3
- import { FormType } from 'src/types';
3
+ import { FormContainerType } from 'src/types';
4
4
  export type IDObject = {
5
5
  id: string;
6
6
  };
@@ -32,7 +32,7 @@ export type InternalTableProps<Data extends {
32
32
  onSorterChange?: (order: SorterOrder | null, key?: string) => void;
33
33
  RowMenu?: React.FC<{
34
34
  record: Data;
35
- formType?: FormType;
35
+ formType?: FormContainerType;
36
36
  }>;
37
37
  empty?: string;
38
38
  showMenuColumn?: boolean;
@@ -1,8 +1,5 @@
1
- /// <reference types="react" />
2
- import { YamlFormProps } from '../components';
3
1
  interface UseOpenFormOptions {
4
2
  id?: string;
5
- renderForm?: (props: YamlFormProps) => React.ReactNode;
6
3
  }
7
4
  export declare function useOpenForm(options?: UseOpenFormOptions): () => void;
8
5
  export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Utility hook for transforming data structures by mapping paths between different object structures.
3
+ * Useful for converting between form values and API data structures.
4
+ */
5
+ import { Unstructured } from 'k8s-api-provider';
6
+ interface UsePathMapOptions {
7
+ /** Array of path mappings, each containing source path and target path arrays */
8
+ pathMap?: {
9
+ from: string[];
10
+ to: string[];
11
+ }[];
12
+ /** Optional function to transform initial values after path mapping */
13
+ transformInitValues?: (values: Record<string, unknown>) => Record<string, unknown>;
14
+ /** Optional function to transform values before applying/saving */
15
+ transformApplyValues?: (values: Record<string, unknown>) => Unstructured;
16
+ }
17
+ /**
18
+ * Hook that provides functions to transform data between different object structures using path mappings
19
+ * @param options Configuration options including path mappings and transform functions
20
+ * @returns Object containing transformation functions for init and apply operations
21
+ */
22
+ declare function usePathMap(options: UsePathMapOptions): {
23
+ transformInitValues: (values: Record<string, unknown>) => Record<string, unknown>;
24
+ transformApplyValues: (values: Record<string, unknown>) => Unstructured;
25
+ };
26
+ export default usePathMap;
@@ -1,9 +1,9 @@
1
- import { ResourceModel } from 'src/models';
1
+ import { StorageClassModel } from 'src/models';
2
2
  import { ResourceConfig } from 'src/types';
3
3
  type GenerateStorageClassFormConfig = {
4
- isEnabledZbs?: boolean;
5
- isEnabledElf?: boolean;
4
+ isEnabledProvisionerA?: boolean;
5
+ isEnabledProvisionerB?: boolean;
6
6
  isVmKsc?: boolean;
7
7
  };
8
- export declare function generateStorageClassFormConfig(options: GenerateStorageClassFormConfig): ResourceConfig<ResourceModel>['formConfig'];
8
+ export declare function generateStorageClassFormConfig(options: GenerateStorageClassFormConfig): ResourceConfig<StorageClassModel>['formConfig'];
9
9
  export {};
@@ -1,53 +1,5 @@
1
- /// <reference types="react" />
2
1
  import { i18n as I18n } from 'i18next';
3
- import { RESOURCE_GROUP } from 'src/types';
4
- export declare const StorageClassConfig: (i18n: I18n) => {
5
- name: string;
6
- basePath: string;
7
- kind: string;
8
- parent: RESOURCE_GROUP;
9
- label: string;
10
- initValue: {
11
- apiVersion: string;
12
- kind: string;
13
- metadata: {
14
- name: string;
15
- };
16
- parameters: {
17
- 'csi.storage.k8s.io/fstype': string;
18
- };
19
- provisioner: string;
20
- reclaimPolicy: string;
21
- allowVolumeExpansion: boolean;
22
- volumeBindingMode: string;
23
- };
24
- formConfig: {
25
- fields?: ((props: {
26
- record?: import("../..").ResourceModel<import("k8s-api-provider").Unstructured> | undefined;
27
- records: import("../..").ResourceModel<import("k8s-api-provider").Unstructured>[];
28
- action: "create" | "edit";
29
- }) => import("../../components").RefineFormField[]) | undefined;
30
- saveButtonText?: string | undefined;
31
- renderForm?: ((props: import("../../components").YamlFormProps) => import("react").ReactNode) | undefined;
32
- formType?: import("src/types").FormType | undefined;
33
- transformInitValues?: ((values: Record<string, unknown>) => Record<string, unknown>) | undefined;
34
- transformApplyValues?: ((values: Record<string, unknown>) => import("k8s-api-provider").Unstructured) | undefined;
35
- formTitle?: string | ((action: "create" | "edit") => string) | undefined;
36
- formDesc?: string | ((action: "create" | "edit") => string) | undefined;
37
- labelWidth?: string | undefined;
38
- formatError?: ((errorBody: unknown) => string) | undefined;
39
- refineCoreProps?: import("@refinedev/core").UseFormProps<import("@refinedev/core").BaseRecord, import("@refinedev/core").HttpError, import("react-hook-form").FieldValues, import("@refinedev/core").BaseRecord, import("@refinedev/core").BaseRecord, import("@refinedev/core").HttpError> | undefined;
40
- useFormProps?: import("@refinedev/react-hook-form").UseFormProps | undefined;
41
- isDisabledChangeMode?: boolean | undefined;
42
- CustomFormModal?: import("react").FC<import("../../components").FormModalProps> | undefined;
43
- } | undefined;
44
- columns: () => (import("../../components").Column<import("../..").ResourceModel<import("k8s-api-provider").Unstructured>> | import("../../components").Column<import("../..").StorageClassModel>)[];
45
- showConfig: () => {
46
- tabs: {
47
- title: string;
48
- key: string;
49
- groups: import("../../components").ShowGroup<import("../..").StorageClassModel>[];
50
- }[];
51
- };
52
- };
2
+ import { StorageClassModel } from 'src/models';
3
+ import { ResourceConfig } from 'src/types';
4
+ export declare const StorageClassConfig: (i18n: I18n) => ResourceConfig<StorageClassModel>;
53
5
  export * from './form';
@@ -1,6 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { UseFormProps } from '@refinedev/react-hook-form';
3
- import { YamlFormProps } from '../components';
4
3
  import { FormModalProps, RefineFormField } from '../components/Form';
5
4
  import { Column, InternalTableProps } from '../components/InternalBaseTable';
6
5
  import { ShowConfig } from '../components/ShowContent';
@@ -16,13 +15,125 @@ export declare enum RESOURCE_GROUP {
16
15
  NODE_MANAGEMENT = "NODE_MANAGEMENT",
17
16
  PROJECT = "PROJECT"
18
17
  }
19
- export declare enum FormType {
18
+ /**
19
+ * 表单容器类型
20
+ */
21
+ export declare enum FormContainerType {
20
22
  PAGE = "PAGE",
21
23
  MODAL = "MODAL"
22
24
  }
25
+ /**
26
+ * 表单类型
27
+ */
28
+ export declare enum FormType {
29
+ YAML = "YAML",
30
+ FORM = "FORM"
31
+ }
32
+ /**
33
+ * 允许切换的表单模式
34
+ */
35
+ export declare enum FormMode {
36
+ FORM = "FORM",
37
+ YAML = "YAML"
38
+ }
23
39
  export type WithId<T> = T & {
24
40
  id: string;
25
41
  };
42
+ export type RefineFormConfig<Model extends ResourceModel = ResourceModel> = {
43
+ formType: FormType.FORM;
44
+ /**
45
+ * 表单字段配置函数
46
+ * @param props 包含记录和动作类型的配置对象
47
+ * @returns 表单字段配置数组
48
+ */
49
+ fields?: (props: {
50
+ record?: Model;
51
+ records: Model[];
52
+ action: 'create' | 'edit';
53
+ }) => RefineFormField[];
54
+ /** Refine Core 的表单属性 */
55
+ refineCoreProps?: UseFormProps['refineCoreProps'];
56
+ /** React Hook Form 的配置属性 */
57
+ useFormProps?: UseFormProps;
58
+ /** 是否禁用切换表单模式(在 YAML 和表单之间切换) */
59
+ isDisabledChangeMode?: boolean;
60
+ /** 表单标签的宽度
61
+ * 默认是 216px
62
+ */
63
+ labelWidth?: string;
64
+ /**
65
+ * 自定义表单渲染函数
66
+ * @returns React节点
67
+ */
68
+ renderForm?: () => React.ReactNode;
69
+ };
70
+ export type YamlFormConfig = {
71
+ formType: FormType.YAML;
72
+ };
73
+ export type ErrorBody = {
74
+ kind: string;
75
+ apiVersion: string;
76
+ metadata: object;
77
+ status: string;
78
+ message: string;
79
+ reason: string;
80
+ details: {
81
+ name: string;
82
+ group: string;
83
+ kind: string;
84
+ causes?: {
85
+ reason: string;
86
+ message: string;
87
+ field: string;
88
+ }[];
89
+ };
90
+ code: number;
91
+ };
92
+ export type CommonFormConfig<Model extends ResourceModel = ResourceModel> = {
93
+ /** 自定义表单模态框组件 */
94
+ CustomFormModal?: React.FC<FormModalProps>;
95
+ /**
96
+ * 初始值转换函数
97
+ * @param values 原始值
98
+ * @returns 转换后的值
99
+ */
100
+ transformInitValues?: (values: Record<string, unknown>) => Record<string, unknown>;
101
+ /**
102
+ * 提交值转换函数,转换为 YAML 格式
103
+ * @param values 表单值
104
+ * @returns YAML格式的数据
105
+ */
106
+ transformApplyValues?: (values: Record<string, unknown>) => Model['_rawYaml'];
107
+ /** 表单容器类型:页面形式或模态框形式
108
+ * PAGE 或者 MODAL
109
+ */
110
+ formContainerType?: FormContainerType;
111
+ /**
112
+ * 表单标题,可以是字符串或根据操作类型返回不同标题的函数
113
+ * @param action 操作类型:create 或 edit
114
+ */
115
+ formTitle?: string | ((action: 'create' | 'edit') => string);
116
+ /**
117
+ * 表单描述,可以是字符串或根据操作类型返回不同描述的函数
118
+ * @param action 操作类型:create 或 edit
119
+ */
120
+ formDesc?: string | ((action: 'create' | 'edit') => string);
121
+ /** 保存按钮文本 */
122
+ saveButtonText?: string;
123
+ /**
124
+ * 错误信息格式化函数,待完善
125
+ * @param errorBody 错误信息体
126
+ * @returns 格式化后的错误信息
127
+ */
128
+ formatError?: (errorBody: ErrorBody) => string;
129
+ /**
130
+ * 路径映射,用于在表单中映射路径
131
+ */
132
+ pathMap?: {
133
+ from: string[];
134
+ to: string[];
135
+ }[];
136
+ };
26
137
  export type ResourceConfig<Model extends ResourceModel = ResourceModel> = {
27
138
  /** 资源名称,用于 API 调用和路由。
28
139
  * 默认复数形式,如:deployments
@@ -81,68 +192,5 @@ export type ResourceConfig<Model extends ResourceModel = ResourceModel> = {
81
192
  */
82
193
  deleteTip?: string;
83
194
  /** 表单相关配置 */
84
- formConfig?: {
85
- /**
86
- * 表单字段配置函数
87
- * @param props 包含记录和动作类型的配置对象
88
- * @returns 表单字段配置数组
89
- */
90
- fields?: (props: {
91
- record?: Model;
92
- records: Model[];
93
- action: 'create' | 'edit';
94
- }) => RefineFormField[];
95
- /** 保存按钮文本 */
96
- saveButtonText?: string;
97
- /**
98
- * 自定义表单渲染函数
99
- * @param props YAML表单属性,待完善
100
- * @returns React节点
101
- */
102
- renderForm?: (props: YamlFormProps) => React.ReactNode;
103
- /** 表单类型:页面形式或模态框形式
104
- * PAGE 或者 MODAL
105
- */
106
- formType?: FormType;
107
- /**
108
- * 初始值转换函数
109
- * @param values 原始值
110
- * @returns 转换后的值
111
- */
112
- transformInitValues?: (values: Record<string, unknown>) => Record<string, unknown>;
113
- /**
114
- * 提交值转换函数,转换为 YAML 格式
115
- * @param values 表单值
116
- * @returns YAML格式的数据
117
- */
118
- transformApplyValues?: (values: Record<string, unknown>) => Model['_rawYaml'];
119
- /**
120
- * 表单标题,可以是字符串或根据操作类型返回不同标题的函数
121
- * @param action 操作类型:create 或 edit
122
- */
123
- formTitle?: string | ((action: 'create' | 'edit') => string);
124
- /**
125
- * 表单描述,可以是字符串或根据操作类型返回不同描述的函数
126
- * @param action 操作类型:create 或 edit
127
- */
128
- formDesc?: string | ((action: 'create' | 'edit') => string);
129
- /** 表单标签的宽度
130
- * 默认是 216px
131
- */
132
- labelWidth?: string;
133
- /**
134
- * 错误信息格式化函数,待完善
135
- * @param errorBody 错误信息体
136
- * @returns 格式化后的错误信息
137
- */
138
- formatError?: (errorBody: unknown) => string;
139
- /** Refine Core 的表单属性 */
140
- refineCoreProps?: UseFormProps['refineCoreProps'];
141
- /** React Hook Form 的配置属性 */
142
- useFormProps?: UseFormProps;
143
- /** 是否禁用切换表单模式(在 YAML 和表单之间切换) */
144
- isDisabledChangeMode?: boolean;
145
- /** 自定义表单模态框组件 */
146
- CustomFormModal?: React.FC<FormModalProps>;
147
- };
195
+ formConfig?: (RefineFormConfig<Model> | YamlFormConfig) & CommonFormConfig<Model>;
148
196
  };
@@ -0,0 +1 @@
1
+ export declare function immutableSet<T extends Record<string, unknown> | unknown[] = Record<string, unknown>>(obj: T, path: string | string[], value: unknown): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dovetail-v2/refine",
3
- "version": "0.1.32",
3
+ "version": "0.2.0-alpha.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",