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

Simplify loading state and avoid races on start/stopping of instances #645

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

edlerd
Copy link
Collaborator

@edlerd edlerd commented Feb 13, 2024

Done

  • Simplify loading state and avoid races on start/stopping of instances

QA

  1. Run the LXD-UI:
    • On the demo server via the link posted by @webteam-app below. This is only available for PRs created by collaborators of the repo. Ask @lorumic or @edlerd for access.
    • With a local copy of this branch, run as described here.
  2. Perform the following QA steps:
    • manually start/stop a bunch of instances quickly after one another (not necessarily bulk actions) to ensure no instance is left in starting/stopping state. This was the broken behaviour before.

@webteam-app
Copy link

Demo starting at https://lxd-ui-645.demos.haus

const [instanceStates, setInstanceStates] = useState(
new Map<string, LoadingTypes>(),
);
const instanceStates = new Map<string, LoadingTypes>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does context trigger re-renders if we remove state here? i.e. does changes in the Map object trigger re-renders in children components subscribed to this context?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, this wasn't working properly when going to detail page / list page and back while a state change is in progress. Switched to a different approach just now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah nice, by using the callback for setState calls you are guaranteed to use the correct previous state, nice! 👍

Signed-off-by: David Edler <david.edler@canonical.com>
@mas-who
Copy link
Contributor

mas-who commented Feb 13, 2024

LGTM 👍

@edlerd edlerd merged commit 27196ec into canonical:main Feb 13, 2024
8 checks passed
@edlerd edlerd deleted the fix-loading-states branch February 13, 2024 14:56
github-actions bot pushed a commit that referenced this pull request Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants