argoproj / argo-workflows

Workflow Engine for Kubernetes
https://argo-workflows.readthedocs.io/
Apache License 2.0
15.11k stars 3.21k forks source link

fix(ui): improve editor performance and fix Submit button. Fixes #13892 #13915

Open MasonM opened 3 days ago

MasonM commented 3 days ago

Fixes #13892

Motivation

The <ObjectEditor> component used by all the edit pages encapsulates the logic for serializing/deserializing the object being edited, but it's extremely inefficient. For example, if you're editing a WorkflowTemplate, every single keystroke will cause parse() to be called twice and stringify() to be called 4 times. For large documents, this serialization/deserialization overhead adds up quickly.

Additionally, the "Submit" button is sometimes incorrectly grayed out, e.g. after clicking the "Update" button. This is happening because useEditableObject() is using reference comparisons on the object being edited, since it doesn't have access to the serialized string version encapsulated by <ObjectEditor>.

Modifications

This decouples <ObjectEditor> from the serialization/deseralization logic and lifts the state involved up to the useEditableObject() hook, as discussed in https://github.com/argoproj/argo-workflows/pull/13593#discussion_r1781972661. Doing so eliminates unnecessary serialization/deseralization: now, if you're editing a WorkflowTemplate, each keystroke will only call parse() once and won't call stringify() at all. This also fixes issues with the Submit button not reflecting the current page state, since useEditableObject() now uses string comparisons instead of ref comparisons.

Also, I did some minor cleanup:

  1. Click on an object and verify "Submit" button isn't grayed out, but "Update" is
  2. Make an edit and verify "Submit" button is grayed out and "Update" button is no longer grayed out
  3. Click "Update" and verify "Submit" button is no longer grayed out, but "Update" is
  4. Verify I can create a new object and submit it Recording of the http://localhost:8080/workflow-templates page:

https://github.com/user-attachments/assets/c07c4aed-4b6c-4c49-a149-0a2aa4c4dad2

I also verified I can edit objects at http://localhost:8080/event-flow and http://localhost:8080/workflow-event-bindings