Skip to content

Commit

Permalink
fix: detecting definition change (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 authored Nov 22, 2023
1 parent 503b41a commit 4b26262
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/web/src/components/molecules/Definition/Definition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Pre} from '@atoms';
import {FullWidthSpace} from '@custom-antd';

import useClusterVersionMatch from '@hooks/useClusterVersionMatch';
import {useLastCallback} from '@hooks/useLastCallback';
import {SystemAccess, useSystemAccess} from '@hooks/useSystemAccess';

import {InlineNotification, notificationCall} from '@molecules';
Expand Down Expand Up @@ -64,13 +65,16 @@ const Definition: React.FC<PropsWithChildren<DefinitionProps>> = props => {
skip: !isReadable,
});

const resetValue = useLastCallback(() => {
setValue(definition);
setWasTouched(false);
});

useEffect(() => {
safeRefetch(refetch);
}, []);

useEffect(() => {
setValue(definition);
}, [definition]);
useEffect(resetValue, [definition]);

const onSave = async () => {
const monaco = await import('react-monaco-editor').then(editor => editor.monaco);
Expand Down Expand Up @@ -122,10 +126,7 @@ const Definition: React.FC<PropsWithChildren<DefinitionProps>> = props => {
title="Definition"
description={`Validate and update your ${label} configuration`}
onConfirm={onSave}
onCancel={() => {
setValue(definition);
setWasTouched(false);
}}
onCancel={resetValue}
readOnly={!isSupported || readOnly}
wasTouched={wasTouched}
>
Expand Down

0 comments on commit 4b26262

Please sign in to comment.