@thoughtspot/ts-chart-sdk 0.0.1-alpha.0
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/dist/ts-chart-sdk.d.ts +312 -0
- package/lib/dist/ts-chart-sdk.d.ts +312 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/main/custom-chart-context.d.ts +38 -0
- package/lib/main/custom-chart-context.d.ts.map +1 -0
- package/lib/main/custom-chart-context.js +176 -0
- package/lib/main/custom-chart-context.js.map +1 -0
- package/lib/main/custom-chart-context.spec.d.ts +2 -0
- package/lib/main/custom-chart-context.spec.d.ts.map +1 -0
- package/lib/main/custom-chart-context.spec.js +315 -0
- package/lib/main/custom-chart-context.spec.js.map +1 -0
- package/lib/main/post-message-event-bridge.d.ts +6 -0
- package/lib/main/post-message-event-bridge.d.ts.map +1 -0
- package/lib/main/post-message-event-bridge.js +41 -0
- package/lib/main/post-message-event-bridge.js.map +1 -0
- package/lib/main/post-message-event-bridge.spec.d.ts +2 -0
- package/lib/main/post-message-event-bridge.spec.d.ts.map +1 -0
- package/lib/main/post-message-event-bridge.spec.js +117 -0
- package/lib/main/post-message-event-bridge.spec.js.map +1 -0
- package/lib/test/test-utils.d.ts +7 -0
- package/lib/test/test-utils.d.ts.map +1 -0
- package/lib/test/test-utils.js +11 -0
- package/lib/test/test-utils.js.map +1 -0
- package/lib/types/answer-column.types.d.ts +69 -0
- package/lib/types/answer-column.types.d.ts.map +1 -0
- package/lib/types/answer-column.types.js +56 -0
- package/lib/types/answer-column.types.js.map +1 -0
- package/lib/types/chart-to-ts-event.types.d.ts +48 -0
- package/lib/types/chart-to-ts-event.types.d.ts.map +1 -0
- package/lib/types/chart-to-ts-event.types.js +16 -0
- package/lib/types/chart-to-ts-event.types.js.map +1 -0
- package/lib/types/common.types.d.ts +51 -0
- package/lib/types/common.types.d.ts.map +1 -0
- package/lib/types/common.types.js +2 -0
- package/lib/types/common.types.js.map +1 -0
- package/lib/types/configurator.types.d.ts +15 -0
- package/lib/types/configurator.types.d.ts.map +1 -0
- package/lib/types/configurator.types.js +2 -0
- package/lib/types/configurator.types.js.map +1 -0
- package/lib/types/ts-to-chart-event.types.d.ts +67 -0
- package/lib/types/ts-to-chart-event.types.d.ts.map +1 -0
- package/lib/types/ts-to-chart-event.types.js +12 -0
- package/lib/types/ts-to-chart-event.types.js.map +1 -0
- package/lib/types/visual-prop.types.d.ts +47 -0
- package/lib/types/visual-prop.types.d.ts.map +1 -0
- package/lib/types/visual-prop.types.js +2 -0
- package/lib/types/visual-prop.types.js.map +1 -0
- package/package.json +88 -0
- package/src/index.ts +7 -0
- package/src/main/custom-chart-context.spec.ts +432 -0
- package/src/main/custom-chart-context.ts +587 -0
- package/src/main/post-message-event-bridge.spec.ts +215 -0
- package/src/main/post-message-event-bridge.ts +88 -0
- package/src/test/test-utils.ts +13 -0
- package/src/types/answer-column.types.ts +174 -0
- package/src/types/chart-to-ts-event.types.ts +159 -0
- package/src/types/common.types.ts +187 -0
- package/src/types/configurator.types.ts +102 -0
- package/src/types/ts-to-chart-event.types.ts +257 -0
- package/src/types/visual-prop.types.ts +271 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* post message event bridge spec file
|
|
3
|
+
*
|
|
4
|
+
* @author Chetan Agrawal <chetan.agrawal@thoughtspot.com>
|
|
5
|
+
*/
|
|
6
|
+
import _ from 'lodash';
|
|
7
|
+
import { postMessageToHostApp } from './post-message-event-bridge';
|
|
8
|
+
|
|
9
|
+
const TIMEOUT_THRESHOLD = 30000;
|
|
10
|
+
|
|
11
|
+
describe('postMessageToHostApp', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.resetAllMocks();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('should resolve the promise with null when successful', async () => {
|
|
17
|
+
// Mock the necessary variables and functions
|
|
18
|
+
const componentId = '123';
|
|
19
|
+
const hostUrl = 'https://example.com';
|
|
20
|
+
const eventPayload = { foo: 'bar' };
|
|
21
|
+
const eventType = 'SOME_EVENT';
|
|
22
|
+
|
|
23
|
+
// mockpost Message
|
|
24
|
+
const mockPostMessage = jest.spyOn(global.parent.window, 'postMessage');
|
|
25
|
+
// mock Message Channel
|
|
26
|
+
const channel = {
|
|
27
|
+
port1: { onmessage: null, close: jest.fn() },
|
|
28
|
+
port2: {},
|
|
29
|
+
};
|
|
30
|
+
const messageChannelMock = { MessageChannel: jest.fn(() => channel) };
|
|
31
|
+
global.MessageChannel = messageChannelMock.MessageChannel as any;
|
|
32
|
+
|
|
33
|
+
// Call the function
|
|
34
|
+
const promise = postMessageToHostApp(
|
|
35
|
+
componentId,
|
|
36
|
+
hostUrl,
|
|
37
|
+
eventPayload,
|
|
38
|
+
eventType as any,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// Simulate a successful response
|
|
42
|
+
const response = { data: { hasError: false } };
|
|
43
|
+
if (_.isFunction(channel.port1.onmessage)) {
|
|
44
|
+
(channel.port1.onmessage as any)(response);
|
|
45
|
+
} else {
|
|
46
|
+
// on message should have been initialized
|
|
47
|
+
throw new Error('on message should have been initialized');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Wait for the promise to resolve
|
|
51
|
+
await expect(promise).resolves.toBeNull();
|
|
52
|
+
|
|
53
|
+
// Verify that the postMessage function was called with the correct
|
|
54
|
+
// arguments
|
|
55
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
56
|
+
{
|
|
57
|
+
componentId,
|
|
58
|
+
payload: eventPayload,
|
|
59
|
+
eventType,
|
|
60
|
+
source: 'ts-chart-sdk',
|
|
61
|
+
},
|
|
62
|
+
hostUrl,
|
|
63
|
+
[channel.port2],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// Verify that the MessageChannel was used correctly
|
|
67
|
+
expect(channel.port1.close).toHaveBeenCalled();
|
|
68
|
+
expect(messageChannelMock.MessageChannel).toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should reject the promise with an error message when there is an error', async () => {
|
|
72
|
+
// Mock the necessary variables and functions
|
|
73
|
+
const componentId = '123';
|
|
74
|
+
const hostUrl = 'https://example.com';
|
|
75
|
+
const eventPayload = { foo: 'bar' };
|
|
76
|
+
const eventType = 'SOME_EVENT';
|
|
77
|
+
|
|
78
|
+
// mockpost Message
|
|
79
|
+
const mockPostMessage = jest.spyOn(global.parent.window, 'postMessage');
|
|
80
|
+
// mock Message Channel
|
|
81
|
+
const channel = {
|
|
82
|
+
port1: { onmessage: null, close: jest.fn() },
|
|
83
|
+
port2: {},
|
|
84
|
+
};
|
|
85
|
+
const messageChannelMock = { MessageChannel: jest.fn(() => channel) };
|
|
86
|
+
global.MessageChannel = messageChannelMock.MessageChannel as any;
|
|
87
|
+
|
|
88
|
+
// Call the function
|
|
89
|
+
const promise = postMessageToHostApp(
|
|
90
|
+
componentId,
|
|
91
|
+
hostUrl,
|
|
92
|
+
eventPayload,
|
|
93
|
+
eventType as any,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Simulate an error response
|
|
97
|
+
const error = new Error('Some error');
|
|
98
|
+
const response = { data: { hasError: true, error } };
|
|
99
|
+
if (_.isFunction(channel.port1.onmessage)) {
|
|
100
|
+
(channel.port1.onmessage as any)(response);
|
|
101
|
+
} else {
|
|
102
|
+
// on message should have been initialized
|
|
103
|
+
throw new Error('on message should have been initialized');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Wait for the promise to reject
|
|
107
|
+
await expect(promise).rejects.toThrow('Some error');
|
|
108
|
+
|
|
109
|
+
// Verify that the postMessage function was called with the correct
|
|
110
|
+
// arguments
|
|
111
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
112
|
+
{
|
|
113
|
+
componentId,
|
|
114
|
+
payload: eventPayload,
|
|
115
|
+
eventType,
|
|
116
|
+
source: 'ts-chart-sdk',
|
|
117
|
+
},
|
|
118
|
+
hostUrl,
|
|
119
|
+
[channel.port2],
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
// Verify that the MessageChannel was used correctly
|
|
123
|
+
expect(channel.port1.close).toHaveBeenCalled();
|
|
124
|
+
expect(messageChannelMock.MessageChannel).toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test(
|
|
128
|
+
'should reject the promise after a timeout',
|
|
129
|
+
async () => {
|
|
130
|
+
const componentId = 'some-component-id';
|
|
131
|
+
const hostUrl = 'https://some-host-url.com';
|
|
132
|
+
const eventPayload = { someKey: 'someValue' };
|
|
133
|
+
const eventType = 'some-event-type';
|
|
134
|
+
|
|
135
|
+
// mockpost Message
|
|
136
|
+
const mockPostMessage = jest.spyOn(
|
|
137
|
+
global.parent.window,
|
|
138
|
+
'postMessage',
|
|
139
|
+
);
|
|
140
|
+
// mock Message Channel
|
|
141
|
+
const channel = {
|
|
142
|
+
port1: { onmessage: null, close: jest.fn() },
|
|
143
|
+
port2: {},
|
|
144
|
+
};
|
|
145
|
+
const messageChannelMock = {
|
|
146
|
+
MessageChannel: jest.fn(() => channel),
|
|
147
|
+
};
|
|
148
|
+
global.MessageChannel = messageChannelMock.MessageChannel as any;
|
|
149
|
+
|
|
150
|
+
const promise = postMessageToHostApp(
|
|
151
|
+
componentId,
|
|
152
|
+
hostUrl,
|
|
153
|
+
eventPayload,
|
|
154
|
+
eventType as any,
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
158
|
+
{
|
|
159
|
+
componentId,
|
|
160
|
+
payload: eventPayload,
|
|
161
|
+
eventType,
|
|
162
|
+
source: 'ts-chart-sdk',
|
|
163
|
+
},
|
|
164
|
+
hostUrl,
|
|
165
|
+
expect.any(Array),
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
await expect(promise).rejects.toThrow(
|
|
169
|
+
'ChartContext: postMessage operation timed out.',
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
TIMEOUT_THRESHOLD + 1000,
|
|
173
|
+
); // added extra timeout for this test
|
|
174
|
+
|
|
175
|
+
test('should reject the promise if some error in postMessage', async () => {
|
|
176
|
+
const componentId = 'some-component-id';
|
|
177
|
+
const hostUrl = 'https://some-host-url.com';
|
|
178
|
+
const eventPayload = { someKey: 'someValue' };
|
|
179
|
+
const eventType = 'some-event-type';
|
|
180
|
+
|
|
181
|
+
// mockpost Message
|
|
182
|
+
const mockPostMessage = jest.spyOn(global.parent.window, 'postMessage');
|
|
183
|
+
mockPostMessage.mockImplementation(() => {
|
|
184
|
+
throw new Error('Some postMessage error');
|
|
185
|
+
});
|
|
186
|
+
// mock Message Channel
|
|
187
|
+
const channel = {
|
|
188
|
+
port1: { onmessage: null, close: jest.fn() },
|
|
189
|
+
port2: {},
|
|
190
|
+
};
|
|
191
|
+
const messageChannelMock = { MessageChannel: jest.fn(() => channel) };
|
|
192
|
+
global.MessageChannel = messageChannelMock.MessageChannel as any;
|
|
193
|
+
|
|
194
|
+
const promise = postMessageToHostApp(
|
|
195
|
+
componentId,
|
|
196
|
+
hostUrl,
|
|
197
|
+
eventPayload,
|
|
198
|
+
eventType as any,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// Wait for the promise to reject
|
|
202
|
+
await expect(promise).rejects.toThrow('Some postMessage error');
|
|
203
|
+
|
|
204
|
+
expect(mockPostMessage).toHaveBeenCalledWith(
|
|
205
|
+
{
|
|
206
|
+
componentId,
|
|
207
|
+
payload: eventPayload,
|
|
208
|
+
eventType,
|
|
209
|
+
source: 'ts-chart-sdk',
|
|
210
|
+
},
|
|
211
|
+
hostUrl,
|
|
212
|
+
expect.any(Array),
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ChartToTSEvent } from '../types/chart-to-ts-event.types';
|
|
2
|
+
|
|
3
|
+
const TIMEOUT_THRESHOLD = 30000; // 30sec
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* method to listen to messages using postMessage from parent.
|
|
7
|
+
*
|
|
8
|
+
* @param {any} handleMessageEvent
|
|
9
|
+
*/
|
|
10
|
+
const init = (handleMessageEvent: any) => {
|
|
11
|
+
window.addEventListener('message', handleMessageEvent);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* stop listening to the messages
|
|
16
|
+
*
|
|
17
|
+
* @param {any} handleMessageEvent
|
|
18
|
+
*/
|
|
19
|
+
const destroy = (handleMessageEvent: any) => {
|
|
20
|
+
window.removeEventListener('message', handleMessageEvent);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} componentId This is required to send the event to the
|
|
25
|
+
* right chart component in case of multiple components
|
|
26
|
+
* @param {string} hostUrl The host application url
|
|
27
|
+
* @param {any} eventPayload payload for the event
|
|
28
|
+
* @param {ChartToTSEvent} eventType type of the event
|
|
29
|
+
* @returns Promise
|
|
30
|
+
*/
|
|
31
|
+
const postMessageToHostApp = (
|
|
32
|
+
componentId: string,
|
|
33
|
+
hostUrl: string,
|
|
34
|
+
eventPayload: any,
|
|
35
|
+
eventType: ChartToTSEvent,
|
|
36
|
+
): Promise<any> =>
|
|
37
|
+
new Promise((resolve, reject) => {
|
|
38
|
+
const channel = new MessageChannel();
|
|
39
|
+
channel.port1.onmessage = (res: any) => {
|
|
40
|
+
channel.port1.close();
|
|
41
|
+
const { hasError, error } = res.data;
|
|
42
|
+
if (hasError) {
|
|
43
|
+
console.log('ChartContext: message failure:', res.data);
|
|
44
|
+
reject(error);
|
|
45
|
+
} else {
|
|
46
|
+
console.log('ChartContext: message success:', res.data);
|
|
47
|
+
resolve(null);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
reject(
|
|
53
|
+
new Error(
|
|
54
|
+
`ChartContext: postMessage operation timed out. ${eventType}`,
|
|
55
|
+
eventPayload,
|
|
56
|
+
),
|
|
57
|
+
);
|
|
58
|
+
}, TIMEOUT_THRESHOLD);
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
window.parent.window.postMessage(
|
|
62
|
+
{
|
|
63
|
+
componentId,
|
|
64
|
+
payload: {
|
|
65
|
+
...eventPayload,
|
|
66
|
+
},
|
|
67
|
+
eventType,
|
|
68
|
+
source: 'ts-chart-sdk',
|
|
69
|
+
},
|
|
70
|
+
hostUrl,
|
|
71
|
+
[channel.port2],
|
|
72
|
+
);
|
|
73
|
+
} catch (err) {
|
|
74
|
+
console.error(
|
|
75
|
+
'ChartContext: error in emitting event:',
|
|
76
|
+
err,
|
|
77
|
+
eventType,
|
|
78
|
+
eventPayload,
|
|
79
|
+
);
|
|
80
|
+
reject(err);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
init as initMessageListener,
|
|
86
|
+
destroy as destroyMessageListener,
|
|
87
|
+
postMessageToHostApp,
|
|
88
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChartModel } from '../types/common.types';
|
|
2
|
+
|
|
3
|
+
const mockChartModel = {
|
|
4
|
+
config: {
|
|
5
|
+
chartConfig: {},
|
|
6
|
+
},
|
|
7
|
+
} as ChartModel;
|
|
8
|
+
|
|
9
|
+
export const mockInitializeContextPayload = {
|
|
10
|
+
componentId: 'COMPONENT_ID',
|
|
11
|
+
hostUrl: 'https://some.chart.app',
|
|
12
|
+
chartModel: mockChartModel,
|
|
13
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
export enum ColumnType {
|
|
2
|
+
UNKNOWN,
|
|
3
|
+
MEASURE,
|
|
4
|
+
ATTRIBUTE,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Defines type of the data associated with a column
|
|
9
|
+
*/
|
|
10
|
+
export enum DataType {
|
|
11
|
+
UNKNOWN,
|
|
12
|
+
// Boolean data type
|
|
13
|
+
BOOL,
|
|
14
|
+
// string data types
|
|
15
|
+
CHAR,
|
|
16
|
+
// Numeric data types
|
|
17
|
+
INT32,
|
|
18
|
+
INT64,
|
|
19
|
+
FLOAT,
|
|
20
|
+
DOUBLE,
|
|
21
|
+
// Date type attributes
|
|
22
|
+
DATE,
|
|
23
|
+
DATE_TIME,
|
|
24
|
+
TIME,
|
|
25
|
+
// Miscellaneous
|
|
26
|
+
MAX_TYPE,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export enum ColumnTimeBucket {
|
|
30
|
+
NO_BUCKET,
|
|
31
|
+
DAILY,
|
|
32
|
+
WEEKLY,
|
|
33
|
+
MONTHLY,
|
|
34
|
+
QUARTERLY,
|
|
35
|
+
YEARLY,
|
|
36
|
+
HOURLY,
|
|
37
|
+
AUTO,
|
|
38
|
+
HOUR_OF_DAY,
|
|
39
|
+
DAY_OF_WEEK,
|
|
40
|
+
DAY_OF_MONTH,
|
|
41
|
+
DAY_OF_QUARTER,
|
|
42
|
+
DAY_OF_YEAR,
|
|
43
|
+
WEEK_OF_MONTH,
|
|
44
|
+
WEEK_OF_QUARTER,
|
|
45
|
+
WEEK_OF_YEAR,
|
|
46
|
+
MONTH_OF_QUARTER,
|
|
47
|
+
MONTH_OF_YEAR,
|
|
48
|
+
QUARTER_OF_YEAR,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Enum values for column format type defined in the worksheet
|
|
53
|
+
*
|
|
54
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
55
|
+
*/
|
|
56
|
+
export enum FormatType {
|
|
57
|
+
NONE,
|
|
58
|
+
PATTERN,
|
|
59
|
+
PERCENTAGE,
|
|
60
|
+
CURRENCY,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Type of currency formatting defined in the worksheet
|
|
65
|
+
*
|
|
66
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
67
|
+
*/
|
|
68
|
+
export enum CurrencyFormatType {
|
|
69
|
+
USER_LOCALE,
|
|
70
|
+
COLUMN,
|
|
71
|
+
ISO_CODE,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Currency Format for the columm defined in the worksheet
|
|
76
|
+
*
|
|
77
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
78
|
+
*/
|
|
79
|
+
export interface CurrencyFormat {
|
|
80
|
+
type: CurrencyFormatType;
|
|
81
|
+
/**
|
|
82
|
+
* column id of the column in case of currency formatted by a column
|
|
83
|
+
*
|
|
84
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
85
|
+
*/
|
|
86
|
+
column: string;
|
|
87
|
+
/**
|
|
88
|
+
* ISO code for the currency types
|
|
89
|
+
*
|
|
90
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
91
|
+
*/
|
|
92
|
+
isoCode: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Defines the type for column formatting in the worksheet and related details.
|
|
97
|
+
* Based on the type of formatting, the pattern and currency formats are defined.
|
|
98
|
+
*
|
|
99
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
100
|
+
*/
|
|
101
|
+
export interface ColumnFormat {
|
|
102
|
+
type: FormatType;
|
|
103
|
+
/**
|
|
104
|
+
* Pattern to define the number formatting style
|
|
105
|
+
*
|
|
106
|
+
* @optional
|
|
107
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
108
|
+
*/
|
|
109
|
+
pattern?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Currency format details
|
|
112
|
+
*
|
|
113
|
+
* @optional
|
|
114
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
115
|
+
*/
|
|
116
|
+
currencyFormat?: CurrencyFormat;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ChartColumn {
|
|
120
|
+
/**
|
|
121
|
+
* Column Id
|
|
122
|
+
*
|
|
123
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
124
|
+
*/
|
|
125
|
+
id: string;
|
|
126
|
+
/**
|
|
127
|
+
* Column Name
|
|
128
|
+
*
|
|
129
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
130
|
+
*/
|
|
131
|
+
name: string;
|
|
132
|
+
/**
|
|
133
|
+
* Type of column if attribute or measure
|
|
134
|
+
*
|
|
135
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
136
|
+
*/
|
|
137
|
+
type: ColumnType;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Type of the time based aggregation
|
|
141
|
+
* when the column data is of type Date, Datetime, Time
|
|
142
|
+
*
|
|
143
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
144
|
+
*/
|
|
145
|
+
timeBucket: ColumnTimeBucket;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Type of data for the column
|
|
149
|
+
*
|
|
150
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
151
|
+
*/
|
|
152
|
+
dataType: DataType;
|
|
153
|
+
|
|
154
|
+
// // worksheet level formatting
|
|
155
|
+
// // (TBD make this more cleaner during export)
|
|
156
|
+
// /**
|
|
157
|
+
// * @deprecated
|
|
158
|
+
// * @hidden To be removed and merged with the format
|
|
159
|
+
// * @version SDK: 0.1 | ThoughtSpot:
|
|
160
|
+
// */
|
|
161
|
+
// formatPattern?: string
|
|
162
|
+
// /**
|
|
163
|
+
// * @deprecated
|
|
164
|
+
// * @hidden To be removed and merged with the format
|
|
165
|
+
// */
|
|
166
|
+
// formatType?: FormatType
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Formatting for the columns defined in the worksheet
|
|
170
|
+
*
|
|
171
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
172
|
+
*/
|
|
173
|
+
format?: ColumnFormat;
|
|
174
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { VisualProps } from './common.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @group Chart to ThoughtSpot Events
|
|
6
|
+
*/
|
|
7
|
+
export enum ChartToTSEvent {
|
|
8
|
+
/**
|
|
9
|
+
* Context Menu events
|
|
10
|
+
*/
|
|
11
|
+
OpenContextMenu = 'OpenContextMenu',
|
|
12
|
+
CloseContextMenu = 'CloseContextMenu',
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Axis Menu events
|
|
16
|
+
*/
|
|
17
|
+
OpenAxisMenu = 'OpenAxisMenu',
|
|
18
|
+
CloseAxisMenu = 'CloseAxisMenu',
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Render life cycle events
|
|
22
|
+
*/
|
|
23
|
+
RenderStart = 'RenderStart',
|
|
24
|
+
RenderError = 'RenderError',
|
|
25
|
+
RenderComplete = 'RenderComplete',
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Visual Props Update
|
|
29
|
+
*/
|
|
30
|
+
UpdateVisualProps = 'UpdateVisualProps',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* This map defines the event type and its corresponding payload needed by event
|
|
35
|
+
*
|
|
36
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
37
|
+
* @group Chart to ThoughtSpot Events
|
|
38
|
+
*/
|
|
39
|
+
export interface ChartToTSEventsPayloadMap {
|
|
40
|
+
/**
|
|
41
|
+
* Trigger to open Context Menu
|
|
42
|
+
*
|
|
43
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
44
|
+
*/
|
|
45
|
+
[ChartToTSEvent.OpenContextMenu]: OpenContextMenuEventPayload;
|
|
46
|
+
/**
|
|
47
|
+
* Trigger to close Context Menu
|
|
48
|
+
*
|
|
49
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
50
|
+
*/
|
|
51
|
+
[ChartToTSEvent.CloseContextMenu]: null;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Trigger to notify the render start
|
|
55
|
+
*
|
|
56
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
57
|
+
*/
|
|
58
|
+
[ChartToTSEvent.RenderStart]: null;
|
|
59
|
+
/**
|
|
60
|
+
* Trigger to notify the render completion
|
|
61
|
+
*
|
|
62
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
63
|
+
*/
|
|
64
|
+
[ChartToTSEvent.RenderComplete]: null;
|
|
65
|
+
/**
|
|
66
|
+
* Trigger to notify the render error
|
|
67
|
+
*
|
|
68
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
69
|
+
*/
|
|
70
|
+
[ChartToTSEvent.RenderError]: RenderErrorEventPayload;
|
|
71
|
+
/**
|
|
72
|
+
* Trigger to update the visual props
|
|
73
|
+
*
|
|
74
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
75
|
+
*/
|
|
76
|
+
[ChartToTSEvent.UpdateVisualProps]: UpdateVisualPropsEventPayload;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @group Chart to ThoughtSpot Events
|
|
82
|
+
*/
|
|
83
|
+
type UpdateVisualPropsEventPayload = VisualProps;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @group Chart to ThoughtSpot Events / Context Menu
|
|
87
|
+
*/
|
|
88
|
+
// start - open context menu payload
|
|
89
|
+
export interface PointVal {
|
|
90
|
+
// column id of the column associated with the value
|
|
91
|
+
columnId: string;
|
|
92
|
+
// value of the point clicked on, mostly makes sense for attributes.
|
|
93
|
+
// this can be an array of values as well.
|
|
94
|
+
value: any;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @group Chart to ThoughtSpot Events / Context Menu
|
|
99
|
+
*/
|
|
100
|
+
export interface Point {
|
|
101
|
+
tuple: PointVal[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* @group Chart to ThoughtSpot Events / Context Menu
|
|
107
|
+
*/
|
|
108
|
+
export interface CustomAction {
|
|
109
|
+
id: string; // id of the action user defined
|
|
110
|
+
label: string; // developer should i18n this
|
|
111
|
+
icon: string; // icon string to show on the context/axis menu
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* This function will need to have a defined set of args.
|
|
115
|
+
* For e.g., pointClick Event, point details and chart model in case on context menu
|
|
116
|
+
* For axis menu, it would be different.
|
|
117
|
+
*
|
|
118
|
+
* Callback will be triggered via postMessage api contract.
|
|
119
|
+
*/
|
|
120
|
+
onClick: (...args: any[]) => void;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
*
|
|
125
|
+
* @group Chart to ThoughtSpot Events
|
|
126
|
+
*/
|
|
127
|
+
export interface OpenContextMenuEventPayload {
|
|
128
|
+
event: Pick<
|
|
129
|
+
PointerEvent,
|
|
130
|
+
| 'x'
|
|
131
|
+
| 'y'
|
|
132
|
+
| 'clientX'
|
|
133
|
+
| 'clientY'
|
|
134
|
+
| 'pageX'
|
|
135
|
+
| 'pageY'
|
|
136
|
+
| 'screenX'
|
|
137
|
+
| 'screenY'
|
|
138
|
+
>;
|
|
139
|
+
clickedPoint: Point;
|
|
140
|
+
selectedPoints?: Point[];
|
|
141
|
+
customActions?: CustomAction[];
|
|
142
|
+
}
|
|
143
|
+
// end - open context menu payload
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @group Chart to ThoughtSpot Events
|
|
147
|
+
*/
|
|
148
|
+
interface RenderErrorEventPayload {
|
|
149
|
+
hasError: boolean;
|
|
150
|
+
error: any;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
*
|
|
155
|
+
* @group Chart to ThoughtSpot Events
|
|
156
|
+
*/
|
|
157
|
+
export enum ErrorType {
|
|
158
|
+
MultipleContextsNotSupported = 'MultipleContextsNotSupported',
|
|
159
|
+
}
|