Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): Hide managed fields in UI doesn't work #2513

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions ui/src/features/common/code-editor/yaml-editor-lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ const YamlEditor: FC<YamlEditorProps> = (props) => {
});
}, []);

// Handle readonly field (without onChange)
const _value = React.useMemo(() => {
if (onChange) {
return value;
}

try {
const data = yaml.parse(value);

// Hide managedFields
if (hideManagedFields && data?.metadata?.managedFields) {
setManagedFieldsValue(data?.metadata?.managedFields);
delete data.metadata.managedFields;

return yaml.stringify(data);
}

return value;
} catch (_) {
return value;
}
}, [value, hideManagedFields]);

const handleEditorDidMount = (editor: monaco.editor.IStandaloneCodeEditor) => {
editorRef.current = editor;
};
Expand All @@ -114,22 +137,24 @@ const YamlEditor: FC<YamlEditorProps> = (props) => {
return (
<>
<Flex
justify='end'
align='center'
className={isHideManagedFieldsDisplayed || label ? 'mb-2 mt-1' : ''}
gap={8}
>
<div>{label}</div>
{isHideManagedFieldsDisplayed && (
<label>
<Checkbox
className='mr-2'
checked={hideManagedFields}
onChange={(e) => setHideManagedFields(e.target.checked)}
/>
Hide Managed Fields
</label>
)}
{toolbar && <div className='ml-4'>{toolbar}</div>}
<Flex align='center' justify='end' gap={8} flex={1}>
{isHideManagedFieldsDisplayed && (
<label>
<Checkbox
className='mr-2'
checked={hideManagedFields}
onChange={(e) => setHideManagedFields(e.target.checked)}
/>
Hide Managed Fields
</label>
)}
{toolbar && <div>{toolbar}</div>}
</Flex>
</Flex>
<div
style={{ border: '1px solid #d9d9d9', height, overflow: 'hidden' }}
Expand All @@ -151,7 +176,7 @@ const YamlEditor: FC<YamlEditorProps> = (props) => {
width={width}
height={height}
language='yaml'
value={value}
value={_value}
onChange={handleOnChange}
onMount={handleEditorDidMount}
/>
Expand Down
44 changes: 0 additions & 44 deletions ui/src/features/stage/analysis-run-modal.tsx

This file was deleted.