Skip to content

Commit 9e3b29d

Browse files
committed
fix: use existing endpoints
1 parent adc597a commit 9e3b29d

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

src/store/reducers/overview/overview.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
import type {Timeout} from '../../../types/api/query';
12
import {api} from '../api';
23

34
export const overviewApi = api.injectEndpoints({
45
endpoints: (build) => ({
56
getOverview: build.query({
6-
queryFn: async ({paths, database}: {paths: string[]; database: string}, {signal}) => {
7+
queryFn: async (
8+
{
9+
paths,
10+
database,
11+
timeout,
12+
concurrentId,
13+
}: {paths: string[]; database: string; timeout?: Timeout; concurrentId?: string},
14+
{signal},
15+
) => {
716
try {
817
const [data, ...additionalData] = await Promise.all(
918
paths.map((p) =>
1019
window.api.getDescribe(
1120
{
1221
path: p,
1322
database,
23+
timeout,
1424
},
15-
{signal},
25+
{signal, concurrentId},
1626
),
1727
),
1828
);

src/store/reducers/tableSchemaData.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,52 @@ import type {EPathType} from '../../types/api/schema';
88
import {isQueryErrorResponse} from '../../utils/query';
99

1010
import {api} from './api';
11-
import {createViewSchemaQuery} from './viewSchema/viewSchema';
11+
import {overviewApi} from './overview/overview';
12+
import {viewSchemaApi} from './viewSchema/viewSchema';
1213

1314
export interface GetTableSchemaDataParams {
1415
path: string;
1516
tenantName: string;
1617
type: EPathType;
1718
}
1819

19-
const tableSchemaDataConcurrentId = 'getTableSchemaData';
20-
2120
const TABLE_SCHEMA_TIMEOUT = 1000;
2221

22+
const getTableSchemaDataConcurrentId = 'getTableSchemaData';
23+
2324
export const tableSchemeDataApi = api.injectEndpoints({
2425
endpoints: (build) => ({
2526
getTableSchemaData: build.mutation<SchemaData[], GetTableSchemaDataParams>({
26-
queryFn: async ({path, tenantName, type}, {signal}) => {
27+
queryFn: async ({path, tenantName, type}, {dispatch}) => {
2728
try {
28-
const schemaData = await window.api.getDescribe(
29-
{
30-
path,
29+
const schemaData = await dispatch(
30+
overviewApi.endpoints.getOverview.initiate({
31+
paths: [path],
3132
database: tenantName,
3233
timeout: TABLE_SCHEMA_TIMEOUT,
33-
},
34-
{signal, concurrentId: tableSchemaDataConcurrentId + 'describe'},
34+
concurrentId: getTableSchemaDataConcurrentId + 'getOverview',
35+
}),
3536
);
3637

3738
if (isViewType(type)) {
38-
const response = await window.api.sendQuery(
39-
{
40-
query: createViewSchemaQuery(path),
39+
const response = await dispatch(
40+
viewSchemaApi.endpoints.getViewSchema.initiate({
4141
database: tenantName,
42-
action: 'execute-scan',
42+
path,
4343
timeout: TABLE_SCHEMA_TIMEOUT,
44-
},
45-
{
46-
withRetries: true,
47-
concurrentId: tableSchemaDataConcurrentId + 'query',
48-
},
44+
concurrentId: getTableSchemaDataConcurrentId + 'getViewSchema',
45+
}),
4946
);
5047

5148
if (isQueryErrorResponse(response)) {
5249
return {error: response};
5350
}
5451

55-
const viewColumnsData = {data: response?.result?.[0]?.columns || []};
56-
const result = prepareViewSchema(viewColumnsData.data);
52+
const result = prepareViewSchema(response.data);
5753
return {data: result};
5854
}
5955

60-
const result = prepareSchemaData(type, schemaData);
56+
const result = prepareSchemaData(type, schemaData.data?.data);
6157

6258
return {data: result};
6359
} catch (error) {

src/store/reducers/viewSchema/viewSchema.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {Timeout} from '../../../types/api/query';
12
import {isQueryErrorResponse} from '../../../utils/query';
23
import {api} from '../api';
34

@@ -8,15 +9,26 @@ export function createViewSchemaQuery(path: string) {
89
export const viewSchemaApi = api.injectEndpoints({
910
endpoints: (build) => ({
1011
getViewSchema: build.query({
11-
queryFn: async ({database, path}: {database: string; path: string}) => {
12+
queryFn: async ({
13+
database,
14+
path,
15+
timeout,
16+
concurrentId,
17+
}: {
18+
database: string;
19+
path: string;
20+
timeout?: Timeout;
21+
concurrentId?: string;
22+
}) => {
1223
try {
1324
const response = await window.api.sendQuery(
1425
{
1526
query: createViewSchemaQuery(path),
1627
database,
1728
action: 'execute-scan',
29+
timeout,
1830
},
19-
{withRetries: true},
31+
{withRetries: true, concurrentId},
2032
);
2133

2234
if (isQueryErrorResponse(response)) {

0 commit comments

Comments
 (0)