From dcf380b298a38bc3e46125f3914045787bd7b74e Mon Sep 17 00:00:00 2001 From: Banks Nussman <115251059+bnussman-akamai@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:02:29 -0500 Subject: [PATCH] refactor: Use Query Key Factor for Object ACL and Fix Incorrect api-v4 type (#11369) * use query key factory * add changesets --------- Co-authored-by: Banks Nussman --- .../pr-11369-fixed-1733335872885.md | 5 +++ packages/api-v4/src/object-storage/objects.ts | 2 +- .../pr-11369-tech-stories-1733335919284.md | 5 +++ .../src/queries/object-storage/queries.ts | 37 ++++++++++++++----- 4 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 packages/api-v4/.changeset/pr-11369-fixed-1733335872885.md create mode 100644 packages/manager/.changeset/pr-11369-tech-stories-1733335919284.md diff --git a/packages/api-v4/.changeset/pr-11369-fixed-1733335872885.md b/packages/api-v4/.changeset/pr-11369-fixed-1733335872885.md new file mode 100644 index 00000000000..59e71de5fa1 --- /dev/null +++ b/packages/api-v4/.changeset/pr-11369-fixed-1733335872885.md @@ -0,0 +1,5 @@ +--- +"@linode/api-v4": Fixed +--- + +Incorrect return type of `updateObjectACL` ([#11369](https://github.com/linode/manager/pull/11369)) diff --git a/packages/api-v4/src/object-storage/objects.ts b/packages/api-v4/src/object-storage/objects.ts index 892b79ddb7f..7cb8f718dcc 100644 --- a/packages/api-v4/src/object-storage/objects.ts +++ b/packages/api-v4/src/object-storage/objects.ts @@ -64,7 +64,7 @@ export const updateObjectACL = ( name: string, acl: Omit ) => - Request( + Request<{}>( setMethod('PUT'), setURL( `${API_ROOT}/object-storage/buckets/${encodeURIComponent( diff --git a/packages/manager/.changeset/pr-11369-tech-stories-1733335919284.md b/packages/manager/.changeset/pr-11369-tech-stories-1733335919284.md new file mode 100644 index 00000000000..2a71def960b --- /dev/null +++ b/packages/manager/.changeset/pr-11369-tech-stories-1733335919284.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tech Stories +--- + +Update `useObjectAccess` to use a query key factory ([#11369](https://github.com/linode/manager/pull/11369)) diff --git a/packages/manager/src/queries/object-storage/queries.ts b/packages/manager/src/queries/object-storage/queries.ts index 4b552df609e..a5aee4fcd4c 100644 --- a/packages/manager/src/queries/object-storage/queries.ts +++ b/packages/manager/src/queries/object-storage/queries.ts @@ -17,6 +17,7 @@ import { import { createQueryKeys } from '@lukemorales/query-key-factory'; import { keepPreviousData, + queryOptions, useInfiniteQuery, useMutation, useQuery, @@ -76,6 +77,17 @@ export const objectStorageQueries = createQueryKeys('object-storage', { queryKey: null, }, objects: { + contextQueries: { + acl: (name: string) => ({ + queryFn: () => + getObjectACL({ + bucket: bucketName, + clusterId: clusterOrRegion, + params: { name }, + }), + queryKey: [name], + }), + }, // This is a placeholder queryFn and QueryKey. View the `useObjectBucketObjectsInfiniteQuery` implementation for details. queryFn: null, queryKey: null, @@ -209,8 +221,9 @@ export const useObjectAccess = ( ) => useQuery({ enabled: queryEnabled, - queryFn: () => getObjectACL({ bucket, clusterId, params }), - queryKey: [bucket, clusterId, params.name], + ...objectStorageQueries + .bucket(clusterId, bucket) + ._ctx.objects._ctx.acl(params.name), }); export const useUpdateBucketAccessMutation = ( @@ -241,16 +254,20 @@ export const useUpdateObjectAccessMutation = ( name: string ) => { const queryClient = useQueryClient(); + + const options = queryOptions( + objectStorageQueries + .bucket(clusterId, bucketName) + ._ctx.objects._ctx.acl(name) + ); + return useMutation<{}, APIError[], ACLType>({ mutationFn: (data) => updateObjectACL(clusterId, bucketName, name, data), - onSuccess: (_, acl) => { - queryClient.setQueryData( - [bucketName, clusterId, name], - (oldData) => ({ - acl, - acl_xml: oldData?.acl_xml ?? null, - }) - ); + onSuccess(_, acl) { + queryClient.setQueryData(options.queryKey, (oldData) => ({ + acl, + acl_xml: oldData?.acl_xml ?? null, + })); }, }); };