Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

feat(chart): adjust chartclient to point to new endpoints #551

Merged
merged 5 commits into from
May 30, 2020
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
9 changes: 4 additions & 5 deletions packages/superset-ui-chart/src/clients/ChartClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
SupersetClient,
SupersetClientInterface,
RequestConfig,
Json,
SupersetClientClass,
} from '@superset-ui/connection';
import { QueryFormData, Datasource } from '@superset-ui/query';
Expand Down Expand Up @@ -52,11 +51,10 @@ export default class ChartClient {
if ('sliceId' in input) {
const promise = this.client
.get({
endpoint: `/api/v1/formData/?slice_id=${input.sliceId}`,
endpoint: `/api/v1/form_data/?slice_id=${input.sliceId}`,
...options,
} as RequestConfig)
.then(response => response.json as Json)
.then(json => json.form_data as QueryFormData);
.then(response => response.json as QueryFormData);

/*
* If formData is also specified, override API result
Expand Down Expand Up @@ -88,7 +86,8 @@ export default class ChartClient {

return this.client
.post({
endpoint: useLegacyApi ? '/superset/explore_json/' : '/api/v1/query/',
headers: { 'Content-Type': 'application/json' },
endpoint: useLegacyApi ? '/superset/explore_json/' : '/api/v1/chart/data',
postPayload: {
[useLegacyApi ? 'form_data' : 'query_context']: buildQuery(formData),
},
Expand Down
39 changes: 13 additions & 26 deletions packages/superset-ui-chart/test/clients/ChartClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../../src';
import { SliceIdAndOrFormData } from '../../src/clients/ChartClient';
import { LOGIN_GLOB } from '../fixtures/constants';
import { sankeyFormData } from '../fixtures/formData';

describe('ChartClient', () => {
let chartClient: ChartClient;
Expand Down Expand Up @@ -40,25 +41,12 @@ describe('ChartClient', () => {
describe('.loadFormData({ sliceId, formData }, options)', () => {
const sliceId = 123;
it('fetches formData if given only sliceId', () => {
fetchMock.get(`glob:*/api/v1/formData/?slice_id=${sliceId}`, {
form_data: {
granularity: 'minute',
viz_type: 'line',
},
});
fetchMock.get(`glob:*/api/v1/form_data/?slice_id=${sliceId}`, sankeyFormData);

return expect(chartClient.loadFormData({ sliceId })).resolves.toEqual({
granularity: 'minute',
viz_type: 'line',
});
return expect(chartClient.loadFormData({ sliceId })).resolves.toEqual(sankeyFormData);
});
it('fetches formData from sliceId and merges with specify formData if both fields are specified', () => {
fetchMock.get(`glob:*/api/v1/formData/?slice_id=${sliceId}`, {
form_data: {
granularity: 'minute',
viz_type: 'line',
},
});
fetchMock.get(`glob:*/api/v1/form_data/?slice_id=${sliceId}`, sankeyFormData);

return expect(
chartClient.loadFormData({
Expand All @@ -69,6 +57,7 @@ describe('ChartClient', () => {
},
}),
).resolves.toEqual({
...sankeyFormData,
granularity: 'second',
viz_type: 'bar',
});
Expand Down Expand Up @@ -103,7 +92,7 @@ describe('ChartClient', () => {
getChartBuildQueryRegistry().registerValue('word_cloud', (formData: QueryFormData) =>
buildQueryContext(formData),
);
fetchMock.post('glob:*/api/v1/query/', {
fetchMock.post('glob:*/api/v1/chart/data', {
field1: 'abc',
field2: 'def',
});
Expand Down Expand Up @@ -139,7 +128,7 @@ describe('ChartClient', () => {
}),
);

fetchMock.post('glob:*/api/v1/query/', () =>
fetchMock.post('glob:*/api/v1/chart/data', () =>
Promise.reject(new Error('Unexpected all to v1 API')),
);

Expand Down Expand Up @@ -219,21 +208,19 @@ describe('ChartClient', () => {
describe('.loadChartData({ sliceId, formData })', () => {
const sliceId = 10120;
it('loadAllDataNecessaryForAChart', () => {
fetchMock.get(`glob:*/api/v1/formData/?slice_id=${sliceId}`, {
form_data: {
granularity: 'minute',
viz_type: 'line',
datasource: '1__table',
color: 'living-coral',
},
fetchMock.get(`glob:*/api/v1/form_data/?slice_id=${sliceId}`, {
granularity: 'minute',
viz_type: 'line',
datasource: '1__table',
color: 'living-coral',
});

fetchMock.get('glob:*/superset/fetch_datasource_metadata?datasourceKey=1__table', {
name: 'transactions',
schema: 'staging',
});

fetchMock.post('glob:*/api/v1/query/', {
fetchMock.post('glob:*/api/v1/chart/data', {
lorem: 'ipsum',
dolor: 'sit',
amet: true,
Expand Down