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, + })); }, }); };