@thoughtspot/ts-chart-sdk 0.0.1-alpha.1 → 0.0.1-alpha.10
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/index.d.ts +1 -0
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +1 -0
- package/cjs/index.js.map +1 -1
- package/cjs/main/custom-chart-context.d.ts +10 -2
- package/cjs/main/custom-chart-context.d.ts.map +1 -1
- package/cjs/main/custom-chart-context.js +117 -2
- package/cjs/main/custom-chart-context.js.map +1 -1
- package/cjs/main/custom-chart-context.spec.js +320 -0
- package/cjs/main/custom-chart-context.spec.js.map +1 -1
- package/cjs/main/post-message-event-bridge.js +1 -1
- package/cjs/main/post-message-event-bridge.js.map +1 -1
- package/cjs/main/post-message-event-bridge.spec.js +5 -3
- package/cjs/main/post-message-event-bridge.spec.js.map +1 -1
- package/cjs/react/mocks/custom-chart-context-mock.d.ts +3 -0
- package/cjs/react/mocks/custom-chart-context-mock.d.ts.map +1 -0
- package/cjs/react/mocks/custom-chart-context-mock.js +100 -0
- package/cjs/react/mocks/custom-chart-context-mock.js.map +1 -0
- package/cjs/react/use-custom-chart-context.d.ts +4 -0
- package/cjs/react/use-custom-chart-context.d.ts.map +1 -0
- package/cjs/react/use-custom-chart-context.js +95 -0
- package/cjs/react/use-custom-chart-context.js.map +1 -0
- package/cjs/react/use-custom-chart-context.spec.d.ts +2 -0
- package/cjs/react/use-custom-chart-context.spec.d.ts.map +1 -0
- package/cjs/react/use-custom-chart-context.spec.js +391 -0
- package/cjs/react/use-custom-chart-context.spec.js.map +1 -0
- package/cjs/react/use-custom-chart-context.util.d.ts +6 -0
- package/cjs/react/use-custom-chart-context.util.d.ts.map +1 -0
- package/cjs/react/use-custom-chart-context.util.js +60 -0
- package/cjs/react/use-custom-chart-context.util.js.map +1 -0
- package/cjs/react/use-custom-chart-types.d.ts +23 -0
- package/cjs/react/use-custom-chart-types.d.ts.map +1 -0
- package/cjs/react/use-custom-chart-types.js +3 -0
- package/cjs/react/use-custom-chart-types.js.map +1 -0
- package/cjs/types/chart-to-ts-event.types.d.ts +54 -4
- package/cjs/types/chart-to-ts-event.types.d.ts.map +1 -1
- package/cjs/types/chart-to-ts-event.types.js +14 -1
- package/cjs/types/chart-to-ts-event.types.js.map +1 -1
- package/cjs/types/common.types.d.ts +2 -0
- package/cjs/types/common.types.d.ts.map +1 -1
- package/cjs/types/ts-to-chart-event.types.d.ts +23 -1
- package/cjs/types/ts-to-chart-event.types.d.ts.map +1 -1
- package/cjs/types/ts-to-chart-event.types.js +2 -0
- package/cjs/types/ts-to-chart-event.types.js.map +1 -1
- package/cjs/types/visual-prop.types.d.ts +27 -1
- package/cjs/types/visual-prop.types.d.ts.map +1 -1
- package/dist/ts-chart-sdk.d.ts +151 -23
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/main/custom-chart-context.d.ts +10 -2
- package/lib/main/custom-chart-context.d.ts.map +1 -1
- package/lib/main/custom-chart-context.js +118 -3
- package/lib/main/custom-chart-context.js.map +1 -1
- package/lib/main/custom-chart-context.spec.js +317 -0
- package/lib/main/custom-chart-context.spec.js.map +1 -1
- package/lib/main/post-message-event-bridge.js +1 -1
- package/lib/main/post-message-event-bridge.js.map +1 -1
- package/lib/main/post-message-event-bridge.spec.js +5 -3
- package/lib/main/post-message-event-bridge.spec.js.map +1 -1
- package/lib/react/mocks/custom-chart-context-mock.d.ts +3 -0
- package/lib/react/mocks/custom-chart-context-mock.d.ts.map +1 -0
- package/lib/react/mocks/custom-chart-context-mock.js +94 -0
- package/lib/react/mocks/custom-chart-context-mock.js.map +1 -0
- package/lib/react/use-custom-chart-context.d.ts +4 -0
- package/lib/react/use-custom-chart-context.d.ts.map +1 -0
- package/lib/react/use-custom-chart-context.js +68 -0
- package/lib/react/use-custom-chart-context.js.map +1 -0
- package/lib/react/use-custom-chart-context.spec.d.ts +2 -0
- package/lib/react/use-custom-chart-context.spec.d.ts.map +1 -0
- package/lib/react/use-custom-chart-context.spec.js +363 -0
- package/lib/react/use-custom-chart-context.spec.js.map +1 -0
- package/lib/react/use-custom-chart-context.util.d.ts +6 -0
- package/lib/react/use-custom-chart-context.util.d.ts.map +1 -0
- package/lib/react/use-custom-chart-context.util.js +51 -0
- package/lib/react/use-custom-chart-context.util.js.map +1 -0
- package/lib/react/use-custom-chart-types.d.ts +23 -0
- package/lib/react/use-custom-chart-types.d.ts.map +1 -0
- package/lib/react/use-custom-chart-types.js +2 -0
- package/lib/react/use-custom-chart-types.js.map +1 -0
- package/lib/types/chart-to-ts-event.types.d.ts +54 -4
- package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
- package/lib/types/chart-to-ts-event.types.js +13 -0
- package/lib/types/chart-to-ts-event.types.js.map +1 -1
- package/lib/types/common.types.d.ts +2 -0
- package/lib/types/common.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.d.ts +23 -1
- package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.js +2 -0
- package/lib/types/ts-to-chart-event.types.js.map +1 -1
- package/lib/types/visual-prop.types.d.ts +27 -1
- package/lib/types/visual-prop.types.d.ts.map +1 -1
- package/package.json +8 -2
- package/src/index.ts +1 -0
- package/src/main/custom-chart-context.spec.ts +426 -0
- package/src/main/custom-chart-context.ts +244 -3
- package/src/main/post-message-event-bridge.spec.ts +5 -3
- package/src/main/post-message-event-bridge.ts +1 -1
- package/src/react/mocks/custom-chart-context-mock.ts +114 -0
- package/src/react/use-custom-chart-context.spec.tsx +464 -0
- package/src/react/use-custom-chart-context.tsx +180 -0
- package/src/react/use-custom-chart-context.util.ts +101 -0
- package/src/react/use-custom-chart-types.ts +70 -0
- package/src/types/chart-to-ts-event.types.ts +215 -3
- package/src/types/common.types.ts +15 -1
- package/src/types/ts-to-chart-event.types.ts +70 -0
- package/src/types/visual-prop.types.ts +137 -0
- package/lib/dist/ts-chart-sdk.d.ts +0 -312
|
@@ -5,13 +5,20 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright: ThoughtSpot Inc. 2023
|
|
7
7
|
*/
|
|
8
|
+
|
|
8
9
|
import _ from 'lodash';
|
|
9
10
|
import {
|
|
11
|
+
AxisMenuActionHandler,
|
|
10
12
|
ChartToTSEvent,
|
|
11
13
|
ChartToTSEventsPayloadMap,
|
|
14
|
+
ContextMenuActionHandler,
|
|
15
|
+
CustomAction,
|
|
12
16
|
ErrorType,
|
|
17
|
+
OpenAxisMenuEventPayload,
|
|
18
|
+
OpenContextMenuEventPayload,
|
|
13
19
|
} from '../types/chart-to-ts-event.types';
|
|
14
20
|
import {
|
|
21
|
+
AppConfig,
|
|
15
22
|
ChartConfig,
|
|
16
23
|
ChartModel,
|
|
17
24
|
ValidationResponse,
|
|
@@ -19,8 +26,10 @@ import {
|
|
|
19
26
|
} from '../types/common.types';
|
|
20
27
|
import { ChartConfigEditorDefinition } from '../types/configurator.types';
|
|
21
28
|
import {
|
|
29
|
+
AxisMenuCustomActionPayload,
|
|
22
30
|
ChartConfigValidateEventPayload,
|
|
23
31
|
ChartModelUpdateEventPayload,
|
|
32
|
+
ContextMenuCustomActionPayload,
|
|
24
33
|
DataUpdateEventPayload,
|
|
25
34
|
GetDataQueryPayload,
|
|
26
35
|
GetDataQueryResponsePayload,
|
|
@@ -104,6 +113,8 @@ export type CustomChartContextProps = {
|
|
|
104
113
|
* on the TS app. If not provided, visual properties will not be configurable in
|
|
105
114
|
* editor
|
|
106
115
|
*
|
|
116
|
+
* @param chartModel
|
|
117
|
+
* @returns {@link VisualPropEditorDefinition}
|
|
107
118
|
* @version SDK: 0.1 | ThoughtSpot:
|
|
108
119
|
*/
|
|
109
120
|
visualPropEditorDefinition?: VisualPropEditorDefinition;
|
|
@@ -116,7 +127,6 @@ const DEFAULT_CHART_CONTEXT_PROPS: Partial<CustomChartContextProps> = {
|
|
|
116
127
|
validateConfig: () => ({ isValid: true }),
|
|
117
128
|
validateVisualProps: () => ({ isValid: true }),
|
|
118
129
|
chartConfigEditorDefinition: undefined,
|
|
119
|
-
visualPropEditorDefinition: undefined,
|
|
120
130
|
};
|
|
121
131
|
|
|
122
132
|
export class CustomChartContext {
|
|
@@ -148,6 +158,13 @@ export class CustomChartContext {
|
|
|
148
158
|
*/
|
|
149
159
|
private chartModel: ChartModel = {} as any;
|
|
150
160
|
|
|
161
|
+
/**
|
|
162
|
+
* App Config object. This contains the app state like locale and timezones.
|
|
163
|
+
*
|
|
164
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
165
|
+
*/
|
|
166
|
+
private appConfig: AppConfig = {};
|
|
167
|
+
|
|
151
168
|
/**
|
|
152
169
|
* Chart Props Object to define the workflow of the application
|
|
153
170
|
*
|
|
@@ -184,6 +201,22 @@ export class CustomChartContext {
|
|
|
184
201
|
*/
|
|
185
202
|
private triggerInitResolve: () => void = _.noop;
|
|
186
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Stores the callbacks of context menu custom action based on custom action id
|
|
206
|
+
*
|
|
207
|
+
* @returns {@link ContextMenuActionHandler}
|
|
208
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
209
|
+
*/
|
|
210
|
+
private contextMenuActionHandler: ContextMenuActionHandler = {};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Stores the callbacks of axis menu custom action based on custom action id
|
|
214
|
+
*
|
|
215
|
+
* @returns {@link AxisMenuActionHandler}
|
|
216
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
217
|
+
*/
|
|
218
|
+
private axisMenuActionHandler: AxisMenuActionHandler = {};
|
|
219
|
+
|
|
187
220
|
/**
|
|
188
221
|
* Constructor to only accept context props as payload
|
|
189
222
|
*
|
|
@@ -232,6 +265,21 @@ export class CustomChartContext {
|
|
|
232
265
|
this.eventListeners[eventType].push(callbackFn);
|
|
233
266
|
}
|
|
234
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Removes specific event listeners on the chart context.
|
|
270
|
+
*
|
|
271
|
+
* @param {T} eventType
|
|
272
|
+
* @returns void
|
|
273
|
+
*/
|
|
274
|
+
public off<T extends keyof TSToChartEventsPayloadMap>(eventType: T): void {
|
|
275
|
+
if (_.isNil(this.eventListeners[eventType])) {
|
|
276
|
+
console.log('No event listener found to remove');
|
|
277
|
+
this.eventListeners[eventType] = [];
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
this.eventListeners[eventType].splice(0, 1);
|
|
281
|
+
}
|
|
282
|
+
|
|
235
283
|
/**
|
|
236
284
|
* Add internal event listeners on the chart context with the required callback.
|
|
237
285
|
*
|
|
@@ -268,6 +316,107 @@ export class CustomChartContext {
|
|
|
268
316
|
*/
|
|
269
317
|
public getChartModel = (): ChartModel => this.chartModel;
|
|
270
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Getter for the chart model object
|
|
321
|
+
*
|
|
322
|
+
* @version SDK: 0.1 | ThoughtSpot:
|
|
323
|
+
*/
|
|
324
|
+
public getAppConfig = (): AppConfig => this.appConfig;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Function to store the context menu custom action callback mapped with action id
|
|
328
|
+
* @param {[OpenContextMenuEventPayload]} eventPayload Event payload bound
|
|
329
|
+
* to the type of the event
|
|
330
|
+
* @returns payload
|
|
331
|
+
*/
|
|
332
|
+
public contextMenuCustomActionPreProcessor(
|
|
333
|
+
eventPayload: [OpenContextMenuEventPayload],
|
|
334
|
+
): [OpenContextMenuEventPayload] {
|
|
335
|
+
// clear out the stored custom events callback for context menu
|
|
336
|
+
this.contextMenuActionHandler = {};
|
|
337
|
+
if (_.isEmpty(eventPayload?.[0]?.customActions)) {
|
|
338
|
+
return eventPayload;
|
|
339
|
+
}
|
|
340
|
+
eventPayload?.[0]?.customActions?.forEach((action: CustomAction) => {
|
|
341
|
+
this.contextMenuActionHandler[action.id] = action.onClick;
|
|
342
|
+
});
|
|
343
|
+
const processedCustomActions = eventPayload[0]?.customActions?.map(
|
|
344
|
+
(action: CustomAction) => {
|
|
345
|
+
return {
|
|
346
|
+
id: action.id,
|
|
347
|
+
label: action.label,
|
|
348
|
+
icon: action.icon,
|
|
349
|
+
};
|
|
350
|
+
},
|
|
351
|
+
);
|
|
352
|
+
const processedPayload: [OpenContextMenuEventPayload] = [
|
|
353
|
+
{
|
|
354
|
+
...eventPayload[0],
|
|
355
|
+
customActions: processedCustomActions as CustomAction[],
|
|
356
|
+
},
|
|
357
|
+
];
|
|
358
|
+
return processedPayload;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Function to store the axis menu custom action callback mapped with action id
|
|
363
|
+
* @param {[OpenAxisMenuEventPayload]} eventPayload Event payload bound
|
|
364
|
+
* to the type of the event
|
|
365
|
+
* @returns payload
|
|
366
|
+
*/
|
|
367
|
+
public axisMenuCustomActionPreProcessor(
|
|
368
|
+
eventPayload: [OpenAxisMenuEventPayload],
|
|
369
|
+
): [OpenAxisMenuEventPayload] {
|
|
370
|
+
// clear out the stored custom events callback for axis menu
|
|
371
|
+
this.axisMenuActionHandler = {};
|
|
372
|
+
if (_.isEmpty(eventPayload?.[0]?.customActions)) {
|
|
373
|
+
return eventPayload;
|
|
374
|
+
}
|
|
375
|
+
eventPayload[0].customActions?.forEach((action: CustomAction) => {
|
|
376
|
+
this.axisMenuActionHandler[action.id] = action.onClick;
|
|
377
|
+
});
|
|
378
|
+
const processedCustomActions = eventPayload?.[0].customActions?.map(
|
|
379
|
+
(action: CustomAction) => {
|
|
380
|
+
return {
|
|
381
|
+
id: action.id,
|
|
382
|
+
label: action.label,
|
|
383
|
+
icon: action.icon,
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
);
|
|
387
|
+
const processedPayload: [OpenAxisMenuEventPayload] = [
|
|
388
|
+
{
|
|
389
|
+
...eventPayload[0],
|
|
390
|
+
customActions: processedCustomActions as CustomAction[],
|
|
391
|
+
},
|
|
392
|
+
];
|
|
393
|
+
return processedPayload;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Function to process the event payload based on event type
|
|
398
|
+
* @param {ChartToTSEventsPayloadMap[T]} eventPayload Event payload bound
|
|
399
|
+
* to the type of the event
|
|
400
|
+
* @returns payload
|
|
401
|
+
*/
|
|
402
|
+
private eventPayloadPreProcessor<T extends keyof ChartToTSEventsPayloadMap>(
|
|
403
|
+
eventType: T,
|
|
404
|
+
eventPayload: ChartToTSEventsPayloadMap[T],
|
|
405
|
+
): ChartToTSEventsPayloadMap[T] {
|
|
406
|
+
switch (eventType) {
|
|
407
|
+
case ChartToTSEvent.OpenContextMenu:
|
|
408
|
+
return this.contextMenuCustomActionPreProcessor(
|
|
409
|
+
eventPayload as [OpenContextMenuEventPayload],
|
|
410
|
+
) as ChartToTSEventsPayloadMap[T];
|
|
411
|
+
case ChartToTSEvent.OpenAxisMenu:
|
|
412
|
+
return this.axisMenuCustomActionPreProcessor(
|
|
413
|
+
eventPayload as [OpenAxisMenuEventPayload],
|
|
414
|
+
) as ChartToTSEventsPayloadMap[T];
|
|
415
|
+
default:
|
|
416
|
+
return eventPayload;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
271
420
|
/**
|
|
272
421
|
* Function to emit Chart to TS Events to the TS application.
|
|
273
422
|
|
|
@@ -286,10 +435,14 @@ export class CustomChartContext {
|
|
|
286
435
|
);
|
|
287
436
|
return Promise.reject(new Error('Context not initialized'));
|
|
288
437
|
}
|
|
438
|
+
const processedPayload = this.eventPayloadPreProcessor(
|
|
439
|
+
eventType,
|
|
440
|
+
eventPayload,
|
|
441
|
+
);
|
|
289
442
|
return PostMessageEventBridge.postMessageToHostApp(
|
|
290
443
|
this.componentId,
|
|
291
444
|
this.hostUrl,
|
|
292
|
-
|
|
445
|
+
processedPayload?.[0] ?? null,
|
|
293
446
|
eventType,
|
|
294
447
|
);
|
|
295
448
|
}
|
|
@@ -431,6 +584,94 @@ export class CustomChartContext {
|
|
|
431
584
|
this.chartContextProps.renderChart(this);
|
|
432
585
|
});
|
|
433
586
|
|
|
587
|
+
/**
|
|
588
|
+
* This event is triggered when the custom context action is triggered from TS app
|
|
589
|
+
*/
|
|
590
|
+
this.onInternal(
|
|
591
|
+
TSToChartEvent.ContextMenuActionClick,
|
|
592
|
+
(
|
|
593
|
+
payload: ContextMenuCustomActionPayload,
|
|
594
|
+
): {
|
|
595
|
+
isValid: boolean;
|
|
596
|
+
error?: unknown;
|
|
597
|
+
} => {
|
|
598
|
+
try {
|
|
599
|
+
const {
|
|
600
|
+
id: customActionCallback,
|
|
601
|
+
clickedPoint,
|
|
602
|
+
selectedPoints,
|
|
603
|
+
event,
|
|
604
|
+
} = payload.customAction;
|
|
605
|
+
const customActionCallbackArgs = {
|
|
606
|
+
id: customActionCallback,
|
|
607
|
+
clickedPoint,
|
|
608
|
+
selectedPoints,
|
|
609
|
+
event,
|
|
610
|
+
};
|
|
611
|
+
this.contextMenuActionHandler[customActionCallback](
|
|
612
|
+
customActionCallbackArgs,
|
|
613
|
+
);
|
|
614
|
+
return {
|
|
615
|
+
isValid: true,
|
|
616
|
+
};
|
|
617
|
+
} catch (error: unknown) {
|
|
618
|
+
console.log(
|
|
619
|
+
'ContextMenuCustomAction: payload recieved:',
|
|
620
|
+
payload,
|
|
621
|
+
'CustomActionCallbackStore:',
|
|
622
|
+
this.axisMenuActionHandler,
|
|
623
|
+
);
|
|
624
|
+
return {
|
|
625
|
+
isValid: false,
|
|
626
|
+
error,
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
);
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* This event is triggered when the custom axis action is triggered from TS app
|
|
634
|
+
*/
|
|
635
|
+
this.onInternal(
|
|
636
|
+
TSToChartEvent.AxisMenuActionClick,
|
|
637
|
+
(
|
|
638
|
+
payload: AxisMenuCustomActionPayload,
|
|
639
|
+
): {
|
|
640
|
+
isValid: boolean;
|
|
641
|
+
error?: unknown;
|
|
642
|
+
} => {
|
|
643
|
+
try {
|
|
644
|
+
const {
|
|
645
|
+
id: customActionCallback,
|
|
646
|
+
columnIds,
|
|
647
|
+
event,
|
|
648
|
+
} = payload.customAction;
|
|
649
|
+
const customActionCallbackArgs = {
|
|
650
|
+
id: customActionCallback,
|
|
651
|
+
columnIds,
|
|
652
|
+
event,
|
|
653
|
+
};
|
|
654
|
+
this.axisMenuActionHandler[customActionCallback](
|
|
655
|
+
customActionCallbackArgs,
|
|
656
|
+
);
|
|
657
|
+
return {
|
|
658
|
+
isValid: true,
|
|
659
|
+
};
|
|
660
|
+
} catch (error: unknown) {
|
|
661
|
+
console.log(
|
|
662
|
+
'AxisMenuCustomAction: payload recieved:',
|
|
663
|
+
payload,
|
|
664
|
+
'CustomActionCallbackStore:',
|
|
665
|
+
this.axisMenuActionHandler,
|
|
666
|
+
);
|
|
667
|
+
return {
|
|
668
|
+
isValid: false,
|
|
669
|
+
error,
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
);
|
|
674
|
+
|
|
434
675
|
// Register External Events
|
|
435
676
|
// These events are readable by the developer
|
|
436
677
|
|
|
@@ -501,6 +742,7 @@ export class CustomChartContext {
|
|
|
501
742
|
this.componentId = payload.componentId;
|
|
502
743
|
this.hostUrl = payload.hostUrl;
|
|
503
744
|
this.chartModel = payload.chartModel;
|
|
745
|
+
this.appConfig = payload.appConfig ?? {};
|
|
504
746
|
|
|
505
747
|
return this.publishChartContextPropsToHost();
|
|
506
748
|
};
|
|
@@ -534,7 +776,6 @@ export class CustomChartContext {
|
|
|
534
776
|
this.chartModel,
|
|
535
777
|
);
|
|
536
778
|
}
|
|
537
|
-
|
|
538
779
|
return {
|
|
539
780
|
isConfigValid: isValid,
|
|
540
781
|
defaultChartConfig,
|
|
@@ -13,7 +13,7 @@ describe('postMessageToHostApp', () => {
|
|
|
13
13
|
jest.resetAllMocks();
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
test('should resolve the promise with
|
|
16
|
+
test('should resolve the promise with data object when successful', async () => {
|
|
17
17
|
// Mock the necessary variables and functions
|
|
18
18
|
const componentId = '123';
|
|
19
19
|
const hostUrl = 'https://example.com';
|
|
@@ -39,7 +39,9 @@ describe('postMessageToHostApp', () => {
|
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
// Simulate a successful response
|
|
42
|
-
const response = {
|
|
42
|
+
const response = {
|
|
43
|
+
data: { hasError: false, randomData: 'randomString' },
|
|
44
|
+
};
|
|
43
45
|
if (_.isFunction(channel.port1.onmessage)) {
|
|
44
46
|
(channel.port1.onmessage as any)(response);
|
|
45
47
|
} else {
|
|
@@ -48,7 +50,7 @@ describe('postMessageToHostApp', () => {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
// Wait for the promise to resolve
|
|
51
|
-
await expect(promise).resolves.
|
|
53
|
+
await expect(promise).resolves.toEqual(response.data);
|
|
52
54
|
|
|
53
55
|
// Verify that the postMessage function was called with the correct
|
|
54
56
|
// arguments
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { CustomChartContextProps } from '../../main/custom-chart-context';
|
|
3
|
+
import { ColumnType } from '../../types/answer-column.types';
|
|
4
|
+
import { ChartConfig, ChartModel } from '../../types/common.types';
|
|
5
|
+
import { Query } from '../../types/ts-to-chart-event.types';
|
|
6
|
+
|
|
7
|
+
export const contextChartProps: CustomChartContextProps = {
|
|
8
|
+
getDefaultChartConfig: (chartModel: ChartModel): ChartConfig[] => {
|
|
9
|
+
const cols = chartModel.columns;
|
|
10
|
+
|
|
11
|
+
const measureColumns = _.filter(
|
|
12
|
+
cols,
|
|
13
|
+
(col) => col.type === ColumnType.MEASURE,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const attributeColumns = _.filter(
|
|
17
|
+
cols,
|
|
18
|
+
(col) => col.type === ColumnType.ATTRIBUTE,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const axisConfig: ChartConfig = {
|
|
22
|
+
key: 'column',
|
|
23
|
+
dimensions: [
|
|
24
|
+
{
|
|
25
|
+
key: 'x',
|
|
26
|
+
columns: [attributeColumns[0]],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: 'y',
|
|
30
|
+
columns: measureColumns.slice(0, 2),
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
return [axisConfig];
|
|
35
|
+
},
|
|
36
|
+
getQueriesFromChartConfig: (chartConfig: ChartConfig[]): Array<Query> => {
|
|
37
|
+
const queries = chartConfig.map(
|
|
38
|
+
(config: ChartConfig): Query =>
|
|
39
|
+
_.reduce(
|
|
40
|
+
config.dimensions,
|
|
41
|
+
(acc: Query, dimension) => ({
|
|
42
|
+
queryColumns: [
|
|
43
|
+
...acc.queryColumns,
|
|
44
|
+
...dimension.columns,
|
|
45
|
+
],
|
|
46
|
+
}),
|
|
47
|
+
{
|
|
48
|
+
queryColumns: [],
|
|
49
|
+
} as Query,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
return queries;
|
|
53
|
+
},
|
|
54
|
+
chartConfigEditorDefinition: [
|
|
55
|
+
{
|
|
56
|
+
key: 'column',
|
|
57
|
+
label: 'Custom Column',
|
|
58
|
+
descriptionText:
|
|
59
|
+
'X Axis can only have attributes, Y Axis can only have measures, Color can only have attributes. ' +
|
|
60
|
+
'Should have just 1 column in Y axis with colors columns.',
|
|
61
|
+
columnSections: [
|
|
62
|
+
{
|
|
63
|
+
key: 'x',
|
|
64
|
+
label: 'Custom X Axis',
|
|
65
|
+
allowAttributeColumns: true,
|
|
66
|
+
allowMeasureColumns: false,
|
|
67
|
+
allowTimeSeriesColumns: true,
|
|
68
|
+
maxColumnCount: 1,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: 'y',
|
|
72
|
+
label: 'Custom Y Axis',
|
|
73
|
+
allowAttributeColumns: false,
|
|
74
|
+
allowMeasureColumns: true,
|
|
75
|
+
allowTimeSeriesColumns: false,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
visualPropEditorDefinition: {
|
|
81
|
+
elements: [
|
|
82
|
+
{
|
|
83
|
+
key: 'color',
|
|
84
|
+
type: 'radio',
|
|
85
|
+
defaultValue: 'red',
|
|
86
|
+
values: ['red', 'green', 'yellow'],
|
|
87
|
+
label: 'Colors',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: 'section',
|
|
91
|
+
key: 'accordion',
|
|
92
|
+
label: 'Accordion',
|
|
93
|
+
children: [
|
|
94
|
+
{
|
|
95
|
+
key: 'Color2',
|
|
96
|
+
type: 'radio',
|
|
97
|
+
defaultValue: 'blue',
|
|
98
|
+
values: ['blue', 'white', 'red'],
|
|
99
|
+
label: 'Color2',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
key: 'datalabels',
|
|
103
|
+
type: 'toggle',
|
|
104
|
+
defaultValue: false,
|
|
105
|
+
label: 'Data Labels',
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
renderChart: (cx) => {
|
|
112
|
+
return Promise.resolve();
|
|
113
|
+
},
|
|
114
|
+
};
|