Skip to content

Commit

Permalink
Remove dead code from browser queries (#2066)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored May 25, 2023
1 parent e68b91d commit fb0eda1
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 116 deletions.
8 changes: 1 addition & 7 deletions packages/toolpad-app/src/appDom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,13 +1081,7 @@ function createRenderTreeNode(node: AppDomNode): RenderTreeNode | null {
}

if (isQuery(node) || isMutation(node)) {
// This is hacky, should we delegate this check to the datasources?
const isBrowserSideRestQuery: boolean =
(node.attributes.dataSource?.value === 'rest' ||
node.attributes.dataSource?.value === 'function') &&
!!(node.attributes.query.value as any).browser;

if (node.attributes.query.value && !isBrowserSideRestQuery) {
if (node.attributes.query.value) {
node = setNamespacedProp(node, 'attributes', 'query', null);
}
}
Expand Down
15 changes: 1 addition & 14 deletions packages/toolpad-app/src/runtime/useDataQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { GridRowsProp } from '@mui/x-data-grid-pro';
import * as React from 'react';
import { useQuery, UseQueryOptions } from '@tanstack/react-query';
import { CanvasHooksContext } from './CanvasHooksContext';
import dataSources from '../toolpadDataSources/runtime';
import * as appDom from '../appDom';

interface ExecDataSourceQueryParams {
Expand Down Expand Up @@ -72,10 +71,6 @@ export function useDataQuery(
const { savedNodes } = React.useContext(CanvasHooksContext);
const queryName = node.name;
const pageName = page.name;
const query = node.attributes.query?.value;
const dataSourceId = node.attributes.dataSource?.value;

const dataSource = dataSourceId ? dataSources[dataSourceId] : null;

// These are only used by the editor to invalidate caches whenever the query changes during editing
const nodeHash: number | undefined = savedNodes ? savedNodes[node.id] : undefined;
Expand All @@ -89,15 +84,7 @@ export function useDataQuery(
refetch,
} = useQuery(
[nodeHash, pageName, queryName, params],
({ signal }) => {
const fetchFromServer = () => execDataSourceQuery({ signal, pageName, queryName, params });

if (query && dataSource?.exec) {
return dataSource?.exec(query, params, fetchFromServer);
}

return fetchFromServer();
},
({ signal }) => execDataSourceQuery({ signal, pageName, queryName, params }),
{
...options,
enabled: isNodeAvailableOnServer && enabled,
Expand Down
13 changes: 2 additions & 11 deletions packages/toolpad-app/src/toolpadDataSources/rest/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { Controller, useForm } from 'react-hook-form';
import { TabContext, TabList } from '@mui/lab';
import { useBrowserJsRuntime } from '@mui/toolpad-core/jsBrowserRuntime';
import { useServerJsRuntime } from '@mui/toolpad-core/jsServerRuntime';
import {
ClientDataSource,
ConnectionEditorProps,
ExecFetchFn,
QueryEditorProps,
} from '../../types';
import { ClientDataSource, ConnectionEditorProps, QueryEditorProps } from '../../types';
import {
FetchPrivateQuery,
FetchQuery,
Expand Down Expand Up @@ -56,7 +51,6 @@ import Devtools from '../../components/Devtools';
import { createHarLog, mergeHar } from '../../utils/har';
import QueryInputPanel from '../QueryInputPanel';
import useFetchPrivate from '../useFetchPrivate';
import { clientExec } from './runtime';
import QueryPreview from '../QueryPreview';
import { usePrivateQuery } from '../context';

Expand Down Expand Up @@ -384,15 +378,12 @@ function QueryEditor({
const [activeTab, setActiveTab] = React.useState('urlQuery');

const fetchPrivate = useFetchPrivate<FetchPrivateQuery, FetchResult>();
const fetchServerPreview = React.useCallback(
const fetchPreview = React.useCallback(
(query: FetchQuery, params: Record<string, string>) =>
fetchPrivate({ kind: 'debugExec', query, params }),
[fetchPrivate],
);

const fetchPreview: ExecFetchFn<FetchQuery, FetchResult> = (query, params) =>
clientExec(query, params, fetchServerPreview);

const [previewHar, setPreviewHar] = React.useState(() => createHarLog());
const {
preview,
Expand Down
74 changes: 0 additions & 74 deletions packages/toolpad-app/src/toolpadDataSources/rest/runtime.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions packages/toolpad-app/src/toolpadDataSources/runtime.tsx

This file was deleted.

0 comments on commit fb0eda1

Please sign in to comment.