Skip to content

chore(ui): centralize react-query cache updates in per-resource mutation hooks #30634

Open

Description

@blakepettersson

Summary

Add ui/src/app/shared/mutations.ts with per-resource useMutation hooks, next to the queryOptions factories in shared/queries.ts, so each mutation owns its cache update.

Follow-up to #30338, raised in review of #30544.

Motivation

Pages migrated to react-query call services.<resource>.<mutation>() and then update the cache themselves with invalidateQueries or setQueryData. That pair is repeated at every call site, and more pages bring more copies. When a call site leaves out the cache update, or doesn't await it, the page keeps showing data from before the change.

Proposal

  • One hook per resource (useProjectMutations(name), useClusterMutations(), useGpgKeyMutations()), wrapping useMutation, with the cache update in onSuccess.
  • onSuccess returns the invalidation promise, so mutateAsync resolves after active queries have refetched.
  • Error handling stays at the call site, keeping the existing per-action notifications.
  • Use isPending instead of hand-rolled "updating" state.
  • Move the pages already migrated (project details, clusters list/details, GnuPG keys) onto the hooks. Later migrations, starting with repositories and certificates, use them from the start.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttriage/pendingThis issue needs further triage to be correctly classified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions