@thoughtspot/visual-embed-sdk 1.24.0-dev → 1.24.0-preRender.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/package.json +2 -3
- package/cjs/src/embed/TsEmbed.d.ts +302 -0
- package/cjs/src/embed/TsEmbed.d.ts.map +1 -0
- package/cjs/src/embed/TsEmbed.js +851 -0
- package/cjs/src/embed/TsEmbed.js.map +1 -0
- package/cjs/src/embed/app.d.ts +4 -1
- package/cjs/src/embed/app.d.ts.map +1 -1
- package/cjs/src/embed/app.js +9 -2
- package/cjs/src/embed/app.js.map +1 -1
- package/cjs/src/embed/base.d.ts +2 -0
- package/cjs/src/embed/base.d.ts.map +1 -1
- package/cjs/src/embed/base.js +2 -0
- package/cjs/src/embed/base.js.map +1 -1
- package/cjs/src/embed/liveboard.d.ts +3 -2
- package/cjs/src/embed/liveboard.d.ts.map +1 -1
- package/cjs/src/embed/liveboard.js +6 -5
- package/cjs/src/embed/liveboard.js.map +1 -1
- package/cjs/src/embed/sage.d.ts +4 -1
- package/cjs/src/embed/sage.d.ts.map +1 -1
- package/cjs/src/embed/sage.js +9 -2
- package/cjs/src/embed/sage.js.map +1 -1
- package/cjs/src/embed/search-bar.d.ts +1 -0
- package/cjs/src/embed/search-bar.d.ts.map +1 -1
- package/cjs/src/embed/search-bar.js +1 -0
- package/cjs/src/embed/search-bar.js.map +1 -1
- package/cjs/src/embed/search.d.ts +5 -1
- package/cjs/src/embed/search.d.ts.map +1 -1
- package/cjs/src/embed/search.js +10 -2
- package/cjs/src/embed/search.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts +14 -7
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +94 -63
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +47 -0
- package/cjs/src/embed/ts-embed.spec.js.map +1 -1
- package/cjs/src/index.d.ts +3 -2
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/index.js +3 -1
- package/cjs/src/index.js.map +1 -1
- package/cjs/src/mixpanel-service.d.ts.map +1 -1
- package/cjs/src/mixpanel-service.js +2 -0
- package/cjs/src/mixpanel-service.js.map +1 -1
- package/cjs/src/mixpanel-service.spec.js +1 -0
- package/cjs/src/mixpanel-service.spec.js.map +1 -1
- package/cjs/src/react/index.d.ts +5 -1
- package/cjs/src/react/index.d.ts.map +1 -1
- package/cjs/src/react/index.js +8 -8
- package/cjs/src/react/index.js.map +1 -1
- package/cjs/src/types.d.ts +60 -19
- package/cjs/src/types.d.ts.map +1 -1
- package/cjs/src/types.js +7 -13
- package/cjs/src/types.js.map +1 -1
- package/cjs/src/utils/graphql/answerService/answer-queries.d.ts +5 -0
- package/cjs/src/utils/graphql/answerService/answer-queries.d.ts.map +1 -0
- package/cjs/src/utils/graphql/answerService/answer-queries.js +80 -0
- package/cjs/src/utils/graphql/answerService/answer-queries.js.map +1 -0
- package/cjs/src/utils/graphql/answerService/answerService.d.ts +61 -0
- package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -0
- package/cjs/src/utils/graphql/answerService/answerService.js +182 -0
- package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -0
- package/cjs/src/utils/graphql/answerService/answerService.spec.d.ts +2 -0
- package/cjs/src/utils/graphql/answerService/answerService.spec.d.ts.map +1 -0
- package/cjs/src/utils/graphql/answerService/answerService.spec.js +201 -0
- package/cjs/src/utils/graphql/answerService/answerService.spec.js.map +1 -0
- package/cjs/src/utils/graphql/graphql-request.d.ts +15 -0
- package/cjs/src/utils/graphql/graphql-request.d.ts.map +1 -0
- package/cjs/src/utils/graphql/graphql-request.js +40 -0
- package/cjs/src/utils/graphql/graphql-request.js.map +1 -0
- package/cjs/src/utils/graphql/sourceService.d.ts +8 -0
- package/cjs/src/utils/graphql/sourceService.d.ts.map +1 -0
- package/cjs/src/utils/graphql/sourceService.js +69 -0
- package/cjs/src/utils/graphql/sourceService.js.map +1 -0
- package/cjs/src/utils/graphql/sourceService.spec.d.ts +2 -0
- package/cjs/src/utils/graphql/sourceService.spec.d.ts.map +1 -0
- package/cjs/src/utils/graphql/sourceService.spec.js +12 -0
- package/cjs/src/utils/graphql/sourceService.spec.js.map +1 -0
- package/cjs/src/utils/processData.d.ts.map +1 -1
- package/cjs/src/utils/processData.js +7 -11
- package/cjs/src/utils/processData.js.map +1 -1
- package/cjs/src/utils/processData.spec.js +13 -17
- package/cjs/src/utils/processData.spec.js.map +1 -1
- package/cjs/src/utils.d.ts +6 -0
- package/cjs/src/utils.d.ts.map +1 -1
- package/cjs/src/utils.js +26 -1
- package/cjs/src/utils.js.map +1 -1
- package/dist/src/embed/app.d.ts +4 -1
- package/dist/src/embed/app.d.ts.map +1 -1
- package/dist/src/embed/base.d.ts +2 -0
- package/dist/src/embed/base.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts +3 -2
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/embed/sage.d.ts +4 -1
- package/dist/src/embed/sage.d.ts.map +1 -1
- package/dist/src/embed/search-bar.d.ts +1 -0
- package/dist/src/embed/search-bar.d.ts.map +1 -1
- package/dist/src/embed/search.d.ts +5 -1
- package/dist/src/embed/search.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +14 -7
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/mixpanel-service.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +5 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/types.d.ts +60 -19
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/graphql/answerService/answer-queries.d.ts +5 -0
- package/dist/src/utils/graphql/answerService/answer-queries.d.ts.map +1 -0
- package/dist/src/utils/graphql/answerService/answerService.d.ts +61 -0
- package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -0
- package/dist/src/utils/graphql/answerService/answerService.spec.d.ts +2 -0
- package/dist/src/utils/graphql/answerService/answerService.spec.d.ts.map +1 -0
- package/dist/src/utils/graphql/graphql-request.d.ts +15 -0
- package/dist/src/utils/graphql/graphql-request.d.ts.map +1 -0
- package/dist/src/utils/graphql/sourceService.d.ts +8 -0
- package/dist/src/utils/graphql/sourceService.d.ts.map +1 -0
- package/dist/src/utils/graphql/sourceService.spec.d.ts +2 -0
- package/dist/src/utils/graphql/sourceService.spec.d.ts.map +1 -0
- package/dist/src/utils/processData.d.ts.map +1 -1
- package/dist/src/utils.d.ts +6 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/tsembed-react.es.js +513 -150
- package/dist/tsembed-react.js +516 -149
- package/dist/tsembed.es.js +556 -146
- package/dist/tsembed.js +556 -145
- package/dist/visual-embed-sdk-react-full.d.ts +152 -33
- package/dist/visual-embed-sdk-react.d.ts +152 -33
- package/dist/visual-embed-sdk.d.ts +147 -32
- package/lib/package.json +2 -3
- package/lib/src/embed/TsEmbed.d.ts +302 -0
- package/lib/src/embed/TsEmbed.d.ts.map +1 -0
- package/lib/src/embed/TsEmbed.js +847 -0
- package/lib/src/embed/TsEmbed.js.map +1 -0
- package/lib/src/embed/app.d.ts +4 -1
- package/lib/src/embed/app.d.ts.map +1 -1
- package/lib/src/embed/app.js +9 -2
- package/lib/src/embed/app.js.map +1 -1
- package/lib/src/embed/base.d.ts +2 -0
- package/lib/src/embed/base.d.ts.map +1 -1
- package/lib/src/embed/base.js +2 -0
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts +3 -2
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +6 -5
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/sage.d.ts +4 -1
- package/lib/src/embed/sage.d.ts.map +1 -1
- package/lib/src/embed/sage.js +9 -2
- package/lib/src/embed/sage.js.map +1 -1
- package/lib/src/embed/search-bar.d.ts +1 -0
- package/lib/src/embed/search-bar.d.ts.map +1 -1
- package/lib/src/embed/search-bar.js +1 -0
- package/lib/src/embed/search-bar.js.map +1 -1
- package/lib/src/embed/search.d.ts +5 -1
- package/lib/src/embed/search.d.ts.map +1 -1
- package/lib/src/embed/search.js +10 -2
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +14 -7
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +94 -63
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +47 -0
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/index.d.ts +3 -2
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +2 -1
- package/lib/src/index.js.map +1 -1
- package/lib/src/mixpanel-service.d.ts.map +1 -1
- package/lib/src/mixpanel-service.js +2 -0
- package/lib/src/mixpanel-service.js.map +1 -1
- package/lib/src/mixpanel-service.spec.js +1 -0
- package/lib/src/mixpanel-service.spec.js.map +1 -1
- package/lib/src/react/index.d.ts +5 -1
- package/lib/src/react/index.d.ts.map +1 -1
- package/lib/src/react/index.js +7 -7
- package/lib/src/react/index.js.map +1 -1
- package/lib/src/types.d.ts +60 -19
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +6 -12
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/graphql/answerService/answer-queries.d.ts +5 -0
- package/lib/src/utils/graphql/answerService/answer-queries.d.ts.map +1 -0
- package/lib/src/utils/graphql/answerService/answer-queries.js +77 -0
- package/lib/src/utils/graphql/answerService/answer-queries.js.map +1 -0
- package/lib/src/utils/graphql/answerService/answerService.d.ts +61 -0
- package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -0
- package/lib/src/utils/graphql/answerService/answerService.js +177 -0
- package/lib/src/utils/graphql/answerService/answerService.js.map +1 -0
- package/lib/src/utils/graphql/answerService/answerService.spec.d.ts +2 -0
- package/lib/src/utils/graphql/answerService/answerService.spec.d.ts.map +1 -0
- package/lib/src/utils/graphql/answerService/answerService.spec.js +199 -0
- package/lib/src/utils/graphql/answerService/answerService.spec.js.map +1 -0
- package/lib/src/utils/graphql/graphql-request.d.ts +15 -0
- package/lib/src/utils/graphql/graphql-request.d.ts.map +1 -0
- package/lib/src/utils/graphql/graphql-request.js +36 -0
- package/lib/src/utils/graphql/graphql-request.js.map +1 -0
- package/lib/src/utils/graphql/sourceService.d.ts +8 -0
- package/lib/src/utils/graphql/sourceService.d.ts.map +1 -0
- package/lib/src/utils/graphql/sourceService.js +65 -0
- package/lib/src/utils/graphql/sourceService.js.map +1 -0
- package/lib/src/utils/graphql/sourceService.spec.d.ts +2 -0
- package/lib/src/utils/graphql/sourceService.spec.d.ts.map +1 -0
- package/lib/src/utils/graphql/sourceService.spec.js +10 -0
- package/lib/src/utils/graphql/sourceService.spec.js.map +1 -0
- package/lib/src/utils/processData.d.ts.map +1 -1
- package/lib/src/utils/processData.js +8 -12
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js +14 -18
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/utils.d.ts +6 -0
- package/lib/src/utils.d.ts.map +1 -1
- package/lib/src/utils.js +23 -0
- package/lib/src/utils.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +153 -33
- package/package.json +2 -3
- package/src/embed/app.ts +13 -6
- package/src/embed/base.ts +2 -0
- package/src/embed/liveboard.ts +7 -5
- package/src/embed/sage.ts +13 -2
- package/src/embed/search-bar.tsx +2 -0
- package/src/embed/search.ts +14 -2
- package/src/embed/ts-embed.spec.ts +49 -0
- package/src/embed/ts-embed.ts +116 -64
- package/src/index.ts +5 -0
- package/src/mixpanel-service.spec.ts +1 -0
- package/src/mixpanel-service.ts +1 -0
- package/src/react/index.tsx +50 -45
- package/src/types.ts +64 -21
- package/src/utils/graphql/answerService/answer-queries.ts +80 -0
- package/src/utils/graphql/answerService/answerService.spec.ts +231 -0
- package/src/utils/graphql/answerService/answerService.ts +234 -0
- package/src/utils/graphql/graphql-request.ts +45 -0
- package/src/utils/graphql/sourceService.spec.ts +10 -0
- package/src/utils/graphql/sourceService.ts +71 -0
- package/src/utils/processData.spec.ts +15 -25
- package/src/utils/processData.ts +13 -15
- package/src/utils.ts +24 -0
- package/src/utils/answerService.spec.ts +0 -41
- package/src/utils/answerService.ts +0 -63
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { getOperationNameFromQuery } from '../../utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param root0
|
|
6
|
+
* @param root0.query
|
|
7
|
+
* @param root0.variables
|
|
8
|
+
* @param root0.thoughtSpotHost
|
|
9
|
+
* @param root0.isCompositeQuery
|
|
10
|
+
*/
|
|
11
|
+
export async function graphqlQuery({
|
|
12
|
+
query,
|
|
13
|
+
variables,
|
|
14
|
+
thoughtSpotHost,
|
|
15
|
+
isCompositeQuery = false,
|
|
16
|
+
}: {
|
|
17
|
+
query: string,
|
|
18
|
+
variables: any,
|
|
19
|
+
thoughtSpotHost: string,
|
|
20
|
+
isCompositeQuery?: boolean
|
|
21
|
+
}) {
|
|
22
|
+
const operationName = getOperationNameFromQuery(query);
|
|
23
|
+
try {
|
|
24
|
+
const response = await fetch(`${thoughtSpotHost}/prism/?op=${operationName}`, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: {
|
|
27
|
+
'content-type': 'application/json;charset=UTF-8',
|
|
28
|
+
'x-requested-by': 'ThoughtSpot',
|
|
29
|
+
accept: '*/*',
|
|
30
|
+
'accept-language': 'en-us',
|
|
31
|
+
},
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
operationName,
|
|
34
|
+
query,
|
|
35
|
+
variables,
|
|
36
|
+
}),
|
|
37
|
+
credentials: 'include',
|
|
38
|
+
});
|
|
39
|
+
const result = await response.json();
|
|
40
|
+
const dataValues = Object.values(result.data);
|
|
41
|
+
return (isCompositeQuery) ? result.data : dataValues[0];
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import 'jest-fetch-mock';
|
|
2
|
+
import { getSourceDetail } from './sourceService';
|
|
3
|
+
|
|
4
|
+
describe('Source service tests', () => {
|
|
5
|
+
test('Should return source detail and cache it', async () => {
|
|
6
|
+
await getSourceDetail('https://tshost', 'id');
|
|
7
|
+
await getSourceDetail('https://tshost', 'id');
|
|
8
|
+
expect(fetchMock).toBeCalledTimes(1);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { graphqlQuery } from './graphql-request';
|
|
2
|
+
|
|
3
|
+
export const getSourceDetailQuery = `
|
|
4
|
+
query GetSourceDetail($ids: [GUID!]!) {
|
|
5
|
+
getSourceDetailById(ids: $ids, type: LOGICAL_TABLE) {
|
|
6
|
+
id
|
|
7
|
+
name
|
|
8
|
+
description
|
|
9
|
+
authorName
|
|
10
|
+
authorDisplayName
|
|
11
|
+
isExternal
|
|
12
|
+
type
|
|
13
|
+
created
|
|
14
|
+
modified
|
|
15
|
+
columns {
|
|
16
|
+
id
|
|
17
|
+
name
|
|
18
|
+
author
|
|
19
|
+
authorDisplayName
|
|
20
|
+
description
|
|
21
|
+
dataType
|
|
22
|
+
type
|
|
23
|
+
modified
|
|
24
|
+
ownerName
|
|
25
|
+
owner
|
|
26
|
+
dataRecency
|
|
27
|
+
sources {
|
|
28
|
+
tableId
|
|
29
|
+
tableName
|
|
30
|
+
columnId
|
|
31
|
+
columnName
|
|
32
|
+
__typename
|
|
33
|
+
}
|
|
34
|
+
synonyms
|
|
35
|
+
cohortAnswerId
|
|
36
|
+
__typename
|
|
37
|
+
}
|
|
38
|
+
relationships
|
|
39
|
+
destinationRelationships
|
|
40
|
+
dataSourceId
|
|
41
|
+
__typename
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
const sourceDetailCache = new Map<string, any>();
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param thoughtSpotHost
|
|
51
|
+
* @param sourceId
|
|
52
|
+
*/
|
|
53
|
+
export async function getSourceDetail(
|
|
54
|
+
thoughtSpotHost: string,
|
|
55
|
+
sourceId: string,
|
|
56
|
+
): Promise<any> {
|
|
57
|
+
if (sourceDetailCache.has(sourceId)) {
|
|
58
|
+
return sourceDetailCache.get(sourceId);
|
|
59
|
+
}
|
|
60
|
+
const details = await graphqlQuery({
|
|
61
|
+
query: getSourceDetailQuery,
|
|
62
|
+
variables: {
|
|
63
|
+
ids: [sourceId],
|
|
64
|
+
},
|
|
65
|
+
thoughtSpotHost,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const souceDetails = details[0];
|
|
69
|
+
sourceDetailCache.set(sourceId, souceDetails);
|
|
70
|
+
return souceDetails;
|
|
71
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as processDataInstance from './processData';
|
|
2
|
-
import * as answerServiceInstance from './answerService';
|
|
2
|
+
import * as answerServiceInstance from './graphql/answerService/answerService';
|
|
3
3
|
import * as auth from '../auth';
|
|
4
4
|
import * as base from '../embed/base';
|
|
5
|
-
import { EmbedEvent,
|
|
5
|
+
import { EmbedEvent, AuthType } from '../types';
|
|
6
6
|
|
|
7
7
|
describe('Unit test for process data', () => {
|
|
8
8
|
beforeAll(() => {
|
|
@@ -16,26 +16,12 @@ describe('Unit test for process data', () => {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
const thoughtSpotHost = 'http://localhost';
|
|
19
|
-
test('processDataInstance, when operation is GetChartWithData', () => {
|
|
20
|
-
const answerService = {};
|
|
21
|
-
const processChartData = {
|
|
22
|
-
answerService,
|
|
23
|
-
data: {
|
|
24
|
-
session: 'session',
|
|
25
|
-
query: 'query',
|
|
26
|
-
operation: OperationType.GetChartWithData,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
jest.spyOn(answerServiceInstance, 'getAnswerServiceInstance').mockReturnValue(
|
|
30
|
-
answerService,
|
|
31
|
-
);
|
|
32
|
-
expect(
|
|
33
|
-
processDataInstance.processCustomAction(processChartData, thoughtSpotHost),
|
|
34
|
-
).toStrictEqual(processChartData);
|
|
35
|
-
});
|
|
36
19
|
|
|
37
20
|
test('ProcessData, when Action is CustomAction', async () => {
|
|
38
|
-
const processedData = {
|
|
21
|
+
const processedData = {
|
|
22
|
+
type: EmbedEvent.CustomAction,
|
|
23
|
+
data: {},
|
|
24
|
+
};
|
|
39
25
|
jest.spyOn(processDataInstance, 'processCustomAction').mockImplementation(async () => ({}));
|
|
40
26
|
expect(
|
|
41
27
|
processDataInstance.processEventData(
|
|
@@ -44,16 +30,20 @@ describe('Unit test for process data', () => {
|
|
|
44
30
|
thoughtSpotHost,
|
|
45
31
|
null,
|
|
46
32
|
),
|
|
47
|
-
).
|
|
33
|
+
).toEqual(expect.objectContaining({
|
|
34
|
+
...processedData,
|
|
35
|
+
answerService: {
|
|
36
|
+
answer: undefined,
|
|
37
|
+
selectedPoints: undefined,
|
|
38
|
+
session: undefined,
|
|
39
|
+
thoughtSpotHost: 'http://localhost',
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
48
42
|
});
|
|
49
43
|
|
|
50
44
|
test('ProcessData, when Action is non CustomAction', () => {
|
|
51
45
|
const processedData = { type: EmbedEvent.Data };
|
|
52
46
|
jest.spyOn(processDataInstance, 'processCustomAction').mockImplementation(async () => ({}));
|
|
53
|
-
jest.spyOn(
|
|
54
|
-
answerServiceInstance,
|
|
55
|
-
'getAnswerServiceInstance',
|
|
56
|
-
).mockImplementation(async () => ({}));
|
|
57
47
|
processDataInstance.processEventData(EmbedEvent.Data, processedData, thoughtSpotHost, null);
|
|
58
48
|
expect(processDataInstance.processCustomAction).not.toBeCalled();
|
|
59
49
|
});
|
package/src/utils/processData.ts
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
notifyLogout,
|
|
7
7
|
} from '../embed/base';
|
|
8
8
|
import { AuthFailureType, initSession } from '../auth';
|
|
9
|
-
import { AuthType,
|
|
10
|
-
import {
|
|
9
|
+
import { AuthType, CustomActionPayload, EmbedEvent } from '../types';
|
|
10
|
+
import { AnswerService } from './graphql/answerService/answerService';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
*
|
|
@@ -15,19 +15,17 @@ import { getAnswerServiceInstance } from './answerService';
|
|
|
15
15
|
* @param thoughtSpotHost
|
|
16
16
|
*/
|
|
17
17
|
export function processCustomAction(e: any, thoughtSpotHost: string) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return e;
|
|
18
|
+
const { session, embedAnswerData, contextMenuPoints } = e.data as CustomActionPayload;
|
|
19
|
+
const answerService = new AnswerService(
|
|
20
|
+
session,
|
|
21
|
+
embedAnswerData,
|
|
22
|
+
thoughtSpotHost,
|
|
23
|
+
contextMenuPoints?.selectedPoints,
|
|
24
|
+
);
|
|
25
|
+
return {
|
|
26
|
+
...e,
|
|
27
|
+
answerService,
|
|
28
|
+
};
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
/**
|
package/src/utils.ts
CHANGED
|
@@ -249,6 +249,30 @@ export function getDOMNode(domSelector: DOMSelector): HTMLElement {
|
|
|
249
249
|
|
|
250
250
|
export const deepMerge = (target: any, source: any) => merge(target, source);
|
|
251
251
|
|
|
252
|
+
export const getOperationNameFromQuery = (query: string) => {
|
|
253
|
+
const regex = /(?:query|mutation)\s+(\w+)/;
|
|
254
|
+
const matches = query.match(regex);
|
|
255
|
+
return matches?.[1];
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
*
|
|
260
|
+
* @param obj
|
|
261
|
+
*/
|
|
262
|
+
export function removeTypename(obj: any) {
|
|
263
|
+
if (!obj || typeof obj !== 'object') return obj;
|
|
264
|
+
|
|
265
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
266
|
+
for (const key in obj) {
|
|
267
|
+
if (key === '__typename') {
|
|
268
|
+
delete obj[key];
|
|
269
|
+
} else if (typeof obj[key] === 'object') {
|
|
270
|
+
removeTypename(obj[key]);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return obj;
|
|
274
|
+
}
|
|
275
|
+
|
|
252
276
|
export const setStyleProperties = (
|
|
253
277
|
element: HTMLElement,
|
|
254
278
|
styleProperties: Partial<CSSStyleDeclaration>,
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getAnswerServiceInstance } from './answerService';
|
|
2
|
-
|
|
3
|
-
describe('Unit test for getAnswerServiceInstance', () => {
|
|
4
|
-
const session = {
|
|
5
|
-
sessionId: '',
|
|
6
|
-
genNo: 2,
|
|
7
|
-
acSession: { sessionId: '', genNo: 1 },
|
|
8
|
-
};
|
|
9
|
-
const query = '';
|
|
10
|
-
const thoughtSpotHost = 'http://10.79.135.124:3000';
|
|
11
|
-
|
|
12
|
-
test('fetchData, when api giving answer data', async () => {
|
|
13
|
-
const mockAnswerResponse = { data: {} };
|
|
14
|
-
global.fetch = jest.fn(() => Promise.resolve({
|
|
15
|
-
json: () => mockAnswerResponse,
|
|
16
|
-
}));
|
|
17
|
-
const answerService = getAnswerServiceInstance(
|
|
18
|
-
session,
|
|
19
|
-
query,
|
|
20
|
-
'GetTableWithHeadlineData',
|
|
21
|
-
thoughtSpotHost,
|
|
22
|
-
);
|
|
23
|
-
const answerData = await answerService.fetchData(1, 500);
|
|
24
|
-
expect(answerData).toStrictEqual(mockAnswerResponse.data);
|
|
25
|
-
expect(answerData).not.toBeInstanceOf(Error);
|
|
26
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('fetchData, when api giving error', async () => {
|
|
30
|
-
global.fetch = jest.fn(() => Promise.reject(new Error('failure')));
|
|
31
|
-
const answerService = getAnswerServiceInstance(
|
|
32
|
-
session,
|
|
33
|
-
query,
|
|
34
|
-
'GetChartWithData',
|
|
35
|
-
thoughtSpotHost,
|
|
36
|
-
);
|
|
37
|
-
const answerData = await answerService.fetchData(1, 500);
|
|
38
|
-
expect(answerData).toBeInstanceOf(Error);
|
|
39
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { SessionInterface, OperationType } from '../types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param session
|
|
6
|
-
* @param query
|
|
7
|
-
* @param operation
|
|
8
|
-
* @param thoughtSpotHost
|
|
9
|
-
*/
|
|
10
|
-
export function getAnswerServiceInstance(
|
|
11
|
-
session: SessionInterface,
|
|
12
|
-
query: string,
|
|
13
|
-
operation: string,
|
|
14
|
-
thoughtSpotHost: string,
|
|
15
|
-
): any {
|
|
16
|
-
let variable: any;
|
|
17
|
-
|
|
18
|
-
const fetchQuery = async (variables: any) => {
|
|
19
|
-
try {
|
|
20
|
-
const response = await fetch(`${thoughtSpotHost}/prism/?op=${operation}`, {
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers: {
|
|
23
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
24
|
-
'x-requested-by': 'ThoughtSpot',
|
|
25
|
-
accept: '*/*',
|
|
26
|
-
'accept-language': 'en-us',
|
|
27
|
-
},
|
|
28
|
-
body: JSON.stringify({
|
|
29
|
-
operationName: operation,
|
|
30
|
-
query,
|
|
31
|
-
variables,
|
|
32
|
-
}),
|
|
33
|
-
credentials: 'include',
|
|
34
|
-
});
|
|
35
|
-
const result = await response.json();
|
|
36
|
-
return result.data;
|
|
37
|
-
} catch (error) {
|
|
38
|
-
return error;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const fetchData = (offset: number, batchSize: number) => {
|
|
43
|
-
if (operation === OperationType.GetChartWithData) {
|
|
44
|
-
variable = { batchSize, offset: offset * batchSize };
|
|
45
|
-
} else {
|
|
46
|
-
variable = {
|
|
47
|
-
dataPaginationParams: {
|
|
48
|
-
isClientPaginated: true,
|
|
49
|
-
offset: offset * batchSize,
|
|
50
|
-
size: batchSize,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return fetchQuery({
|
|
55
|
-
session,
|
|
56
|
-
...variable,
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
fetchData,
|
|
62
|
-
};
|
|
63
|
-
}
|