chore: remove fetch explore json (#24669)

This commit is contained in:
John Bodley 2023-07-13 09:18:15 -07:00 committed by GitHub
parent 146b5c839c
commit a3db5844f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 131 deletions

View File

@ -1,49 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { SupersetClient, Method, Endpoint } from '../../../connection';
import { QueryFormData } from '../../types/QueryFormData';
import { LegacyChartDataResponse } from './types';
import { BaseParams } from '../types';
export interface Params extends BaseParams {
method?: Method;
endpoint?: Endpoint;
formData: QueryFormData;
}
export default async function fetchExploreJson({
client = SupersetClient,
method = 'POST',
requestConfig,
endpoint = '/superset/explore_json/',
formData,
}: Params) {
const { json } = await client.request({
...requestConfig,
method,
endpoint,
searchParams:
method === 'GET'
? new URLSearchParams({ form_data: JSON.stringify(formData) })
: undefined,
postPayload: method === 'POST' ? { form_data: formData } : undefined,
});
return json as LegacyChartDataResponse;
}

View File

@ -17,7 +17,6 @@
* under the License.
*/
export { default as fetchExploreJson } from './fetchExploreJson';
export { default as getFormData } from './getFormData';
export { default as getDatasourceMetadata } from './getDatasourceMetadata';

View File

@ -1,81 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import fetchMock from 'fetch-mock';
import { fetchExploreJson } from '../../../../src/query/api/legacy';
import setupClientForTest from '../setupClientForTest';
describe('fetchExploreJson()', () => {
beforeAll(setupClientForTest);
afterEach(fetchMock.restore);
it('returns a promise of LegacyChartDataResponse', () => {
fetchMock.post('glob:*/superset/explore_json/', {
field1: 'abc',
field2: 'def',
});
return expect(
fetchExploreJson({
formData: {
granularity: 'minute',
viz_type: 'word_cloud',
datasource: '1__table',
},
}),
).resolves.toEqual({
field1: 'abc',
field2: 'def',
});
});
it('uses GET when specified', async () => {
expect.assertions(4);
const mockUrl = 'glob:*/superset/explore_json/*';
fetchMock.get(mockUrl, {
field1: 'abc',
field2: 'def',
});
const result = await fetchExploreJson({
method: 'GET',
formData: {
granularity: 'minute',
viz_type: 'word_cloud',
datasource: '1__table',
},
});
expect(result).toEqual({
field1: 'abc',
field2: 'def',
});
const mockCalls = fetchMock.calls(mockUrl);
expect(mockCalls).toHaveLength(1);
expect(mockCalls[0][0]).toEqual(
'http://localhost/superset/explore_json/?form_data=%7B%22granularity%22%3A%22minute%22%2C%22viz_type%22%3A%22word_cloud%22%2C%22datasource%22%3A%221__table%22%7D',
);
expect(mockCalls[0][1]).toEqual(
expect.objectContaining({
method: 'GET',
body: undefined,
}),
);
});
});