@dovetail-v2/refine 0.1.31 → 0.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1242,7 +1242,7 @@ var __publicField = (obj, key, value) => {
1242
1242
  const taint_effect_NoExecute_tooltip_3$1 = "Pods with tolerance and a duration set will run for the specified time and then be evicted.";
1243
1243
  const taint_effect_PreferNoSchedule_tooltip$1 = "The control plane will try to avoid scheduling pods without taint tolerance to the node, but full avoidance isn't guaranteed.";
1244
1244
  const cant_delete_resource$1 = "Unable to delete {{resource}}";
1245
- const cant_delete_resource_with_name$1 = "The {{resource}} <0>{name}</0> cannot be deleted.";
1245
+ const cant_delete_resource_with_name$1 = "The {{resource}} <0>{{name}}</0> cannot be deleted.";
1246
1246
  const close$1 = "Close";
1247
1247
  const dovetail$1 = {
1248
1248
  copy: copy$2,
@@ -11438,11 +11438,21 @@ var __publicField = (obj, key, value) => {
11438
11438
  RESOURCE_GROUP2["PROJECT"] = "PROJECT";
11439
11439
  return RESOURCE_GROUP2;
11440
11440
  })(RESOURCE_GROUP || {});
11441
+ var FormContainerType = /* @__PURE__ */ ((FormContainerType2) => {
11442
+ FormContainerType2["PAGE"] = "PAGE";
11443
+ FormContainerType2["MODAL"] = "MODAL";
11444
+ return FormContainerType2;
11445
+ })(FormContainerType || {});
11441
11446
  var FormType = /* @__PURE__ */ ((FormType2) => {
11442
- FormType2["PAGE"] = "PAGE";
11443
- FormType2["MODAL"] = "MODAL";
11447
+ FormType2["YAML"] = "YAML";
11448
+ FormType2["FORM"] = "FORM";
11444
11449
  return FormType2;
11445
11450
  })(FormType || {});
11451
+ var FormMode = /* @__PURE__ */ ((FormMode2) => {
11452
+ FormMode2["FORM"] = "FORM";
11453
+ FormMode2["YAML"] = "YAML";
11454
+ return FormMode2;
11455
+ })(FormMode || {});
11446
11456
  function getInitialValues(config) {
11447
11457
  return config.initValue || {
11448
11458
  apiVersion: config.apiVersion,
@@ -11459,11 +11469,11 @@ var __publicField = (obj, key, value) => {
11459
11469
  const pushModal = eagle.usePushModal();
11460
11470
  const go = core.useGo();
11461
11471
  return function openForm() {
11462
- var _a, _b, _c;
11472
+ var _a, _b;
11463
11473
  if (resource == null ? void 0 : resource.name) {
11464
11474
  const config = configs[resource.name];
11465
- const formType = (_a = config.formConfig) == null ? void 0 : _a.formType;
11466
- if (formType === void 0 || formType === FormType.MODAL) {
11475
+ const formType = (_a = config.formConfig) == null ? void 0 : _a.formContainerType;
11476
+ if (formType === void 0 || formType === FormContainerType.MODAL) {
11467
11477
  pushModal({
11468
11478
  component: ((_b = config.formConfig) == null ? void 0 : _b.CustomFormModal) || FormModal,
11469
11479
  props: {
@@ -11471,8 +11481,7 @@ var __publicField = (obj, key, value) => {
11471
11481
  id: options == null ? void 0 : options.id,
11472
11482
  formProps: {
11473
11483
  initialValues: getInitialValues(config)
11474
- },
11475
- renderForm: (options == null ? void 0 : options.renderForm) || ((_c = config.formConfig) == null ? void 0 : _c.renderForm)
11484
+ }
11476
11485
  }
11477
11486
  });
11478
11487
  } else if (options == null ? void 0 : options.id) {
@@ -11520,12 +11529,13 @@ var __publicField = (obj, key, value) => {
11520
11529
  resource: resource == null ? void 0 : resource.name,
11521
11530
  action: AccessControlAuth.Delete
11522
11531
  });
11532
+ const formType = ((_a = config.formConfig) == null ? void 0 : _a.formType) || FormType.FORM;
11523
11533
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
11524
11534
  /* @__PURE__ */ jsxRuntimeExports.jsx(
11525
11535
  eagle.Dropdown,
11526
11536
  {
11527
11537
  overlay: /* @__PURE__ */ jsxRuntimeExports.jsxs(eagle.Menu, { children: [
11528
- isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || config.hideEdit ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Menu.Item, { onClick: openForm, children: /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Icon, { src: iconsReact.EditPen16PrimaryIcon, children: ((_a = config.formConfig) == null ? void 0 : _a.fields) ? t2("dovetail.edit") : t2("dovetail.edit_yaml") }) }),
11538
+ isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || config.hideEdit ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Menu.Item, { onClick: openForm, children: /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Icon, { src: iconsReact.EditPen16PrimaryIcon, children: formType === FormType.FORM ? t2("dovetail.edit") : t2("dovetail.edit_yaml") }) }),
11529
11539
  /* @__PURE__ */ jsxRuntimeExports.jsx(
11530
11540
  eagle.Menu.Item,
11531
11541
  {
@@ -12383,7 +12393,7 @@ var __publicField = (obj, key, value) => {
12383
12393
  marginRight: 8
12384
12394
  },
12385
12395
  onClick: openForm,
12386
- children: ((_e = config.formConfig) == null ? void 0 : _e.fields) ? t2("dovetail.edit") : t2("dovetail.edit_yaml")
12396
+ children: ((_e = config.formConfig) == null ? void 0 : _e.formType) === FormType.FORM ? t2("dovetail.edit") : t2("dovetail.edit_yaml")
12387
12397
  })
12388
12398
  }) : null, /* @__PURE__ */ jsxRuntimeExports.jsx(Dropdown, {
12389
12399
  record,
@@ -19528,7 +19538,7 @@ var __publicField = (obj, key, value) => {
19528
19538
  }
19529
19539
  ]
19530
19540
  });
19531
- const style_j3z7so = "";
19541
+ const style_10p48dp = "";
19532
19542
  const ToolBarStyle = "t1joof7s";
19533
19543
  const ToolBarHeaderStyle = "tti58uh";
19534
19544
  const ErrorIconStyle = "e15yt16p";
@@ -36323,6 +36333,33 @@ WARNING: This link could potentially be dangerous`)) {
36323
36333
  }
36324
36334
  );
36325
36335
  }
36336
+ function FormModeSegmentControl({
36337
+ formConfig,
36338
+ mode,
36339
+ onChangeMode
36340
+ }) {
36341
+ const { isDisabledChangeMode } = formConfig;
36342
+ return !isDisabledChangeMode ? /* @__PURE__ */ jsxRuntimeExports.jsx(
36343
+ eagle.SegmentControl,
36344
+ {
36345
+ style: { fontWeight: "normal" },
36346
+ value: mode,
36347
+ options: [
36348
+ {
36349
+ value: FormMode.FORM,
36350
+ label: i18n.t("dovetail.form")
36351
+ },
36352
+ {
36353
+ value: FormMode.YAML,
36354
+ label: i18n.t("dovetail.yaml")
36355
+ }
36356
+ ],
36357
+ onChange: (val) => {
36358
+ onChangeMode(val);
36359
+ }
36360
+ }
36361
+ ) : null;
36362
+ }
36326
36363
  var isCheckBoxInput = (element) => element.type === "checkbox";
36327
36364
  var isDateObject = (value2) => value2 instanceof Date;
36328
36365
  var isNullOrUndefined = (value2) => value2 == null;
@@ -37900,8 +37937,8 @@ WARNING: This link could potentially be dangerous`)) {
37900
37937
  _formControl.current.formState = getProxyFormState(formState, control);
37901
37938
  return _formControl.current;
37902
37939
  }
37903
- function useFieldsConfig(config, resourceId) {
37904
- var _a, _b, _c, _d;
37940
+ function useFieldsConfig(config, formConfig, resourceId) {
37941
+ var _a, _b, _c;
37905
37942
  const action = resourceId ? "edit" : "create";
37906
37943
  const listQuery = core.useList({
37907
37944
  resource: config == null ? void 0 : config.name,
@@ -37915,40 +37952,91 @@ WARNING: This link could potentially be dangerous`)) {
37915
37952
  meta: { resourceBasePath: config == null ? void 0 : config.basePath, kind: config == null ? void 0 : config.kind },
37916
37953
  id: resourceId
37917
37954
  });
37918
- return (_d = (_a = config == null ? void 0 : config.formConfig) == null ? void 0 : _a.fields) == null ? void 0 : _d.call(_a, {
37919
- record: (_b = showQuery.queryResult.data) == null ? void 0 : _b.data,
37920
- records: ((_c = listQuery.data) == null ? void 0 : _c.data) || [],
37955
+ return (_c = formConfig == null ? void 0 : formConfig.fields) == null ? void 0 : _c.call(formConfig, {
37956
+ record: (_a = showQuery.queryResult.data) == null ? void 0 : _a.data,
37957
+ records: ((_b = listQuery.data) == null ? void 0 : _b.data) || [],
37958
+ action
37959
+ });
37960
+ }
37961
+ const RefineFormContent_ahna8x = "";
37962
+ function renderCommonFormFiled(props) {
37963
+ const {
37964
+ field,
37965
+ fieldConfig,
37921
37966
  action
37967
+ } = props;
37968
+ const {
37969
+ value: value2,
37970
+ onChange,
37971
+ onBlur,
37972
+ name: name2
37973
+ } = field;
37974
+ let ele = /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Fields.String, {
37975
+ placeholder: fieldConfig.placeholder,
37976
+ input: {
37977
+ value: value2,
37978
+ onChange,
37979
+ onBlur,
37980
+ name: name2,
37981
+ onFocus: () => null
37982
+ },
37983
+ meta: {}
37922
37984
  });
37985
+ switch (fieldConfig.type) {
37986
+ case "number":
37987
+ ele = /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Fields.Integer, {
37988
+ className: "c154n7ie",
37989
+ placeholder: fieldConfig.placeholder,
37990
+ input: {
37991
+ value: value2,
37992
+ onChange,
37993
+ onBlur,
37994
+ name: name2,
37995
+ onFocus: () => null
37996
+ },
37997
+ meta: {}
37998
+ });
37999
+ }
38000
+ if (action === "edit" && fieldConfig.disabledWhenEdit) {
38001
+ ele = /* @__PURE__ */ jsxRuntimeExports.jsx("div", {
38002
+ children: value2
38003
+ });
38004
+ }
38005
+ return ele;
37923
38006
  }
37924
- const RefineFormContent_7gh3uw = "";
37925
38007
  const RefineFormContent = (props) => {
37926
38008
  const {
37927
38009
  config,
37928
38010
  formResult,
37929
38011
  resourceId,
37930
- errorMsgs
38012
+ errorMsgs,
38013
+ formConfig
37931
38014
  } = props;
37932
38015
  const {
37933
38016
  control,
37934
- getValues
38017
+ getValues,
38018
+ watch,
38019
+ trigger
37935
38020
  } = formResult;
37936
38021
  const action = resourceId ? "edit" : "create";
37937
- const formFieldsConfig = useFieldsConfig(config, resourceId);
37938
- const fields = formFieldsConfig == null ? void 0 : formFieldsConfig.map((c2) => {
37939
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Controller, {
38022
+ const formValues = watch();
38023
+ const formFieldsConfig = useFieldsConfig(config, formConfig, resourceId);
38024
+ const fields = formFieldsConfig == null ? void 0 : formFieldsConfig.map((fieldConfig) => {
38025
+ var _a;
38026
+ const isDisplay = ((_a = fieldConfig.condition) == null ? void 0 : _a.call(fieldConfig, formValues, lodashEs.get(formValues, fieldConfig.path.join(".")))) !== false;
38027
+ return isDisplay ? /* @__PURE__ */ jsxRuntimeExports.jsx(Controller, {
37940
38028
  control,
37941
- name: c2.path.join("."),
38029
+ name: fieldConfig.path.join("."),
37942
38030
  rules: {
37943
38031
  validate(value2) {
37944
38032
  const formValue = getValues();
37945
- if (!c2.validators || c2.validators.length === 0)
38033
+ if (!fieldConfig.validators || fieldConfig.validators.length === 0)
37946
38034
  return true;
37947
- for (const func of c2.validators) {
38035
+ for (const func of fieldConfig.validators) {
37948
38036
  const {
37949
38037
  isValid,
37950
38038
  errorMsg
37951
- } = func(value2, formValue);
38039
+ } = func(value2, formValue, FormType.FORM);
37952
38040
  if (!isValid)
37953
38041
  return errorMsg;
37954
38042
  }
@@ -37956,79 +38044,42 @@ WARNING: This link could potentially be dangerous`)) {
37956
38044
  }
37957
38045
  },
37958
38046
  render: ({
37959
- field: {
37960
- onChange,
37961
- onBlur,
37962
- value: value2,
37963
- name: name2
37964
- },
38047
+ field,
37965
38048
  fieldState
37966
38049
  }) => {
37967
- var _a, _b;
37968
- const formValue = getValues();
37969
- let ele = /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Fields.String, {
37970
- placeholder: c2.placeholder,
37971
- input: {
37972
- value: value2,
37973
- onChange,
37974
- onBlur,
37975
- name: name2,
37976
- onFocus: () => null
37977
- },
37978
- meta: {}
37979
- });
37980
- switch (c2.type) {
37981
- case "number":
37982
- ele = /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Fields.Integer, {
37983
- className: "c154n7ie",
37984
- placeholder: c2.placeholder,
37985
- input: {
37986
- value: value2,
37987
- onChange,
37988
- onBlur,
37989
- name: name2,
37990
- onFocus: () => null
37991
- },
37992
- meta: {}
37993
- });
37994
- }
37995
- if (action === "edit" && c2.disabledWhenEdit) {
37996
- ele = /* @__PURE__ */ jsxRuntimeExports.jsx("div", {
37997
- children: value2
37998
- });
37999
- }
38000
- if (c2 == null ? void 0 : c2.render) {
38001
- ele = c2.render(value2, onChange, formValue, onBlur, action, control);
38002
- }
38003
- if (c2.helperText) {
38004
- ele = /* @__PURE__ */ jsxRuntimeExports.jsxs(eagle.Space, {
38005
- size: 4,
38006
- direction: "vertical",
38007
- className: "c1c9j4da",
38008
- children: [ele, /* @__PURE__ */ jsxRuntimeExports.jsx("div", {
38009
- className: cx_default(eagle.Typo.Footnote.f2_regular, "cjxv8cf"),
38010
- children: c2.helperText
38011
- })]
38012
- });
38050
+ var _a2;
38051
+ const renderProps = {
38052
+ field,
38053
+ fieldConfig,
38054
+ action,
38055
+ control,
38056
+ trigger
38057
+ };
38058
+ let ele = null;
38059
+ if (fieldConfig == null ? void 0 : fieldConfig.render) {
38060
+ ele = fieldConfig.render(renderProps);
38061
+ } else {
38062
+ ele = renderCommonFormFiled(renderProps);
38013
38063
  }
38014
38064
  return /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Form.Item, {
38015
- label: c2.label,
38065
+ label: fieldConfig.label,
38016
38066
  colon: false,
38017
38067
  labelCol: {
38018
- flex: `0 0 ${((_a = config == null ? void 0 : config.formConfig) == null ? void 0 : _a.labelWidth) || "216px"}`
38068
+ flex: `0 0 ${(formConfig == null ? void 0 : formConfig.labelWidth) || "216px"}`
38019
38069
  },
38020
- help: (_b = fieldState.error) == null ? void 0 : _b.message,
38070
+ help: (_a2 = fieldState.error) == null ? void 0 : _a2.message,
38071
+ extra: fieldConfig.helperText,
38021
38072
  validateStatus: fieldState.invalid ? "error" : void 0,
38022
- "data-test-id": c2.key,
38073
+ "data-test-id": fieldConfig.key,
38023
38074
  children: ele
38024
- }, c2.key);
38075
+ }, fieldConfig.key);
38025
38076
  }
38026
- }, c2.key);
38077
+ }, fieldConfig.key) : null;
38027
38078
  });
38028
38079
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(eagle.Space, {
38029
38080
  direction: "vertical",
38030
38081
  size: 16,
38031
- className: "c1xsnuvk",
38082
+ className: "c1c9j4da",
38032
38083
  children: [fields, /* @__PURE__ */ jsxRuntimeExports.jsx(FormErrorAlert, {
38033
38084
  errorMsgs: errorMsgs || [],
38034
38085
  style: {
@@ -38038,6 +38089,59 @@ WARNING: This link could potentially be dangerous`)) {
38038
38089
  })]
38039
38090
  });
38040
38091
  };
38092
+ function immutableSet(obj, path2, value2) {
38093
+ return lodashEs.setWith(lodashEs.clone(obj), path2, value2, lodashEs.clone);
38094
+ }
38095
+ function usePathMap(options) {
38096
+ const { pathMap, transformInitValues, transformApplyValues } = options;
38097
+ return {
38098
+ /**
38099
+ * Transforms initial values by mapping paths from source to target structure
38100
+ * @param values Initial values to transform
38101
+ * @returns Transformed values with updated paths
38102
+ */
38103
+ transformInitValues(values) {
38104
+ const initValues = values._rawYaml || values;
38105
+ let result = initValues;
38106
+ for (const { from, to } of pathMap || []) {
38107
+ result = immutableSet(initValues, to, lodashEs.get(initValues, from));
38108
+ const fromPath = [...from];
38109
+ const lastKey = fromPath.pop();
38110
+ if (lastKey) {
38111
+ const obj = lodashEs.get(result, fromPath.join("."));
38112
+ if (obj && typeof obj === "object") {
38113
+ delete obj[lastKey];
38114
+ }
38115
+ }
38116
+ }
38117
+ return (transformInitValues == null ? void 0 : transformInitValues(result)) || result;
38118
+ },
38119
+ /**
38120
+ * Transforms values back to original structure before applying/saving
38121
+ * @param values Values to transform back
38122
+ * @returns Transformed values in original structure
38123
+ */
38124
+ transformApplyValues(values) {
38125
+ let result = values;
38126
+ for (const { from, to } of pathMap || []) {
38127
+ result = immutableSet(
38128
+ values,
38129
+ from,
38130
+ lodashEs.get(result, to)
38131
+ );
38132
+ const toPath = [...to];
38133
+ const lastKey = toPath.pop();
38134
+ if (lastKey) {
38135
+ const obj = lodashEs.get(result, toPath.join("."));
38136
+ if (obj && typeof obj === "object") {
38137
+ delete obj[lastKey];
38138
+ }
38139
+ }
38140
+ }
38141
+ return (transformApplyValues == null ? void 0 : transformApplyValues(result)) || result;
38142
+ }
38143
+ };
38144
+ }
38041
38145
  var isArray$4 = Array.isArray;
38042
38146
  var isArray_1 = isArray$4;
38043
38147
  var freeGlobal$1 = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
@@ -38675,8 +38779,12 @@ WARNING: This link could potentially be dangerous`)) {
38675
38779
  };
38676
38780
  };
38677
38781
  const useRefineForm = (props) => {
38678
- var _a, _b, _c;
38679
- const { config, id, refineProps } = props;
38782
+ const { formConfig, config, id, refineProps } = props;
38783
+ const { transformInitValues, transformApplyValues } = usePathMap({
38784
+ pathMap: formConfig == null ? void 0 : formConfig.pathMap,
38785
+ transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
38786
+ transformApplyValues: formConfig == null ? void 0 : formConfig.transformApplyValues
38787
+ });
38680
38788
  const [responseErrorMsgs, setResponseErrorMsgs] = React.useState([]);
38681
38789
  const { i18n: i18n2 } = useTranslation();
38682
38790
  const result = useForm({
@@ -38685,14 +38793,14 @@ WARNING: This link could potentially be dangerous`)) {
38685
38793
  refineCoreProps: {
38686
38794
  errorNotification: false,
38687
38795
  successNotification: () => {
38688
- var _a2;
38796
+ var _a;
38689
38797
  const formValue = result.getValues();
38690
38798
  return {
38691
38799
  message: i18n2.t(
38692
38800
  id ? "dovetail.edit_resource_success" : "dovetail.create_success_toast",
38693
38801
  {
38694
38802
  kind: transformResourceKindInSentence(config.displayName || config.kind, i18n2.language),
38695
- name: (_a2 = formValue.metadata) == null ? void 0 : _a2.name,
38803
+ name: (_a = formValue.metadata) == null ? void 0 : _a.name,
38696
38804
  interpolation: { escapeValue: false }
38697
38805
  }
38698
38806
  ).trim(),
@@ -38707,20 +38815,20 @@ WARNING: This link could potentially be dangerous`)) {
38707
38815
  ...refineProps
38708
38816
  },
38709
38817
  defaultValues: config == null ? void 0 : config.initValue,
38710
- transformApplyValues: (_a = config.formConfig) == null ? void 0 : _a.transformApplyValues,
38711
- transformInitValues: (_b = config.formConfig) == null ? void 0 : _b.transformInitValues,
38712
- ...(_c = config.formConfig) == null ? void 0 : _c.useFormProps
38818
+ transformApplyValues,
38819
+ transformInitValues,
38820
+ ...formConfig == null ? void 0 : formConfig.useFormProps
38713
38821
  });
38714
38822
  React.useEffect(() => {
38715
- var _a2, _b2;
38716
- const response = (_a2 = result.refineCore.mutationResult.error) == null ? void 0 : _a2.response;
38823
+ var _a, _b;
38824
+ const response = (_a = result.refineCore.mutationResult.error) == null ? void 0 : _a.response;
38717
38825
  if (response && !(response == null ? void 0 : response.bodyUsed)) {
38718
- (_b2 = response.json) == null ? void 0 : _b2.call(response).then((body) => {
38719
- var _a3, _b3;
38720
- setResponseErrorMsgs([].concat(((_b3 = (_a3 = config.formConfig) == null ? void 0 : _a3.formatError) == null ? void 0 : _b3.call(_a3, body)) || getCommonErrors(body, i18n2)));
38826
+ (_b = response.json) == null ? void 0 : _b.call(response).then((body) => {
38827
+ var _a2;
38828
+ setResponseErrorMsgs([].concat(((_a2 = formConfig == null ? void 0 : formConfig.formatError) == null ? void 0 : _a2.call(formConfig, body)) || getCommonErrors(body, i18n2)));
38721
38829
  });
38722
38830
  }
38723
- }, [config.formConfig, result, i18n2]);
38831
+ }, [formConfig, result, i18n2]);
38724
38832
  return { formResult: result, responseErrorMsgs };
38725
38833
  };
38726
38834
  const index_2ivb33 = "";
@@ -39198,7 +39306,7 @@ WARNING: This link could potentially be dangerous`)) {
39198
39306
  const { path: path2, validators } = rule2;
39199
39307
  const value2 = lodashEs.get(formValue, path2);
39200
39308
  for (const validator of validators || []) {
39201
- const { isValid, errorMsg } = validator(value2, formValue);
39309
+ const { isValid, errorMsg } = validator(value2, formValue, FormType.YAML);
39202
39310
  if (!isValid) {
39203
39311
  errorMap[path2.join(".")] = `${errorMsg}(${path2.join(".")})`;
39204
39312
  break;
@@ -39335,6 +39443,7 @@ WARNING: This link could potentially be dangerous`)) {
39335
39443
  schemaStrategy = "Optional",
39336
39444
  isShowLayout = true,
39337
39445
  useFormProps,
39446
+ config,
39338
39447
  transformInitValues,
39339
39448
  transformApplyValues,
39340
39449
  onSaveButtonPropsChange,
@@ -39346,8 +39455,6 @@ WARNING: This link could potentially be dangerous`)) {
39346
39455
  resource
39347
39456
  } = core.useResource();
39348
39457
  const action = actionFromProps || actionFromResource;
39349
- const configs = React.useContext(ConfigsContext);
39350
- const config = configs[(resource == null ? void 0 : resource.name) || ""];
39351
39458
  const {
39352
39459
  t: t2,
39353
39460
  i18n: i18n2
@@ -39463,6 +39570,159 @@ WARNING: This link could potentially be dangerous`)) {
39463
39570
  })
39464
39571
  });
39465
39572
  }
39573
+ function RefineFormContainer({
39574
+ id,
39575
+ config,
39576
+ customYamlFormProps,
39577
+ formConfig,
39578
+ isYamlMode,
39579
+ onSuccess,
39580
+ onError,
39581
+ onSaveButtonPropsChange
39582
+ }) {
39583
+ const action = id ? "edit" : "create";
39584
+ const fieldsConfig = useFieldsConfig(config, formConfig, id);
39585
+ const refineFormResult = useRefineForm({
39586
+ config,
39587
+ id,
39588
+ refineProps: {
39589
+ onMutationSuccess: () => {
39590
+ onSuccess == null ? void 0 : onSuccess();
39591
+ },
39592
+ onMutationError() {
39593
+ onError == null ? void 0 : onError();
39594
+ },
39595
+ redirect: false,
39596
+ ...formConfig == null ? void 0 : formConfig.refineCoreProps
39597
+ }
39598
+ });
39599
+ const yamlFormProps = React.useMemo(() => {
39600
+ const transformApplyValues = (formConfig == null ? void 0 : formConfig.transformApplyValues) || ((v) => v);
39601
+ return {
39602
+ ...customYamlFormProps,
39603
+ config,
39604
+ transformInitValues: void 0,
39605
+ transformApplyValues: void 0,
39606
+ initialValuesForCreate: transformApplyValues(
39607
+ refineFormResult.formResult.getValues()
39608
+ ),
39609
+ initialValuesForEdit: transformApplyValues(refineFormResult.formResult.getValues()),
39610
+ id,
39611
+ action,
39612
+ isShowLayout: false,
39613
+ useFormProps: {
39614
+ redirect: false
39615
+ },
39616
+ rules: fieldsConfig == null ? void 0 : fieldsConfig.map((config2) => ({
39617
+ path: config2.path,
39618
+ validators: config2.validators
39619
+ })),
39620
+ onSaveButtonPropsChange,
39621
+ onErrorsChange(errors) {
39622
+ if (errors.length) {
39623
+ onError == null ? void 0 : onError();
39624
+ }
39625
+ },
39626
+ onFinish: onSuccess
39627
+ };
39628
+ }, [
39629
+ action,
39630
+ customYamlFormProps,
39631
+ fieldsConfig,
39632
+ config,
39633
+ id,
39634
+ refineFormResult,
39635
+ formConfig,
39636
+ onSaveButtonPropsChange,
39637
+ onSuccess,
39638
+ onError
39639
+ ]);
39640
+ React.useEffect(() => {
39641
+ if (!isYamlMode) {
39642
+ onSaveButtonPropsChange == null ? void 0 : onSaveButtonPropsChange(refineFormResult.formResult.saveButtonProps);
39643
+ }
39644
+ }, [isYamlMode, onSaveButtonPropsChange]);
39645
+ if (isYamlMode) {
39646
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlForm, { ...yamlFormProps });
39647
+ }
39648
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
39649
+ !(formConfig == null ? void 0 : formConfig.isDisabledChangeMode) ? /* @__PURE__ */ jsxRuntimeExports.jsx(
39650
+ eagle.Alert,
39651
+ {
39652
+ type: "warning",
39653
+ message: i18n.t("dovetail.change_form_mode_alert"),
39654
+ style: { marginBottom: "16px" }
39655
+ }
39656
+ ) : void 0,
39657
+ (formConfig == null ? void 0 : formConfig.renderForm) ? formConfig == null ? void 0 : formConfig.renderForm() : /* @__PURE__ */ jsxRuntimeExports.jsx(
39658
+ RefineFormContent,
39659
+ {
39660
+ formResult: refineFormResult.formResult,
39661
+ config,
39662
+ formConfig,
39663
+ errorMsgs: refineFormResult.responseErrorMsgs,
39664
+ resourceId: id
39665
+ }
39666
+ )
39667
+ ] });
39668
+ }
39669
+ function YamlFormContainer({
39670
+ id,
39671
+ customYamlFormProps,
39672
+ config,
39673
+ formConfig,
39674
+ onSuccess,
39675
+ onError,
39676
+ onSaveButtonPropsChange
39677
+ }) {
39678
+ const action = id ? "edit" : "create";
39679
+ const {
39680
+ transformInitValues,
39681
+ transformApplyValues
39682
+ } = usePathMap({
39683
+ pathMap: formConfig == null ? void 0 : formConfig.pathMap,
39684
+ transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
39685
+ transformApplyValues: (formConfig == null ? void 0 : formConfig.transformApplyValues) || ((v) => v)
39686
+ });
39687
+ const yamlFormProps = React.useMemo(
39688
+ () => {
39689
+ return {
39690
+ ...customYamlFormProps,
39691
+ config,
39692
+ transformInitValues,
39693
+ transformApplyValues,
39694
+ initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || config.initValue,
39695
+ initialValuesForEdit: void 0,
39696
+ id,
39697
+ action,
39698
+ isShowLayout: false,
39699
+ useFormProps: {
39700
+ redirect: false
39701
+ },
39702
+ rules: void 0,
39703
+ onSaveButtonPropsChange,
39704
+ onErrorsChange(errors) {
39705
+ if (errors.length) {
39706
+ onError == null ? void 0 : onError();
39707
+ }
39708
+ },
39709
+ onFinish: onSuccess
39710
+ };
39711
+ },
39712
+ [
39713
+ id,
39714
+ action,
39715
+ customYamlFormProps,
39716
+ config,
39717
+ transformInitValues,
39718
+ transformApplyValues,
39719
+ onSuccess,
39720
+ onError,
39721
+ onSaveButtonPropsChange
39722
+ ]
39723
+ );
39724
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlForm, { ...yamlFormProps });
39725
+ }
39466
39726
  const FormModal_64brhp = "";
39467
39727
  const FormDescStyle = "f1nltbcu";
39468
39728
  const ErrorStyle = "e1qgcca6";
@@ -39496,11 +39756,11 @@ WARNING: This link could potentially be dangerous`)) {
39496
39756
  });
39497
39757
  }
39498
39758
  function FormModal(props) {
39499
- var _a, _b, _c, _d, _e, _f;
39759
+ var _a, _b, _c;
39500
39760
  const {
39501
39761
  resource: resourceFromProps,
39502
39762
  id,
39503
- renderForm
39763
+ yamlFormProps: customYamlFormProps
39504
39764
  } = props;
39505
39765
  const {
39506
39766
  i18n: i18n2
@@ -39509,74 +39769,17 @@ WARNING: This link could potentially be dangerous`)) {
39509
39769
  resource
39510
39770
  } = core.useResource();
39511
39771
  const configs = React.useContext(ConfigsContext);
39512
- const [yamlSaveButtonProps, setYamlSaveButtonProps] = React.useState({});
39772
+ const [saveButtonProps, setSaveButtonProps] = React.useState({});
39513
39773
  const [isError, setIsError] = React.useState(false);
39514
- const [mode, setMode] = React.useState(
39515
- "form"
39516
- /* Form */
39517
- );
39518
- const isYamlMode = mode === "yaml";
39774
+ const [mode, setMode] = React.useState(FormMode.FORM);
39775
+ const isYamlMode = mode === FormMode.YAML;
39519
39776
  const popModal = eagle.usePopModal();
39520
39777
  const pushModal = eagle.usePushModal();
39521
39778
  const config = configs[resourceFromProps || (resource == null ? void 0 : resource.name) || ""];
39522
- const isDisabledChangeMode = (_a = config.formConfig) == null ? void 0 : _a.isDisabledChangeMode;
39779
+ const isDisabledChangeMode = config.formConfig && "isDisabledChangeMode" in config.formConfig && config.formConfig.isDisabledChangeMode;
39523
39780
  const okText = i18n2.t(id ? "dovetail.save" : "dovetail.create");
39524
39781
  const action = id ? "edit" : "create";
39525
- const fieldsConfig = useFieldsConfig(config, id);
39526
- const refineFormResult = useRefineForm({
39527
- config,
39528
- id,
39529
- refineProps: {
39530
- onMutationSuccess: () => {
39531
- popModal();
39532
- },
39533
- redirect: false,
39534
- ...(_b = config.formConfig) == null ? void 0 : _b.refineCoreProps
39535
- }
39536
- });
39537
- const yamlFormProps = React.useMemo(() => {
39538
- var _a2, _b2, _c2;
39539
- const transformApplyValues = ((_a2 = config.formConfig) == null ? void 0 : _a2.transformApplyValues) || ((v) => v);
39540
- return {
39541
- ...props.formProps,
39542
- transformInitValues: isYamlMode ? void 0 : (_b2 = config.formConfig) == null ? void 0 : _b2.transformInitValues,
39543
- transformApplyValues: isYamlMode ? void 0 : transformApplyValues,
39544
- initialValuesForCreate: isYamlMode ? transformApplyValues(refineFormResult.formResult.getValues()) : ((_c2 = props.formProps) == null ? void 0 : _c2.initialValuesForCreate) || (config == null ? void 0 : config.initValue),
39545
- initialValuesForEdit: isYamlMode ? transformApplyValues(refineFormResult.formResult.getValues()) : void 0,
39546
- id,
39547
- action,
39548
- isShowLayout: false,
39549
- useFormProps: {
39550
- redirect: false
39551
- },
39552
- rules: isYamlMode ? fieldsConfig == null ? void 0 : fieldsConfig.map((config2) => ({
39553
- path: config2.path,
39554
- validators: config2.validators
39555
- })) : void 0,
39556
- onSaveButtonPropsChange: setYamlSaveButtonProps,
39557
- onErrorsChange(errors) {
39558
- setIsError(!!errors.length);
39559
- },
39560
- onFinish: popModal
39561
- };
39562
- }, [props.formProps, (_c = config.formConfig) == null ? void 0 : _c.transformInitValues, (_d = config.formConfig) == null ? void 0 : _d.transformApplyValues, config == null ? void 0 : config.initValue, id, action, refineFormResult.formResult, isYamlMode, fieldsConfig, popModal]);
39563
- const isYamlForm = !((_e = config.formConfig) == null ? void 0 : _e.fields);
39564
- const formEle = (() => {
39565
- if (renderForm) {
39566
- return renderForm(yamlFormProps);
39567
- }
39568
- if (isYamlForm || isYamlMode)
39569
- return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlForm, {
39570
- ...yamlFormProps
39571
- });
39572
- return /* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormContent, {
39573
- formResult: refineFormResult.formResult,
39574
- config,
39575
- errorMsgs: refineFormResult.responseErrorMsgs,
39576
- resourceId: id
39577
- });
39578
- })();
39579
- const saveButtonProps = isYamlForm || isYamlMode ? yamlSaveButtonProps : refineFormResult.formResult.saveButtonProps;
39782
+ const isYamlForm = ((_a = config.formConfig) == null ? void 0 : _a.formType) === FormType.YAML;
39580
39783
  const onCancel = React.useCallback(() => {
39581
39784
  popModal();
39582
39785
  }, [popModal]);
@@ -39586,15 +39789,12 @@ WARNING: This link could potentially be dangerous`)) {
39586
39789
  (_a2 = saveButtonProps.onClick) == null ? void 0 : _a2.call(saveButtonProps, e2);
39587
39790
  }, [saveButtonProps]);
39588
39791
  const onChangeMode = React.useCallback((value2) => {
39589
- if (value2 === "form") {
39792
+ if (value2 === FormMode.FORM) {
39590
39793
  pushModal({
39591
39794
  component: ConfirmModal,
39592
39795
  props: {
39593
39796
  onOk: () => {
39594
- setMode(
39595
- "form"
39596
- /* Form */
39597
- );
39797
+ setMode(FormMode.FORM);
39598
39798
  }
39599
39799
  }
39600
39800
  });
@@ -39602,17 +39802,18 @@ WARNING: This link could potentially be dangerous`)) {
39602
39802
  setMode(value2);
39603
39803
  }
39604
39804
  }, [pushModal]);
39605
- const errorText = (() => {
39606
- if (!!refineFormResult.responseErrorMsgs.length || isError) {
39805
+ const errorText = React.useMemo(() => {
39806
+ if (isError) {
39607
39807
  return i18n2.t(id ? "dovetail.save_failed" : "dovetail.create_failed");
39608
39808
  }
39609
- })();
39809
+ return "";
39810
+ }, [isError, id, i18n2]);
39610
39811
  const title = React.useMemo(() => {
39611
- var _a2, _b2, _c2, _d2;
39812
+ var _a2, _b2, _c2, _d;
39612
39813
  if (typeof ((_a2 = config.formConfig) == null ? void 0 : _a2.formTitle) === "string")
39613
39814
  return (_b2 = config.formConfig) == null ? void 0 : _b2.formTitle;
39614
39815
  if (typeof ((_c2 = config.formConfig) == null ? void 0 : _c2.formTitle) === "function") {
39615
- return (_d2 = config.formConfig) == null ? void 0 : _d2.formTitle(action);
39816
+ return (_d = config.formConfig) == null ? void 0 : _d.formTitle(action);
39616
39817
  }
39617
39818
  const label2 = config.displayName || (config == null ? void 0 : config.kind);
39618
39819
  return i18n2.t(id ? "dovetail.edit_resource" : "dovetail.create_resource", {
@@ -39620,14 +39821,41 @@ WARNING: This link could potentially be dangerous`)) {
39620
39821
  });
39621
39822
  }, [action, config.formConfig, config.displayName, config == null ? void 0 : config.kind, i18n2, id]);
39622
39823
  const desc = React.useMemo(() => {
39623
- var _a2, _b2, _c2, _d2;
39824
+ var _a2, _b2, _c2, _d;
39624
39825
  if (typeof ((_a2 = config.formConfig) == null ? void 0 : _a2.formDesc) === "string")
39625
39826
  return (_b2 = config.formConfig) == null ? void 0 : _b2.formDesc;
39626
39827
  if (typeof ((_c2 = config.formConfig) == null ? void 0 : _c2.formDesc) === "function") {
39627
- return (_d2 = config.formConfig) == null ? void 0 : _d2.formDesc(action);
39828
+ return (_d = config.formConfig) == null ? void 0 : _d.formDesc(action);
39628
39829
  }
39629
39830
  return "";
39630
39831
  }, [action, config.formConfig]);
39832
+ const formEle = React.useMemo(() => {
39833
+ var _a2;
39834
+ const commonFormProps = {
39835
+ id,
39836
+ config,
39837
+ customYamlFormProps,
39838
+ onSaveButtonPropsChange: setSaveButtonProps,
39839
+ onError: () => {
39840
+ setIsError(true);
39841
+ },
39842
+ onSuccess: () => {
39843
+ setIsError(false);
39844
+ popModal();
39845
+ }
39846
+ };
39847
+ if (config.formConfig && (((_a2 = config.formConfig) == null ? void 0 : _a2.formType) === FormType.FORM || "fields" in config.formConfig)) {
39848
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormContainer, {
39849
+ ...commonFormProps,
39850
+ isYamlMode,
39851
+ formConfig: config.formConfig
39852
+ });
39853
+ }
39854
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlFormContainer, {
39855
+ ...commonFormProps,
39856
+ formConfig: config.formConfig
39857
+ });
39858
+ }, [id, customYamlFormProps, config, isYamlMode, popModal, setSaveButtonProps]);
39631
39859
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(eagle.Modal, {
39632
39860
  className: cx_default(FullscreenModalStyle),
39633
39861
  style: {
@@ -39638,21 +39866,10 @@ WARNING: This link could potentially be dangerous`)) {
39638
39866
  className: TitleWrapperStyle,
39639
39867
  children: [/* @__PURE__ */ jsxRuntimeExports.jsx("span", {
39640
39868
  children: title
39641
- }), !(isYamlForm || isDisabledChangeMode) ? /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.SegmentControl, {
39642
- style: {
39643
- fontWeight: "normal"
39644
- },
39645
- value: mode,
39646
- options: [{
39647
- value: "form",
39648
- label: i18n2.t("dovetail.form")
39649
- }, {
39650
- value: "yaml",
39651
- label: i18n2.t("dovetail.yaml")
39652
- }],
39653
- onChange: (val) => {
39654
- onChangeMode(val);
39655
- }
39869
+ }), ((_b = config.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ jsxRuntimeExports.jsx(FormModeSegmentControl, {
39870
+ formConfig: config.formConfig,
39871
+ mode,
39872
+ onChangeMode
39656
39873
  }) : null]
39657
39874
  }),
39658
39875
  error: errorText ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", {
@@ -39661,7 +39878,7 @@ WARNING: This link could potentially be dangerous`)) {
39661
39878
  }) : "",
39662
39879
  okButtonProps: {
39663
39880
  ...saveButtonProps,
39664
- children: (_f = config.formConfig) == null ? void 0 : _f.saveButtonText,
39881
+ children: (_c = config.formConfig) == null ? void 0 : _c.saveButtonText,
39665
39882
  onClick: onOk
39666
39883
  },
39667
39884
  closeIcon: /* @__PURE__ */ jsxRuntimeExports.jsx(CloseCircleFilled$1, {}),
@@ -39672,12 +39889,6 @@ WARNING: This link could potentially be dangerous`)) {
39672
39889
  children: [desc ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", {
39673
39890
  className: FormDescStyle,
39674
39891
  children: desc
39675
- }) : void 0, !isYamlForm && mode === "form" && !isDisabledChangeMode ? /* @__PURE__ */ jsxRuntimeExports.jsx(eagle.Alert, {
39676
- type: "warning",
39677
- message: i18n2.t("dovetail.change_form_mode_alert"),
39678
- style: {
39679
- marginBottom: "16px"
39680
- }
39681
39892
  }) : void 0, formEle]
39682
39893
  });
39683
39894
  }
@@ -39732,10 +39943,11 @@ WARNING: This link could potentially be dangerous`)) {
39732
39943
  return {
39733
39944
  initialValues: getInitialValues(config),
39734
39945
  transformInitValues: (_a2 = config.formConfig) == null ? void 0 : _a2.transformInitValues,
39735
- transformApplyValues: (_b = config.formConfig) == null ? void 0 : _b.transformApplyValues
39946
+ transformApplyValues: (_b = config.formConfig) == null ? void 0 : _b.transformApplyValues,
39947
+ config
39736
39948
  };
39737
39949
  }, [config]);
39738
- if ((_a = config.formConfig) == null ? void 0 : _a.fields) {
39950
+ if (((_a = config.formConfig) == null ? void 0 : _a.formType) === FormType.FORM) {
39739
39951
  return /* @__PURE__ */ jsxRuntimeExports.jsx(RefineFormPage, { config });
39740
39952
  }
39741
39953
  return /* @__PURE__ */ jsxRuntimeExports.jsx(YamlForm, { ...formProps });
@@ -39748,7 +39960,7 @@ WARNING: This link could potentially be dangerous`)) {
39748
39960
  /* @__PURE__ */ jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}`, exact: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceList, { config }) }),
39749
39961
  !config.noShow ? /* @__PURE__ */ jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/show`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceShow, { config }) }) : null,
39750
39962
  // the modals would render in ModalStack
39751
- ((_a = config.formConfig) == null ? void 0 : _a.formType) === FormType.PAGE ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
39963
+ ((_a = config.formConfig) == null ? void 0 : _a.formContainerType) === FormContainerType.PAGE ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
39752
39964
  /* @__PURE__ */ jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/create`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceForm, { config }) }),
39753
39965
  /* @__PURE__ */ jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/edit`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResourceForm, { config }) })
39754
39966
  ] }) : null
@@ -41317,8 +41529,10 @@ WARNING: This link could potentially be dangerous`)) {
41317
41529
  exports2.EventModel = EventModel;
41318
41530
  exports2.EventsTab = EventsTab;
41319
41531
  exports2.EventsTableTabField = EventsTableTabField;
41532
+ exports2.FormContainerType = FormContainerType;
41320
41533
  exports2.FormErrorAlert = FormErrorAlert;
41321
41534
  exports2.FormModal = FormModal;
41535
+ exports2.FormMode = FormMode;
41322
41536
  exports2.FormType = FormType;
41323
41537
  exports2.GlobalStoreContext = GlobalStoreContext;
41324
41538
  exports2.INGRESS_INIT_VALUE = INGRESS_INIT_VALUE;
@@ -41511,6 +41725,7 @@ WARNING: This link could potentially be dangerous`)) {
41511
41725
  exports2.namespaceRules = namespaceRules;
41512
41726
  exports2.pruneBeforeEdit = pruneBeforeEdit;
41513
41727
  exports2.relationPlugin = relationPlugin;
41728
+ exports2.renderCommonFormFiled = renderCommonFormFiled;
41514
41729
  exports2.resolveRef = resolveRef;
41515
41730
  exports2.rfc1035LabelRules = rfc1035LabelRules;
41516
41731
  exports2.rfc1123LabelRules = rfc1123LabelRules;