forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): add more query wrappers (apache#570)
* feat: add more api wrappers * test: add unit tests
- Loading branch information
1 parent
ed99565
commit d277421
Showing
14 changed files
with
163 additions
and
27 deletions.
There are no files selected for viewing
7 changes: 3 additions & 4 deletions
7
...ary_superset_ui/superset-ui/packages/superset-ui-query/src/api/legacy/fetchExploreJson.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...uperset_ui/superset-ui/packages/superset-ui-query/src/api/legacy/getDatasourceMetadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SupersetClient, RequestConfig } from '@superset-ui/connection'; | ||
import { Datasource } from '../../types/Datasource'; | ||
import { BaseParams } from '../types'; | ||
|
||
export interface Params extends BaseParams { | ||
datasourceKey: string; | ||
} | ||
|
||
export default function getDatasourceMetadata({ | ||
client = SupersetClient, | ||
datasourceKey, | ||
requestConfig, | ||
}: Params) { | ||
return client | ||
.get({ | ||
endpoint: `/superset/fetch_datasource_metadata?datasourceKey=${datasourceKey}`, | ||
...requestConfig, | ||
} as RequestConfig) | ||
.then(response => response.json as Datasource); | ||
} |
26 changes: 26 additions & 0 deletions
26
...emporary_superset_ui/superset-ui/packages/superset-ui-query/src/api/legacy/getFormData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SupersetClient, RequestConfig } from '@superset-ui/connection'; | ||
import { BaseParams } from '../types'; | ||
import { QueryFormData } from '../../types/QueryFormData'; | ||
|
||
export interface Params extends BaseParams { | ||
sliceId: number; | ||
overrideFormData?: Partial<QueryFormData>; | ||
} | ||
|
||
export default function getFormData({ | ||
client = SupersetClient, | ||
sliceId, | ||
overrideFormData, | ||
requestConfig, | ||
}: Params) { | ||
const promise = client | ||
.get({ | ||
endpoint: `/api/v1/form_data/?slice_id=${sliceId}`, | ||
...requestConfig, | ||
} as RequestConfig) | ||
.then(response => response.json as QueryFormData); | ||
|
||
return overrideFormData | ||
? promise.then(formData => ({ ...formData, ...overrideFormData })) | ||
: promise; | ||
} |
3 changes: 3 additions & 0 deletions
3
...tend/temporary_superset_ui/superset-ui/packages/superset-ui-query/src/api/legacy/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as fetchExploreJson } from './fetchExploreJson'; | ||
export { default as getFormData } from './getFormData'; | ||
export { default as getDatasourceMetadata } from './getDatasourceMetadata'; |
10 changes: 10 additions & 0 deletions
10
...et-frontend/temporary_superset_ui/superset-ui/packages/superset-ui-query/src/api/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { | ||
RequestConfig, | ||
SupersetClientInterface, | ||
SupersetClientClass, | ||
} from '@superset-ui/connection'; | ||
|
||
export interface BaseParams { | ||
client?: SupersetClientInterface | SupersetClientClass; | ||
requestConfig?: Partial<RequestConfig>; | ||
} |
2 changes: 2 additions & 0 deletions
2
...frontend/temporary_superset_ui/superset-ui/packages/superset-ui-query/src/api/v1/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as postChartData } from './postChartData'; |
7 changes: 3 additions & 4 deletions
7
.../temporary_superset_ui/superset-ui/packages/superset-ui-query/src/api/v1/postChartData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...mporary_superset_ui/superset-ui/packages/superset-ui-query/test/api/fixtures/constants.ts
This file was deleted.
Oops, something went wrong.
11 changes: 3 additions & 8 deletions
11
...perset_ui/superset-ui/packages/superset-ui-query/test/api/legacy/fetchExploreJson.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...t_ui/superset-ui/packages/superset-ui-query/test/api/legacy/getDatasourceMetadata.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fetchMock from 'fetch-mock'; | ||
import setupClientForTest from '../setupClientForTest'; | ||
import { getDatasourceMetadata } from '../../../src/api/legacy'; | ||
|
||
describe('getFormData()', () => { | ||
beforeAll(setupClientForTest); | ||
|
||
afterEach(fetchMock.restore); | ||
|
||
it('returns datasource metadata for given datasource key', () => { | ||
const mockData = { | ||
field1: 'abc', | ||
field2: 'def', | ||
}; | ||
|
||
fetchMock.get('glob:*/superset/fetch_datasource_metadata?datasourceKey=1__table', mockData); | ||
|
||
return expect( | ||
getDatasourceMetadata({ | ||
datasourceKey: '1__table', | ||
}), | ||
).resolves.toEqual(mockData); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
...ry_superset_ui/superset-ui/packages/superset-ui-query/test/api/legacy/getFormData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import fetchMock from 'fetch-mock'; | ||
import setupClientForTest from '../setupClientForTest'; | ||
import { getFormData } from '../../../src/api/legacy'; | ||
|
||
describe('getFormData()', () => { | ||
beforeAll(setupClientForTest); | ||
|
||
afterEach(fetchMock.restore); | ||
|
||
const mockData = { | ||
datasource: '1__table', | ||
viz_type: 'sankey', | ||
slice_id: 1, | ||
url_params: {}, | ||
granularity_sqla: null, | ||
time_grain_sqla: 'P1D', | ||
time_range: 'Last week', | ||
groupby: ['source', 'target'], | ||
metric: 'sum__value', | ||
adhoc_filters: [], | ||
row_limit: 1000, | ||
}; | ||
|
||
it('returns formData for given slice id', () => { | ||
fetchMock.get(`glob:*/api/v1/form_data/?slice_id=1`, mockData); | ||
|
||
return expect( | ||
getFormData({ | ||
sliceId: 1, | ||
}), | ||
).resolves.toEqual(mockData); | ||
}); | ||
|
||
it('overrides formData when overrideFormData is specified', () => { | ||
fetchMock.get(`glob:*/api/v1/form_data/?slice_id=1`, mockData); | ||
|
||
return expect( | ||
getFormData({ | ||
sliceId: 1, | ||
overrideFormData: { | ||
metric: 'avg__value', | ||
}, | ||
}), | ||
).resolves.toEqual({ | ||
...mockData, | ||
metric: 'avg__value', | ||
}); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
...mporary_superset_ui/superset-ui/packages/superset-ui-query/test/api/setupClientForTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import fetchMock from 'fetch-mock'; | ||
import { SupersetClient } from '@superset-ui/connection'; | ||
|
||
const LOGIN_GLOB = 'glob:*superset/csrf_token/*'; | ||
|
||
export default function setupClientForTest() { | ||
fetchMock.get(LOGIN_GLOB, { csrf_token: '1234' }); | ||
SupersetClient.reset(); | ||
SupersetClient.configure().init(); | ||
} |
12 changes: 4 additions & 8 deletions
12
...rary_superset_ui/superset-ui/packages/superset-ui-query/test/api/v1/postChartData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters