@dovetail-v2/refine 0.4.2-alpha.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/refine.cjs CHANGED
@@ -475,6 +475,8 @@ const state$1 = "Status";
475
475
  const name$1 = "Name";
476
476
  const pod$1 = "Pod";
477
477
  const cancel$1 = "Cancel";
478
+ const prev_step$1 = "Previous";
479
+ const next_step$1 = "Next";
478
480
  const create$1 = "Create";
479
481
  const confirm_delete_text$1 = "Are you sure you want to delete the {{kind}} <0>{{target}}</0>?";
480
482
  const edit$1 = "Edit";
@@ -637,6 +639,7 @@ const edit_form$1 = "Edit form";
637
639
  const data_expired$1 = "Data expired";
638
640
  const data_expired_body$1 = "The data in this form is no longer the latest version. To avoid saving errors, please discard this edit and reopen the form to edit again.";
639
641
  const data_expired_note$1 = "Your current entries will not be saved.";
642
+ const resource_version_conflict$1 = "The data in this form is no longer the latest version. Please discard this edit and reopen the form to edit again.";
640
643
  const abandon_edit$1 = "Discard edit";
641
644
  const exit_yaml_tip$1 = "If you go back to the form, any changes made to the YAML file will be lost.";
642
645
  const value_optional$1 = "Value (optional)";
@@ -753,6 +756,8 @@ const dovetail$1 = {
753
756
  name: name$1,
754
757
  pod: pod$1,
755
758
  cancel: cancel$1,
759
+ prev_step: prev_step$1,
760
+ next_step: next_step$1,
756
761
  "delete": "Delete",
757
762
  create: create$1,
758
763
  confirm_delete_text: confirm_delete_text$1,
@@ -918,6 +923,7 @@ const dovetail$1 = {
918
923
  data_expired: data_expired$1,
919
924
  data_expired_body: data_expired_body$1,
920
925
  data_expired_note: data_expired_note$1,
926
+ resource_version_conflict: resource_version_conflict$1,
921
927
  abandon_edit: abandon_edit$1,
922
928
  exit_yaml_tip: exit_yaml_tip$1,
923
929
  value_optional: value_optional$1,
@@ -1029,6 +1035,8 @@ const edit_yaml = "编辑 YAML";
1029
1035
  const copied = "已复制";
1030
1036
  const already_reset = "已重置";
1031
1037
  const cancel = "取消";
1038
+ const prev_step = "上一步";
1039
+ const next_step = "下一步";
1032
1040
  const create = "创建";
1033
1041
  const delete_resource = "删除{{resource}}";
1034
1042
  const confirm_delete_text = "确认删除{{kind}} <0>{{target}}</0> 吗?";
@@ -1201,6 +1209,7 @@ const edit_form = "编辑表单";
1201
1209
  const data_expired = "数据已过期";
1202
1210
  const data_expired_body = "当前表单中的数据已不是最新版。为避免保存失败,请放弃本次编辑,并重新打开表单进行编辑。";
1203
1211
  const data_expired_note = "当前已填写内容将不会保留。";
1212
+ const resource_version_conflict = "当前表单中的数据已不是最新版,请放弃本次编辑,并重新打开表单进行编辑。";
1204
1213
  const abandon_edit = "放弃编辑";
1205
1214
  const exit_yaml_tip = "返回编辑表单,不会保留对 YAML 文件做出的所有更改。";
1206
1215
  const form = "表单";
@@ -1306,6 +1315,8 @@ const dovetail = {
1306
1315
  copied,
1307
1316
  already_reset,
1308
1317
  cancel,
1318
+ prev_step,
1319
+ next_step,
1309
1320
  "delete": "删除",
1310
1321
  create,
1311
1322
  delete_resource,
@@ -1481,6 +1492,7 @@ const dovetail = {
1481
1492
  data_expired,
1482
1493
  data_expired_body,
1483
1494
  data_expired_note,
1495
+ resource_version_conflict,
1484
1496
  abandon_edit,
1485
1497
  exit_yaml_tip,
1486
1498
  form,
@@ -10706,26 +10718,6 @@ function usePathMap(options) {
10706
10718
  transformApplyValues
10707
10719
  };
10708
10720
  }
10709
- const useResourceVersionCheck = ({
10710
- queryResult
10711
- }) => {
10712
- var _a, _b, _c;
10713
- const initialResourceVersionRef = React.useRef();
10714
- const [isExpired, setIsExpired] = React.useState(false);
10715
- const currentResourceVersion = (_c = (_b = (_a = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _a.data) == null ? void 0 : _b.metadata) == null ? void 0 : _c.resourceVersion;
10716
- React.useEffect(() => {
10717
- if (!currentResourceVersion)
10718
- return;
10719
- if (!initialResourceVersionRef.current) {
10720
- initialResourceVersionRef.current = currentResourceVersion;
10721
- return;
10722
- }
10723
- if (currentResourceVersion !== initialResourceVersionRef.current) {
10724
- setIsExpired(true);
10725
- }
10726
- }, [currentResourceVersion]);
10727
- return isExpired;
10728
- };
10729
10721
  function getInitialValues(resourceConfig) {
10730
10722
  return resourceConfig.initValue || {
10731
10723
  apiVersion: resourceConfig.apiVersion,
@@ -10734,42 +10726,6 @@ function getInitialValues(resourceConfig) {
10734
10726
  spec: {}
10735
10727
  };
10736
10728
  }
10737
- const button_1v659kh = "";
10738
- const WarningButtonStyle = "wwyz7ti";
10739
- const DataExpiredModal_eazxh6 = "";
10740
- const NoteStyle = "n609wlp";
10741
- function DataExpiredModal({
10742
- onAbandon
10743
- }) {
10744
- const {
10745
- t: t2
10746
- } = common.useTranslation();
10747
- return /* @__PURE__ */ common.jsxRuntimeExports.jsxs(eagle.SmallDialog, {
10748
- title: t2("dovetail.data_expired"),
10749
- closable: false,
10750
- maskClosable: false,
10751
- cancelButtonProps: {
10752
- style: {
10753
- display: "none"
10754
- }
10755
- },
10756
- okText: t2("dovetail.abandon_edit"),
10757
- okButtonProps: {
10758
- className: WarningButtonStyle
10759
- },
10760
- onOk: (popModal) => {
10761
- popModal();
10762
- onAbandon();
10763
- },
10764
- children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx("div", {
10765
- className: eagle.Typo.Label.l2_regular,
10766
- children: t2("dovetail.data_expired_body")
10767
- }), /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", {
10768
- className: `${eagle.Typo.Label.l2_regular} ${NoteStyle}`,
10769
- children: t2("dovetail.data_expired_note")
10770
- })]
10771
- });
10772
- }
10773
10729
  const index_az4wrx = "";
10774
10730
  const WrapperStyle$5 = "w1akirqw";
10775
10731
  const TitleStyle$2 = "t30srnq";
@@ -10809,7 +10765,7 @@ const Separator = () => {
10809
10765
  const style_1o641u6 = "";
10810
10766
  const ToolBarStyle = "t1joof7s";
10811
10767
  const ToolBarHeaderStyle = "tti58uh";
10812
- const ErrorIconStyle = "e15yt16p";
10768
+ const ErrorIconStyle$1 = "e15yt16p";
10813
10769
  const WrapperStyle$4 = "w3ccqks";
10814
10770
  const TitleStyle$1 = "t7zbd78";
10815
10771
  const IconStyle = "i1e4ouxy";
@@ -11039,7 +10995,7 @@ const YamlEditorComponent = React.forwardRef(
11039
10995
  ] })
11040
10996
  ] }),
11041
10997
  errorMsgs.length ? /* @__PURE__ */ common.jsxRuntimeExports.jsxs(eagle.Space, { className: ErrorWrapperStyle, size: 8, align: "start", children: [
11042
- /* @__PURE__ */ common.jsxRuntimeExports.jsx(iconsReact.XmarkFailedSeriousWarningFill16RedIcon, { className: ErrorIconStyle }),
10998
+ /* @__PURE__ */ common.jsxRuntimeExports.jsx(iconsReact.XmarkFailedSeriousWarningFill16RedIcon, { className: ErrorIconStyle$1 }),
11043
10999
  /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", { children: errorMsgs.map((errorMsg, index2) => /* @__PURE__ */ common.jsxRuntimeExports.jsxs("pre", { className: ErrorMsgStyle, children: [
11044
11000
  errorMsgs.length > 1 ? `${index2 + 1}. ` : "",
11045
11001
  errorMsg
@@ -11099,6 +11055,67 @@ function copyToClipboard(text) {
11099
11055
  document.execCommand("copy");
11100
11056
  document.body.removeChild(input);
11101
11057
  }
11058
+ const useGlobalStore = (name2 = "default") => {
11059
+ const globalStores = React.useContext(GlobalStoreContext);
11060
+ return globalStores[name2];
11061
+ };
11062
+ const ResourceVersionConflictRetryContext = React.createContext(null);
11063
+ function Retry409Provider({
11064
+ children
11065
+ }) {
11066
+ const initialResourceRef = React.useRef();
11067
+ return React.createElement(
11068
+ ResourceVersionConflictRetryContext.Provider,
11069
+ {
11070
+ value: initialResourceRef
11071
+ },
11072
+ children
11073
+ );
11074
+ }
11075
+ function use409Retry({
11076
+ action,
11077
+ dataProviderName,
11078
+ id,
11079
+ mutationMeta
11080
+ }) {
11081
+ const { t: t2 } = common.useTranslation();
11082
+ const globalStore = useGlobalStore(dataProviderName);
11083
+ const sharedInitialResourceRef = React.useContext(ResourceVersionConflictRetryContext);
11084
+ const localInitialResourceRef = React.useRef();
11085
+ const initialResourceRef = sharedInitialResourceRef || localInitialResourceRef;
11086
+ const isEditAction = action === "edit" || !!id;
11087
+ const captureInitialResource = React.useCallback((resource) => {
11088
+ var _a;
11089
+ if (!isEditAction || initialResourceRef.current || !resource) {
11090
+ return;
11091
+ }
11092
+ const rawResource = (_a = globalStore == null ? void 0 : globalStore.restoreItem) == null ? void 0 : _a.call(globalStore, resource);
11093
+ if (!rawResource) {
11094
+ return;
11095
+ }
11096
+ initialResourceRef.current = lodashEs.cloneDeep(rawResource);
11097
+ }, [globalStore, initialResourceRef, isEditAction]);
11098
+ const retryMutationMeta = React.useMemo(() => {
11099
+ const restMutationMeta = lodashEs.omit(mutationMeta, "resourceVersionConflictRetry");
11100
+ if (!isEditAction) {
11101
+ return restMutationMeta;
11102
+ }
11103
+ return {
11104
+ ...restMutationMeta,
11105
+ resourceVersionConflictRetry: {
11106
+ // refine 的 mutationMeta 在 hook 创建时就会固定;用 getter 让 provider 在保存瞬间读取最新的初始版本。
11107
+ get initialResource() {
11108
+ return initialResourceRef.current;
11109
+ },
11110
+ conflictMessage: t2("dovetail.resource_version_conflict")
11111
+ }
11112
+ };
11113
+ }, [initialResourceRef, isEditAction, mutationMeta, t2]);
11114
+ return {
11115
+ captureInitialResource,
11116
+ mutationMeta: retryMutationMeta
11117
+ };
11118
+ }
11102
11119
  function useK8sYamlEditor() {
11103
11120
  const foldSymbol = React.useCallback(function(editor, symbol) {
11104
11121
  const model = editor.getModel();
@@ -11209,10 +11226,6 @@ function generateYamlBySchema(defaultValue, schema) {
11209
11226
  const content = yaml$2.dump(merged);
11210
11227
  return content.replace(/(')(#.+?)(')/g, "$2").replace(/( +)(#)/g, "$2$1");
11211
11228
  }
11212
- const useGlobalStore = (name2 = "default") => {
11213
- const globalStores = React.useContext(GlobalStoreContext);
11214
- return globalStores[name2];
11215
- };
11216
11229
  const useYamlForm = ({
11217
11230
  action: actionFromProps,
11218
11231
  resource,
@@ -11250,7 +11263,7 @@ const useYamlForm = ({
11250
11263
  onSubmitAbort,
11251
11264
  rules
11252
11265
  } = {}) => {
11253
- var _a;
11266
+ var _a, _b;
11254
11267
  const editor = React.useRef(null);
11255
11268
  const { t: t2 } = common.useTranslation();
11256
11269
  const [isYamlValid, setIsYamlValid] = React.useState(true);
@@ -11261,7 +11274,17 @@ const useYamlForm = ({
11261
11274
  const [beforeSubmitErrors, setBeforeSubmitErrors] = React.useState([]);
11262
11275
  const [errorResponseBody, setErrorResponseBody] = React.useState(null);
11263
11276
  const useResourceResult = core.useResource();
11264
- const globalStore = useGlobalStore();
11277
+ const globalStore = useGlobalStore(dataProviderName);
11278
+ const action = React.useMemo(
11279
+ () => actionFromProps || useResourceResult.action,
11280
+ [actionFromProps, useResourceResult.action]
11281
+ );
11282
+ const { captureInitialResource, mutationMeta: finalMutationMeta } = use409Retry({
11283
+ action,
11284
+ dataProviderName,
11285
+ id: idFromProps,
11286
+ mutationMeta
11287
+ });
11265
11288
  const {
11266
11289
  schema,
11267
11290
  loading: isLoadingSchema,
@@ -11298,7 +11321,7 @@ const useYamlForm = ({
11298
11321
  meta: core.pickNotDeprecated(meta, metaData),
11299
11322
  metaData: core.pickNotDeprecated(meta, metaData),
11300
11323
  queryMeta,
11301
- mutationMeta,
11324
+ mutationMeta: finalMutationMeta,
11302
11325
  liveMode,
11303
11326
  liveParams,
11304
11327
  mutationMode,
@@ -11313,12 +11336,12 @@ const useYamlForm = ({
11313
11336
  overtimeOptions
11314
11337
  });
11315
11338
  const { formLoading, onFinish, queryResult } = useFormCoreResult;
11339
+ React.useEffect(() => {
11340
+ var _a2;
11341
+ captureInitialResource((_a2 = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _a2.data);
11342
+ }, [captureInitialResource, (_a = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _a.data]);
11316
11343
  const { warnWhenUnsavedChanges: warnWhenUnsavedChangesRefine, setWarnWhen } = core.useWarnAboutChange();
11317
11344
  const warnWhenUnsavedChanges = warnWhenUnsavedChangesProp ?? warnWhenUnsavedChangesRefine;
11318
- const action = React.useMemo(
11319
- () => actionFromProps || useResourceResult.action,
11320
- [actionFromProps, useResourceResult.action]
11321
- );
11322
11345
  const initialValues = React.useMemo(() => {
11323
11346
  var _a2;
11324
11347
  const initialValues2 = (action === "edit" && ((_a2 = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _a2.data) ? initialValuesForEdit || (globalStore == null ? void 0 : globalStore.restoreItem(queryResult.data.data)) : initialValuesForCreate) || {};
@@ -11361,10 +11384,10 @@ const useYamlForm = ({
11361
11384
  }
11362
11385
  },
11363
11386
  onEditorCreate(editorInstance) {
11364
- var _a3, _b;
11387
+ var _a3, _b2;
11365
11388
  const editorValue = yaml$2.dump(initialValues);
11366
11389
  (_a3 = editor.current) == null ? void 0 : _a3.setEditorValue(editorValue);
11367
- (_b = editor.current) == null ? void 0 : _b.setValue(editorValue);
11390
+ (_b2 = editor.current) == null ? void 0 : _b2.setValue(editorValue);
11368
11391
  if (action === "edit") {
11369
11392
  fold2(editorInstance);
11370
11393
  }
@@ -11377,7 +11400,7 @@ const useYamlForm = ({
11377
11400
  initialValues,
11378
11401
  schemas,
11379
11402
  resource,
11380
- (_a = useResourceResult.resource) == null ? void 0 : _a.name,
11403
+ (_b = useResourceResult.resource) == null ? void 0 : _b.name,
11381
11404
  action,
11382
11405
  finalErrors,
11383
11406
  fold2
@@ -11417,7 +11440,7 @@ const useYamlForm = ({
11417
11440
  formProps: {
11418
11441
  ...formSF.formProps,
11419
11442
  onFinish: async (values) => {
11420
- var _a2, _b;
11443
+ var _a2, _b2;
11421
11444
  setBeforeSubmitErrors([]);
11422
11445
  onSubmitStart == null ? void 0 : onSubmitStart();
11423
11446
  const errors = [
@@ -11437,7 +11460,7 @@ const useYamlForm = ({
11437
11460
  return;
11438
11461
  }
11439
11462
  try {
11440
- const objectValues = editor.current ? yaml$2.load(((_b = editor.current) == null ? void 0 : _b.getEditorValue()) || "") : values;
11463
+ const objectValues = editor.current ? yaml$2.load(((_b2 = editor.current) == null ? void 0 : _b2.getEditorValue()) || "") : values;
11441
11464
  let finalValues = (transformApplyValues == null ? void 0 : transformApplyValues(objectValues)) || objectValues;
11442
11465
  if (beforeSubmit) {
11443
11466
  try {
@@ -11539,6 +11562,7 @@ function YamlForm(props) {
11539
11562
  id,
11540
11563
  action: actionFromProps,
11541
11564
  resource: resource == null ? void 0 : resource.name,
11565
+ dataProviderName: resourceConfig.dataProviderName,
11542
11566
  editorOptions: {
11543
11567
  isSkipSchema: schemaStrategy === "None"
11544
11568
  /* None */
@@ -11661,31 +11685,6 @@ function YamlFormContainer({
11661
11685
  onSaveButtonPropsChange
11662
11686
  }) {
11663
11687
  const action = id ? "edit" : "create";
11664
- const pushModal = eagle.usePushModal();
11665
- const popModal = eagle.usePopModal();
11666
- const hasShownExpiredRef = React.useRef(false);
11667
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11668
- const queryResult = core.useOne({
11669
- resource: resourceConfig.name,
11670
- id,
11671
- liveMode: id ? "auto" : "off",
11672
- queryOptions: { enabled: !!id }
11673
- });
11674
- const isExpired = useResourceVersionCheck({ queryResult });
11675
- React.useEffect(() => {
11676
- if (!isExpired || isSubmitting || hasShownExpiredRef.current) {
11677
- return;
11678
- }
11679
- hasShownExpiredRef.current = true;
11680
- pushModal({
11681
- component: DataExpiredModal,
11682
- props: {
11683
- onAbandon: () => {
11684
- popModal();
11685
- }
11686
- }
11687
- });
11688
- }, [isExpired, isSubmitting, pushModal, popModal]);
11689
11688
  const { transformInitValues, transformApplyValues } = usePathMap({
11690
11689
  pathMap: formConfig == null ? void 0 : formConfig.pathMap,
11691
11690
  transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
@@ -11705,13 +11704,7 @@ function YamlFormContainer({
11705
11704
  action,
11706
11705
  isShowLayout: false,
11707
11706
  useFormProps: {
11708
- redirect: false,
11709
- onSubmitStart: () => {
11710
- setIsSubmitting(true);
11711
- },
11712
- onSubmitAbort: () => {
11713
- setIsSubmitting(false);
11714
- }
11707
+ redirect: false
11715
11708
  },
11716
11709
  rules: void 0,
11717
11710
  onSaveButtonPropsChange,
@@ -16093,8 +16086,121 @@ function ResourceShow(props) {
16093
16086
  }
16094
16087
  );
16095
16088
  }
16089
+ const button_1v659kh = "";
16090
+ const WarningButtonStyle = "wwyz7ti";
16096
16091
  const modal_1eijuvm = "";
16097
16092
  const SmallModalStyle = "s1nc293e";
16093
+ const ExtraSubmitFooter_15u4r8u = "";
16094
+ const FooterStyle = "f16wn4bu";
16095
+ const FooterLeftStyle = "fk5l2b4";
16096
+ const FooterRightStyle = "f1r3vl4u";
16097
+ const ErrorStyle = "e1y8i1r4";
16098
+ const ErrorIconStyle = "e16fn5cj";
16099
+ const PrevIconStyle = "prji3wx";
16100
+ function useExtraSubmitFooter({
16101
+ action,
16102
+ cancelText,
16103
+ defaultSubmitText,
16104
+ errorText,
16105
+ extraSubmitButton,
16106
+ fallbackFooter,
16107
+ isYamlMode,
16108
+ nextStepText,
16109
+ prevStepText,
16110
+ saveButtonProps,
16111
+ step,
16112
+ stepCount,
16113
+ onCancel,
16114
+ onNextStep,
16115
+ onPrevStep,
16116
+ onSubmit
16117
+ }) {
16118
+ const shouldShowExtraSubmitButton = React.useMemo(() => {
16119
+ if (!extraSubmitButton || isYamlMode) {
16120
+ return false;
16121
+ }
16122
+ if (extraSubmitButton.action && extraSubmitButton.action !== action) {
16123
+ return false;
16124
+ }
16125
+ if (extraSubmitButton.step !== step) {
16126
+ return false;
16127
+ }
16128
+ return step < stepCount - 1;
16129
+ }, [action, extraSubmitButton, isYamlMode, step, stepCount]);
16130
+ return React.useMemo(() => {
16131
+ if (!shouldShowExtraSubmitButton) {
16132
+ return fallbackFooter;
16133
+ }
16134
+ return /* @__PURE__ */ common.jsxRuntimeExports.jsx(ExtraSubmitFooter, {
16135
+ cancelText,
16136
+ errorText,
16137
+ extraSubmitText: (extraSubmitButton == null ? void 0 : extraSubmitButton.text) || defaultSubmitText,
16138
+ nextStepText,
16139
+ prevText: prevStepText,
16140
+ saveButtonProps,
16141
+ showPrevButton: step > 0,
16142
+ onCancel,
16143
+ onNextStep,
16144
+ onPrevStep,
16145
+ onSubmit
16146
+ });
16147
+ }, [cancelText, defaultSubmitText, errorText, extraSubmitButton == null ? void 0 : extraSubmitButton.text, fallbackFooter, onCancel, onNextStep, onPrevStep, onSubmit, nextStepText, prevStepText, saveButtonProps, shouldShowExtraSubmitButton, step]);
16148
+ }
16149
+ const ExtraSubmitFooter = ({
16150
+ cancelText,
16151
+ errorText,
16152
+ extraSubmitText,
16153
+ nextStepText,
16154
+ prevText,
16155
+ saveButtonProps,
16156
+ showPrevButton,
16157
+ onCancel,
16158
+ onNextStep,
16159
+ onPrevStep,
16160
+ onSubmit
16161
+ }) => {
16162
+ const finalSaveButtonProps = lodashEs.omit(saveButtonProps, "onClick");
16163
+ return /* @__PURE__ */ common.jsxRuntimeExports.jsxs("div", {
16164
+ className: FooterStyle,
16165
+ children: [/* @__PURE__ */ common.jsxRuntimeExports.jsxs("div", {
16166
+ className: FooterLeftStyle,
16167
+ children: [showPrevButton ? /* @__PURE__ */ common.jsxRuntimeExports.jsxs(eagle.Button, {
16168
+ type: "link",
16169
+ onClick: onPrevStep,
16170
+ children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx(iconsReact.ArrowChevronLeft16BoldBlueIcon, {
16171
+ className: PrevIconStyle
16172
+ }), prevText]
16173
+ }) : null, errorText ? /* @__PURE__ */ common.jsxRuntimeExports.jsxs("span", {
16174
+ className: common.cx_default(ErrorStyle, eagle.Typo.Label.l2_regular),
16175
+ children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx(iconsReact.ExclamationErrorCircleFill16RedIcon, {
16176
+ className: ErrorIconStyle
16177
+ }), errorText]
16178
+ }) : null]
16179
+ }), /* @__PURE__ */ common.jsxRuntimeExports.jsxs("div", {
16180
+ className: FooterRightStyle,
16181
+ children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx(eagle.Button, {
16182
+ type: "quiet",
16183
+ size: "large",
16184
+ onClick: onCancel,
16185
+ children: /* @__PURE__ */ common.jsxRuntimeExports.jsx("span", {
16186
+ className: eagle.Typo.Label.l1_bold_title,
16187
+ children: cancelText
16188
+ })
16189
+ }), /* @__PURE__ */ common.jsxRuntimeExports.jsx(eagle.Button, {
16190
+ size: "large",
16191
+ type: "secondary",
16192
+ onClick: onNextStep,
16193
+ children: nextStepText
16194
+ }), /* @__PURE__ */ common.jsxRuntimeExports.jsx(eagle.Button, {
16195
+ ...finalSaveButtonProps,
16196
+ size: "large",
16197
+ type: "primary",
16198
+ onClick: onSubmit,
16199
+ children: extraSubmitText
16200
+ })]
16201
+ })]
16202
+ });
16203
+ };
16098
16204
  function FormModeSegmentControl({
16099
16205
  formConfig,
16100
16206
  mode,
@@ -16928,9 +17034,16 @@ const useForm = ({
16928
17034
  onSubmitAbort,
16929
17035
  ...rest
16930
17036
  } = {}) => {
17037
+ var _a;
16931
17038
  const { options } = core.useRefineContext();
16932
17039
  const disableServerSideValidation = (options == null ? void 0 : options.disableServerSideValidation) || disableServerSideValidationProp;
16933
17040
  const translate = core.useTranslate();
17041
+ const { captureInitialResource, mutationMeta } = use409Retry({
17042
+ action: refineCoreProps == null ? void 0 : refineCoreProps.action,
17043
+ dataProviderName: refineCoreProps == null ? void 0 : refineCoreProps.dataProviderName,
17044
+ id: refineCoreProps == null ? void 0 : refineCoreProps.id,
17045
+ mutationMeta: refineCoreProps == null ? void 0 : refineCoreProps.mutationMeta
17046
+ });
16934
17047
  const { warnWhenUnsavedChanges: warnWhenUnsavedChangesRefine, setWarnWhen } = core.useWarnAboutChange();
16935
17048
  const warnWhenUnsavedChanges = warnWhenUnsavedChangesProp ?? warnWhenUnsavedChangesRefine;
16936
17049
  const useHookFormResult = reactHookForm.useForm({
@@ -16950,10 +17063,11 @@ const useForm = ({
16950
17063
  } = useHookFormResult;
16951
17064
  const useFormCoreResult = core.useForm({
16952
17065
  ...refineCoreProps,
17066
+ mutationMeta,
16953
17067
  onMutationError: (error, _variables, _context) => {
16954
- var _a, _b;
17068
+ var _a2, _b;
16955
17069
  if (disableServerSideValidation) {
16956
- (_a = refineCoreProps == null ? void 0 : refineCoreProps.onMutationError) == null ? void 0 : _a.call(refineCoreProps, error, _variables, _context);
17070
+ (_a2 = refineCoreProps == null ? void 0 : refineCoreProps.onMutationError) == null ? void 0 : _a2.call(refineCoreProps, error, _variables, _context);
16957
17071
  return;
16958
17072
  }
16959
17073
  const errors = error == null ? void 0 : error.errors;
@@ -16986,10 +17100,14 @@ const useForm = ({
16986
17100
  });
16987
17101
  const { queryResult, onFinish, formLoading, onFinishAutoSave } = useFormCoreResult;
16988
17102
  React.useEffect(() => {
16989
- var _a;
17103
+ var _a2;
17104
+ captureInitialResource((_a2 = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _a2.data);
17105
+ }, [captureInitialResource, (_a = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _a.data]);
17106
+ React.useEffect(() => {
17107
+ var _a2;
16990
17108
  if (formState.isDirty)
16991
17109
  return;
16992
- const data2 = (_a = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _a.data;
17110
+ const data2 = (_a2 = queryResult == null ? void 0 : queryResult.data) == null ? void 0 : _a2.data;
16993
17111
  if (!data2)
16994
17112
  return;
16995
17113
  const transformedData = transformInitValues ? transformInitValues(data2) : data2;
@@ -17017,13 +17135,13 @@ const useForm = ({
17017
17135
  }, [watch]);
17018
17136
  const onValuesChange = React.useCallback(
17019
17137
  (changeValues) => {
17020
- var _a;
17138
+ var _a2;
17021
17139
  if (warnWhenUnsavedChanges) {
17022
17140
  setWarnWhen(true);
17023
17141
  }
17024
17142
  if (refineCoreProps == null ? void 0 : refineCoreProps.autoSave) {
17025
17143
  setWarnWhen(false);
17026
- const onFinishProps = (_a = refineCoreProps.autoSave) == null ? void 0 : _a.onFinish;
17144
+ const onFinishProps = (_a2 = refineCoreProps.autoSave) == null ? void 0 : _a2.onFinish;
17027
17145
  if (onFinishProps) {
17028
17146
  return onFinishAutoSave(onFinishProps(changeValues));
17029
17147
  }
@@ -17141,6 +17259,7 @@ const useRefineForm = (props) => {
17141
17259
  resource: resourceConfig.name,
17142
17260
  action: id ? "edit" : "create",
17143
17261
  id,
17262
+ dataProviderName: resourceConfig.dataProviderName,
17144
17263
  liveMode: id ? "auto" : "off",
17145
17264
  ...refineProps
17146
17265
  },
@@ -17154,10 +17273,11 @@ const useRefineForm = (props) => {
17154
17273
  ...formConfig == null ? void 0 : formConfig.useFormProps
17155
17274
  });
17156
17275
  React.useEffect(() => {
17157
- var _a, _b;
17276
+ var _a, _b, _c;
17158
17277
  const response = (_a = result.refineCore.mutationResult.error) == null ? void 0 : _a.response;
17278
+ const message2 = (_b = result.refineCore.mutationResult.error) == null ? void 0 : _b.message;
17159
17279
  if (response && !(response == null ? void 0 : response.bodyUsed)) {
17160
- (_b = response.json) == null ? void 0 : _b.call(response).then((body) => {
17280
+ (_c = response.json) == null ? void 0 : _c.call(response).then((body) => {
17161
17281
  var _a2;
17162
17282
  setResponseErrorMsgs(
17163
17283
  [].concat(
@@ -17165,8 +17285,10 @@ const useRefineForm = (props) => {
17165
17285
  )
17166
17286
  );
17167
17287
  });
17288
+ } else if (message2 && responseErrorMsgs[0] !== message2) {
17289
+ setResponseErrorMsgs([message2]);
17168
17290
  }
17169
- }, [formConfig, result, i18n2]);
17291
+ }, [formConfig, result, i18n2, responseErrorMsgs]);
17170
17292
  return {
17171
17293
  formResult: result,
17172
17294
  responseErrorMsgs,
@@ -17187,10 +17309,6 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17187
17309
  }, ref) {
17188
17310
  var _a, _b;
17189
17311
  const action = id ? "edit" : "create";
17190
- const pushModal = eagle.usePushModal();
17191
- const popModal = eagle.usePopModal();
17192
- const hasShownExpiredRef = React.useRef(false);
17193
- const [isSubmitting, setIsSubmitting] = React.useState(false);
17194
17312
  const refineFormResult = useRefineForm({
17195
17313
  resourceConfig,
17196
17314
  id,
@@ -17199,7 +17317,6 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17199
17317
  onSuccess == null ? void 0 : onSuccess(data2);
17200
17318
  },
17201
17319
  onMutationError() {
17202
- setIsSubmitting(false);
17203
17320
  onError == null ? void 0 : onError();
17204
17321
  },
17205
17322
  redirect: false,
@@ -17213,35 +17330,11 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17213
17330
  ...options,
17214
17331
  onBeforeSubmitError: (errors) => {
17215
17332
  if (errors.length) {
17216
- setIsSubmitting(false);
17217
17333
  onError == null ? void 0 : onError();
17218
17334
  }
17219
- },
17220
- onSubmitStart: () => {
17221
- setIsSubmitting(true);
17222
- },
17223
- onSubmitAbort: () => {
17224
- setIsSubmitting(false);
17225
17335
  }
17226
17336
  }
17227
17337
  });
17228
- const isExpired = useResourceVersionCheck({
17229
- queryResult: refineFormResult.formResult.refineCore.queryResult
17230
- });
17231
- React.useEffect(() => {
17232
- if (!isExpired || isSubmitting || hasShownExpiredRef.current) {
17233
- return;
17234
- }
17235
- hasShownExpiredRef.current = true;
17236
- pushModal({
17237
- component: DataExpiredModal,
17238
- props: {
17239
- onAbandon: () => {
17240
- popModal();
17241
- }
17242
- }
17243
- });
17244
- }, [isExpired, isSubmitting, pushModal, popModal]);
17245
17338
  const fieldsConfig = useFieldsConfig(
17246
17339
  resourceConfig,
17247
17340
  { fields: formConfig == null ? void 0 : formConfig.fields },
@@ -17275,13 +17368,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
17275
17368
  isShowLayout: false,
17276
17369
  useFormProps: {
17277
17370
  redirect: false,
17278
- mutationMeta: (_a2 = formConfig == null ? void 0 : formConfig.refineCoreProps) == null ? void 0 : _a2.mutationMeta,
17279
- onSubmitStart: () => {
17280
- setIsSubmitting(true);
17281
- },
17282
- onSubmitAbort: () => {
17283
- setIsSubmitting(false);
17284
- }
17371
+ mutationMeta: (_a2 = formConfig == null ? void 0 : formConfig.refineCoreProps) == null ? void 0 : _a2.mutationMeta
17285
17372
  },
17286
17373
  rules: fieldsConfig == null ? void 0 : fieldsConfig.filter(
17287
17374
  (config) => "isSkipValidationInYaml" in config && !config.isSkipValidationInYaml
@@ -17398,7 +17485,7 @@ function ConfirmModal({
17398
17485
  });
17399
17486
  }
17400
17487
  function FormModal(props) {
17401
- var _a, _b, _c, _d, _e;
17488
+ var _a, _b, _c, _d, _e, _f;
17402
17489
  const {
17403
17490
  id,
17404
17491
  yamlFormProps: customYamlFormProps,
@@ -17536,37 +17623,59 @@ function FormModal(props) {
17536
17623
  setStep(nextStep);
17537
17624
  }
17538
17625
  }, [step]);
17539
- return /* @__PURE__ */ common.jsxRuntimeExports.jsxs(eagle.WizardDialog, {
17540
- style: {
17541
- "--max-modal-width": isYamlForm || !isDisabledChangeMode ? "1024px" : "648px"
17542
- },
17543
- title: /* @__PURE__ */ common.jsxRuntimeExports.jsxs("div", {
17544
- className: TitleWrapperStyle,
17545
- children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx("span", {
17546
- children: title
17547
- }), ((_c = resourceConfig.formConfig) == null ? void 0 : _c.formType) === FormType.FORM ? /* @__PURE__ */ common.jsxRuntimeExports.jsx(FormModeSegmentControl, {
17548
- formConfig: resourceConfig.formConfig,
17549
- mode,
17550
- onChangeMode
17551
- }) : null]
17552
- }),
17553
- error: errorText,
17554
- steps,
17626
+ const extraSubmitButton = ((_c = resourceConfig.formConfig) == null ? void 0 : _c.formType) === FormType.FORM ? resourceConfig.formConfig.extraSubmitButton : void 0;
17627
+ const footer = useExtraSubmitFooter({
17628
+ action,
17629
+ cancelText: (modalProps == null ? void 0 : modalProps.cancelText) || i18n2.t("dovetail.cancel"),
17630
+ defaultSubmitText: okText,
17631
+ errorText,
17632
+ extraSubmitButton,
17633
+ fallbackFooter: modalProps == null ? void 0 : modalProps.footer,
17634
+ isYamlMode,
17635
+ nextStepText: (modalProps == null ? void 0 : modalProps.nextText) || i18n2.t("dovetail.next_step"),
17636
+ prevStepText: (modalProps == null ? void 0 : modalProps.prevText) || i18n2.t("dovetail.prev_step"),
17637
+ saveButtonProps,
17555
17638
  step,
17556
- onStepChange: handleStepChange,
17557
- onOk,
17558
- okButtonProps: {
17559
- ...lodashEs.omit(saveButtonProps, "onClick"),
17560
- children: (_d = resourceConfig.formConfig) == null ? void 0 : _d.saveButtonText
17561
- },
17562
- okText: ((_e = resourceConfig.formConfig) == null ? void 0 : _e.saveButtonText) || okText,
17563
- destroyOnClose: true,
17564
- destroyOtherStep: true,
17565
- ...modalProps,
17566
- children: [desc ? /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", {
17567
- className: FormDescStyle,
17568
- children: desc
17569
- }) : void 0, formEle]
17639
+ stepCount: (steps == null ? void 0 : steps.length) || 0,
17640
+ onCancel: popModal,
17641
+ onNextStep: () => handleStepChange(step + 1),
17642
+ onPrevStep: () => handleStepChange(step - 1),
17643
+ onSubmit: onOk
17644
+ });
17645
+ return /* @__PURE__ */ common.jsxRuntimeExports.jsx(Retry409Provider, {
17646
+ children: /* @__PURE__ */ common.jsxRuntimeExports.jsxs(eagle.WizardDialog, {
17647
+ style: {
17648
+ "--max-modal-width": isYamlForm || !isDisabledChangeMode ? "1024px" : "648px"
17649
+ },
17650
+ title: /* @__PURE__ */ common.jsxRuntimeExports.jsxs("div", {
17651
+ className: TitleWrapperStyle,
17652
+ children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx("span", {
17653
+ children: title
17654
+ }), ((_d = resourceConfig.formConfig) == null ? void 0 : _d.formType) === FormType.FORM ? /* @__PURE__ */ common.jsxRuntimeExports.jsx(FormModeSegmentControl, {
17655
+ formConfig: resourceConfig.formConfig,
17656
+ mode,
17657
+ onChangeMode
17658
+ }) : null]
17659
+ }),
17660
+ error: errorText,
17661
+ steps,
17662
+ step,
17663
+ onStepChange: handleStepChange,
17664
+ onOk,
17665
+ okButtonProps: {
17666
+ ...lodashEs.omit(saveButtonProps, "onClick"),
17667
+ children: (_e = resourceConfig.formConfig) == null ? void 0 : _e.saveButtonText
17668
+ },
17669
+ okText: ((_f = resourceConfig.formConfig) == null ? void 0 : _f.saveButtonText) || okText,
17670
+ footer,
17671
+ destroyOnClose: true,
17672
+ destroyOtherStep: true,
17673
+ ...modalProps,
17674
+ children: [desc ? /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", {
17675
+ className: FormDescStyle,
17676
+ children: desc
17677
+ }) : void 0, formEle]
17678
+ })
17570
17679
  });
17571
17680
  }
17572
17681
  const RefineFormPage_1v0fhor = "";