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

Update usePrivateQuery options to follow useQuery options #654

Merged
merged 2 commits into from
Jul 12, 2022
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
16 changes: 7 additions & 9 deletions packages/toolpad-app/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,17 @@ function createFetcher(endpoint: string, type: 'query' | 'mutation'): MethodsOfG
);
}

export interface UseQueryFnOptions<F extends (...args: any[]) => any>
extends Omit<
UseQueryOptions<Awaited<ReturnType<F>>, unknown, Awaited<ReturnType<F>>, any[]>,
'queryKey' | 'queryFn' | 'enabled'
> {}

interface UseQueryFn<M extends MethodsGroup> {
<K extends keyof M & string>(
name: K,
params: Parameters<M[K]> | null,
options?: Omit<
UseQueryOptions<
Awaited<ReturnType<M[K]>>,
unknown,
Awaited<ReturnType<M[K]>>,
[K, Parameters<M[K]> | null]
>,
'queryKey' | 'queryFn' | 'enabled'
>,
options?: UseQueryFnOptions<M[K]>,
): UseQueryResult<Awaited<ReturnType<M[K]>>>;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-app/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function readConfig(): ServerConfig & typeof sharedConfig {
databaseUrl: process.env.TOOLPAD_DATABASE_URL,
googleSheetsClientId: process.env.TOOLPAD_DATASOURCE_GOOGLESHEETS_CLIENT_ID,
googleSheetsClientSecret: process.env.TOOLPAD_DATASOURCE_GOOGLESHEETS_CLIENT_SECRET,
externalUrl: process.env.TOOLPAD_EXTERNAL_URL,
externalUrl: process.env.TOOLPAD_EXTERNAL_URL || `http://localhost:${process.env.PORT || 3000}`,
encryptionKeys,
};
}
Expand Down
6 changes: 3 additions & 3 deletions packages/toolpad-app/src/toolpadDataSources/context.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UseQueryResult } from 'react-query';
import { NodeId } from '@mui/toolpad-core';
import { createProvidedContext } from '../utils/react';
import client from '../api';
import client, { UseQueryFnOptions } from '../api';

export interface ConnectionContext {
appId: string;
Expand All @@ -15,12 +15,12 @@ export { useConnectionContext, ConnectionContextProvider };

export function usePrivateQuery<Q = unknown, R = unknown>(
query: Q | null,
retry?: boolean | number,
options?: UseQueryFnOptions<any>,
): UseQueryResult<R> {
const { appId, connectionId } = useConnectionContext();
return client.useQuery(
'dataSourceFetchPrivate',
query == null ? null : [appId, connectionId, query],
{ retry: retry ?? 3 },
options,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function ConnectionParamsInput({
{
type: GoogleSheetsPrivateQueryType.CONNECTION_STATUS,
},
false,
{ retry: false },
);
return (
<Stack direction="column" gap={1}>
Expand Down