@dovetail-v2/refine 0.3.19-alpha.2 → 0.3.19-alpha.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.
@@ -7,11 +7,8 @@ interface K8sDropdownProps {
7
7
  record: ResourceModel;
8
8
  size?: DropdownSize;
9
9
  customButton?: React.ReactNode;
10
- resourceName?: string;
11
- config?: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig' | 'hideEdit'>;
12
- displayName?: string;
10
+ resourceConfig?: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig' | 'hideEdit'>;
13
11
  deleteDialogProps?: Partial<DeleteDialogProps>;
14
- hideEdit?: boolean;
15
12
  }
16
13
  export declare function K8sDropdown(props: React.PropsWithChildren<K8sDropdownProps>): JSX.Element;
17
14
  export default K8sDropdown;
@@ -17,7 +17,7 @@ export interface ConfirmModalProps {
17
17
  }
18
18
  export type FormModalProps = {
19
19
  id?: string;
20
- config: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig'>;
20
+ resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig'>;
21
21
  yamlFormProps?: YamlFormProps;
22
22
  options?: {
23
23
  initialValues?: Record<string, unknown>;
@@ -7,7 +7,7 @@ import { YamlFormProps } from './YamlForm';
7
7
  interface RefineFormContainerProps {
8
8
  id: string;
9
9
  isYamlMode: boolean;
10
- config: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'basePath' | 'formConfig'>;
10
+ resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'basePath' | 'formConfig'>;
11
11
  step: number;
12
12
  formConfig: (RefineFormConfig & CommonFormConfig) | undefined;
13
13
  customYamlFormProps?: YamlFormProps;
@@ -5,7 +5,7 @@ import { RefineFormFieldRenderProps } from 'src/components/Form/type';
5
5
  import { ResourceModel } from 'src/models';
6
6
  import { CommonFormConfig, RefineFormConfig, ResourceConfig } from 'src/types';
7
7
  type RefineFormContentProps<Model extends ResourceModel> = {
8
- config?: Pick<ResourceConfig<Model>, 'name' | 'displayName' | 'kind' | 'initValue' | 'basePath' | 'formConfig'>;
8
+ resourceConfig?: Pick<ResourceConfig<Model>, 'name' | 'displayName' | 'kind' | 'initValue' | 'basePath' | 'formConfig'>;
9
9
  step?: number;
10
10
  formConfig?: CommonFormConfig & RefineFormConfig;
11
11
  formResult: UseFormReturnType;
@@ -14,7 +14,7 @@ export interface YamlFormProps<Model extends ResourceModel = ResourceModel> {
14
14
  id?: string;
15
15
  resource?: string;
16
16
  action?: FormAction;
17
- config: Pick<ResourceConfig<Model>, 'displayName' | 'dataProviderName' | 'basePath' | 'kind' | 'parent'>;
17
+ resourceConfig: Pick<ResourceConfig<Model>, 'displayName' | 'dataProviderName' | 'basePath' | 'kind' | 'parent'>;
18
18
  initialValuesForCreate?: Record<string, unknown>;
19
19
  initialValuesForEdit?: Record<string, unknown>;
20
20
  schemaStrategy?: SchemaStrategy;
@@ -7,12 +7,12 @@ import { YamlFormConfig } from 'src/types';
7
7
  import { YamlFormProps } from './YamlForm';
8
8
  interface YamlFormContainerProps {
9
9
  id: string;
10
- config: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig' | 'dataProviderName' | 'parent'>;
10
+ resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig' | 'dataProviderName' | 'parent'>;
11
11
  customYamlFormProps?: YamlFormProps;
12
12
  formConfig?: YamlFormConfig & CommonFormConfig;
13
13
  onSuccess?: (data: UpdateResponse<BaseRecord> | CreateResponse<BaseRecord>) => void;
14
14
  onError?: () => void;
15
15
  onSaveButtonPropsChange?: (props: SaveButtonProps) => void;
16
16
  }
17
- declare function YamlFormContainer({ id, customYamlFormProps, config, formConfig, onSuccess, onError, onSaveButtonPropsChange, }: YamlFormContainerProps): JSX.Element;
17
+ declare function YamlFormContainer({ id, customYamlFormProps, resourceConfig, formConfig, onSuccess, onError, onSaveButtonPropsChange, }: YamlFormContainerProps): JSX.Element;
18
18
  export default YamlFormContainer;
@@ -1,7 +1,7 @@
1
1
  import { FieldValues } from 'react-hook-form';
2
2
  import { ResourceModel } from 'src/models';
3
3
  import { RefineFormConfig, ResourceConfig } from 'src/types';
4
- declare function useFieldsConfig<Model extends ResourceModel>(config?: Pick<ResourceConfig<Model>, 'name' | 'displayName' | 'kind' | 'initValue' | 'basePath' | 'formConfig'>, formConfig?: {
4
+ declare function useFieldsConfig<Model extends ResourceModel>(resourceConfig?: Pick<ResourceConfig<Model>, 'name' | 'displayName' | 'kind' | 'initValue' | 'basePath' | 'formConfig'>, formConfig?: {
5
5
  fields: RefineFormConfig['fields'];
6
6
  }, resourceId?: string, step?: number, customOptions?: Record<string, unknown>, transformedInitValues?: FieldValues): (import("./type").RefineFormField | import("./type").RefineFormSection)[] | undefined;
7
7
  export default useFieldsConfig;
@@ -7,7 +7,7 @@ interface UseRefineFormOptions {
7
7
  export declare const useRefineForm: (props: {
8
8
  formConfig?: RefineFormConfig & CommonFormConfig;
9
9
  id?: string;
10
- config: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'formConfig'>;
10
+ resourceConfig: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'formConfig'>;
11
11
  refineProps?: UseFormProps['refineCoreProps'];
12
12
  options?: UseRefineFormOptions;
13
13
  }) => {
@@ -2,7 +2,7 @@
2
2
  import { ResourceModel } from '../../../models';
3
3
  import { ResourceConfig } from '../../../types';
4
4
  type Props<Model extends ResourceModel> = {
5
- config: ResourceConfig<Model>;
5
+ resourceConfig: ResourceConfig<Model>;
6
6
  };
7
7
  export declare function ResourceForm<Model extends ResourceModel>(props: Props<Model>): JSX.Element;
8
8
  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
- config?: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig'>;
5
+ resourceConfig?: Pick<ResourceConfig, 'name' | 'displayName' | 'kind' | 'initValue' | 'apiVersion' | 'basePath' | 'formConfig'>;
6
6
  resourceName?: string;
7
7
  initialValues?: Record<string, unknown>;
8
8
  customOptions?: Record<string, unknown>;
package/dist/refine.cjs CHANGED
@@ -10584,22 +10584,22 @@ function useOpenForm() {
10584
10584
  const go = core.useGo();
10585
10585
  return function openForm(options) {
10586
10586
  var _a, _b;
10587
- const finalResourceName = (options == null ? void 0 : options.resourceName) || ((_a = options == null ? void 0 : options.config) == null ? void 0 : _a.name) || (resource == null ? void 0 : resource.name);
10588
- if (finalResourceName || (options == null ? void 0 : options.config)) {
10589
- const config = (options == null ? void 0 : options.config) || configs[finalResourceName || ""];
10590
- const formType = (_b = config.formConfig) == null ? void 0 : _b.formContainerType;
10587
+ const finalResourceName = (options == null ? void 0 : options.resourceName) || ((_a = options == null ? void 0 : options.resourceConfig) == null ? void 0 : _a.name) || (resource == null ? void 0 : resource.name);
10588
+ if (finalResourceName || (options == null ? void 0 : options.resourceConfig)) {
10589
+ const resourceConfig = (options == null ? void 0 : options.resourceConfig) || configs[finalResourceName || ""];
10590
+ const formType = (_b = resourceConfig.formConfig) == null ? void 0 : _b.formContainerType;
10591
10591
  if (formType === void 0 || formType === FormContainerType.MODAL) {
10592
10592
  pushModal({
10593
10593
  component: () => {
10594
10594
  var _a2;
10595
- const ModalComponent = ((_a2 = config.formConfig) == null ? void 0 : _a2.CustomFormModal) || FormModal;
10595
+ const ModalComponent = ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.CustomFormModal) || FormModal;
10596
10596
  return /* @__PURE__ */ common.jsxRuntimeExports.jsx(
10597
10597
  ModalComponent,
10598
10598
  {
10599
10599
  id: options == null ? void 0 : options.id,
10600
- config,
10600
+ resourceConfig,
10601
10601
  yamlFormProps: {
10602
- config
10602
+ resourceConfig
10603
10603
  },
10604
10604
  options,
10605
10605
  onSuccess: options == null ? void 0 : options.onSuccess
@@ -10837,23 +10837,20 @@ function K8sDropdown(props) {
10837
10837
  const {
10838
10838
  record,
10839
10839
  size = "normal",
10840
- resourceName: resourceNameFromProps,
10841
- config: configFromProps,
10840
+ resourceConfig,
10842
10841
  customButton,
10843
- deleteDialogProps,
10844
- displayName,
10845
- hideEdit
10842
+ deleteDialogProps
10846
10843
  } = props;
10847
10844
  const globalStore = useGlobalStore();
10848
10845
  const useResourceResult = core.useResource();
10849
10846
  const configs = React.useContext(ConfigsContext);
10850
- const resourceName = resourceNameFromProps || getResourceNameByKind(record.kind || "", configs);
10851
- const config = configFromProps || configs[resourceName || ""];
10847
+ const resourceName = (resourceConfig == null ? void 0 : resourceConfig.name) || getResourceNameByKind(record.kind || "", configs);
10848
+ const config = resourceConfig || configs[resourceName || ""];
10852
10849
  const { t: t2, i18n: i18n2 } = common.useTranslation();
10853
10850
  const { openDeleteConfirmModal } = useDeleteModal({
10854
10851
  resourceName: resourceName || "",
10855
10852
  deleteDialogProps,
10856
- displayName,
10853
+ displayName: config.displayName,
10857
10854
  meta: record.apiVersion ? {
10858
10855
  kind: record.kind || "",
10859
10856
  resourceBasePath: (
@@ -10884,12 +10881,12 @@ function K8sDropdown(props) {
10884
10881
  eagle.Dropdown,
10885
10882
  {
10886
10883
  overlay: /* @__PURE__ */ common.jsxRuntimeExports.jsxs(eagle.Menu, { children: [
10887
- isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || hideEdit || (config == null ? void 0 : config.hideEdit) ? null : /* @__PURE__ */ common.jsxRuntimeExports.jsx(
10884
+ isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || (config == null ? void 0 : config.hideEdit) ? null : /* @__PURE__ */ common.jsxRuntimeExports.jsx(
10888
10885
  eagle.Menu.Item,
10889
10886
  {
10890
- onClick: () => openForm({ id: record.id, resourceName, config }),
10887
+ onClick: () => openForm({ id: record.id, resourceName, resourceConfig: config }),
10891
10888
  children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(eagle.Icon, { src: iconsReact.EditPen16PrimaryIcon, children: formType === FormType.FORM ? `${t2("dovetail.edit")}${transformResourceKindInSentence(
10892
- displayName || (config == null ? void 0 : config.displayName) || record.kind || "",
10889
+ config.displayName || record.kind || "",
10893
10890
  i18n2.language
10894
10891
  )}` : t2("dovetail.edit_yaml") })
10895
10892
  }
@@ -14684,10 +14681,10 @@ function ResourceShow(props) {
14684
14681
  }
14685
14682
  );
14686
14683
  }
14687
- function getInitialValues(config) {
14688
- return config.initValue || {
14689
- apiVersion: config.apiVersion,
14690
- kind: config.kind,
14684
+ function getInitialValues(resourceConfig) {
14685
+ return resourceConfig.initValue || {
14686
+ apiVersion: resourceConfig.apiVersion,
14687
+ kind: resourceConfig.kind,
14691
14688
  ...BASE_INIT_VALUE,
14692
14689
  spec: {}
14693
14690
  };
@@ -14826,19 +14823,19 @@ const SpaceStyle = "sea7f83";
14826
14823
  const VerticalFormItemStyle = "v1jthrhz";
14827
14824
  const IntegerStyle = "i1brpchs";
14828
14825
  const ContentWrapper = "c11mae2d";
14829
- function useFieldsConfig(config, formConfig, resourceId, step, customOptions, transformedInitValues) {
14826
+ function useFieldsConfig(resourceConfig, formConfig, resourceId, step, customOptions, transformedInitValues) {
14830
14827
  var _a, _b, _c;
14831
14828
  const action = resourceId ? "edit" : "create";
14832
14829
  const listQuery = core.useList({
14833
- resource: config == null ? void 0 : config.name,
14834
- meta: { resourceBasePath: config == null ? void 0 : config.basePath, kind: config == null ? void 0 : config.kind },
14830
+ resource: resourceConfig == null ? void 0 : resourceConfig.name,
14831
+ meta: { resourceBasePath: resourceConfig == null ? void 0 : resourceConfig.basePath, kind: resourceConfig == null ? void 0 : resourceConfig.kind },
14835
14832
  pagination: {
14836
14833
  mode: "off"
14837
14834
  }
14838
14835
  });
14839
14836
  const showQuery = core.useShow({
14840
- resource: config == null ? void 0 : config.name,
14841
- meta: { resourceBasePath: config == null ? void 0 : config.basePath, kind: config == null ? void 0 : config.kind },
14837
+ resource: resourceConfig == null ? void 0 : resourceConfig.name,
14838
+ meta: { resourceBasePath: resourceConfig == null ? void 0 : resourceConfig.basePath, kind: resourceConfig == null ? void 0 : resourceConfig.kind },
14842
14839
  id: resourceId
14843
14840
  });
14844
14841
  return (_c = formConfig == null ? void 0 : formConfig.fields) == null ? void 0 : _c.call(formConfig, {
@@ -14953,7 +14950,7 @@ const MemoizedFormField = React.memo(function FormField({
14953
14950
  });
14954
14951
  function FieldsContent(props) {
14955
14952
  const {
14956
- config,
14953
+ resourceConfig,
14957
14954
  formConfig,
14958
14955
  resourceId,
14959
14956
  step,
@@ -14965,7 +14962,7 @@ function FieldsContent(props) {
14965
14962
  const { control, getValues, watch, trigger } = formResult;
14966
14963
  const action = resourceId ? "edit" : "create";
14967
14964
  const formFieldsConfig = useFieldsConfig(
14968
- config,
14965
+ resourceConfig,
14969
14966
  { fields },
14970
14967
  resourceId,
14971
14968
  step,
@@ -14983,7 +14980,7 @@ function FieldsContent(props) {
14983
14980
  children: /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", { className: ContentWrapper, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(
14984
14981
  FieldsContent,
14985
14982
  {
14986
- config,
14983
+ resourceConfig,
14987
14984
  formConfig,
14988
14985
  resourceId,
14989
14986
  step,
@@ -15013,7 +15010,7 @@ function FieldsContent(props) {
15013
15010
  }
15014
15011
  const RefineFormContent = (props) => {
15015
15012
  const {
15016
- config,
15013
+ resourceConfig: config,
15017
15014
  formResult,
15018
15015
  resourceId,
15019
15016
  errorMsgs,
@@ -15027,7 +15024,7 @@ const RefineFormContent = (props) => {
15027
15024
  /* @__PURE__ */ common.jsxRuntimeExports.jsx(
15028
15025
  FieldsContent,
15029
15026
  {
15030
- config,
15027
+ resourceConfig: config,
15031
15028
  formConfig,
15032
15029
  fields: formConfig == null ? void 0 : formConfig.fields,
15033
15030
  resourceId,
@@ -15738,7 +15735,7 @@ const useForm = ({
15738
15735
  };
15739
15736
  };
15740
15737
  const useRefineForm = (props) => {
15741
- const { formConfig, config, id, refineProps, options } = props;
15738
+ const { formConfig, resourceConfig, id, refineProps, options } = props;
15742
15739
  const { transformInitValues, transformApplyValues } = usePathMap({
15743
15740
  pathMap: formConfig == null ? void 0 : formConfig.pathMap,
15744
15741
  transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
@@ -15757,7 +15754,7 @@ const useRefineForm = (props) => {
15757
15754
  return {
15758
15755
  message: i18n2.t(id ? "dovetail.edit_resource_success" : "dovetail.create_success_toast", {
15759
15756
  kind: transformResourceKindInSentence(
15760
- config.displayName || config.kind,
15757
+ resourceConfig.displayName || resourceConfig.kind,
15761
15758
  i18n2.language
15762
15759
  ),
15763
15760
  name: (_a = formValue.metadata) == null ? void 0 : _a.name,
@@ -15767,13 +15764,13 @@ const useRefineForm = (props) => {
15767
15764
  type: "success"
15768
15765
  };
15769
15766
  },
15770
- resource: config.name,
15767
+ resource: resourceConfig.name,
15771
15768
  action: id ? "edit" : "create",
15772
15769
  id,
15773
15770
  liveMode: "off",
15774
15771
  ...refineProps
15775
15772
  },
15776
- defaultValues: (options == null ? void 0 : options.initialValues) || (config == null ? void 0 : config.initValue),
15773
+ defaultValues: (options == null ? void 0 : options.initialValues) || (resourceConfig == null ? void 0 : resourceConfig.initValue),
15777
15774
  transformApplyValues,
15778
15775
  transformInitValues,
15779
15776
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -16471,7 +16468,7 @@ function YamlForm(props) {
16471
16468
  schemaStrategy = "Optional",
16472
16469
  isShowLayout = true,
16473
16470
  useFormProps,
16474
- config,
16471
+ resourceConfig,
16475
16472
  transformInitValues,
16476
16473
  transformApplyValues,
16477
16474
  beforeSubmit,
@@ -16515,7 +16512,7 @@ function YamlForm(props) {
16515
16512
  beforeSubmit,
16516
16513
  successNotification(data2) {
16517
16514
  var _a;
16518
- const displayName = config.displayName || ((_a = resource == null ? void 0 : resource.meta) == null ? void 0 : _a.kind);
16515
+ const displayName = resourceConfig.displayName || ((_a = resource == null ? void 0 : resource.meta) == null ? void 0 : _a.kind);
16519
16516
  return {
16520
16517
  message: i18n2.t(action === "create" ? "dovetail.create_success_toast" : "dovetail.save_yaml_success_toast", {
16521
16518
  kind: transformResourceKindInSentence(displayName, i18n2.language),
@@ -16532,10 +16529,10 @@ function YamlForm(props) {
16532
16529
  transformApplyValues,
16533
16530
  mutationMeta: {
16534
16531
  updateType: "put",
16535
- dataProviderName: config.dataProviderName,
16536
- resourceBasePath: config.basePath,
16537
- kind: config.kind,
16538
- label: `${config.kind}s`
16532
+ dataProviderName: resourceConfig.dataProviderName,
16533
+ resourceBasePath: resourceConfig.basePath,
16534
+ kind: resourceConfig.kind,
16535
+ label: `${resourceConfig.kind}s`
16539
16536
  },
16540
16537
  ...useFormProps
16541
16538
  });
@@ -16618,7 +16615,7 @@ function YamlForm(props) {
16618
16615
  }
16619
16616
  const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16620
16617
  id,
16621
- config,
16618
+ resourceConfig,
16622
16619
  step,
16623
16620
  customYamlFormProps,
16624
16621
  formConfig,
@@ -16631,7 +16628,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16631
16628
  var _a, _b;
16632
16629
  const action = id ? "edit" : "create";
16633
16630
  const refineFormResult = useRefineForm({
16634
- config,
16631
+ resourceConfig,
16635
16632
  id,
16636
16633
  refineProps: {
16637
16634
  onMutationSuccess: (data2) => {
@@ -16657,7 +16654,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16657
16654
  }
16658
16655
  });
16659
16656
  const fieldsConfig = useFieldsConfig(
16660
- config,
16657
+ resourceConfig,
16661
16658
  { fields: formConfig == null ? void 0 : formConfig.fields },
16662
16659
  id,
16663
16660
  step,
@@ -16673,8 +16670,8 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16673
16670
  if (isYamlMode) {
16674
16671
  return {
16675
16672
  ...customYamlFormProps,
16676
- resource: config.name,
16677
- config,
16673
+ resource: resourceConfig.name,
16674
+ resourceConfig,
16678
16675
  transformInitValues: void 0,
16679
16676
  transformApplyValues: void 0,
16680
16677
  initialValuesForCreate: transformApplyValues(
@@ -16690,10 +16687,10 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16690
16687
  redirect: false
16691
16688
  },
16692
16689
  rules: fieldsConfig == null ? void 0 : fieldsConfig.filter(
16693
- (config2) => "isSkipValidationInYaml" in config2 && !config2.isSkipValidationInYaml
16694
- ).map((config2) => ({
16695
- path: "path" in config2 ? config2.path : [],
16696
- validators: "validators" in config2 ? config2.validators : void 0
16690
+ (config) => "isSkipValidationInYaml" in config && !config.isSkipValidationInYaml
16691
+ ).map((config) => ({
16692
+ path: "path" in config ? config.path : [],
16693
+ validators: "validators" in config ? config.validators : void 0
16697
16694
  })),
16698
16695
  onSaveButtonPropsChange,
16699
16696
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -16706,14 +16703,14 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16706
16703
  };
16707
16704
  }
16708
16705
  return {
16709
- config
16706
+ resourceConfig
16710
16707
  };
16711
16708
  }, [
16712
16709
  action,
16713
16710
  isYamlMode,
16714
16711
  customYamlFormProps,
16715
16712
  fieldsConfig,
16716
- config,
16713
+ resourceConfig,
16717
16714
  id,
16718
16715
  refineFormResult,
16719
16716
  formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -16755,7 +16752,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16755
16752
  RefineFormContent,
16756
16753
  {
16757
16754
  formResult: refineFormResult.formResult,
16758
- config,
16755
+ resourceConfig,
16759
16756
  step,
16760
16757
  formConfig,
16761
16758
  errorMsgs: [
@@ -16772,7 +16769,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16772
16769
  function YamlFormContainer({
16773
16770
  id,
16774
16771
  customYamlFormProps,
16775
- config,
16772
+ resourceConfig,
16776
16773
  formConfig,
16777
16774
  onSuccess,
16778
16775
  onError,
@@ -16787,12 +16784,12 @@ function YamlFormContainer({
16787
16784
  const yamlFormProps = React.useMemo(() => {
16788
16785
  return {
16789
16786
  ...customYamlFormProps,
16790
- resource: config.name,
16791
- config,
16787
+ resource: resourceConfig.name,
16788
+ resourceConfig,
16792
16789
  transformInitValues,
16793
16790
  transformApplyValues,
16794
16791
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
16795
- initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(config),
16792
+ initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(resourceConfig),
16796
16793
  initialValuesForEdit: void 0,
16797
16794
  id,
16798
16795
  action,
@@ -16813,7 +16810,7 @@ function YamlFormContainer({
16813
16810
  id,
16814
16811
  action,
16815
16812
  customYamlFormProps,
16816
- config,
16813
+ resourceConfig,
16817
16814
  formConfig == null ? void 0 : formConfig.beforeSubmit,
16818
16815
  transformInitValues,
16819
16816
  transformApplyValues,
@@ -16861,7 +16858,7 @@ function FormModal(props) {
16861
16858
  yamlFormProps: customYamlFormProps,
16862
16859
  modalProps,
16863
16860
  options,
16864
- config,
16861
+ resourceConfig,
16865
16862
  onSuccess
16866
16863
  } = props;
16867
16864
  const {
@@ -16875,10 +16872,10 @@ function FormModal(props) {
16875
16872
  const refineFormContainerRef = React.useRef(null);
16876
16873
  const popModal = eagle.usePopModal();
16877
16874
  const pushModal = eagle.usePushModal();
16878
- const isDisabledChangeMode = config.formConfig && "isDisabledChangeMode" in config.formConfig && config.formConfig.isDisabledChangeMode;
16875
+ const isDisabledChangeMode = resourceConfig.formConfig && "isDisabledChangeMode" in resourceConfig.formConfig && resourceConfig.formConfig.isDisabledChangeMode;
16879
16876
  const okText = i18n2.t(id ? "dovetail.save" : "dovetail.create");
16880
16877
  const action = id ? "edit" : "create";
16881
- const isYamlForm = ((_a = config.formConfig) == null ? void 0 : _a.formType) === FormType.YAML;
16878
+ const isYamlForm = ((_a = resourceConfig.formConfig) == null ? void 0 : _a.formType) === FormType.YAML;
16882
16879
  const onOk = React.useCallback((e2) => {
16883
16880
  var _a2;
16884
16881
  setIsError(false);
@@ -16906,30 +16903,30 @@ function FormModal(props) {
16906
16903
  }, [isError, id, i18n2]);
16907
16904
  const title = React.useMemo(() => {
16908
16905
  var _a2, _b2, _c2, _d2;
16909
- if (typeof ((_a2 = config.formConfig) == null ? void 0 : _a2.formTitle) === "string")
16910
- return (_b2 = config.formConfig) == null ? void 0 : _b2.formTitle;
16911
- if (typeof ((_c2 = config.formConfig) == null ? void 0 : _c2.formTitle) === "function") {
16912
- return (_d2 = config.formConfig) == null ? void 0 : _d2.formTitle(action);
16906
+ if (typeof ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formTitle) === "string")
16907
+ return (_b2 = resourceConfig.formConfig) == null ? void 0 : _b2.formTitle;
16908
+ if (typeof ((_c2 = resourceConfig.formConfig) == null ? void 0 : _c2.formTitle) === "function") {
16909
+ return (_d2 = resourceConfig.formConfig) == null ? void 0 : _d2.formTitle(action);
16913
16910
  }
16914
- const label2 = config.displayName || (config == null ? void 0 : config.kind);
16911
+ const label2 = resourceConfig.displayName || (resourceConfig == null ? void 0 : resourceConfig.kind);
16915
16912
  return i18n2.t(id ? "dovetail.edit_resource" : "dovetail.create_resource", {
16916
16913
  resource: transformResourceKindInSentence(label2, i18n2.language)
16917
16914
  });
16918
- }, [action, config.formConfig, config.displayName, config == null ? void 0 : config.kind, i18n2, id]);
16915
+ }, [action, resourceConfig.formConfig, resourceConfig.displayName, resourceConfig == null ? void 0 : resourceConfig.kind, i18n2, id]);
16919
16916
  const desc = React.useMemo(() => {
16920
16917
  var _a2, _b2, _c2, _d2;
16921
- if (typeof ((_a2 = config.formConfig) == null ? void 0 : _a2.formDesc) === "string")
16922
- return (_b2 = config.formConfig) == null ? void 0 : _b2.formDesc;
16923
- if (typeof ((_c2 = config.formConfig) == null ? void 0 : _c2.formDesc) === "function") {
16924
- return (_d2 = config.formConfig) == null ? void 0 : _d2.formDesc(action);
16918
+ if (typeof ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formDesc) === "string")
16919
+ return (_b2 = resourceConfig.formConfig) == null ? void 0 : _b2.formDesc;
16920
+ if (typeof ((_c2 = resourceConfig.formConfig) == null ? void 0 : _c2.formDesc) === "function") {
16921
+ return (_d2 = resourceConfig.formConfig) == null ? void 0 : _d2.formDesc(action);
16925
16922
  }
16926
16923
  return "";
16927
- }, [action, config.formConfig]);
16924
+ }, [action, resourceConfig.formConfig]);
16928
16925
  const formEle = React.useMemo(() => {
16929
16926
  var _a2;
16930
16927
  const commonFormProps = {
16931
16928
  id,
16932
- config,
16929
+ resourceConfig,
16933
16930
  customYamlFormProps,
16934
16931
  onSaveButtonPropsChange: setSaveButtonProps,
16935
16932
  onError: () => {
@@ -16941,28 +16938,28 @@ function FormModal(props) {
16941
16938
  onSuccess == null ? void 0 : onSuccess(data2);
16942
16939
  }
16943
16940
  };
16944
- if (config.formConfig && (((_a2 = config.formConfig) == null ? void 0 : _a2.formType) === FormType.FORM || "fields" in config.formConfig)) {
16941
+ if (resourceConfig.formConfig && (((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formType) === FormType.FORM || "fields" in resourceConfig.formConfig)) {
16945
16942
  return /* @__PURE__ */ common.jsxRuntimeExports.jsx(RefineFormContainer, {
16946
16943
  ...commonFormProps,
16947
16944
  ref: refineFormContainerRef,
16948
16945
  step,
16949
16946
  options,
16950
16947
  isYamlMode,
16951
- formConfig: config.formConfig
16948
+ formConfig: resourceConfig.formConfig
16952
16949
  });
16953
16950
  }
16954
16951
  return /* @__PURE__ */ common.jsxRuntimeExports.jsx(YamlFormContainer, {
16955
16952
  ...commonFormProps,
16956
- formConfig: config.formConfig
16953
+ formConfig: resourceConfig.formConfig
16957
16954
  });
16958
- }, [id, customYamlFormProps, config, isYamlMode, step, options, popModal, setSaveButtonProps, onSuccess]);
16955
+ }, [id, customYamlFormProps, resourceConfig, isYamlMode, step, options, popModal, setSaveButtonProps, onSuccess]);
16959
16956
  const steps = React.useMemo(() => {
16960
16957
  var _a2, _b2;
16961
16958
  if (isYamlMode) {
16962
16959
  return void 0;
16963
16960
  }
16964
- if (config.formConfig && "steps" in config.formConfig) {
16965
- return (_b2 = (_a2 = config.formConfig) == null ? void 0 : _a2.steps) == null ? void 0 : _b2.map((step2, index2) => ({
16961
+ if (resourceConfig.formConfig && "steps" in resourceConfig.formConfig) {
16962
+ return (_b2 = (_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.steps) == null ? void 0 : _b2.map((step2, index2) => ({
16966
16963
  title: step2.title,
16967
16964
  children: /* @__PURE__ */ common.jsxRuntimeExports.jsxs(common.jsxRuntimeExports.Fragment, {
16968
16965
  children: [desc && index2 === 0 ? /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", {
@@ -16973,7 +16970,7 @@ function FormModal(props) {
16973
16970
  }));
16974
16971
  }
16975
16972
  return void 0;
16976
- }, [config.formConfig, desc, formEle, isYamlMode]);
16973
+ }, [resourceConfig.formConfig, desc, formEle, isYamlMode]);
16977
16974
  const handleStepChange = React.useCallback(async (nextStep) => {
16978
16975
  var _a2, _b2;
16979
16976
  const isNextStep = nextStep > step;
@@ -16995,8 +16992,8 @@ function FormModal(props) {
16995
16992
  className: TitleWrapperStyle,
16996
16993
  children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx("span", {
16997
16994
  children: title
16998
- }), ((_b = config.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ common.jsxRuntimeExports.jsx(FormModeSegmentControl, {
16999
- formConfig: config.formConfig,
16995
+ }), ((_b = resourceConfig.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ common.jsxRuntimeExports.jsx(FormModeSegmentControl, {
16996
+ formConfig: resourceConfig.formConfig,
17000
16997
  mode,
17001
16998
  onChangeMode
17002
16999
  }) : null]
@@ -17008,9 +17005,9 @@ function FormModal(props) {
17008
17005
  onOk,
17009
17006
  okButtonProps: {
17010
17007
  ...lodashEs.omit(saveButtonProps, "onClick"),
17011
- children: (_c = config.formConfig) == null ? void 0 : _c.saveButtonText
17008
+ children: (_c = resourceConfig.formConfig) == null ? void 0 : _c.saveButtonText
17012
17009
  },
17013
- okText: ((_d = config.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
17010
+ okText: ((_d = resourceConfig.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
17014
17011
  destroyOnClose: true,
17015
17012
  destroyOtherStep: true,
17016
17013
  ...modalProps,
@@ -17034,7 +17031,7 @@ const RefineFormPage = (props) => {
17034
17031
  const {
17035
17032
  formResult
17036
17033
  } = useRefineForm({
17037
- config,
17034
+ resourceConfig: config,
17038
17035
  id
17039
17036
  });
17040
17037
  const action = id ? "edit" : "create";
@@ -17053,7 +17050,7 @@ const RefineFormPage = (props) => {
17053
17050
  direction: "vertical",
17054
17051
  className: "c1pvtlkp",
17055
17052
  children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx(RefineFormContent, {
17056
- config,
17053
+ resourceConfig: config,
17057
17054
  formResult,
17058
17055
  resourceId: id,
17059
17056
  transformedInitValues: formResult.transformedInitValues
@@ -17066,18 +17063,18 @@ const RefineFormPage = (props) => {
17066
17063
  };
17067
17064
  function ResourceForm(props) {
17068
17065
  var _a;
17069
- const { config } = props;
17066
+ const { resourceConfig } = props;
17070
17067
  const formProps = React.useMemo(() => {
17071
17068
  var _a2, _b;
17072
17069
  return {
17073
- initialValues: getInitialValues(config),
17074
- transformInitValues: (_a2 = config.formConfig) == null ? void 0 : _a2.transformInitValues,
17075
- transformApplyValues: (_b = config.formConfig) == null ? void 0 : _b.transformApplyValues,
17076
- config
17070
+ initialValues: getInitialValues(resourceConfig),
17071
+ transformInitValues: (_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.transformInitValues,
17072
+ transformApplyValues: (_b = resourceConfig.formConfig) == null ? void 0 : _b.transformApplyValues,
17073
+ resourceConfig
17077
17074
  };
17078
- }, [config]);
17079
- if (((_a = config.formConfig) == null ? void 0 : _a.formType) === FormType.FORM) {
17080
- return /* @__PURE__ */ common.jsxRuntimeExports.jsx(RefineFormPage, { config });
17075
+ }, [resourceConfig]);
17076
+ if (((_a = resourceConfig.formConfig) == null ? void 0 : _a.formType) === FormType.FORM) {
17077
+ return /* @__PURE__ */ common.jsxRuntimeExports.jsx(RefineFormPage, { config: resourceConfig });
17081
17078
  }
17082
17079
  return /* @__PURE__ */ common.jsxRuntimeExports.jsx(YamlForm, { ...formProps });
17083
17080
  }
@@ -17090,8 +17087,8 @@ function ResourceCRUD(props) {
17090
17087
  !config.noShow ? /* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/show`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceShow, { config }) }) : null,
17091
17088
  // the modals would render in ModalStack
17092
17089
  ((_a = config.formConfig) == null ? void 0 : _a.formContainerType) === FormContainerType.PAGE ? /* @__PURE__ */ common.jsxRuntimeExports.jsxs(common.jsxRuntimeExports.Fragment, { children: [
17093
- /* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/create`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceForm, { config }) }),
17094
- /* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/edit`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceForm, { config }) })
17090
+ /* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/create`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceForm, { resourceConfig: config }) }),
17091
+ /* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/edit`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceForm, { resourceConfig: config }) })
17095
17092
  ] }) : null
17096
17093
  ] }, config.name);
17097
17094
  }) });
package/dist/refine.js CHANGED
@@ -10565,22 +10565,22 @@ function useOpenForm() {
10565
10565
  const go = useGo();
10566
10566
  return function openForm(options) {
10567
10567
  var _a, _b;
10568
- const finalResourceName = (options == null ? void 0 : options.resourceName) || ((_a = options == null ? void 0 : options.config) == null ? void 0 : _a.name) || (resource == null ? void 0 : resource.name);
10569
- if (finalResourceName || (options == null ? void 0 : options.config)) {
10570
- const config = (options == null ? void 0 : options.config) || configs[finalResourceName || ""];
10571
- const formType = (_b = config.formConfig) == null ? void 0 : _b.formContainerType;
10568
+ const finalResourceName = (options == null ? void 0 : options.resourceName) || ((_a = options == null ? void 0 : options.resourceConfig) == null ? void 0 : _a.name) || (resource == null ? void 0 : resource.name);
10569
+ if (finalResourceName || (options == null ? void 0 : options.resourceConfig)) {
10570
+ const resourceConfig = (options == null ? void 0 : options.resourceConfig) || configs[finalResourceName || ""];
10571
+ const formType = (_b = resourceConfig.formConfig) == null ? void 0 : _b.formContainerType;
10572
10572
  if (formType === void 0 || formType === FormContainerType.MODAL) {
10573
10573
  pushModal({
10574
10574
  component: () => {
10575
10575
  var _a2;
10576
- const ModalComponent = ((_a2 = config.formConfig) == null ? void 0 : _a2.CustomFormModal) || FormModal;
10576
+ const ModalComponent = ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.CustomFormModal) || FormModal;
10577
10577
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
10578
10578
  ModalComponent,
10579
10579
  {
10580
10580
  id: options == null ? void 0 : options.id,
10581
- config,
10581
+ resourceConfig,
10582
10582
  yamlFormProps: {
10583
- config
10583
+ resourceConfig
10584
10584
  },
10585
10585
  options,
10586
10586
  onSuccess: options == null ? void 0 : options.onSuccess
@@ -10818,23 +10818,20 @@ function K8sDropdown(props) {
10818
10818
  const {
10819
10819
  record,
10820
10820
  size = "normal",
10821
- resourceName: resourceNameFromProps,
10822
- config: configFromProps,
10821
+ resourceConfig,
10823
10822
  customButton,
10824
- deleteDialogProps,
10825
- displayName,
10826
- hideEdit
10823
+ deleteDialogProps
10827
10824
  } = props;
10828
10825
  const globalStore = useGlobalStore();
10829
10826
  const useResourceResult = useResource();
10830
10827
  const configs = useContext(ConfigsContext);
10831
- const resourceName = resourceNameFromProps || getResourceNameByKind(record.kind || "", configs);
10832
- const config = configFromProps || configs[resourceName || ""];
10828
+ const resourceName = (resourceConfig == null ? void 0 : resourceConfig.name) || getResourceNameByKind(record.kind || "", configs);
10829
+ const config = resourceConfig || configs[resourceName || ""];
10833
10830
  const { t: t2, i18n: i18n2 } = useTranslation();
10834
10831
  const { openDeleteConfirmModal } = useDeleteModal({
10835
10832
  resourceName: resourceName || "",
10836
10833
  deleteDialogProps,
10837
- displayName,
10834
+ displayName: config.displayName,
10838
10835
  meta: record.apiVersion ? {
10839
10836
  kind: record.kind || "",
10840
10837
  resourceBasePath: (
@@ -10865,12 +10862,12 @@ function K8sDropdown(props) {
10865
10862
  Dropdown,
10866
10863
  {
10867
10864
  overlay: /* @__PURE__ */ jsxRuntimeExports.jsxs(Menu$1, { children: [
10868
- isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || hideEdit || (config == null ? void 0 : config.hideEdit) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(
10865
+ isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || (config == null ? void 0 : config.hideEdit) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(
10869
10866
  Menu$1.Item,
10870
10867
  {
10871
- onClick: () => openForm({ id: record.id, resourceName, config }),
10868
+ onClick: () => openForm({ id: record.id, resourceName, resourceConfig: config }),
10872
10869
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(Icon, { src: EditPen16PrimaryIcon, children: formType === FormType.FORM ? `${t2("dovetail.edit")}${transformResourceKindInSentence(
10873
- displayName || (config == null ? void 0 : config.displayName) || record.kind || "",
10870
+ config.displayName || record.kind || "",
10874
10871
  i18n2.language
10875
10872
  )}` : t2("dovetail.edit_yaml") })
10876
10873
  }
@@ -14665,10 +14662,10 @@ function ResourceShow(props) {
14665
14662
  }
14666
14663
  );
14667
14664
  }
14668
- function getInitialValues(config) {
14669
- return config.initValue || {
14670
- apiVersion: config.apiVersion,
14671
- kind: config.kind,
14665
+ function getInitialValues(resourceConfig) {
14666
+ return resourceConfig.initValue || {
14667
+ apiVersion: resourceConfig.apiVersion,
14668
+ kind: resourceConfig.kind,
14672
14669
  ...BASE_INIT_VALUE,
14673
14670
  spec: {}
14674
14671
  };
@@ -14807,19 +14804,19 @@ const SpaceStyle = "sea7f83";
14807
14804
  const VerticalFormItemStyle = "v1jthrhz";
14808
14805
  const IntegerStyle = "i1brpchs";
14809
14806
  const ContentWrapper = "c11mae2d";
14810
- function useFieldsConfig(config, formConfig, resourceId, step, customOptions, transformedInitValues) {
14807
+ function useFieldsConfig(resourceConfig, formConfig, resourceId, step, customOptions, transformedInitValues) {
14811
14808
  var _a, _b, _c;
14812
14809
  const action = resourceId ? "edit" : "create";
14813
14810
  const listQuery = useList({
14814
- resource: config == null ? void 0 : config.name,
14815
- meta: { resourceBasePath: config == null ? void 0 : config.basePath, kind: config == null ? void 0 : config.kind },
14811
+ resource: resourceConfig == null ? void 0 : resourceConfig.name,
14812
+ meta: { resourceBasePath: resourceConfig == null ? void 0 : resourceConfig.basePath, kind: resourceConfig == null ? void 0 : resourceConfig.kind },
14816
14813
  pagination: {
14817
14814
  mode: "off"
14818
14815
  }
14819
14816
  });
14820
14817
  const showQuery = useShow({
14821
- resource: config == null ? void 0 : config.name,
14822
- meta: { resourceBasePath: config == null ? void 0 : config.basePath, kind: config == null ? void 0 : config.kind },
14818
+ resource: resourceConfig == null ? void 0 : resourceConfig.name,
14819
+ meta: { resourceBasePath: resourceConfig == null ? void 0 : resourceConfig.basePath, kind: resourceConfig == null ? void 0 : resourceConfig.kind },
14823
14820
  id: resourceId
14824
14821
  });
14825
14822
  return (_c = formConfig == null ? void 0 : formConfig.fields) == null ? void 0 : _c.call(formConfig, {
@@ -14934,7 +14931,7 @@ const MemoizedFormField = memo(function FormField({
14934
14931
  });
14935
14932
  function FieldsContent(props) {
14936
14933
  const {
14937
- config,
14934
+ resourceConfig,
14938
14935
  formConfig,
14939
14936
  resourceId,
14940
14937
  step,
@@ -14946,7 +14943,7 @@ function FieldsContent(props) {
14946
14943
  const { control, getValues, watch, trigger } = formResult;
14947
14944
  const action = resourceId ? "edit" : "create";
14948
14945
  const formFieldsConfig = useFieldsConfig(
14949
- config,
14946
+ resourceConfig,
14950
14947
  { fields },
14951
14948
  resourceId,
14952
14949
  step,
@@ -14964,7 +14961,7 @@ function FieldsContent(props) {
14964
14961
  children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: ContentWrapper, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
14965
14962
  FieldsContent,
14966
14963
  {
14967
- config,
14964
+ resourceConfig,
14968
14965
  formConfig,
14969
14966
  resourceId,
14970
14967
  step,
@@ -14994,7 +14991,7 @@ function FieldsContent(props) {
14994
14991
  }
14995
14992
  const RefineFormContent = (props) => {
14996
14993
  const {
14997
- config,
14994
+ resourceConfig: config,
14998
14995
  formResult,
14999
14996
  resourceId,
15000
14997
  errorMsgs,
@@ -15008,7 +15005,7 @@ const RefineFormContent = (props) => {
15008
15005
  /* @__PURE__ */ jsxRuntimeExports.jsx(
15009
15006
  FieldsContent,
15010
15007
  {
15011
- config,
15008
+ resourceConfig: config,
15012
15009
  formConfig,
15013
15010
  fields: formConfig == null ? void 0 : formConfig.fields,
15014
15011
  resourceId,
@@ -15719,7 +15716,7 @@ const useForm = ({
15719
15716
  };
15720
15717
  };
15721
15718
  const useRefineForm = (props) => {
15722
- const { formConfig, config, id, refineProps, options } = props;
15719
+ const { formConfig, resourceConfig, id, refineProps, options } = props;
15723
15720
  const { transformInitValues, transformApplyValues } = usePathMap({
15724
15721
  pathMap: formConfig == null ? void 0 : formConfig.pathMap,
15725
15722
  transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
@@ -15738,7 +15735,7 @@ const useRefineForm = (props) => {
15738
15735
  return {
15739
15736
  message: i18n2.t(id ? "dovetail.edit_resource_success" : "dovetail.create_success_toast", {
15740
15737
  kind: transformResourceKindInSentence(
15741
- config.displayName || config.kind,
15738
+ resourceConfig.displayName || resourceConfig.kind,
15742
15739
  i18n2.language
15743
15740
  ),
15744
15741
  name: (_a = formValue.metadata) == null ? void 0 : _a.name,
@@ -15748,13 +15745,13 @@ const useRefineForm = (props) => {
15748
15745
  type: "success"
15749
15746
  };
15750
15747
  },
15751
- resource: config.name,
15748
+ resource: resourceConfig.name,
15752
15749
  action: id ? "edit" : "create",
15753
15750
  id,
15754
15751
  liveMode: "off",
15755
15752
  ...refineProps
15756
15753
  },
15757
- defaultValues: (options == null ? void 0 : options.initialValues) || (config == null ? void 0 : config.initValue),
15754
+ defaultValues: (options == null ? void 0 : options.initialValues) || (resourceConfig == null ? void 0 : resourceConfig.initValue),
15758
15755
  transformApplyValues,
15759
15756
  transformInitValues,
15760
15757
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -16452,7 +16449,7 @@ function YamlForm(props) {
16452
16449
  schemaStrategy = "Optional",
16453
16450
  isShowLayout = true,
16454
16451
  useFormProps,
16455
- config,
16452
+ resourceConfig,
16456
16453
  transformInitValues,
16457
16454
  transformApplyValues,
16458
16455
  beforeSubmit,
@@ -16496,7 +16493,7 @@ function YamlForm(props) {
16496
16493
  beforeSubmit,
16497
16494
  successNotification(data2) {
16498
16495
  var _a;
16499
- const displayName = config.displayName || ((_a = resource == null ? void 0 : resource.meta) == null ? void 0 : _a.kind);
16496
+ const displayName = resourceConfig.displayName || ((_a = resource == null ? void 0 : resource.meta) == null ? void 0 : _a.kind);
16500
16497
  return {
16501
16498
  message: i18n2.t(action === "create" ? "dovetail.create_success_toast" : "dovetail.save_yaml_success_toast", {
16502
16499
  kind: transformResourceKindInSentence(displayName, i18n2.language),
@@ -16513,10 +16510,10 @@ function YamlForm(props) {
16513
16510
  transformApplyValues,
16514
16511
  mutationMeta: {
16515
16512
  updateType: "put",
16516
- dataProviderName: config.dataProviderName,
16517
- resourceBasePath: config.basePath,
16518
- kind: config.kind,
16519
- label: `${config.kind}s`
16513
+ dataProviderName: resourceConfig.dataProviderName,
16514
+ resourceBasePath: resourceConfig.basePath,
16515
+ kind: resourceConfig.kind,
16516
+ label: `${resourceConfig.kind}s`
16520
16517
  },
16521
16518
  ...useFormProps
16522
16519
  });
@@ -16599,7 +16596,7 @@ function YamlForm(props) {
16599
16596
  }
16600
16597
  const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16601
16598
  id,
16602
- config,
16599
+ resourceConfig,
16603
16600
  step,
16604
16601
  customYamlFormProps,
16605
16602
  formConfig,
@@ -16612,7 +16609,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16612
16609
  var _a, _b;
16613
16610
  const action = id ? "edit" : "create";
16614
16611
  const refineFormResult = useRefineForm({
16615
- config,
16612
+ resourceConfig,
16616
16613
  id,
16617
16614
  refineProps: {
16618
16615
  onMutationSuccess: (data2) => {
@@ -16638,7 +16635,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16638
16635
  }
16639
16636
  });
16640
16637
  const fieldsConfig = useFieldsConfig(
16641
- config,
16638
+ resourceConfig,
16642
16639
  { fields: formConfig == null ? void 0 : formConfig.fields },
16643
16640
  id,
16644
16641
  step,
@@ -16654,8 +16651,8 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16654
16651
  if (isYamlMode) {
16655
16652
  return {
16656
16653
  ...customYamlFormProps,
16657
- resource: config.name,
16658
- config,
16654
+ resource: resourceConfig.name,
16655
+ resourceConfig,
16659
16656
  transformInitValues: void 0,
16660
16657
  transformApplyValues: void 0,
16661
16658
  initialValuesForCreate: transformApplyValues(
@@ -16671,10 +16668,10 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16671
16668
  redirect: false
16672
16669
  },
16673
16670
  rules: fieldsConfig == null ? void 0 : fieldsConfig.filter(
16674
- (config2) => "isSkipValidationInYaml" in config2 && !config2.isSkipValidationInYaml
16675
- ).map((config2) => ({
16676
- path: "path" in config2 ? config2.path : [],
16677
- validators: "validators" in config2 ? config2.validators : void 0
16671
+ (config) => "isSkipValidationInYaml" in config && !config.isSkipValidationInYaml
16672
+ ).map((config) => ({
16673
+ path: "path" in config ? config.path : [],
16674
+ validators: "validators" in config ? config.validators : void 0
16678
16675
  })),
16679
16676
  onSaveButtonPropsChange,
16680
16677
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -16687,14 +16684,14 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16687
16684
  };
16688
16685
  }
16689
16686
  return {
16690
- config
16687
+ resourceConfig
16691
16688
  };
16692
16689
  }, [
16693
16690
  action,
16694
16691
  isYamlMode,
16695
16692
  customYamlFormProps,
16696
16693
  fieldsConfig,
16697
- config,
16694
+ resourceConfig,
16698
16695
  id,
16699
16696
  refineFormResult,
16700
16697
  formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -16736,7 +16733,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16736
16733
  RefineFormContent,
16737
16734
  {
16738
16735
  formResult: refineFormResult.formResult,
16739
- config,
16736
+ resourceConfig,
16740
16737
  step,
16741
16738
  formConfig,
16742
16739
  errorMsgs: [
@@ -16753,7 +16750,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16753
16750
  function YamlFormContainer({
16754
16751
  id,
16755
16752
  customYamlFormProps,
16756
- config,
16753
+ resourceConfig,
16757
16754
  formConfig,
16758
16755
  onSuccess,
16759
16756
  onError,
@@ -16768,12 +16765,12 @@ function YamlFormContainer({
16768
16765
  const yamlFormProps = useMemo(() => {
16769
16766
  return {
16770
16767
  ...customYamlFormProps,
16771
- resource: config.name,
16772
- config,
16768
+ resource: resourceConfig.name,
16769
+ resourceConfig,
16773
16770
  transformInitValues,
16774
16771
  transformApplyValues,
16775
16772
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
16776
- initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(config),
16773
+ initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(resourceConfig),
16777
16774
  initialValuesForEdit: void 0,
16778
16775
  id,
16779
16776
  action,
@@ -16794,7 +16791,7 @@ function YamlFormContainer({
16794
16791
  id,
16795
16792
  action,
16796
16793
  customYamlFormProps,
16797
- config,
16794
+ resourceConfig,
16798
16795
  formConfig == null ? void 0 : formConfig.beforeSubmit,
16799
16796
  transformInitValues,
16800
16797
  transformApplyValues,
@@ -16842,7 +16839,7 @@ function FormModal(props) {
16842
16839
  yamlFormProps: customYamlFormProps,
16843
16840
  modalProps,
16844
16841
  options,
16845
- config,
16842
+ resourceConfig,
16846
16843
  onSuccess
16847
16844
  } = props;
16848
16845
  const {
@@ -16856,10 +16853,10 @@ function FormModal(props) {
16856
16853
  const refineFormContainerRef = useRef(null);
16857
16854
  const popModal = usePopModal();
16858
16855
  const pushModal = usePushModal();
16859
- const isDisabledChangeMode = config.formConfig && "isDisabledChangeMode" in config.formConfig && config.formConfig.isDisabledChangeMode;
16856
+ const isDisabledChangeMode = resourceConfig.formConfig && "isDisabledChangeMode" in resourceConfig.formConfig && resourceConfig.formConfig.isDisabledChangeMode;
16860
16857
  const okText = i18n2.t(id ? "dovetail.save" : "dovetail.create");
16861
16858
  const action = id ? "edit" : "create";
16862
- const isYamlForm = ((_a = config.formConfig) == null ? void 0 : _a.formType) === FormType.YAML;
16859
+ const isYamlForm = ((_a = resourceConfig.formConfig) == null ? void 0 : _a.formType) === FormType.YAML;
16863
16860
  const onOk = useCallback((e2) => {
16864
16861
  var _a2;
16865
16862
  setIsError(false);
@@ -16887,30 +16884,30 @@ function FormModal(props) {
16887
16884
  }, [isError, id, i18n2]);
16888
16885
  const title = useMemo(() => {
16889
16886
  var _a2, _b2, _c2, _d2;
16890
- if (typeof ((_a2 = config.formConfig) == null ? void 0 : _a2.formTitle) === "string")
16891
- return (_b2 = config.formConfig) == null ? void 0 : _b2.formTitle;
16892
- if (typeof ((_c2 = config.formConfig) == null ? void 0 : _c2.formTitle) === "function") {
16893
- return (_d2 = config.formConfig) == null ? void 0 : _d2.formTitle(action);
16887
+ if (typeof ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formTitle) === "string")
16888
+ return (_b2 = resourceConfig.formConfig) == null ? void 0 : _b2.formTitle;
16889
+ if (typeof ((_c2 = resourceConfig.formConfig) == null ? void 0 : _c2.formTitle) === "function") {
16890
+ return (_d2 = resourceConfig.formConfig) == null ? void 0 : _d2.formTitle(action);
16894
16891
  }
16895
- const label2 = config.displayName || (config == null ? void 0 : config.kind);
16892
+ const label2 = resourceConfig.displayName || (resourceConfig == null ? void 0 : resourceConfig.kind);
16896
16893
  return i18n2.t(id ? "dovetail.edit_resource" : "dovetail.create_resource", {
16897
16894
  resource: transformResourceKindInSentence(label2, i18n2.language)
16898
16895
  });
16899
- }, [action, config.formConfig, config.displayName, config == null ? void 0 : config.kind, i18n2, id]);
16896
+ }, [action, resourceConfig.formConfig, resourceConfig.displayName, resourceConfig == null ? void 0 : resourceConfig.kind, i18n2, id]);
16900
16897
  const desc = useMemo(() => {
16901
16898
  var _a2, _b2, _c2, _d2;
16902
- if (typeof ((_a2 = config.formConfig) == null ? void 0 : _a2.formDesc) === "string")
16903
- return (_b2 = config.formConfig) == null ? void 0 : _b2.formDesc;
16904
- if (typeof ((_c2 = config.formConfig) == null ? void 0 : _c2.formDesc) === "function") {
16905
- return (_d2 = config.formConfig) == null ? void 0 : _d2.formDesc(action);
16899
+ if (typeof ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formDesc) === "string")
16900
+ return (_b2 = resourceConfig.formConfig) == null ? void 0 : _b2.formDesc;
16901
+ if (typeof ((_c2 = resourceConfig.formConfig) == null ? void 0 : _c2.formDesc) === "function") {
16902
+ return (_d2 = resourceConfig.formConfig) == null ? void 0 : _d2.formDesc(action);
16906
16903
  }
16907
16904
  return "";
16908
- }, [action, config.formConfig]);
16905
+ }, [action, resourceConfig.formConfig]);
16909
16906
  const formEle = useMemo(() => {
16910
16907
  var _a2;
16911
16908
  const commonFormProps = {
16912
16909
  id,
16913
- config,
16910
+ resourceConfig,
16914
16911
  customYamlFormProps,
16915
16912
  onSaveButtonPropsChange: setSaveButtonProps,
16916
16913
  onError: () => {
@@ -16922,28 +16919,28 @@ function FormModal(props) {
16922
16919
  onSuccess == null ? void 0 : onSuccess(data2);
16923
16920
  }
16924
16921
  };
16925
- if (config.formConfig && (((_a2 = config.formConfig) == null ? void 0 : _a2.formType) === FormType.FORM || "fields" in config.formConfig)) {
16922
+ if (resourceConfig.formConfig && (((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formType) === FormType.FORM || "fields" in resourceConfig.formConfig)) {
16926
16923
  return /* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormContainer, {
16927
16924
  ...commonFormProps,
16928
16925
  ref: refineFormContainerRef,
16929
16926
  step,
16930
16927
  options,
16931
16928
  isYamlMode,
16932
- formConfig: config.formConfig
16929
+ formConfig: resourceConfig.formConfig
16933
16930
  });
16934
16931
  }
16935
16932
  return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlFormContainer, {
16936
16933
  ...commonFormProps,
16937
- formConfig: config.formConfig
16934
+ formConfig: resourceConfig.formConfig
16938
16935
  });
16939
- }, [id, customYamlFormProps, config, isYamlMode, step, options, popModal, setSaveButtonProps, onSuccess]);
16936
+ }, [id, customYamlFormProps, resourceConfig, isYamlMode, step, options, popModal, setSaveButtonProps, onSuccess]);
16940
16937
  const steps = useMemo(() => {
16941
16938
  var _a2, _b2;
16942
16939
  if (isYamlMode) {
16943
16940
  return void 0;
16944
16941
  }
16945
- if (config.formConfig && "steps" in config.formConfig) {
16946
- return (_b2 = (_a2 = config.formConfig) == null ? void 0 : _a2.steps) == null ? void 0 : _b2.map((step2, index2) => ({
16942
+ if (resourceConfig.formConfig && "steps" in resourceConfig.formConfig) {
16943
+ return (_b2 = (_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.steps) == null ? void 0 : _b2.map((step2, index2) => ({
16947
16944
  title: step2.title,
16948
16945
  children: /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
16949
16946
  children: [desc && index2 === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", {
@@ -16954,7 +16951,7 @@ function FormModal(props) {
16954
16951
  }));
16955
16952
  }
16956
16953
  return void 0;
16957
- }, [config.formConfig, desc, formEle, isYamlMode]);
16954
+ }, [resourceConfig.formConfig, desc, formEle, isYamlMode]);
16958
16955
  const handleStepChange = useCallback(async (nextStep) => {
16959
16956
  var _a2, _b2;
16960
16957
  const isNextStep = nextStep > step;
@@ -16976,8 +16973,8 @@ function FormModal(props) {
16976
16973
  className: TitleWrapperStyle,
16977
16974
  children: [/* @__PURE__ */ jsxRuntimeExports.jsx("span", {
16978
16975
  children: title
16979
- }), ((_b = config.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ jsxRuntimeExports.jsx(FormModeSegmentControl, {
16980
- formConfig: config.formConfig,
16976
+ }), ((_b = resourceConfig.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ jsxRuntimeExports.jsx(FormModeSegmentControl, {
16977
+ formConfig: resourceConfig.formConfig,
16981
16978
  mode,
16982
16979
  onChangeMode
16983
16980
  }) : null]
@@ -16989,9 +16986,9 @@ function FormModal(props) {
16989
16986
  onOk,
16990
16987
  okButtonProps: {
16991
16988
  ...omit$1(saveButtonProps, "onClick"),
16992
- children: (_c = config.formConfig) == null ? void 0 : _c.saveButtonText
16989
+ children: (_c = resourceConfig.formConfig) == null ? void 0 : _c.saveButtonText
16993
16990
  },
16994
- okText: ((_d = config.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
16991
+ okText: ((_d = resourceConfig.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
16995
16992
  destroyOnClose: true,
16996
16993
  destroyOtherStep: true,
16997
16994
  ...modalProps,
@@ -17015,7 +17012,7 @@ const RefineFormPage = (props) => {
17015
17012
  const {
17016
17013
  formResult
17017
17014
  } = useRefineForm({
17018
- config,
17015
+ resourceConfig: config,
17019
17016
  id
17020
17017
  });
17021
17018
  const action = id ? "edit" : "create";
@@ -17034,7 +17031,7 @@ const RefineFormPage = (props) => {
17034
17031
  direction: "vertical",
17035
17032
  className: "c1pvtlkp",
17036
17033
  children: [/* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormContent, {
17037
- config,
17034
+ resourceConfig: config,
17038
17035
  formResult,
17039
17036
  resourceId: id,
17040
17037
  transformedInitValues: formResult.transformedInitValues
@@ -17047,18 +17044,18 @@ const RefineFormPage = (props) => {
17047
17044
  };
17048
17045
  function ResourceForm(props) {
17049
17046
  var _a;
17050
- const { config } = props;
17047
+ const { resourceConfig } = props;
17051
17048
  const formProps = useMemo(() => {
17052
17049
  var _a2, _b;
17053
17050
  return {
17054
- initialValues: getInitialValues(config),
17055
- transformInitValues: (_a2 = config.formConfig) == null ? void 0 : _a2.transformInitValues,
17056
- transformApplyValues: (_b = config.formConfig) == null ? void 0 : _b.transformApplyValues,
17057
- config
17051
+ initialValues: getInitialValues(resourceConfig),
17052
+ transformInitValues: (_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.transformInitValues,
17053
+ transformApplyValues: (_b = resourceConfig.formConfig) == null ? void 0 : _b.transformApplyValues,
17054
+ resourceConfig
17058
17055
  };
17059
- }, [config]);
17060
- if (((_a = config.formConfig) == null ? void 0 : _a.formType) === FormType.FORM) {
17061
- return /* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormPage, { config });
17056
+ }, [resourceConfig]);
17057
+ if (((_a = resourceConfig.formConfig) == null ? void 0 : _a.formType) === FormType.FORM) {
17058
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormPage, { config: resourceConfig });
17062
17059
  }
17063
17060
  return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlForm, { ...formProps });
17064
17061
  }
@@ -17071,8 +17068,8 @@ function ResourceCRUD(props) {
17071
17068
  !config.noShow ? /* @__PURE__ */ jsxRuntimeExports.jsx(Route, { path: `${urlPrefix}/${config.name}/show`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceShow, { config }) }) : null,
17072
17069
  // the modals would render in ModalStack
17073
17070
  ((_a = config.formConfig) == null ? void 0 : _a.formContainerType) === FormContainerType.PAGE ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
17074
- /* @__PURE__ */ jsxRuntimeExports.jsx(Route, { path: `${urlPrefix}/${config.name}/create`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceForm, { config }) }),
17075
- /* @__PURE__ */ jsxRuntimeExports.jsx(Route, { path: `${urlPrefix}/${config.name}/edit`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceForm, { config }) })
17071
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Route, { path: `${urlPrefix}/${config.name}/create`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceForm, { resourceConfig: config }) }),
17072
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Route, { path: `${urlPrefix}/${config.name}/edit`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceForm, { resourceConfig: config }) })
17076
17073
  ] }) : null
17077
17074
  ] }, config.name);
17078
17075
  }) });
@@ -1,3 +1,3 @@
1
1
  import { ResourceModel } from 'src/models';
2
2
  import { ResourceConfig } from 'src/types';
3
- export declare function getInitialValues<Model extends ResourceModel = ResourceModel>(config: Pick<ResourceConfig<Model>, 'apiVersion' | 'kind' | 'initValue'>): Record<string, unknown>;
3
+ export declare function getInitialValues<Model extends ResourceModel = ResourceModel>(resourceConfig: Pick<ResourceConfig<Model>, 'apiVersion' | 'kind' | 'initValue'>): Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dovetail-v2/refine",
3
- "version": "0.3.19-alpha.2",
3
+ "version": "0.3.19-alpha.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",