Skip to content

Commit

Permalink
fix form flickering & rerender on edit
Browse files Browse the repository at this point in the history
  • Loading branch information
OliwiaGowor committed Aug 23, 2024
1 parent 46d7548 commit e86963a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/resources/CustomResourceDefinitions/CRCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { usePrepareLayout } from 'shared/hooks/usePrepareLayout';
import { useCustomResourceUrl } from 'resources/CustomResourceDefinitions/useCustomResourceUrl';

import { createTemplate } from './templates';
import { useTranslation } from 'react-i18next';
import { useNotification } from 'shared/contexts/NotificationContext';

function CRCreate({
onChange,
Expand All @@ -17,6 +19,8 @@ function CRCreate({
resource: initialCustomResource,
...props
}) {
const { t } = useTranslation();
const notification = useNotification();
const [cr, setCr] = useState(
cloneDeep(initialCustomResource) || createTemplate(crd),
);
Expand All @@ -37,7 +41,7 @@ function CRCreate({
? nextQuery
: currentQuery;

const currentVersion = crd.spec.versions.find(ver => ver.storage).name;
const currentVersion = crd.spec.versions?.find(ver => ver.storage).name;
const namespace =
crd.spec.scope === 'Namespaced'
? `/namespaces/${cr.metadata?.namespace || ''}`
Expand Down Expand Up @@ -66,6 +70,11 @@ function CRCreate({
onlyYaml
layoutNumber={layoutNumber}
afterCreatedFn={() => {
notification.notifySuccess({
content: t('common.create-form.messages.patch-success', {
resourceType: crd.spec.names.kind,
}),
});
navigate(`${customUrl(cr)}${goToLayoutQuery}`);
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Spinner } from 'shared/components/Spinner/Spinner';
import { ReadonlyEditorPanel } from 'shared/components/ReadonlyEditorPanel';
import { activeNamespaceIdState } from 'state/activeNamespaceIdAtom';
import CRCreate from 'resources/CustomResourceDefinitions/CRCreate';
import { useCallback } from 'react';

export default function CustomResource({ params }) {
const namespace = useRecoilValue(activeNamespaceIdState);
Expand All @@ -27,6 +28,11 @@ export default function CustomResource({ params }) {
},
);

const CRCreateWrapper = useCallback(
props => <CRCreate {...props} crd={data} layoutNumber="MidColumn" />,
[data],
);

if (loading) return <Spinner />;

const versions = data?.spec?.versions;
Expand Down Expand Up @@ -61,9 +67,7 @@ export default function CustomResource({ params }) {
resourceType={crdName}
resourceName={resourceName}
namespace={namespace}
createResourceForm={props => (
<CRCreate {...props} crd={data} layoutNumber="MidColumn" />
)}
createResourceForm={CRCreateWrapper}
customComponents={[yamlPreview]}
layoutCloseCreateUrl={params.layoutCloseCreateUrl}
disableDelete={isModule}
Expand Down

0 comments on commit e86963a

Please sign in to comment.