Skip to content

Commit

Permalink
fix(ui): Fix editor. Fixes #5613 Fixes #5617 (#5620)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec authored and simster7 committed Apr 19, 2021
1 parent dafa983 commit 026c127
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const CronWorkflowCreator = ({onCreate, namespace}: {namespace: string; o
icon='plus'
onClick={() => {
services.cronWorkflows
.create(cronWorkflow, cronWorkflow.metadata.namespace)
.create(cronWorkflow, Utils.getNamespace(cronWorkflow.metadata.namespace))
.then(onCreate)
.catch(setError);
}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export const EventFlowPage = ({history, location, match}: RouteComponentProps<an
nodeGenresTitle={'Type'}
nodeGenres={genres}
nodeClassNamesTitle={'Status'}
nodeClassNames={{Pending: true, Ready: true, Running: true, Failed: true, Succeeded: true, Error: true}}
nodeClassNames={{'': true, 'Pending': true, 'Ready': true, 'Running': true, 'Failed': true, 'Succeeded': true, 'Error': true}}
iconShapes={{workflow: 'circle', collapsed: 'circle', conditions: 'circle'}}
horizontal={true}
selectedNode={selectedNode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const EventSourceCreator = ({onCreate, namespace}: {namespace: string; on
icon='plus'
onClick={() => {
services.eventSource
.create(eventSource, eventSource.metadata.namespace)
.create(eventSource, Utils.getNamespace(eventSource.metadata.namespace))
.then(onCreate)
.catch(setError);
}}>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/sensors/components/sensor-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const SensorCreator = ({namespace, onCreate}: {namespace: string; onCreat
icon='plus'
onClick={() => {
services.sensor
.create(sensor, sensor.metadata.namespace)
.create(sensor, Utils.getNamespace(sensor.metadata.namespace))
.then(onCreate)
.catch(setError);
}}>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/shared/components/filter-drop-down.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export const FilterDropDown = (props: FilterDropDownProps) => {
.filter(item => item.values)
.map((item, i) => (
<div key={i}>
<li className={classNames('top-bar__filter-item', {title: true})}>
<li key={i} className={classNames('top-bar__filter-item', {title: true})}>
<span>{item.title}</span>
</li>
{Object.entries(item.values)
.sort()
.map(([label, checked]) => (
<li className={classNames('top-bar__filter-item')}>
<li key={label} className={classNames('top-bar__filter-item')}>
<React.Fragment>
<Checkbox id={`filter__${label}`} checked={checked} onChange={v => item.onChange(label, v)} />
<label htmlFor={`filter__${label}`}>{label}</label>
Expand Down
49 changes: 27 additions & 22 deletions ui/src/app/shared/components/object-editor/object-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {PhaseIcon} from '../phase-icon';
import {ToggleButton} from '../toggle-button';

interface Props<T> {
type: string;
type?: string;
value: T;
buttons?: React.ReactNode;
onChange?: (value: T) => void;
Expand All @@ -26,6 +26,13 @@ export const ObjectEditor = <T extends any>({type, value, buttons, onChange}: Pr
useEffect(() => storage.setItem('lang', lang, defaultLang), [lang]);
useEffect(() => setText(stringify(value, lang)), [value]);
useEffect(() => setText(stringify(parse(text), lang)), [lang]);
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);
}
}, [text, lang]);

useEffect(() => {
if (type && lang === 'json') {
Expand Down Expand Up @@ -79,31 +86,29 @@ export const ObjectEditor = <T extends any>({type, value, buttons, onChange}: Pr
scrollBeyondLastLine: true
}}
onChange={v => {
try {
onChange(parse(v));
setError(null);
} catch (e) {
setError(e);
if (onChange) {
try {
onChange(parse(v));
setError(null);
} catch (e) {
setError(e);
}
}
}}
/>
</div>
<div style={{paddingTop: '1em'}}>
{error && (
<>
<PhaseIcon value='Error' /> {error.message}
</>
)}
</div>
<div>
{onChange && (
<>
<i className='fa fa-info-circle' />{' '}
{lang === 'json' ? <>Full auto-completion enabled.</> : <>Basic completion for YAML. Switch to JSON for full auto-completion.</>}
</>
)}{' '}
<a href='https://argoproj.github.io/argo-workflows/ide-setup/'>Learn how to get auto-completion in your IDE.</a>
</div>
{error && (
<div style={{paddingTop: '1em'}}>
<PhaseIcon value='Error' /> {error.message}
</div>
)}
{onChange && (
<div>
<i className='fa fa-info-circle' />{' '}
{lang === 'json' ? <>Full auto-completion enabled.</> : <>Basic completion for YAML. Switch to JSON for full auto-completion.</>}{' '}
<a href='https://argoproj.github.io/argo-workflows/ide-setup/'>Learn how to get auto-completion in your IDE.</a>
</div>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const WorkflowTemplateCreator = ({namespace, onCreate}: {namespace: strin
icon='plus'
onClick={() => {
services.workflowTemplate
.create(template, template.metadata.namespace)
.create(template, Utils.getNamespace(template.metadata.namespace))
.then(onCreate)
.catch(setError);
}}>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/workflows/components/workflow-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const WorkflowCreator = ({namespace, onCreate}: {namespace: string; onCre
icon='plus'
onClick={() => {
services.workflows
.create(workflow, workflow.metadata.namespace)
.create(workflow, Utils.getNamespace(workflow.metadata.namespace))
.then(onCreate)
.catch(setError);
}}>
Expand Down

0 comments on commit 026c127

Please sign in to comment.