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): improve editor performance and fix Submit button. Fixes #13892 #13915

Merged
merged 2 commits into from
Nov 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {UploadButton} from '../shared/components/upload-button';
import {exampleClusterWorkflowTemplate} from '../shared/examples';
import {ClusterWorkflowTemplate} from '../shared/models';
import {services} from '../shared/services';
import {ClusterWorkflowTemplateEditor} from './cluster-workflow-template-editor';
import {useEditableObject} from '../shared/use-editable-object';
import {WorkflowTemplateEditor} from '../workflow-templates/workflow-template-editor';

export function ClusterWorkflowTemplateCreator({onCreate}: {onCreate: (workflow: ClusterWorkflowTemplate) => void}) {
const [template, setTemplate] = useState<ClusterWorkflowTemplate>(exampleClusterWorkflowTemplate());
const {object: template, setObject: setTemplate, serialization, lang, setLang} = useEditableObject(exampleClusterWorkflowTemplate());
const [error, setError] = useState<Error>();
return (
<>
Expand All @@ -31,7 +32,7 @@ export function ClusterWorkflowTemplateCreator({onCreate}: {onCreate: (workflow:
</Button>
</div>
<ErrorNotice error={error} />
<ClusterWorkflowTemplateEditor template={template} onChange={setTemplate} onError={setError} />
<WorkflowTemplateEditor template={template} serialization={serialization} lang={lang} onLangChange={setLang} onChange={setTemplate} onError={setError} />
<div>
<ExampleManifests />.
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {services} from '../shared/services';
import {useCollectEvent} from '../shared/use-collect-event';
import {useEditableObject} from '../shared/use-editable-object';
import {useQueryParams} from '../shared/use-query-params';
import {WorkflowTemplateEditor} from '../workflow-templates/workflow-template-editor';
import {SubmitWorkflowPanel} from '../workflows/components/submit-workflow-panel';
import {WorkflowDetailsList} from '../workflows/components/workflow-details-list/workflow-details-list';
import {ClusterWorkflowTemplateEditor} from './cluster-workflow-template-editor';

import '../workflows/components/workflow-details/workflow-details.scss';

Expand All @@ -37,7 +37,7 @@ export function ClusterWorkflowTemplateDetails({history, location, match}: Route
const [columns, setColumns] = useState<models.Column[]>([]);

const [error, setError] = useState<Error>();
const [template, edited, setTemplate, resetTemplate] = useEditableObject<ClusterWorkflowTemplate>();
const {object: template, setObject: setTemplate, resetObject: resetTemplate, serialization, edited, lang, setLang} = useEditableObject<ClusterWorkflowTemplate>();

useEffect(
useQueryParams(history, p => {
Expand Down Expand Up @@ -138,7 +138,16 @@ export function ClusterWorkflowTemplateDetails({history, location, match}: Route
{!template ? (
<Loading />
) : (
<ClusterWorkflowTemplateEditor template={template} onChange={setTemplate} onError={setError} onTabSelected={setTab} selectedTabKey={tab} />
<WorkflowTemplateEditor
template={template}
serialization={serialization}
lang={lang}
onLangChange={setLang}
onChange={setTemplate}
onError={setError}
onTabSelected={setTab}
selectedTabKey={tab}
/>
)}
</>
{template && (
Expand Down

This file was deleted.

5 changes: 3 additions & 2 deletions ui/src/cron-workflows/cron-workflow-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {exampleCronWorkflow} from '../shared/examples';
import {CronWorkflow} from '../shared/models';
import * as nsUtils from '../shared/namespaces';
import {services} from '../shared/services';
import {useEditableObject} from '../shared/use-editable-object';
import {CronWorkflowEditor} from './cron-workflow-editor';

export function CronWorkflowCreator({onCreate, namespace}: {namespace: string; onCreate: (cronWorkflow: CronWorkflow) => void}) {
const [cronWorkflow, setCronWorkflow] = useState<CronWorkflow>(exampleCronWorkflow(nsUtils.getNamespaceWithDefault(namespace)));
const {object: cronWorkflow, setObject: setCronWorkflow, serialization, lang, setLang} = useEditableObject(exampleCronWorkflow(nsUtils.getNamespaceWithDefault(namespace)));
const [error, setError] = useState<Error>();
return (
<>
Expand All @@ -32,7 +33,7 @@ export function CronWorkflowCreator({onCreate, namespace}: {namespace: string; o
</Button>
</div>
<ErrorNotice error={error} />
<CronWorkflowEditor cronWorkflow={cronWorkflow} onChange={setCronWorkflow} onError={setError} />
<CronWorkflowEditor cronWorkflow={cronWorkflow} serialization={serialization} lang={lang} onLangChange={setLang} onChange={setCronWorkflow} onError={setError} />
<p>
<ExampleManifests />.
</p>
Expand Down
13 changes: 11 additions & 2 deletions ui/src/cron-workflows/cron-workflow-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function CronWorkflowDetails({match, location, history}: RouteComponentPr
const [workflows, setWorkflows] = useState<Workflow[]>([]);
const [columns, setColumns] = useState<models.Column[]>([]);

const [cronWorkflow, edited, setCronWorkflow, resetCronWorkflow] = useEditableObject<CronWorkflow>();
const {object: cronWorkflow, setObject: setCronWorkflow, resetObject: resetCronWorkflow, serialization, edited, lang, setLang} = useEditableObject<CronWorkflow>();
const [error, setError] = useState<Error>();

useEffect(
Expand Down Expand Up @@ -207,7 +207,16 @@ export function CronWorkflowDetails({match, location, history}: RouteComponentPr
{!cronWorkflow ? (
<Loading />
) : (
<CronWorkflowEditor cronWorkflow={cronWorkflow} onChange={setCronWorkflow} onError={setError} selectedTabKey={tab} onTabSelected={setTab} />
<CronWorkflowEditor
cronWorkflow={cronWorkflow}
serialization={serialization}
lang={lang}
onLangChange={setLang}
onChange={setCronWorkflow}
onError={setError}
selectedTabKey={tab}
onTabSelected={setTab}
/>
)}
<SlidingPanel isShown={!!sidePanel} onClose={() => setSidePanel(null)}>
{sidePanel === 'share' && <WidgetGallery namespace={namespace} label={'workflows.argoproj.io/cron-workflow=' + name} />}
Expand Down
22 changes: 19 additions & 3 deletions ui/src/cron-workflows/cron-workflow-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {LabelsAndAnnotationsEditor} from '../shared/components/editors/labels-an
import {MetadataEditor} from '../shared/components/editors/metadata-editor';
import {WorkflowParametersEditor} from '../shared/components/editors/workflow-parameters-editor';
import {ObjectEditor} from '../shared/components/object-editor';
import type {Lang} from '../shared/components/object-parser';
import {CronWorkflow} from '../shared/models';
import {CronWorkflowSpecEditor} from './cron-workflow-spec-editior';
import {CronWorkflowStatusViewer} from './cron-workflow-status-viewer';
Expand All @@ -14,10 +15,16 @@ export function CronWorkflowEditor({
onTabSelected,
onError,
onChange,
cronWorkflow
onLangChange,
cronWorkflow,
serialization,
lang
}: {
cronWorkflow: CronWorkflow;
onChange: (cronWorkflow: CronWorkflow) => void;
serialization: string;
lang: Lang;
onChange: (cronWorkflow: string | CronWorkflow) => void;
onLangChange: (lang: Lang) => void;
onError: (error: Error) => void;
onTabSelected?: (tab: string) => void;
selectedTabKey?: string;
Expand All @@ -41,7 +48,16 @@ export function CronWorkflowEditor({
{
key: 'manifest',
title: 'Manifest',
content: <ObjectEditor type='io.argoproj.workflow.v1alpha1.CronWorkflow' value={cronWorkflow} onChange={x => onChange({...x})} />
content: (
<ObjectEditor
type='io.argoproj.workflow.v1alpha1.CronWorkflow'
value={cronWorkflow}
text={serialization}
lang={lang}
onLangChange={onLangChange}
onChange={onChange}
/>
)
},
{
key: 'cron',
Expand Down
4 changes: 2 additions & 2 deletions ui/src/event-flow/event-flow-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {GraphPanel} from '../shared/components/graph/graph-panel';
import {Node} from '../shared/components/graph/types';
import {Links} from '../shared/components/links';
import {NamespaceFilter} from '../shared/components/namespace-filter';
import {ResourceEditor} from '../shared/components/resource-editor/resource-editor';
import {SerializingObjectEditor} from '../shared/components/object-editor';
import {ZeroState} from '../shared/components/zero-state';
import {Context} from '../shared/context';
import {Footnote} from '../shared/footnote';
Expand Down Expand Up @@ -317,7 +317,7 @@ export function EventFlowPage({history, location, match}: RouteComponentProps<an
{
title: 'SUMMARY',
key: 'summary',
content: <ResourceEditor kind={selected.kind} value={selected.value} />
content: <SerializingObjectEditor type={'io.argoproj.workflow.v1alpha1.' + selected.kind} value={selected.value} />
},
{
title: 'LOGS',
Expand Down
5 changes: 3 additions & 2 deletions ui/src/event-sources/event-source-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {exampleEventSource} from '../shared/examples';
import {EventSource} from '../shared/models';
import * as nsUtils from '../shared/namespaces';
import {services} from '../shared/services';
import {useEditableObject} from '../shared/use-editable-object';
import {EventSourceEditor} from './event-source-editor';

export function EventSourceCreator({onCreate, namespace}: {namespace: string; onCreate: (eventSource: EventSource) => void}) {
const [eventSource, setEventSource] = useState<EventSource>(exampleEventSource(nsUtils.getNamespaceWithDefault(namespace)));
const {object: eventSource, setObject: setEventSource, serialization, lang, setLang} = useEditableObject(exampleEventSource(nsUtils.getNamespaceWithDefault(namespace)));
const [error, setError] = useState<Error>();
return (
<>
Expand All @@ -31,7 +32,7 @@ export function EventSourceCreator({onCreate, namespace}: {namespace: string; on
</Button>
</div>
<ErrorNotice error={error} />
<EventSourceEditor eventSource={eventSource} onChange={setEventSource} onError={setError} />
<EventSourceEditor eventSource={eventSource} serialization={serialization} lang={lang} onChange={setEventSource} onLangChange={setLang} onError={setError} />
<p>
<a href='https://github.com/argoproj/argo-events/tree/stable/examples/event-sources'>
Example event sources <i className='fa fa-external-link-alt' />
Expand Down
13 changes: 11 additions & 2 deletions ui/src/event-sources/event-source-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function EventSourceDetails({history, location, match}: RouteComponentPro
);

const [error, setError] = useState<Error>();
const [eventSource, edited, setEventSource, resetEventSource] = useEditableObject<EventSource>();
const {object: eventSource, setObject: setEventSource, resetObject: resetEventSource, serialization, edited, lang, setLang} = useEditableObject<EventSource>();

const selected = (() => {
if (!selectedNode) {
Expand Down Expand Up @@ -139,7 +139,16 @@ export function EventSourceDetails({history, location, match}: RouteComponentPro
{!eventSource ? (
<Loading />
) : (
<EventSourceEditor eventSource={eventSource} onChange={setEventSource} onError={setError} onTabSelected={setTab} selectedTabKey={tab} />
<EventSourceEditor
eventSource={eventSource}
serialization={serialization}
lang={lang}
onChange={setEventSource}
onLangChange={setLang}
onError={setError}
onTabSelected={setTab}
selectedTabKey={tab}
/>
)}
</>
<SlidingPanel isShown={!!selected} onClose={() => setSelectedNode(null)}>
Expand Down
22 changes: 19 additions & 3 deletions ui/src/event-sources/event-source-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ import * as React from 'react';

import {MetadataEditor} from '../shared/components/editors/metadata-editor';
import {ObjectEditor} from '../shared/components/object-editor';
import type {Lang} from '../shared/components/object-parser';
import {EventSource} from '../shared/models';

export function EventSourceEditor({
onChange,
onLangChange,
onTabSelected,
selectedTabKey,
eventSource
eventSource,
serialization,
lang
}: {
eventSource: EventSource;
onChange: (template: EventSource) => void;
serialization: string;
lang: Lang;
onChange: (template: string | EventSource) => void;
onLangChange: (lang: Lang) => void;
onError: (error: Error) => void;
onTabSelected?: (tab: string) => void;
selectedTabKey?: string;
Expand All @@ -27,7 +34,16 @@ export function EventSourceEditor({
{
key: 'manifest',
title: 'Manifest',
content: <ObjectEditor type='io.argoproj.events.v1alpha1.EventSource' value={eventSource} onChange={x => onChange({...x})} />
content: (
<ObjectEditor
type='io.argoproj.events.v1alpha1.EventSource'
value={eventSource}
text={serialization}
lang={lang}
onLangChange={onLangChange}
onChange={onChange}
/>
)
},

{
Expand Down
5 changes: 3 additions & 2 deletions ui/src/sensors/sensor-creator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {exampleSensor} from '../shared/examples';
import {Sensor} from '../shared/models';
import * as nsUtils from '../shared/namespaces';
import {services} from '../shared/services';
import {useEditableObject} from '../shared/use-editable-object';
import {SensorEditor} from './sensor-editor';

export function SensorCreator({namespace, onCreate}: {namespace: string; onCreate: (sensor: Sensor) => void}) {
const [sensor, setSensor] = useState<Sensor>(exampleSensor(nsUtils.getNamespaceWithDefault(namespace)));
const {object: sensor, setObject: setSensor, serialization, lang, setLang} = useEditableObject(exampleSensor(nsUtils.getNamespaceWithDefault(namespace)));
const [error, setError] = useState<Error>();
return (
<>
Expand All @@ -31,7 +32,7 @@ export function SensorCreator({namespace, onCreate}: {namespace: string; onCreat
</Button>
</div>
<ErrorNotice error={error} />
<SensorEditor sensor={sensor} onChange={setSensor} onError={setError} />
<SensorEditor sensor={sensor} serialization={serialization} lang={lang} onChange={setSensor} onLangChange={setLang} onError={setError} />
<p>
<a href='https://github.com/argoproj/argo-events/tree/stable/examples/sensors'>
Example sensors <i className='fa fa-external-link-alt' />
Expand Down
17 changes: 15 additions & 2 deletions ui/src/sensors/sensor-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function SensorDetails({match, location, history}: RouteComponentProps<an
const [name] = useState(match.params.name);
const [tab, setTab] = useState<string>(queryParams.get('tab'));

const [sensor, edited, setSensor, resetSensor] = useEditableObject<Sensor>();
const {object: sensor, setObject: setSensor, resetObject: resetSensor, serialization, edited, lang, setLang} = useEditableObject<Sensor>();
const [selectedLogNode, setSelectedLogNode] = useState<Node>(queryParams.get('selectedLogNode'));
const [error, setError] = useState<Error>();

Expand Down Expand Up @@ -125,7 +125,20 @@ export function SensorDetails({match, location, history}: RouteComponentProps<an
}}>
<>
<ErrorNotice error={error} />
{!sensor ? <Loading /> : <SensorEditor sensor={sensor} onChange={setSensor} onError={setError} selectedTabKey={tab} onTabSelected={setTab} />}
{!sensor ? (
<Loading />
) : (
<SensorEditor
sensor={sensor}
serialization={serialization}
lang={lang}
onChange={setSensor}
onLangChange={setLang}
onError={setError}
selectedTabKey={tab}
onTabSelected={setTab}
/>
)}
</>
{!!selectedLogNode && (
<SensorSidePanel
Expand Down
Loading
Loading