Skip to content

Commit

Permalink
Remove externalUrl from REST datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed Oct 5, 2023
1 parent 6210e87 commit 92f3367
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
12 changes: 6 additions & 6 deletions packages/toolpad-app/src/toolpadDataSources/rest/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
ResponseType,
IntrospectionResult,
} from './types';
import { getAuthenticationHeaders, getDefaultUrl, parseBaseUrl } from './shared';
import { getAuthenticationHeaders, parseBaseUrl } from './shared';
import BindableEditor, {
RenderControlParams,
} from '../../toolpad/AppEditor/PageEditor/BindableEditor';
Expand All @@ -46,14 +46,13 @@ import BodyEditor from './BodyEditor';
import TabPanel from '../../components/TabPanel';
import JsonView from '../../components/JsonView';
import useQueryPreview from '../useQueryPreview';
import TransformInput from '../TranformInput';
import TransformInput from '../TransformInput';
import Devtools from '../../components/Devtools';
import { createHarLog, mergeHar } from '../../utils/har';
import QueryInputPanel from '../QueryInputPanel';
import useFetchPrivate from '../useFetchPrivate';
import QueryPreview from '../QueryPreview';
import { usePrivateQuery } from '../context';
import config from '../../config';

const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'];

Expand Down Expand Up @@ -257,8 +256,7 @@ function QueryEditor({
const connectionParams = isBrowserSide ? null : rawConnectionParams;
const baseUrl = isBrowserSide ? null : connectionParams?.baseUrl ?? null;
// input.attributes.query.url will be reset when it's empty
const urlValue: BindableAttrValue<string> =
input.attributes.query.url ?? getDefaultUrl(config, connectionParams);
const urlValue: BindableAttrValue<string> | undefined = input.attributes.query.url;

const introspection = usePrivateQuery<FetchPrivateQuery, IntrospectionResult>(
{
Expand Down Expand Up @@ -437,7 +435,7 @@ function QueryEditor({
label="url"
propType={{ type: 'string' }}
renderControl={(props) => <UrlControl baseUrl={baseUrl} {...props} />}
value={urlValue}
value={urlValue || ''}
onChange={handleUrlChange}
/>
</Box>
Expand Down Expand Up @@ -564,7 +562,9 @@ function QueryEditor({
}

function getInitialQueryValue(): FetchQuery {
const url = new URL('/static/movies.json', window.location.href).href;
return {
url,
method: 'GET',
headers: [],
browser: false,
Expand Down
8 changes: 6 additions & 2 deletions packages/toolpad-app/src/toolpadDataSources/rest/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from './types';
import { Maybe } from '../../utils/types';
import applyTransform from '../applyTransform';
import { HTTP_NO_BODY, getAuthenticationHeaders, getDefaultUrl, parseBaseUrl } from './shared';
import { HTTP_NO_BODY, getAuthenticationHeaders, parseBaseUrl } from './shared';
import type { IToolpadProject } from '../server';

async function loadEnvFile(project: IToolpadProject) {
Expand Down Expand Up @@ -148,7 +148,11 @@ async function execBase(
parameters: params,
};

const urlvalue = fetchQuery.url || getDefaultUrl(project.getRuntimeConfig(), connection);
const urlvalue = fetchQuery.url;

if (!urlvalue) {
throw new Error(`Missing url`);
}

const resolvedUrl = resolveBindable(jsRuntime, urlvalue, queryScope);
const resolvedSearchParams = resolveBindableEntries(
Expand Down
15 changes: 1 addition & 14 deletions packages/toolpad-app/src/toolpadDataSources/rest/shared.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { BindableAttrValue } from '@mui/toolpad-core';
import { ensureSuffix } from '@mui/toolpad-utils/strings';
import { Maybe } from '../../utils/types';
import { Authentication, RestConnectionParams } from './types';
import type { RuntimeConfig } from '../../config';
import { Authentication } from './types';

export const HTTP_NO_BODY = new Set(['GET', 'HEAD']);

Expand Down Expand Up @@ -35,14 +33,3 @@ export function parseBaseUrl(baseUrl: string): URL {
parsedBase.hash = '';
return parsedBase;
}

export function getDefaultUrl(
config: RuntimeConfig,
connection?: RestConnectionParams | null,
): BindableAttrValue<string> {
const baseUrl = connection?.baseUrl;

return baseUrl
? ''
: new URL('/static/movies.json', config.externalUrl || window.location.href).href;
}

0 comments on commit 92f3367

Please sign in to comment.