Skip to content

Commit cd106b1

Browse files
committed
fix: CustomResources afterCreatefn
1 parent 1f89812 commit cd106b1

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/resources/CustomResourceDefinitions/CRCreate.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState } from 'react';
2-
import { useNavigate } from 'react-router-dom';
2+
import { useNavigate, useParams } from 'react-router-dom';
33
import { cloneDeep } from 'lodash';
44

55
import { ResourceForm } from 'shared/ResourceForm';
@@ -11,6 +11,8 @@ import { createTemplate } from './templates';
1111
import { useTranslation } from 'react-i18next';
1212
import { useNotification } from 'shared/contexts/NotificationContext';
1313
import { BusyIndicator } from '@ui5/webcomponents-react';
14+
import { useRecoilState } from 'recoil';
15+
import { columnLayoutState } from 'state/columnLayoutAtom';
1416

1517
function CRCreateForm({
1618
onChange,
@@ -20,6 +22,8 @@ function CRCreateForm({
2022
resource: initialCustomResource,
2123
...props
2224
}) {
25+
const { crdName } = useParams();
26+
const [layoutColumn, setLayoutColumn] = useRecoilState(columnLayoutState);
2327
const { t } = useTranslation();
2428
const notification = useNotification();
2529
const [cr, setCr] = useState(
@@ -30,6 +34,8 @@ function CRCreateForm({
3034
initialCustomResource || createTemplate(crd),
3135
);
3236

37+
const isEdit = !!initialUnchangedResource?.metadata?.name;
38+
3339
const customUrl = useCustomResourceUrl(crd);
3440

3541
const navigate = useNavigate();
@@ -65,11 +71,26 @@ function CRCreateForm({
6571
layoutNumber={layoutNumber}
6672
afterCreatedFn={() => {
6773
notification.notifySuccess({
68-
content: t('common.create-form.messages.patch-success', {
69-
resourceType: crd.spec.names.kind,
70-
}),
74+
content: t(
75+
isEdit
76+
? 'common.create-form.messages.patch-success'
77+
: 'common.create-form.messages.create-success',
78+
{
79+
resourceType: crd.spec.names.kind,
80+
},
81+
),
7182
});
7283
navigate(`${customUrl(cr)}${nextQuery}`);
84+
setLayoutColumn({
85+
...layoutColumn,
86+
layout: 'ThreeColumnsEndExpanded',
87+
showCreate: null,
88+
endColumn: {
89+
resourceName: cr.metadata.name,
90+
resourceType: crdName,
91+
namespaceId: cr.metadata.namespace,
92+
},
93+
});
7394
}}
7495
/>
7596
);

0 commit comments

Comments
 (0)