Skip to content

Commit

Permalink
add a parameter to query options to update the ref use to ensure Acce…
Browse files Browse the repository at this point in the history
…sstoken is valid and then use in queryFn of useQuery.

The ref was only update when the token change, and was not update when the selected bucket changes causing the query to be potentially called for the wrong bucket
  • Loading branch information
JeanMarcMilletScality committed Sep 3, 2024
1 parent 93a003a commit 94d5093
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/react/ui-elements/EmptyBucket/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const EmptyBucket = ({ bucketName }: EmptyBucketProps) => {
refetchOnWindowFocus: false,
refetchOnMount: true,
refetchOnReconnect: false,
additionalDepsToUpdateQueryFn: [bucketName],
},
(data) => createDeleteObjectsData(data.DeleteMarkers, data.Versions),
);
Expand Down Expand Up @@ -209,12 +210,12 @@ export const EmptyBucket = ({ bucketName }: EmptyBucketProps) => {
}
overlayStyle={{
width: '9rem',
display: isBucketEmpty ? 'none' : undefined,
display: isBucketEmpty ? undefined : 'none',
}}
>
<Button
icon={<Icon name="Eraser" />}
disabled={!isBucketEmpty}
disabled={isBucketEmpty}
variant="danger"
onClick={handleEmptyClick}
label={EMPTY_CONFIRMATION_MODAL_TITLE}
Expand Down
9 changes: 7 additions & 2 deletions src/react/utils/IAMhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const useAwsPaginatedEntities = <
ENTITY,
TError,
MARKER_TYPE
>,
> & { additionalDepsToUpdateQueryFn?: unknown[] },
getEntitiesFromResult: (data: API_RESPONSE) => ENTITY[],
preventNextPagesRetrieval = false,
): AWS_PAGINATED_ENTITIES<ENTITY> => {
Expand Down Expand Up @@ -96,7 +96,7 @@ export const useAwsPaginatedEntities = <
>();
useEffect(() => {
ref.current = reactQueryOptions?.queryFn;
}, [token]);
}, [token, ...(reactQueryOptions.additionalDepsToUpdateQueryFn || [])]);
//--------------------------------------------------------------------

const {
Expand All @@ -116,16 +116,19 @@ export const useAwsPaginatedEntities = <
return ref.current?.(ctx, ctx.pageParam);
},
});

const pageIndex = data?.pageParams?.length || 0;
const entities =
data &&
data.pages &&
data.pages.flatMap((page) => getEntitiesFromResult(page));

useMemo(() => {
if (pageIndex === 0 || (pageIndex === 1 && internalStatus === 'success')) {
setFirstPageStatus(internalStatus);
}
}, [internalStatus, pageIndex]);

useMemo(() => {
if (
internalStatus === 'idle' ||
Expand Down Expand Up @@ -165,11 +168,13 @@ export const useAwsPaginatedEntities = <
firstPageStatus,
} as AWS_PAGINATED_ENTITIES<ENTITY>;
};

type AccessKeyObject = {
accessKey: string;
createdOn: string;
status: string;
};

export const useAccessKeyOutdatedStatus = (
accessKeyObject: AccessKeyObject,
) => {
Expand Down

0 comments on commit 94d5093

Please sign in to comment.