@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/components/Dropdowns/K8sDropdown/index.d.ts +2 -3
- package/dist/components/Form/FormModal.d.ts +2 -1
- package/dist/components/Form/RefineFormContainer.d.ts +1 -1
- package/dist/components/Form/RefineFormContent.d.ts +1 -1
- package/dist/components/Form/YamlForm.d.ts +1 -1
- package/dist/components/Form/YamlFormContainer.d.ts +2 -2
- package/dist/components/Form/useFieldsConfig.d.ts +1 -1
- package/dist/components/Form/useRefineForm.d.ts +1 -1
- package/dist/components/ResourceCRUD/create/index.d.ts +1 -1
- package/dist/hooks/useOpenForm.d.ts +2 -0
- package/dist/refine.cjs +126 -112
- package/dist/refine.js +126 -112
- package/dist/utils/form.d.ts +1 -1
- package/package.json +1 -1
package/dist/refine.cjs
CHANGED
|
@@ -10583,23 +10583,23 @@ function useOpenForm() {
|
|
|
10583
10583
|
const pushModal = eagle.usePushModal();
|
|
10584
10584
|
const go = core.useGo();
|
|
10585
10585
|
return function openForm(options) {
|
|
10586
|
-
var _a;
|
|
10587
|
-
const finalResourceName = (options == null ? void 0 : options.resourceName) || (resource == null ? void 0 : resource.name);
|
|
10588
|
-
if (finalResourceName) {
|
|
10589
|
-
const
|
|
10590
|
-
const formType = (
|
|
10586
|
+
var _a, _b;
|
|
10587
|
+
const finalResourceName = (options == null ? void 0 : options.resourceName) || ((_a = options == null ? void 0 : options.resourceConfig) == null ? void 0 : _a.name) || (resource == null ? void 0 : resource.name);
|
|
10588
|
+
if (finalResourceName || (options == null ? void 0 : options.resourceConfig)) {
|
|
10589
|
+
const resourceConfig = (options == null ? void 0 : options.resourceConfig) || configs[finalResourceName || ""];
|
|
10590
|
+
const formType = (_b = resourceConfig.formConfig) == null ? void 0 : _b.formContainerType;
|
|
10591
10591
|
if (formType === void 0 || formType === FormContainerType.MODAL) {
|
|
10592
10592
|
pushModal({
|
|
10593
10593
|
component: () => {
|
|
10594
10594
|
var _a2;
|
|
10595
|
-
const ModalComponent = ((_a2 =
|
|
10595
|
+
const ModalComponent = ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.CustomFormModal) || FormModal;
|
|
10596
10596
|
return /* @__PURE__ */ common.jsxRuntimeExports.jsx(
|
|
10597
10597
|
ModalComponent,
|
|
10598
10598
|
{
|
|
10599
|
-
resource: finalResourceName,
|
|
10600
10599
|
id: options == null ? void 0 : options.id,
|
|
10600
|
+
resourceConfig,
|
|
10601
10601
|
yamlFormProps: {
|
|
10602
|
-
|
|
10602
|
+
resourceConfig
|
|
10603
10603
|
},
|
|
10604
10604
|
options,
|
|
10605
10605
|
onSuccess: options == null ? void 0 : options.onSuccess
|
|
@@ -10612,7 +10612,7 @@ function useOpenForm() {
|
|
|
10612
10612
|
edit2(options.id);
|
|
10613
10613
|
} else {
|
|
10614
10614
|
go({
|
|
10615
|
-
to: navigation.createUrl(finalResourceName),
|
|
10615
|
+
to: navigation.createUrl(finalResourceName || ""),
|
|
10616
10616
|
options: {
|
|
10617
10617
|
keepQuery: true
|
|
10618
10618
|
}
|
|
@@ -10837,25 +10837,26 @@ function K8sDropdown(props) {
|
|
|
10837
10837
|
const {
|
|
10838
10838
|
record,
|
|
10839
10839
|
size = "normal",
|
|
10840
|
-
|
|
10840
|
+
resourceConfig,
|
|
10841
10841
|
customButton,
|
|
10842
|
-
deleteDialogProps
|
|
10843
|
-
displayName,
|
|
10844
|
-
hideEdit
|
|
10842
|
+
deleteDialogProps
|
|
10845
10843
|
} = props;
|
|
10846
10844
|
const globalStore = useGlobalStore();
|
|
10847
10845
|
const useResourceResult = core.useResource();
|
|
10848
10846
|
const configs = React.useContext(ConfigsContext);
|
|
10849
|
-
const resourceName =
|
|
10850
|
-
const config = configs[resourceName || ""];
|
|
10847
|
+
const resourceName = (resourceConfig == null ? void 0 : resourceConfig.name) || getResourceNameByKind(record.kind || "", configs);
|
|
10848
|
+
const config = resourceConfig || configs[resourceName || ""];
|
|
10851
10849
|
const { t: t2, i18n: i18n2 } = common.useTranslation();
|
|
10852
10850
|
const { openDeleteConfirmModal } = useDeleteModal({
|
|
10853
10851
|
resourceName: resourceName || "",
|
|
10854
10852
|
deleteDialogProps,
|
|
10855
|
-
displayName,
|
|
10853
|
+
displayName: config.displayName,
|
|
10856
10854
|
meta: record.apiVersion ? {
|
|
10857
10855
|
kind: record.kind || "",
|
|
10858
|
-
resourceBasePath: (
|
|
10856
|
+
resourceBasePath: (
|
|
10857
|
+
// k8s 通用规则,apiVersion 包含 / 则使用 apis,否则使用 api
|
|
10858
|
+
(((_a = record.apiVersion) == null ? void 0 : _a.includes("/")) ? "apis" : "api") + `/${record.apiVersion}`
|
|
10859
|
+
)
|
|
10859
10860
|
} : void 0
|
|
10860
10861
|
});
|
|
10861
10862
|
const download2 = useDownloadYAML();
|
|
@@ -10880,10 +10881,16 @@ function K8sDropdown(props) {
|
|
|
10880
10881
|
eagle.Dropdown,
|
|
10881
10882
|
{
|
|
10882
10883
|
overlay: /* @__PURE__ */ common.jsxRuntimeExports.jsxs(eagle.Menu, { children: [
|
|
10883
|
-
isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false ||
|
|
10884
|
-
|
|
10885
|
-
|
|
10886
|
-
|
|
10884
|
+
isInShowPage || (canEditData == null ? void 0 : canEditData.can) === false || (config == null ? void 0 : config.hideEdit) ? null : /* @__PURE__ */ common.jsxRuntimeExports.jsx(
|
|
10885
|
+
eagle.Menu.Item,
|
|
10886
|
+
{
|
|
10887
|
+
onClick: () => openForm({ id: record.id, resourceName, resourceConfig: config }),
|
|
10888
|
+
children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(eagle.Icon, { src: iconsReact.EditPen16PrimaryIcon, children: formType === FormType.FORM ? `${t2("dovetail.edit")}${transformResourceKindInSentence(
|
|
10889
|
+
config.displayName || record.kind || "",
|
|
10890
|
+
i18n2.language
|
|
10891
|
+
)}` : t2("dovetail.edit_yaml") })
|
|
10892
|
+
}
|
|
10893
|
+
),
|
|
10887
10894
|
/* @__PURE__ */ common.jsxRuntimeExports.jsx(
|
|
10888
10895
|
eagle.Menu.Item,
|
|
10889
10896
|
{
|
|
@@ -14620,7 +14627,7 @@ function ListPage(props) {
|
|
|
14620
14627
|
})]
|
|
14621
14628
|
}) : void 0, /* @__PURE__ */ common.jsxRuntimeExports.jsxs("div", {
|
|
14622
14629
|
className: common.cx_default(ListContentStyle, contentClassName),
|
|
14623
|
-
style: !config.customFilterBar && config.nonNsResource ? {
|
|
14630
|
+
style: !customFilterBar && !config.customFilterBar && config.nonNsResource ? {
|
|
14624
14631
|
paddingTop: 0
|
|
14625
14632
|
} : {},
|
|
14626
14633
|
children: [customFilterBar || config.customFilterBar || !config.nonNsResource && /* @__PURE__ */ common.jsxRuntimeExports.jsx(NamespacesFilter, {
|
|
@@ -14674,10 +14681,10 @@ function ResourceShow(props) {
|
|
|
14674
14681
|
}
|
|
14675
14682
|
);
|
|
14676
14683
|
}
|
|
14677
|
-
function getInitialValues(
|
|
14678
|
-
return
|
|
14679
|
-
apiVersion:
|
|
14680
|
-
kind:
|
|
14684
|
+
function getInitialValues(resourceConfig) {
|
|
14685
|
+
return resourceConfig.initValue || {
|
|
14686
|
+
apiVersion: resourceConfig.apiVersion,
|
|
14687
|
+
kind: resourceConfig.kind,
|
|
14681
14688
|
...BASE_INIT_VALUE,
|
|
14682
14689
|
spec: {}
|
|
14683
14690
|
};
|
|
@@ -14816,19 +14823,19 @@ const SpaceStyle = "sea7f83";
|
|
|
14816
14823
|
const VerticalFormItemStyle = "v1jthrhz";
|
|
14817
14824
|
const IntegerStyle = "i1brpchs";
|
|
14818
14825
|
const ContentWrapper = "c11mae2d";
|
|
14819
|
-
function useFieldsConfig(
|
|
14826
|
+
function useFieldsConfig(resourceConfig, formConfig, resourceId, step, customOptions, transformedInitValues) {
|
|
14820
14827
|
var _a, _b, _c;
|
|
14821
14828
|
const action = resourceId ? "edit" : "create";
|
|
14822
14829
|
const listQuery = core.useList({
|
|
14823
|
-
resource:
|
|
14824
|
-
meta: { resourceBasePath:
|
|
14830
|
+
resource: resourceConfig == null ? void 0 : resourceConfig.name,
|
|
14831
|
+
meta: { resourceBasePath: resourceConfig == null ? void 0 : resourceConfig.basePath, kind: resourceConfig == null ? void 0 : resourceConfig.kind },
|
|
14825
14832
|
pagination: {
|
|
14826
14833
|
mode: "off"
|
|
14827
14834
|
}
|
|
14828
14835
|
});
|
|
14829
14836
|
const showQuery = core.useShow({
|
|
14830
|
-
resource:
|
|
14831
|
-
meta: { resourceBasePath:
|
|
14837
|
+
resource: resourceConfig == null ? void 0 : resourceConfig.name,
|
|
14838
|
+
meta: { resourceBasePath: resourceConfig == null ? void 0 : resourceConfig.basePath, kind: resourceConfig == null ? void 0 : resourceConfig.kind },
|
|
14832
14839
|
id: resourceId
|
|
14833
14840
|
});
|
|
14834
14841
|
return (_c = formConfig == null ? void 0 : formConfig.fields) == null ? void 0 : _c.call(formConfig, {
|
|
@@ -14943,7 +14950,7 @@ const MemoizedFormField = React.memo(function FormField({
|
|
|
14943
14950
|
});
|
|
14944
14951
|
function FieldsContent(props) {
|
|
14945
14952
|
const {
|
|
14946
|
-
|
|
14953
|
+
resourceConfig,
|
|
14947
14954
|
formConfig,
|
|
14948
14955
|
resourceId,
|
|
14949
14956
|
step,
|
|
@@ -14955,7 +14962,7 @@ function FieldsContent(props) {
|
|
|
14955
14962
|
const { control, getValues, watch, trigger } = formResult;
|
|
14956
14963
|
const action = resourceId ? "edit" : "create";
|
|
14957
14964
|
const formFieldsConfig = useFieldsConfig(
|
|
14958
|
-
|
|
14965
|
+
resourceConfig,
|
|
14959
14966
|
{ fields },
|
|
14960
14967
|
resourceId,
|
|
14961
14968
|
step,
|
|
@@ -14973,7 +14980,7 @@ function FieldsContent(props) {
|
|
|
14973
14980
|
children: /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", { className: ContentWrapper, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(
|
|
14974
14981
|
FieldsContent,
|
|
14975
14982
|
{
|
|
14976
|
-
|
|
14983
|
+
resourceConfig,
|
|
14977
14984
|
formConfig,
|
|
14978
14985
|
resourceId,
|
|
14979
14986
|
step,
|
|
@@ -15003,7 +15010,7 @@ function FieldsContent(props) {
|
|
|
15003
15010
|
}
|
|
15004
15011
|
const RefineFormContent = (props) => {
|
|
15005
15012
|
const {
|
|
15006
|
-
config,
|
|
15013
|
+
resourceConfig: config,
|
|
15007
15014
|
formResult,
|
|
15008
15015
|
resourceId,
|
|
15009
15016
|
errorMsgs,
|
|
@@ -15017,7 +15024,7 @@ const RefineFormContent = (props) => {
|
|
|
15017
15024
|
/* @__PURE__ */ common.jsxRuntimeExports.jsx(
|
|
15018
15025
|
FieldsContent,
|
|
15019
15026
|
{
|
|
15020
|
-
config,
|
|
15027
|
+
resourceConfig: config,
|
|
15021
15028
|
formConfig,
|
|
15022
15029
|
fields: formConfig == null ? void 0 : formConfig.fields,
|
|
15023
15030
|
resourceId,
|
|
@@ -15728,7 +15735,7 @@ const useForm = ({
|
|
|
15728
15735
|
};
|
|
15729
15736
|
};
|
|
15730
15737
|
const useRefineForm = (props) => {
|
|
15731
|
-
const { formConfig,
|
|
15738
|
+
const { formConfig, resourceConfig, id, refineProps, options } = props;
|
|
15732
15739
|
const { transformInitValues, transformApplyValues } = usePathMap({
|
|
15733
15740
|
pathMap: formConfig == null ? void 0 : formConfig.pathMap,
|
|
15734
15741
|
transformInitValues: formConfig == null ? void 0 : formConfig.transformInitValues,
|
|
@@ -15745,25 +15752,25 @@ const useRefineForm = (props) => {
|
|
|
15745
15752
|
var _a;
|
|
15746
15753
|
const formValue = result.getValues();
|
|
15747
15754
|
return {
|
|
15748
|
-
message: i18n2.t(
|
|
15749
|
-
|
|
15750
|
-
|
|
15751
|
-
|
|
15752
|
-
|
|
15753
|
-
|
|
15754
|
-
}
|
|
15755
|
-
).trim(),
|
|
15755
|
+
message: i18n2.t(id ? "dovetail.edit_resource_success" : "dovetail.create_success_toast", {
|
|
15756
|
+
kind: transformResourceKindInSentence(
|
|
15757
|
+
resourceConfig.displayName || resourceConfig.kind,
|
|
15758
|
+
i18n2.language
|
|
15759
|
+
),
|
|
15760
|
+
name: (_a = formValue.metadata) == null ? void 0 : _a.name,
|
|
15761
|
+
interpolation: { escapeValue: false }
|
|
15762
|
+
}).trim(),
|
|
15756
15763
|
description: "Success",
|
|
15757
15764
|
type: "success"
|
|
15758
15765
|
};
|
|
15759
15766
|
},
|
|
15760
|
-
resource:
|
|
15767
|
+
resource: resourceConfig.name,
|
|
15761
15768
|
action: id ? "edit" : "create",
|
|
15762
15769
|
id,
|
|
15763
15770
|
liveMode: "off",
|
|
15764
15771
|
...refineProps
|
|
15765
15772
|
},
|
|
15766
|
-
defaultValues: (options == null ? void 0 : options.initialValues) || (
|
|
15773
|
+
defaultValues: (options == null ? void 0 : options.initialValues) || (resourceConfig == null ? void 0 : resourceConfig.initValue),
|
|
15767
15774
|
transformApplyValues,
|
|
15768
15775
|
transformInitValues,
|
|
15769
15776
|
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
@@ -15776,11 +15783,19 @@ const useRefineForm = (props) => {
|
|
|
15776
15783
|
if (response && !(response == null ? void 0 : response.bodyUsed)) {
|
|
15777
15784
|
(_b = response.json) == null ? void 0 : _b.call(response).then((body) => {
|
|
15778
15785
|
var _a2;
|
|
15779
|
-
setResponseErrorMsgs(
|
|
15786
|
+
setResponseErrorMsgs(
|
|
15787
|
+
[].concat(
|
|
15788
|
+
((_a2 = formConfig == null ? void 0 : formConfig.formatError) == null ? void 0 : _a2.call(formConfig, body)) || getCommonErrors(body, i18n2)
|
|
15789
|
+
)
|
|
15790
|
+
);
|
|
15780
15791
|
});
|
|
15781
15792
|
}
|
|
15782
15793
|
}, [formConfig, result, i18n2]);
|
|
15783
|
-
return {
|
|
15794
|
+
return {
|
|
15795
|
+
formResult: result,
|
|
15796
|
+
responseErrorMsgs,
|
|
15797
|
+
beforeSubmitErrors: result.beforeSubmitErrors
|
|
15798
|
+
};
|
|
15784
15799
|
};
|
|
15785
15800
|
const index_2ivb33 = "";
|
|
15786
15801
|
const Style = "s1bsn3us";
|
|
@@ -16453,7 +16468,7 @@ function YamlForm(props) {
|
|
|
16453
16468
|
schemaStrategy = "Optional",
|
|
16454
16469
|
isShowLayout = true,
|
|
16455
16470
|
useFormProps,
|
|
16456
|
-
|
|
16471
|
+
resourceConfig,
|
|
16457
16472
|
transformInitValues,
|
|
16458
16473
|
transformApplyValues,
|
|
16459
16474
|
beforeSubmit,
|
|
@@ -16497,7 +16512,7 @@ function YamlForm(props) {
|
|
|
16497
16512
|
beforeSubmit,
|
|
16498
16513
|
successNotification(data2) {
|
|
16499
16514
|
var _a;
|
|
16500
|
-
const displayName =
|
|
16515
|
+
const displayName = resourceConfig.displayName || ((_a = resource == null ? void 0 : resource.meta) == null ? void 0 : _a.kind);
|
|
16501
16516
|
return {
|
|
16502
16517
|
message: i18n2.t(action === "create" ? "dovetail.create_success_toast" : "dovetail.save_yaml_success_toast", {
|
|
16503
16518
|
kind: transformResourceKindInSentence(displayName, i18n2.language),
|
|
@@ -16513,7 +16528,11 @@ function YamlForm(props) {
|
|
|
16513
16528
|
transformInitValues,
|
|
16514
16529
|
transformApplyValues,
|
|
16515
16530
|
mutationMeta: {
|
|
16516
|
-
updateType: "put"
|
|
16531
|
+
updateType: "put",
|
|
16532
|
+
dataProviderName: resourceConfig.dataProviderName,
|
|
16533
|
+
resourceBasePath: resourceConfig.basePath,
|
|
16534
|
+
kind: resourceConfig.kind,
|
|
16535
|
+
label: `${resourceConfig.kind}s`
|
|
16517
16536
|
},
|
|
16518
16537
|
...useFormProps
|
|
16519
16538
|
});
|
|
@@ -16596,7 +16615,7 @@ function YamlForm(props) {
|
|
|
16596
16615
|
}
|
|
16597
16616
|
const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
16598
16617
|
id,
|
|
16599
|
-
|
|
16618
|
+
resourceConfig,
|
|
16600
16619
|
step,
|
|
16601
16620
|
customYamlFormProps,
|
|
16602
16621
|
formConfig,
|
|
@@ -16609,7 +16628,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16609
16628
|
var _a, _b;
|
|
16610
16629
|
const action = id ? "edit" : "create";
|
|
16611
16630
|
const refineFormResult = useRefineForm({
|
|
16612
|
-
|
|
16631
|
+
resourceConfig,
|
|
16613
16632
|
id,
|
|
16614
16633
|
refineProps: {
|
|
16615
16634
|
onMutationSuccess: (data2) => {
|
|
@@ -16635,7 +16654,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16635
16654
|
}
|
|
16636
16655
|
});
|
|
16637
16656
|
const fieldsConfig = useFieldsConfig(
|
|
16638
|
-
|
|
16657
|
+
resourceConfig,
|
|
16639
16658
|
{ fields: formConfig == null ? void 0 : formConfig.fields },
|
|
16640
16659
|
id,
|
|
16641
16660
|
step,
|
|
@@ -16651,8 +16670,8 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16651
16670
|
if (isYamlMode) {
|
|
16652
16671
|
return {
|
|
16653
16672
|
...customYamlFormProps,
|
|
16654
|
-
resource:
|
|
16655
|
-
|
|
16673
|
+
resource: resourceConfig.name,
|
|
16674
|
+
resourceConfig,
|
|
16656
16675
|
transformInitValues: void 0,
|
|
16657
16676
|
transformApplyValues: void 0,
|
|
16658
16677
|
initialValuesForCreate: transformApplyValues(
|
|
@@ -16668,10 +16687,10 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16668
16687
|
redirect: false
|
|
16669
16688
|
},
|
|
16670
16689
|
rules: fieldsConfig == null ? void 0 : fieldsConfig.filter(
|
|
16671
|
-
(
|
|
16672
|
-
).map((
|
|
16673
|
-
path: "path" in
|
|
16674
|
-
validators: "validators" in
|
|
16690
|
+
(config) => "isSkipValidationInYaml" in config && !config.isSkipValidationInYaml
|
|
16691
|
+
).map((config) => ({
|
|
16692
|
+
path: "path" in config ? config.path : [],
|
|
16693
|
+
validators: "validators" in config ? config.validators : void 0
|
|
16675
16694
|
})),
|
|
16676
16695
|
onSaveButtonPropsChange,
|
|
16677
16696
|
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
@@ -16684,14 +16703,14 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16684
16703
|
};
|
|
16685
16704
|
}
|
|
16686
16705
|
return {
|
|
16687
|
-
|
|
16706
|
+
resourceConfig
|
|
16688
16707
|
};
|
|
16689
16708
|
}, [
|
|
16690
16709
|
action,
|
|
16691
16710
|
isYamlMode,
|
|
16692
16711
|
customYamlFormProps,
|
|
16693
16712
|
fieldsConfig,
|
|
16694
|
-
|
|
16713
|
+
resourceConfig,
|
|
16695
16714
|
id,
|
|
16696
16715
|
refineFormResult,
|
|
16697
16716
|
formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
@@ -16733,7 +16752,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16733
16752
|
RefineFormContent,
|
|
16734
16753
|
{
|
|
16735
16754
|
formResult: refineFormResult.formResult,
|
|
16736
|
-
|
|
16755
|
+
resourceConfig,
|
|
16737
16756
|
step,
|
|
16738
16757
|
formConfig,
|
|
16739
16758
|
errorMsgs: [
|
|
@@ -16750,7 +16769,7 @@ const RefineFormContainer = React.forwardRef(function RefineFormContainer2({
|
|
|
16750
16769
|
function YamlFormContainer({
|
|
16751
16770
|
id,
|
|
16752
16771
|
customYamlFormProps,
|
|
16753
|
-
|
|
16772
|
+
resourceConfig,
|
|
16754
16773
|
formConfig,
|
|
16755
16774
|
onSuccess,
|
|
16756
16775
|
onError,
|
|
@@ -16765,12 +16784,12 @@ function YamlFormContainer({
|
|
|
16765
16784
|
const yamlFormProps = React.useMemo(() => {
|
|
16766
16785
|
return {
|
|
16767
16786
|
...customYamlFormProps,
|
|
16768
|
-
resource:
|
|
16769
|
-
|
|
16787
|
+
resource: resourceConfig.name,
|
|
16788
|
+
resourceConfig,
|
|
16770
16789
|
transformInitValues,
|
|
16771
16790
|
transformApplyValues,
|
|
16772
16791
|
beforeSubmit: formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16773
|
-
initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(
|
|
16792
|
+
initialValuesForCreate: (customYamlFormProps == null ? void 0 : customYamlFormProps.initialValuesForCreate) || getInitialValues(resourceConfig),
|
|
16774
16793
|
initialValuesForEdit: void 0,
|
|
16775
16794
|
id,
|
|
16776
16795
|
action,
|
|
@@ -16791,7 +16810,7 @@ function YamlFormContainer({
|
|
|
16791
16810
|
id,
|
|
16792
16811
|
action,
|
|
16793
16812
|
customYamlFormProps,
|
|
16794
|
-
|
|
16813
|
+
resourceConfig,
|
|
16795
16814
|
formConfig == null ? void 0 : formConfig.beforeSubmit,
|
|
16796
16815
|
transformInitValues,
|
|
16797
16816
|
transformApplyValues,
|
|
@@ -16835,20 +16854,16 @@ function ConfirmModal({
|
|
|
16835
16854
|
function FormModal(props) {
|
|
16836
16855
|
var _a, _b, _c, _d;
|
|
16837
16856
|
const {
|
|
16838
|
-
resource: resourceFromProps,
|
|
16839
16857
|
id,
|
|
16840
16858
|
yamlFormProps: customYamlFormProps,
|
|
16841
16859
|
modalProps,
|
|
16842
16860
|
options,
|
|
16861
|
+
resourceConfig,
|
|
16843
16862
|
onSuccess
|
|
16844
16863
|
} = props;
|
|
16845
16864
|
const {
|
|
16846
16865
|
i18n: i18n2
|
|
16847
16866
|
} = common.useTranslation();
|
|
16848
|
-
const {
|
|
16849
|
-
resource
|
|
16850
|
-
} = core.useResource();
|
|
16851
|
-
const configs = React.useContext(ConfigsContext);
|
|
16852
16867
|
const [saveButtonProps, setSaveButtonProps] = React.useState({});
|
|
16853
16868
|
const [isError, setIsError] = React.useState(false);
|
|
16854
16869
|
const [mode, setMode] = React.useState(FormMode.FORM);
|
|
@@ -16857,11 +16872,10 @@ function FormModal(props) {
|
|
|
16857
16872
|
const refineFormContainerRef = React.useRef(null);
|
|
16858
16873
|
const popModal = eagle.usePopModal();
|
|
16859
16874
|
const pushModal = eagle.usePushModal();
|
|
16860
|
-
const
|
|
16861
|
-
const isDisabledChangeMode = config.formConfig && "isDisabledChangeMode" in config.formConfig && config.formConfig.isDisabledChangeMode;
|
|
16875
|
+
const isDisabledChangeMode = resourceConfig.formConfig && "isDisabledChangeMode" in resourceConfig.formConfig && resourceConfig.formConfig.isDisabledChangeMode;
|
|
16862
16876
|
const okText = i18n2.t(id ? "dovetail.save" : "dovetail.create");
|
|
16863
16877
|
const action = id ? "edit" : "create";
|
|
16864
|
-
const isYamlForm = ((_a =
|
|
16878
|
+
const isYamlForm = ((_a = resourceConfig.formConfig) == null ? void 0 : _a.formType) === FormType.YAML;
|
|
16865
16879
|
const onOk = React.useCallback((e2) => {
|
|
16866
16880
|
var _a2;
|
|
16867
16881
|
setIsError(false);
|
|
@@ -16889,30 +16903,30 @@ function FormModal(props) {
|
|
|
16889
16903
|
}, [isError, id, i18n2]);
|
|
16890
16904
|
const title = React.useMemo(() => {
|
|
16891
16905
|
var _a2, _b2, _c2, _d2;
|
|
16892
|
-
if (typeof ((_a2 =
|
|
16893
|
-
return (_b2 =
|
|
16894
|
-
if (typeof ((_c2 =
|
|
16895
|
-
return (_d2 =
|
|
16906
|
+
if (typeof ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formTitle) === "string")
|
|
16907
|
+
return (_b2 = resourceConfig.formConfig) == null ? void 0 : _b2.formTitle;
|
|
16908
|
+
if (typeof ((_c2 = resourceConfig.formConfig) == null ? void 0 : _c2.formTitle) === "function") {
|
|
16909
|
+
return (_d2 = resourceConfig.formConfig) == null ? void 0 : _d2.formTitle(action);
|
|
16896
16910
|
}
|
|
16897
|
-
const label2 =
|
|
16911
|
+
const label2 = resourceConfig.displayName || (resourceConfig == null ? void 0 : resourceConfig.kind);
|
|
16898
16912
|
return i18n2.t(id ? "dovetail.edit_resource" : "dovetail.create_resource", {
|
|
16899
16913
|
resource: transformResourceKindInSentence(label2, i18n2.language)
|
|
16900
16914
|
});
|
|
16901
|
-
}, [action,
|
|
16915
|
+
}, [action, resourceConfig.formConfig, resourceConfig.displayName, resourceConfig == null ? void 0 : resourceConfig.kind, i18n2, id]);
|
|
16902
16916
|
const desc = React.useMemo(() => {
|
|
16903
16917
|
var _a2, _b2, _c2, _d2;
|
|
16904
|
-
if (typeof ((_a2 =
|
|
16905
|
-
return (_b2 =
|
|
16906
|
-
if (typeof ((_c2 =
|
|
16907
|
-
return (_d2 =
|
|
16918
|
+
if (typeof ((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formDesc) === "string")
|
|
16919
|
+
return (_b2 = resourceConfig.formConfig) == null ? void 0 : _b2.formDesc;
|
|
16920
|
+
if (typeof ((_c2 = resourceConfig.formConfig) == null ? void 0 : _c2.formDesc) === "function") {
|
|
16921
|
+
return (_d2 = resourceConfig.formConfig) == null ? void 0 : _d2.formDesc(action);
|
|
16908
16922
|
}
|
|
16909
16923
|
return "";
|
|
16910
|
-
}, [action,
|
|
16924
|
+
}, [action, resourceConfig.formConfig]);
|
|
16911
16925
|
const formEle = React.useMemo(() => {
|
|
16912
16926
|
var _a2;
|
|
16913
16927
|
const commonFormProps = {
|
|
16914
16928
|
id,
|
|
16915
|
-
|
|
16929
|
+
resourceConfig,
|
|
16916
16930
|
customYamlFormProps,
|
|
16917
16931
|
onSaveButtonPropsChange: setSaveButtonProps,
|
|
16918
16932
|
onError: () => {
|
|
@@ -16924,28 +16938,28 @@ function FormModal(props) {
|
|
|
16924
16938
|
onSuccess == null ? void 0 : onSuccess(data2);
|
|
16925
16939
|
}
|
|
16926
16940
|
};
|
|
16927
|
-
if (
|
|
16941
|
+
if (resourceConfig.formConfig && (((_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.formType) === FormType.FORM || "fields" in resourceConfig.formConfig)) {
|
|
16928
16942
|
return /* @__PURE__ */ common.jsxRuntimeExports.jsx(RefineFormContainer, {
|
|
16929
16943
|
...commonFormProps,
|
|
16930
16944
|
ref: refineFormContainerRef,
|
|
16931
16945
|
step,
|
|
16932
16946
|
options,
|
|
16933
16947
|
isYamlMode,
|
|
16934
|
-
formConfig:
|
|
16948
|
+
formConfig: resourceConfig.formConfig
|
|
16935
16949
|
});
|
|
16936
16950
|
}
|
|
16937
16951
|
return /* @__PURE__ */ common.jsxRuntimeExports.jsx(YamlFormContainer, {
|
|
16938
16952
|
...commonFormProps,
|
|
16939
|
-
formConfig:
|
|
16953
|
+
formConfig: resourceConfig.formConfig
|
|
16940
16954
|
});
|
|
16941
|
-
}, [id, customYamlFormProps,
|
|
16955
|
+
}, [id, customYamlFormProps, resourceConfig, isYamlMode, step, options, popModal, setSaveButtonProps, onSuccess]);
|
|
16942
16956
|
const steps = React.useMemo(() => {
|
|
16943
16957
|
var _a2, _b2;
|
|
16944
16958
|
if (isYamlMode) {
|
|
16945
16959
|
return void 0;
|
|
16946
16960
|
}
|
|
16947
|
-
if (
|
|
16948
|
-
return (_b2 = (_a2 =
|
|
16961
|
+
if (resourceConfig.formConfig && "steps" in resourceConfig.formConfig) {
|
|
16962
|
+
return (_b2 = (_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.steps) == null ? void 0 : _b2.map((step2, index2) => ({
|
|
16949
16963
|
title: step2.title,
|
|
16950
16964
|
children: /* @__PURE__ */ common.jsxRuntimeExports.jsxs(common.jsxRuntimeExports.Fragment, {
|
|
16951
16965
|
children: [desc && index2 === 0 ? /* @__PURE__ */ common.jsxRuntimeExports.jsx("div", {
|
|
@@ -16956,7 +16970,7 @@ function FormModal(props) {
|
|
|
16956
16970
|
}));
|
|
16957
16971
|
}
|
|
16958
16972
|
return void 0;
|
|
16959
|
-
}, [
|
|
16973
|
+
}, [resourceConfig.formConfig, desc, formEle, isYamlMode]);
|
|
16960
16974
|
const handleStepChange = React.useCallback(async (nextStep) => {
|
|
16961
16975
|
var _a2, _b2;
|
|
16962
16976
|
const isNextStep = nextStep > step;
|
|
@@ -16978,8 +16992,8 @@ function FormModal(props) {
|
|
|
16978
16992
|
className: TitleWrapperStyle,
|
|
16979
16993
|
children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx("span", {
|
|
16980
16994
|
children: title
|
|
16981
|
-
}), ((_b =
|
|
16982
|
-
formConfig:
|
|
16995
|
+
}), ((_b = resourceConfig.formConfig) == null ? void 0 : _b.formType) === FormType.FORM ? /* @__PURE__ */ common.jsxRuntimeExports.jsx(FormModeSegmentControl, {
|
|
16996
|
+
formConfig: resourceConfig.formConfig,
|
|
16983
16997
|
mode,
|
|
16984
16998
|
onChangeMode
|
|
16985
16999
|
}) : null]
|
|
@@ -16991,9 +17005,9 @@ function FormModal(props) {
|
|
|
16991
17005
|
onOk,
|
|
16992
17006
|
okButtonProps: {
|
|
16993
17007
|
...lodashEs.omit(saveButtonProps, "onClick"),
|
|
16994
|
-
children: (_c =
|
|
17008
|
+
children: (_c = resourceConfig.formConfig) == null ? void 0 : _c.saveButtonText
|
|
16995
17009
|
},
|
|
16996
|
-
okText: ((_d =
|
|
17010
|
+
okText: ((_d = resourceConfig.formConfig) == null ? void 0 : _d.saveButtonText) || okText,
|
|
16997
17011
|
destroyOnClose: true,
|
|
16998
17012
|
destroyOtherStep: true,
|
|
16999
17013
|
...modalProps,
|
|
@@ -17017,7 +17031,7 @@ const RefineFormPage = (props) => {
|
|
|
17017
17031
|
const {
|
|
17018
17032
|
formResult
|
|
17019
17033
|
} = useRefineForm({
|
|
17020
|
-
config,
|
|
17034
|
+
resourceConfig: config,
|
|
17021
17035
|
id
|
|
17022
17036
|
});
|
|
17023
17037
|
const action = id ? "edit" : "create";
|
|
@@ -17036,7 +17050,7 @@ const RefineFormPage = (props) => {
|
|
|
17036
17050
|
direction: "vertical",
|
|
17037
17051
|
className: "c1pvtlkp",
|
|
17038
17052
|
children: [/* @__PURE__ */ common.jsxRuntimeExports.jsx(RefineFormContent, {
|
|
17039
|
-
config,
|
|
17053
|
+
resourceConfig: config,
|
|
17040
17054
|
formResult,
|
|
17041
17055
|
resourceId: id,
|
|
17042
17056
|
transformedInitValues: formResult.transformedInitValues
|
|
@@ -17049,18 +17063,18 @@ const RefineFormPage = (props) => {
|
|
|
17049
17063
|
};
|
|
17050
17064
|
function ResourceForm(props) {
|
|
17051
17065
|
var _a;
|
|
17052
|
-
const {
|
|
17066
|
+
const { resourceConfig } = props;
|
|
17053
17067
|
const formProps = React.useMemo(() => {
|
|
17054
17068
|
var _a2, _b;
|
|
17055
17069
|
return {
|
|
17056
|
-
initialValues: getInitialValues(
|
|
17057
|
-
transformInitValues: (_a2 =
|
|
17058
|
-
transformApplyValues: (_b =
|
|
17059
|
-
|
|
17070
|
+
initialValues: getInitialValues(resourceConfig),
|
|
17071
|
+
transformInitValues: (_a2 = resourceConfig.formConfig) == null ? void 0 : _a2.transformInitValues,
|
|
17072
|
+
transformApplyValues: (_b = resourceConfig.formConfig) == null ? void 0 : _b.transformApplyValues,
|
|
17073
|
+
resourceConfig
|
|
17060
17074
|
};
|
|
17061
|
-
}, [
|
|
17062
|
-
if (((_a =
|
|
17063
|
-
return /* @__PURE__ */ common.jsxRuntimeExports.jsx(RefineFormPage, { config });
|
|
17075
|
+
}, [resourceConfig]);
|
|
17076
|
+
if (((_a = resourceConfig.formConfig) == null ? void 0 : _a.formType) === FormType.FORM) {
|
|
17077
|
+
return /* @__PURE__ */ common.jsxRuntimeExports.jsx(RefineFormPage, { config: resourceConfig });
|
|
17064
17078
|
}
|
|
17065
17079
|
return /* @__PURE__ */ common.jsxRuntimeExports.jsx(YamlForm, { ...formProps });
|
|
17066
17080
|
}
|
|
@@ -17073,8 +17087,8 @@ function ResourceCRUD(props) {
|
|
|
17073
17087
|
!config.noShow ? /* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/show`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceShow, { config }) }) : null,
|
|
17074
17088
|
// the modals would render in ModalStack
|
|
17075
17089
|
((_a = config.formConfig) == null ? void 0 : _a.formContainerType) === FormContainerType.PAGE ? /* @__PURE__ */ common.jsxRuntimeExports.jsxs(common.jsxRuntimeExports.Fragment, { children: [
|
|
17076
|
-
/* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/create`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceForm, { config }) }),
|
|
17077
|
-
/* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/edit`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceForm, { config }) })
|
|
17090
|
+
/* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/create`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceForm, { resourceConfig: config }) }),
|
|
17091
|
+
/* @__PURE__ */ common.jsxRuntimeExports.jsx(reactRouterDom.Route, { path: `${urlPrefix}/${config.name}/edit`, children: /* @__PURE__ */ common.jsxRuntimeExports.jsx(ResourceForm, { resourceConfig: config }) })
|
|
17078
17092
|
] }) : null
|
|
17079
17093
|
] }, config.name);
|
|
17080
17094
|
}) });
|