Skip to content
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

fix: exlcude batch jobs from global loading #2711

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions webapp/src/component/MandatoryDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ import { useIsFetching, useIsMutating } from 'react-query';
import { useConfig, useUser } from 'tg.globalContext/helpers';
import { usePosthog } from 'tg.hooks/usePosthog';
import { usePlausible } from 'tg.hooks/plausible';
import { CustomOptions } from 'tg.service/http/useQueryApi';

export const MandatoryDataProvider = (props: any) => {
const userData = useUser();
const config = useConfig();

const isFetching = useGlobalContext((c) => c.initialData.isFetching);

const isGloballyFetching = useIsFetching();
const isGloballyMutating = useIsMutating();
const isGloballyFetching = useIsFetching({
predicate(query) {
return !(query.options as unknown as CustomOptions).noGlobalLoading;
},
});
const isGloballyMutating = useIsMutating({
predicate(query) {
return !(query.options as unknown as CustomOptions).noGlobalLoading;
},
});

useGlobalLoading(
Boolean(isGloballyFetching || isGloballyMutating || isFetching)
Expand Down
1 change: 1 addition & 0 deletions webapp/src/hooks/ProjectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const [ProjectContext, useProjectActions, useProjectContext] =
path: { projectId: id },
options: {
enabled: Boolean(connected),
noGlobalLoading: true,
staleTime: 0,
onSuccess(data) {
setBatchOperations(
Expand Down
13 changes: 10 additions & 3 deletions webapp/src/service/http/useQueryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {
ResponseContent,
} from './ApiSchemaHttpService';

export type CustomOptions = {
noGlobalLoading?: boolean;
};

export type QueryProps<
Url extends keyof Paths,
Method extends keyof Paths[Url],
Expand All @@ -30,7 +34,8 @@ export type QueryProps<
url: Url;
method: Method;
fetchOptions?: RequestOptions;
options?: UseQueryOptions<ResponseContent<Url, Method, Paths>, ApiError>;
options?: UseQueryOptions<ResponseContent<Url, Method, Paths>, ApiError> &
CustomOptions;
} & RequestParamsType<Url, Method, Paths>;

export type InfiniteQueryProps<
Expand All @@ -44,7 +49,8 @@ export type InfiniteQueryProps<
options?: UseInfiniteQueryOptions<
ResponseContent<Url, Method, Paths>,
ApiError
>;
> &
CustomOptions;
} & RequestParamsType<Url, Method, Paths>;

type Split<S extends string> = S extends `${infer Prefix}/${infer Rest}`
Expand All @@ -66,7 +72,8 @@ export type MutationProps<
ResponseContent<Url, Method, Paths>,
ApiError,
RequestParamsType<Url, Method, Paths>
>;
> &
CustomOptions;
invalidatePrefix?: Prefix | Prefix[];
};

Expand Down
Loading