Skip to content

Commit

Permalink
fix(ui): Fix YAML/JSON toggle. Fixes #5690 (#5694)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec authored and simster7 committed Apr 19, 2021
1 parent 279b78b commit b7b4b3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions ui/src/app/shared/components/object-editor/object-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {createRef, useEffect, useState} from 'react';
import MonacoEditor from 'react-monaco-editor';
import {uiUrl} from '../../base';
import {ScopedLocalStorage} from '../../scoped-local-storage';
import {Button} from '../button';
import {parse, stringify} from '../object-parser';
import {PhaseIcon} from '../phase-icon';
import {ToggleButton} from '../toggle-button';

interface Props<T> {
type?: string;
Expand All @@ -29,8 +29,10 @@ export const ObjectEditor = <T extends any>({type, value, buttons, onChange}: Pr
useEffect(() => {
// we ONLY want to change the text, if the normalized version has changed, this prevents white-space changes
// from resulting in a significant change
if (text !== stringify(parse(editor.current.editor.getValue()), lang)) {
editor.current.editor.setValue(text);
const editorText = stringify(parse(editor.current.editor.getValue()), lang);
const editorLang = editor.current.editor.getValue().startsWith('{') ? 'json' : 'yaml';
if (text !== editorText || lang !== editorLang) {
editor.current.editor.setValue(stringify(parse(text), lang));
}
}, [text, lang]);

Expand Down Expand Up @@ -66,9 +68,9 @@ export const ObjectEditor = <T extends any>({type, value, buttons, onChange}: Pr
return (
<>
<div style={{paddingBottom: '1em'}}>
<ToggleButton toggled={lang === 'yaml'} onToggle={() => setLang(lang === 'yaml' ? 'json' : 'yaml')}>
YAML
</ToggleButton>
<Button outline={true} onClick={() => setLang(lang === 'yaml' ? 'json' : 'yaml')}>
<span style={{fontWeight: lang === 'json' ? 'bold' : 'normal'}}>JSON</span>/<span style={{fontWeight: lang === 'yaml' ? 'bold' : 'normal'}}>YAML</span>
</Button>
{buttons}
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const WorkflowNodeSummary = (props: Props) => {
<div className='white-box'>
<div className='white-box__details'>{<AttributeRows attributes={attributes} />}</div>
<div>
{props.onShowYaml && <Button onClick={() => props.onShowYaml(props.node.id)}>YAML</Button>}{' '}
{props.onShowYaml && <Button onClick={() => props.onShowYaml(props.node.id)}>MANIFEST</Button>}{' '}
{props.node.type === 'Pod' && props.onShowContainerLogs && (
<DropDownButton
onClick={() => showLogs()}
Expand Down

0 comments on commit b7b4b3f

Please sign in to comment.