Skip to content

[dashboard] don't invalidate useOrganizations on update of user settings #19198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions components/dashboard/src/data/organizations/orgs-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* See License.AGPL.txt in the project root for license information.
*/

import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useCallback } from "react";
import { useLocation } from "react-router";
Expand All @@ -15,19 +14,20 @@ import { Organization } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";

export function useOrganizationsInvalidator() {
const user = useCurrentUser();

const queryClient = useQueryClient();
return useCallback(() => {
console.log("Invalidating orgs... " + JSON.stringify(getQueryKey(user)));
queryClient.invalidateQueries(getQueryKey(user));
}, [user, queryClient]);
console.log("Invalidating orgs... " + JSON.stringify(getQueryKey(user?.id)));
queryClient.invalidateQueries(getQueryKey(user?.id));
}, [user?.id, queryClient]);
}

export function useOrganizations() {
const user = useCurrentUser();
const query = useQuery<Organization[], Error>(
getQueryKey(user),
getQueryKey(user?.id),
async () => {
console.log("Fetching orgs... " + JSON.stringify(getQueryKey(user)));
console.log("Fetching orgs... " + JSON.stringify(getQueryKey(user?.id)));
if (!user) {
console.log("useOrganizations with empty user");
return [];
Expand All @@ -47,8 +47,8 @@ export function useOrganizations() {
return query;
}

function getQueryKey(user?: User) {
return noPersistence(["organizations", user?.id]);
function getQueryKey(userId?: string) {
return noPersistence(["organizations", userId]);
}

// Custom hook to return the current org if one is selected
Expand Down