@dovetail-v2/refine 0.3.19-alpha.1 → 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.
package/dist/refine.js CHANGED
@@ -10564,23 +10564,23 @@ function useOpenForm() {
10564
10564
  const pushModal = usePushModal();
10565
10565
  const go = useGo();
10566
10566
  return function openForm(options) {
10567
- var _a;
10568
- const finalResourceName = (options == null ? void 0 : options.resourceName) || (resource == null ? void 0 : resource.name);
10569
- if (finalResourceName) {
10570
- const config = configs[finalResourceName];
10571
- const formType = (_a = config.formConfig) == null ? void 0 : _a.formContainerType;
10567
+ var _a, _b;
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
- resource: finalResourceName,
10581
10580
  id: options == null ? void 0 : options.id,
10581
+ resourceConfig,
10582
10582
  yamlFormProps: {
10583
- config
10583
+ resourceConfig
10584
10584
  },
10585
10585
  options,
10586
10586
  onSuccess: options == null ? void 0 : options.onSuccess
@@ -10593,7 +10593,7 @@ function useOpenForm() {
10593
10593
  edit2(options.id);
10594
10594
  } else {
10595
10595
  go({
10596
- to: navigation.createUrl(finalResourceName),
10596
+ to: navigation.createUrl(finalResourceName || ""),
10597
10597
  options: {
10598
10598
  keepQuery: true
10599
10599
  }
@@ -10818,25 +10818,26 @@ function K8sDropdown(props) {
10818
10818
  const {
10819
10819
  record,
10820
10820
  size = "normal",
10821
- resourceName: resourceNameFromProps,
10821
+ resourceConfig,
10822
10822
  customButton,
10823
- deleteDialogProps,
10824
- displayName,
10825
- hideEdit
10823
+ deleteDialogProps
10826
10824
  } = props;
10827
10825
  const globalStore = useGlobalStore();
10828
10826
  const useResourceResult = useResource();
10829
10827
  const configs = useContext(ConfigsContext);
10830
- const resourceName = resourceNameFromProps || getResourceNameByKind(record.kind || "", configs);
10831
- const config = configs[resourceName || ""];
10828
+ const resourceName = (resourceConfig == null ? void 0 : resourceConfig.name) || getResourceNameByKind(record.kind || "", configs);
10829
+ const config = resourceConfig || configs[resourceName || ""];
10832
10830
  const { t: t2, i18n: i18n2 } = useTranslation();
10833
10831
  const { openDeleteConfirmModal } = useDeleteModal({
10834
10832
  resourceName: resourceName || "",
10835
10833
  deleteDialogProps,
10836
- displayName,
10834
+ displayName: config.displayName,
10837
10835
  meta: record.apiVersion ? {
10838
10836
  kind: record.kind || "",
10839
- resourceBasePath: (((_a = record.apiVersion) == null ? void 0 : _a.includes("/")) ? "apis" : "api") + `/${record.apiVersion}`
10837
+ resourceBasePath: (
10838
+ // k8s 通用规则,apiVersion 包含 / 则使用 apis,否则使用 api
10839
+ (((_a = record.apiVersion) == null ? void 0 : _a.includes("/")) ? "apis" : "api") + `/${record.apiVersion}`
10840
+ )
10840
10841
  } : void 0
10841
10842
  });
10842
10843
  const download2 = useDownloadYAML();
@@ -10861,10 +10862,16 @@ function K8sDropdown(props) {
10861
10862
  Dropdown,
10862
10863
  {
10863
10864
  overlay: /* @__PURE__ */ jsxRuntimeExports.jsxs(Menu$1, { children: [
10864
- isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || hideEdit || (config == null ? void 0 : config.hideEdit) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(Menu$1.Item, { onClick: () => openForm({ id: record.id, resourceName }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Icon, { src: EditPen16PrimaryIcon, children: formType === FormType.FORM ? `${t2("dovetail.edit")}${transformResourceKindInSentence(
10865
- (config == null ? void 0 : config.displayName) || record.kind || "",
10866
- i18n2.language
10867
- )}` : t2("dovetail.edit_yaml") }) }),
10865
+ isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || (config == null ? void 0 : config.hideEdit) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(
10866
+ Menu$1.Item,
10867
+ {
10868
+ onClick: () => openForm({ id: record.id, resourceName, resourceConfig: config }),
10869
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Icon, { src: EditPen16PrimaryIcon, children: formType === FormType.FORM ? `${t2("dovetail.edit")}${transformResourceKindInSentence(
10870
+ config.displayName || record.kind || "",
10871
+ i18n2.language
10872
+ )}` : t2("dovetail.edit_yaml") })
10873
+ }
10874
+ ),
10868
10875
  /* @__PURE__ */ jsxRuntimeExports.jsx(
10869
10876
  Menu$1.Item,
10870
10877
  {
@@ -14601,7 +14608,7 @@ function ListPage(props) {
14601
14608
  })]
14602
14609
  }) : void 0, /* @__PURE__ */ jsxRuntimeExports.jsxs("div", {
14603
14610
  className: cx_default(ListContentStyle, contentClassName),
14604
- style: !config.customFilterBar && config.nonNsResource ? {
14611
+ style: !customFilterBar && !config.customFilterBar && config.nonNsResource ? {
14605
14612
  paddingTop: 0
14606
14613
  } : {},
14607
14614
  children: [customFilterBar || config.customFilterBar || !config.nonNsResource && /* @__PURE__ */ jsxRuntimeExports.jsx(NamespacesFilter, {
@@ -14655,10 +14662,10 @@ function ResourceShow(props) {
14655
14662
  }
14656
14663
  );
14657
14664
  }
14658
- function getInitialValues(config) {
14659
- return config.initValue || {
14660
- apiVersion: config.apiVersion,
14661
- kind: config.kind,
14665
+ function getInitialValues(resourceConfig) {
14666
+ return resourceConfig.initValue || {
14667
+ apiVersion: resourceConfig.apiVersion,
14668
+ kind: resourceConfig.kind,
14662
14669
  ...BASE_INIT_VALUE,
14663
14670
  spec: {}
14664
14671
  };
@@ -14797,19 +14804,19 @@ const SpaceStyle = "sea7f83";
14797
14804
  const VerticalFormItemStyle = "v1jthrhz";
14798
14805
  const IntegerStyle = "i1brpchs";
14799
14806
  const ContentWrapper = "c11mae2d";
14800
- function useFieldsConfig(config, formConfig, resourceId, step, customOptions, transformedInitValues) {
14807
+ function useFieldsConfig(resourceConfig, formConfig, resourceId, step, customOptions, transformedInitValues) {
14801
14808
  var _a, _b, _c;
14802
14809
  const action = resourceId ? "edit" : "create";
14803
14810
  const listQuery = useList({
14804
- resource: config == null ? void 0 : config.name,
14805
- 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 },
14806
14813
  pagination: {
14807
14814
  mode: "off"
14808
14815
  }
14809
14816
  });
14810
14817
  const showQuery = useShow({
14811
- resource: config == null ? void 0 : config.name,
14812
- 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 },
14813
14820
  id: resourceId
14814
14821
  });
14815
14822
  return (_c = formConfig == null ? void 0 : formConfig.fields) == null ? void 0 : _c.call(formConfig, {
@@ -14924,7 +14931,7 @@ const MemoizedFormField = memo(function FormField({
14924
14931
  });
14925
14932
  function FieldsContent(props) {
14926
14933
  const {
14927
- config,
14934
+ resourceConfig,
14928
14935
  formConfig,
14929
14936
  resourceId,
14930
14937
  step,
@@ -14936,7 +14943,7 @@ function FieldsContent(props) {
14936
14943
  const { control, getValues, watch, trigger } = formResult;
14937
14944
  const action = resourceId ? "edit" : "create";
14938
14945
  const formFieldsConfig = useFieldsConfig(
14939
- config,
14946
+ resourceConfig,
14940
14947
  { fields },
14941
14948
  resourceId,
14942
14949
  step,
@@ -14954,7 +14961,7 @@ function FieldsContent(props) {
14954
14961
  children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: ContentWrapper, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
14955
14962
  FieldsContent,
14956
14963
  {
14957
- config,
14964
+ resourceConfig,
14958
14965
  formConfig,
14959
14966
  resourceId,
14960
14967
  step,
@@ -14984,7 +14991,7 @@ function FieldsContent(props) {
14984
14991
  }
14985
14992
  const RefineFormContent = (props) => {
14986
14993
  const {
14987
- config,
14994
+ resourceConfig: config,
14988
14995
  formResult,
14989
14996
  resourceId,
14990
14997
  errorMsgs,
@@ -14998,7 +15005,7 @@ const RefineFormContent = (props) => {
14998
15005
  /* @__PURE__ */ jsxRuntimeExports.jsx(
14999
15006
  FieldsContent,
15000
15007
  {
15001
- config,
15008
+ resourceConfig: config,
15002
15009
  formConfig,
15003
15010
  fields: formConfig == null ? void 0 : formConfig.fields,
15004
15011
  resourceId,
@@ -15709,7 +15716,7 @@ const useForm = ({
15709
15716
  };
15710
15717
  };
15711
15718
  const useRefineForm = (props) => {
15712
- const { formConfig, config, id, refineProps, options } = props;
15719
+ const { formConfig, resourceConfig, id, refineProps, options } = props;
15713
15720
  const { transformInitValues, transformApplyValues } = usePathMap({
15714
15721
  pathMap: formConfig == null ? void 0 : formConfig.pathMap,
15715
15722
  transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
@@ -15726,25 +15733,25 @@ const useRefineForm = (props) => {
15726
15733
  var _a;
15727
15734
  const formValue = result.getValues();
15728
15735
  return {
15729
- message: i18n2.t(
15730
- id ? "dovetail.edit_resource_success" : "dovetail.create_success_toast",
15731
- {
15732
- kind: transformResourceKindInSentence(config.displayName || config.kind, i18n2.language),
15733
- name: (_a = formValue.metadata) == null ? void 0 : _a.name,
15734
- interpolation: { escapeValue: false }
15735
- }
15736
- ).trim(),
15736
+ message: i18n2.t(id ? "dovetail.edit_resource_success" : "dovetail.create_success_toast", {
15737
+ kind: transformResourceKindInSentence(
15738
+ resourceConfig.displayName || resourceConfig.kind,
15739
+ i18n2.language
15740
+ ),
15741
+ name: (_a = formValue.metadata) == null ? void 0 : _a.name,
15742
+ interpolation: { escapeValue: false }
15743
+ }).trim(),
15737
15744
  description: "Success",
15738
15745
  type: "success"
15739
15746
  };
15740
15747
  },
15741
- resource: config.name,
15748
+ resource: resourceConfig.name,
15742
15749
  action: id ? "edit" : "create",
15743
15750
  id,
15744
15751
  liveMode: "off",
15745
15752
  ...refineProps
15746
15753
  },
15747
- 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),
15748
15755
  transformApplyValues,
15749
15756
  transformInitValues,
15750
15757
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -15757,11 +15764,19 @@ const useRefineForm = (props) => {
15757
15764
  if (response && !(response == null ? void 0 : response.bodyUsed)) {
15758
15765
  (_b = response.json) == null ? void 0 : _b.call(response).then((body) => {
15759
15766
  var _a2;
15760
- setResponseErrorMsgs([].concat(((_a2 = formConfig == null ? void 0 : formConfig.formatError) == null ? void 0 : _a2.call(formConfig, body)) || getCommonErrors(body, i18n2)));
15767
+ setResponseErrorMsgs(
15768
+ [].concat(
15769
+ ((_a2 = formConfig == null ? void 0 : formConfig.formatError) == null ? void 0 : _a2.call(formConfig, body)) || getCommonErrors(body, i18n2)
15770
+ )
15771
+ );
15761
15772
  });
15762
15773
  }
15763
15774
  }, [formConfig, result, i18n2]);
15764
- return { formResult: result, responseErrorMsgs, beforeSubmitErrors: result.beforeSubmitErrors };
15775
+ return {
15776
+ formResult: result,
15777
+ responseErrorMsgs,
15778
+ beforeSubmitErrors: result.beforeSubmitErrors
15779
+ };
15765
15780
  };
15766
15781
  const index_2ivb33 = "";
15767
15782
  const Style = "s1bsn3us";
@@ -16434,7 +16449,7 @@ function YamlForm(props) {
16434
16449
  schemaStrategy = "Optional",
16435
16450
  isShowLayout = true,
16436
16451
  useFormProps,
16437
- config,
16452
+ resourceConfig,
16438
16453
  transformInitValues,
16439
16454
  transformApplyValues,
16440
16455
  beforeSubmit,
@@ -16478,7 +16493,7 @@ function YamlForm(props) {
16478
16493
  beforeSubmit,
16479
16494
  successNotification(data2) {
16480
16495
  var _a;
16481
- 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);
16482
16497
  return {
16483
16498
  message: i18n2.t(action === "create" ? "dovetail.create_success_toast" : "dovetail.save_yaml_success_toast", {
16484
16499
  kind: transformResourceKindInSentence(displayName, i18n2.language),
@@ -16494,7 +16509,11 @@ function YamlForm(props) {
16494
16509
  transformInitValues,
16495
16510
  transformApplyValues,
16496
16511
  mutationMeta: {
16497
- updateType: "put"
16512
+ updateType: "put",
16513
+ dataProviderName: resourceConfig.dataProviderName,
16514
+ resourceBasePath: resourceConfig.basePath,
16515
+ kind: resourceConfig.kind,
16516
+ label: `${resourceConfig.kind}s`
16498
16517
  },
16499
16518
  ...useFormProps
16500
16519
  });
@@ -16577,7 +16596,7 @@ function YamlForm(props) {
16577
16596
  }
16578
16597
  const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16579
16598
  id,
16580
- config,
16599
+ resourceConfig,
16581
16600
  step,
16582
16601
  customYamlFormProps,
16583
16602
  formConfig,
@@ -16590,7 +16609,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16590
16609
  var _a, _b;
16591
16610
  const action = id ? "edit" : "create";
16592
16611
  const refineFormResult = useRefineForm({
16593
- config,
16612
+ resourceConfig,
16594
16613
  id,
16595
16614
  refineProps: {
16596
16615
  onMutationSuccess: (data2) => {
@@ -16616,7 +16635,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16616
16635
  }
16617
16636
  });
16618
16637
  const fieldsConfig = useFieldsConfig(
16619
- config,
16638
+ resourceConfig,
16620
16639
  { fields: formConfig == null ? void 0 : formConfig.fields },
16621
16640
  id,
16622
16641
  step,
@@ -16632,8 +16651,8 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16632
16651
  if (isYamlMode) {
16633
16652
  return {
16634
16653
  ...customYamlFormProps,
16635
- resource: config.name,
16636
- config,
16654
+ resource: resourceConfig.name,
16655
+ resourceConfig,
16637
16656
  transformInitValues: void 0,
16638
16657
  transformApplyValues: void 0,
16639
16658
  initialValuesForCreate: transformApplyValues(
@@ -16649,10 +16668,10 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16649
16668
  redirect: false
16650
16669
  },
16651
16670
  rules: fieldsConfig == null ? void 0 : fieldsConfig.filter(
16652
- (config2) => "isSkipValidationInYaml" in config2 && !config2.isSkipValidationInYaml
16653
- ).map((config2) => ({
16654
- path: "path" in config2 ? config2.path : [],
16655
- 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
16656
16675
  })),
16657
16676
  onSaveButtonPropsChange,
16658
16677
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -16665,14 +16684,14 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16665
16684
  };
16666
16685
  }
16667
16686
  return {
16668
- config
16687
+ resourceConfig
16669
16688
  };
16670
16689
  }, [
16671
16690
  action,
16672
16691
  isYamlMode,
16673
16692
  customYamlFormProps,
16674
16693
  fieldsConfig,
16675
- config,
16694
+ resourceConfig,
16676
16695
  id,
16677
16696
  refineFormResult,
16678
16697
  formConfig == null ? void 0 : formConfig.beforeSubmit,
@@ -16714,7 +16733,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16714
16733
  RefineFormContent,
16715
16734
  {
16716
16735
  formResult: refineFormResult.formResult,
16717
- config,
16736
+ resourceConfig,
16718
16737
  step,
16719
16738
  formConfig,
16720
16739
  errorMsgs: [
@@ -16731,7 +16750,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
16731
16750
  function YamlFormContainer({
16732
16751
  id,
16733
16752
  customYamlFormProps,
16734
- config,
16753
+ resourceConfig,
16735
16754
  formConfig,
16736
16755
  onSuccess,
16737
16756
  onError,
@@ -16746,12 +16765,12 @@ function YamlFormContainer({
16746
16765
  const yamlFormProps = useMemo(() => {
16747
16766
  return {
16748
16767
  ...customYamlFormProps,
16749
- resource: config.name,
16750
- config,
16768
+ resource: resourceConfig.name,
16769
+ resourceConfig,
16751
16770
  transformInitValues,
16752
16771
  transformApplyValues,
16753
16772
  beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
16754
- initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(config),
16773
+ initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(resourceConfig),
16755
16774
  initialValuesForEdit: void 0,
16756
16775
  id,
16757
16776
  action,
@@ -16772,7 +16791,7 @@ function YamlFormContainer({
16772
16791
  id,
16773
16792
  action,
16774
16793
  customYamlFormProps,
16775
- config,
16794
+ resourceConfig,
16776
16795
  formConfig == null ? void 0 : formConfig.beforeSubmit,
16777
16796
  transformInitValues,
16778
16797
  transformApplyValues,
@@ -16816,20 +16835,16 @@ function ConfirmModal({
16816
16835
  function FormModal(props) {
16817
16836
  var _a, _b, _c, _d;
16818
16837
  const {
16819
- resource: resourceFromProps,
16820
16838
  id,
16821
16839
  yamlFormProps: customYamlFormProps,
16822
16840
  modalProps,
16823
16841
  options,
16842
+ resourceConfig,
16824
16843
  onSuccess
16825
16844
  } = props;
16826
16845
  const {
16827
16846
  i18n: i18n2
16828
16847
  } = useTranslation();
16829
- const {
16830
- resource
16831
- } = useResource();
16832
- const configs = useContext(ConfigsContext);
16833
16848
  const [saveButtonProps, setSaveButtonProps] = useState({});
16834
16849
  const [isError, setIsError] = useState(false);
16835
16850
  const [mode, setMode] = useState(FormMode.FORM);
@@ -16838,11 +16853,10 @@ function FormModal(props) {
16838
16853
  const refineFormContainerRef = useRef(null);
16839
16854
  const popModal = usePopModal();
16840
16855
  const pushModal = usePushModal();
16841
- const config = configs[resourceFromProps || (resource == null ? void 0 : resource.name) || ""];
16842
- const isDisabledChangeMode = config.formConfig && "isDisabledChangeMode" in config.formConfig && config.formConfig.isDisabledChangeMode;
16856
+ const isDisabledChangeMode = resourceConfig.formConfig && "isDisabledChangeMode" in resourceConfig.formConfig && resourceConfig.formConfig.isDisabledChangeMode;
16843
16857
  const okText = i18n2.t(id ? "dovetail.save" : "dovetail.create");
16844
16858
  const action = id ? "edit" : "create";
16845
- 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;
16846
16860
  const onOk = useCallback((e2) => {
16847
16861
  var _a2;
16848
16862
  setIsError(false);
@@ -16870,30 +16884,30 @@ function FormModal(props) {
16870
16884
  }, [isError, id, i18n2]);
16871
16885
  const title = useMemo(() => {
16872
16886
  var _a2, _b2, _c2, _d2;
16873
- if (typeof ((_a2 = config.formConfig) == null ? void 0 : _a2.formTitle) === "string")
16874
- return (_b2 = config.formConfig) == null ? void 0 : _b2.formTitle;
16875
- if (typeof ((_c2 = config.formConfig) == null ? void 0 : _c2.formTitle) === "function") {
16876
- 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);
16877
16891
  }
16878
- const label2 = config.displayName || (config == null ? void 0 : config.kind);
16892
+ const label2 = resourceConfig.displayName || (resourceConfig == null ? void 0 : resourceConfig.kind);
16879
16893
  return i18n2.t(id ? "dovetail.edit_resource" : "dovetail.create_resource", {
16880
16894
  resource: transformResourceKindInSentence(label2, i18n2.language)
16881
16895
  });
16882
- }, [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]);
16883
16897
  const desc = useMemo(() => {
16884
16898
  var _a2, _b2, _c2, _d2;
16885
- if (typeof ((_a2 = config.formConfig) == null ? void 0 : _a2.formDesc) === "string")
16886
- return (_b2 = config.formConfig) == null ? void 0 : _b2.formDesc;
16887
- if (typeof ((_c2 = config.formConfig) == null ? void 0 : _c2.formDesc) === "function") {
16888
- 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);
16889
16903
  }
16890
16904
  return "";
16891
- }, [action, config.formConfig]);
16905
+ }, [action, resourceConfig.formConfig]);
16892
16906
  const formEle = useMemo(() => {
16893
16907
  var _a2;
16894
16908
  const commonFormProps = {
16895
16909
  id,
16896
- config,
16910
+ resourceConfig,
16897
16911
  customYamlFormProps,
16898
16912
  onSaveButtonPropsChange: setSaveButtonProps,
16899
16913
  onError: () => {
@@ -16905,28 +16919,28 @@ function FormModal(props) {
16905
16919
  onSuccess == null ? void 0 : onSuccess(data2);
16906
16920
  }
16907
16921
  };
16908
- 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)) {
16909
16923
  return /* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormContainer, {
16910
16924
  ...commonFormProps,
16911
16925
  ref: refineFormContainerRef,
16912
16926
  step,
16913
16927
  options,
16914
16928
  isYamlMode,
16915
- formConfig: config.formConfig
16929
+ formConfig: resourceConfig.formConfig
16916
16930
  });
16917
16931
  }
16918
16932
  return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlFormContainer, {
16919
16933
  ...commonFormProps,
16920
- formConfig: config.formConfig
16934
+ formConfig: resourceConfig.formConfig
16921
16935
  });
16922
- }, [id, customYamlFormProps, config, isYamlMode, step, options, popModal, setSaveButtonProps, onSuccess]);
16936
+ }, [id, customYamlFormProps, resourceConfig, isYamlMode, step, options, popModal, setSaveButtonProps, onSuccess]);
16923
16937
  const steps = useMemo(() => {
16924
16938
  var _a2, _b2;
16925
16939
  if (isYamlMode) {
16926
16940
  return void 0;
16927
16941
  }
16928
- if (config.formConfig && "steps" in config.formConfig) {
16929
- 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) => ({
16930
16944
  title: step2.title,
16931
16945
  children: /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
16932
16946
  children: [desc && index2 === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", {
@@ -16937,7 +16951,7 @@ function FormModal(props) {
16937
16951
  }));
16938
16952
  }
16939
16953
  return void 0;
16940
- }, [config.formConfig, desc, formEle, isYamlMode]);
16954
+ }, [resourceConfig.formConfig, desc, formEle, isYamlMode]);
16941
16955
  const handleStepChange = useCallback(async (nextStep) => {
16942
16956
  var _a2, _b2;
16943
16957
  const isNextStep = nextStep > step;
@@ -16959,8 +16973,8 @@ function FormModal(props) {
16959
16973
  className: TitleWrapperStyle,
16960
16974
  children: [/* @__PURE__ */ jsxRuntimeExports.jsx("span", {
16961
16975
  children: title
16962
- }), ((_b = config.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ jsxRuntimeExports.jsx(FormModeSegmentControl, {
16963
- formConfig: config.formConfig,
16976
+ }), ((_b = resourceConfig.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ jsxRuntimeExports.jsx(FormModeSegmentControl, {
16977
+ formConfig: resourceConfig.formConfig,
16964
16978
  mode,
16965
16979
  onChangeMode
16966
16980
  }) : null]
@@ -16972,9 +16986,9 @@ function FormModal(props) {
16972
16986
  onOk,
16973
16987
  okButtonProps: {
16974
16988
  ...omit$1(saveButtonProps, "onClick"),
16975
- children: (_c = config.formConfig) == null ? void 0 : _c.saveButtonText
16989
+ children: (_c = resourceConfig.formConfig) == null ? void 0 : _c.saveButtonText
16976
16990
  },
16977
- okText: ((_d = config.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
16991
+ okText: ((_d = resourceConfig.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
16978
16992
  destroyOnClose: true,
16979
16993
  destroyOtherStep: true,
16980
16994
  ...modalProps,
@@ -16998,7 +17012,7 @@ const RefineFormPage = (props) => {
16998
17012
  const {
16999
17013
  formResult
17000
17014
  } = useRefineForm({
17001
- config,
17015
+ resourceConfig: config,
17002
17016
  id
17003
17017
  });
17004
17018
  const action = id ? "edit" : "create";
@@ -17017,7 +17031,7 @@ const RefineFormPage = (props) => {
17017
17031
  direction: "vertical",
17018
17032
  className: "c1pvtlkp",
17019
17033
  children: [/* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormContent, {
17020
- config,
17034
+ resourceConfig: config,
17021
17035
  formResult,
17022
17036
  resourceId: id,
17023
17037
  transformedInitValues: formResult.transformedInitValues
@@ -17030,18 +17044,18 @@ const RefineFormPage = (props) => {
17030
17044
  };
17031
17045
  function ResourceForm(props) {
17032
17046
  var _a;
17033
- const { config } = props;
17047
+ const { resourceConfig } = props;
17034
17048
  const formProps = useMemo(() => {
17035
17049
  var _a2, _b;
17036
17050
  return {
17037
- initialValues: getInitialValues(config),
17038
- transformInitValues: (_a2 = config.formConfig) == null ? void 0 : _a2.transformInitValues,
17039
- transformApplyValues: (_b = config.formConfig) == null ? void 0 : _b.transformApplyValues,
17040
- 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
17041
17055
  };
17042
- }, [config]);
17043
- if (((_a = config.formConfig) == null ? void 0 : _a.formType) === FormType.FORM) {
17044
- 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 });
17045
17059
  }
17046
17060
  return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlForm, { ...formProps });
17047
17061
  }
@@ -17054,8 +17068,8 @@ function ResourceCRUD(props) {
17054
17068
  !config.noShow ? /* @__PURE__ */ jsxRuntimeExports.jsx(Route, { path: `${urlPrefix}/${config.name}/show`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceShow, { config }) }) : null,
17055
17069
  // the modals would render in ModalStack
17056
17070
  ((_a = config.formConfig) == null ? void 0 : _a.formContainerType) === FormContainerType.PAGE ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
17057
- /* @__PURE__ */ jsxRuntimeExports.jsx(Route, { path: `${urlPrefix}/${config.name}/create`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceForm, { config }) }),
17058
- /* @__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 }) })
17059
17073
  ] }) : null
17060
17074
  ] }, config.name);
17061
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: ResourceConfig<Model>): 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.1",
3
+ "version": "0.3.19-alpha.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",