Skip to content

Commit

Permalink
fix: 🪟🐛 Fix instance admin hook (#12584)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes committed May 23, 2024
1 parent c2f6dc1 commit e6ff96c
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions airbyte-webapp/src/core/api/hooks/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,19 @@ let currentIsInstanceAdminEnabled = false;

export const useIsInstanceAdminEnabled = () => {
const showInstanceAdminWarning = useFeature(FeatureItem.ShowAdminWarningInWorkspace); // we only want to use the "viewonly" mode if we in an env that shows the banner (ie: for now, cloud only)
return useSuspenseQuery([SCOPE_INSTANCE, "isInstanceAdminEnabled"], () => currentIsInstanceAdminEnabled, {
initialData: showInstanceAdminWarning ? currentIsInstanceAdminEnabled : true,
cacheTime: Infinity,
});
return useSuspenseQuery(
[SCOPE_INSTANCE, "isInstanceAdminEnabled"],
async () => (showInstanceAdminWarning ? currentIsInstanceAdminEnabled : true),
{
cacheTime: Infinity,
}
);
};

export const useSetIsInstanceAdminEnabled = () => {
const queryClient = useQueryClient();
return (isEnabled: boolean) => {
/*
react-query docs for setQueryData say
> If the query is not utilized by a query hook in the default cacheTime of 5 minutes,
> the query will be garbage collected.
unclear if the actually uses the default vs the cacheTime of Infinity used by the query, so
just in case we'll track the current value and return it from the query function if its called again
*/
currentIsInstanceAdminEnabled = isEnabled;
queryClient.setQueryData([SCOPE_INSTANCE, "isInstanceAdminEnabled"], isEnabled);
queryClient.invalidateQueries([SCOPE_INSTANCE, "isInstanceAdminEnabled"]);
};
};

0 comments on commit e6ff96c

Please sign in to comment.