Skip to content

Commit b72e969

Browse files
author
Cerebro
committed
feat(locations): combine metrics and bucket-list loading/error states
Part of the implementation plan from scality/agent-task#343.
1 parent 25ddfc6 commit b72e969

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/react/next-architecture/domain/business/locations.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,12 @@ export const useListLocationsForCurrentAccount = ({
160160
enabled: !!accountCannonicalId,
161161
});
162162

163-
const {
164-
bucketList,
165-
status: bucketListStatus,
166-
isFetching: bucketListIsFetching,
167-
error: bucketListError,
168-
} = useBucketList();
163+
const { bucketList, status: bucketListStatus } = useBucketList();
169164

170165
const bucketLocationIds = useMemo(() => {
166+
if (bucketListStatus === 'error') {
167+
return [];
168+
}
171169
return Array.from(
172170
new Set(
173171
bucketList
@@ -176,7 +174,7 @@ export const useListLocationsForCurrentAccount = ({
176174
.filter((location): location is string => !!location),
177175
),
178176
);
179-
}, [bucketList, accountCannonicalId]);
177+
}, [bucketList, accountCannonicalId, bucketListStatus]);
180178

181179
if (account === undefined) {
182180
return {
@@ -215,6 +213,14 @@ export const useListLocationsForCurrentAccount = ({
215213
};
216214
}
217215

216+
if (bucketListStatus === 'idle' || bucketListStatus === 'loading') {
217+
return {
218+
locations: {
219+
status: 'loading',
220+
},
221+
};
222+
}
223+
218224
const accountLocationsKey = Array.from(new Set([...Object.keys(accountLocationData), ...bucketLocationIds]));
219225

220226
if (allLocations.locations.status !== 'success') {

0 commit comments

Comments
 (0)