@thoughtspot/ts-chart-sdk 0.0.1-alpha.2 → 0.0.1-alpha.5

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.
Files changed (83) hide show
  1. package/cjs/index.d.ts +1 -0
  2. package/cjs/index.d.ts.map +1 -1
  3. package/cjs/index.js +1 -0
  4. package/cjs/index.js.map +1 -1
  5. package/cjs/main/custom-chart-context.d.ts +1 -0
  6. package/cjs/main/custom-chart-context.d.ts.map +1 -1
  7. package/cjs/main/custom-chart-context.js +8 -0
  8. package/cjs/main/custom-chart-context.js.map +1 -1
  9. package/cjs/main/custom-chart-context.spec.js +69 -0
  10. package/cjs/main/custom-chart-context.spec.js.map +1 -1
  11. package/cjs/react/mocks/custom-chart-context-mock.d.ts +3 -0
  12. package/cjs/react/mocks/custom-chart-context-mock.d.ts.map +1 -0
  13. package/cjs/react/mocks/custom-chart-context-mock.js +100 -0
  14. package/cjs/react/mocks/custom-chart-context-mock.js.map +1 -0
  15. package/cjs/react/use-custom-chart-context.d.ts +4 -0
  16. package/cjs/react/use-custom-chart-context.d.ts.map +1 -0
  17. package/cjs/react/use-custom-chart-context.js +95 -0
  18. package/cjs/react/use-custom-chart-context.js.map +1 -0
  19. package/cjs/react/use-custom-chart-context.spec.d.ts +2 -0
  20. package/cjs/react/use-custom-chart-context.spec.d.ts.map +1 -0
  21. package/cjs/react/use-custom-chart-context.spec.js +391 -0
  22. package/cjs/react/use-custom-chart-context.spec.js.map +1 -0
  23. package/cjs/react/use-custom-chart-context.util.d.ts +6 -0
  24. package/cjs/react/use-custom-chart-context.util.d.ts.map +1 -0
  25. package/cjs/react/use-custom-chart-context.util.js +60 -0
  26. package/cjs/react/use-custom-chart-context.util.js.map +1 -0
  27. package/cjs/react/use-custom-chart-types.d.ts +23 -0
  28. package/cjs/react/use-custom-chart-types.d.ts.map +1 -0
  29. package/cjs/react/use-custom-chart-types.js +3 -0
  30. package/cjs/react/use-custom-chart-types.js.map +1 -0
  31. package/cjs/types/chart-to-ts-event.types.d.ts +12 -4
  32. package/cjs/types/chart-to-ts-event.types.d.ts.map +1 -1
  33. package/cjs/types/chart-to-ts-event.types.js +2 -0
  34. package/cjs/types/chart-to-ts-event.types.js.map +1 -1
  35. package/cjs/types/visual-prop.types.d.ts +12 -0
  36. package/cjs/types/visual-prop.types.d.ts.map +1 -1
  37. package/lib/index.d.ts +1 -0
  38. package/lib/index.d.ts.map +1 -1
  39. package/lib/index.js +1 -0
  40. package/lib/index.js.map +1 -1
  41. package/lib/main/custom-chart-context.d.ts +1 -0
  42. package/lib/main/custom-chart-context.d.ts.map +1 -1
  43. package/lib/main/custom-chart-context.js +8 -0
  44. package/lib/main/custom-chart-context.js.map +1 -1
  45. package/lib/main/custom-chart-context.spec.js +69 -0
  46. package/lib/main/custom-chart-context.spec.js.map +1 -1
  47. package/lib/react/mocks/custom-chart-context-mock.d.ts +3 -0
  48. package/lib/react/mocks/custom-chart-context-mock.d.ts.map +1 -0
  49. package/lib/react/mocks/custom-chart-context-mock.js +94 -0
  50. package/lib/react/mocks/custom-chart-context-mock.js.map +1 -0
  51. package/lib/react/use-custom-chart-context.d.ts +4 -0
  52. package/lib/react/use-custom-chart-context.d.ts.map +1 -0
  53. package/lib/react/use-custom-chart-context.js +68 -0
  54. package/lib/react/use-custom-chart-context.js.map +1 -0
  55. package/lib/react/use-custom-chart-context.spec.d.ts +2 -0
  56. package/lib/react/use-custom-chart-context.spec.d.ts.map +1 -0
  57. package/lib/react/use-custom-chart-context.spec.js +363 -0
  58. package/lib/react/use-custom-chart-context.spec.js.map +1 -0
  59. package/lib/react/use-custom-chart-context.util.d.ts +6 -0
  60. package/lib/react/use-custom-chart-context.util.d.ts.map +1 -0
  61. package/lib/react/use-custom-chart-context.util.js +51 -0
  62. package/lib/react/use-custom-chart-context.util.js.map +1 -0
  63. package/lib/react/use-custom-chart-types.d.ts +23 -0
  64. package/lib/react/use-custom-chart-types.d.ts.map +1 -0
  65. package/lib/react/use-custom-chart-types.js +2 -0
  66. package/lib/react/use-custom-chart-types.js.map +1 -0
  67. package/lib/types/chart-to-ts-event.types.d.ts +12 -4
  68. package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
  69. package/lib/types/chart-to-ts-event.types.js +2 -0
  70. package/lib/types/chart-to-ts-event.types.js.map +1 -1
  71. package/lib/types/visual-prop.types.d.ts +12 -0
  72. package/lib/types/visual-prop.types.d.ts.map +1 -1
  73. package/package.json +8 -2
  74. package/src/index.ts +1 -0
  75. package/src/main/custom-chart-context.spec.ts +116 -0
  76. package/src/main/custom-chart-context.ts +15 -0
  77. package/src/react/mocks/custom-chart-context-mock.ts +114 -0
  78. package/src/react/use-custom-chart-context.spec.tsx +464 -0
  79. package/src/react/use-custom-chart-context.tsx +180 -0
  80. package/src/react/use-custom-chart-context.util.ts +101 -0
  81. package/src/react/use-custom-chart-types.ts +70 -0
  82. package/src/types/chart-to-ts-event.types.ts +47 -2
  83. package/src/types/visual-prop.types.ts +68 -0
@@ -0,0 +1,101 @@
1
+ import _ from 'lodash';
2
+ import { CustomChartContext } from '../main/custom-chart-context';
3
+ import {
4
+ ChartToTSEvent,
5
+ ChartToTSEventsPayloadMap,
6
+ } from '../types/chart-to-ts-event.types';
7
+ import {
8
+ TSToChartEvent,
9
+ TSToChartEventsPayloadMap,
10
+ } from '../types/ts-to-chart-event.types';
11
+ import {
12
+ ChartToTSEventEmitters,
13
+ TSToChartEventListener,
14
+ TSToChartEventOffListener,
15
+ } from './use-custom-chart-types';
16
+
17
+ /**
18
+ *
19
+ * @param ctx Custom Chart Context
20
+ * @returns List of event emitters
21
+ */
22
+ export const emitter = (ctx: CustomChartContext): ChartToTSEventEmitters => {
23
+ const validEvents = Object.keys(
24
+ ChartToTSEvent,
25
+ ) as (keyof ChartToTSEventsPayloadMap)[];
26
+ return validEvents.reduce((acc, eventKey) => {
27
+ const eventName = eventKey as keyof ChartToTSEventsPayloadMap;
28
+ const emitterKey = `emit${eventKey}` as keyof ChartToTSEventEmitters;
29
+
30
+ acc[emitterKey] = (
31
+ ...args: ChartToTSEventsPayloadMap[keyof ChartToTSEventsPayloadMap]
32
+ ): Promise<void> => {
33
+ if (!ctx || _.isEmpty(ctx)) {
34
+ console.log('Context is not initialized');
35
+ return Promise.reject(new Error('Context not initialized'));
36
+ }
37
+ return ctx.emitEvent(eventName, ...args);
38
+ };
39
+
40
+ return acc;
41
+ }, {} as ChartToTSEventEmitters);
42
+ };
43
+
44
+ /**
45
+ *
46
+ * @param ctx Custom Chart Context
47
+ * @returns List of event listeners
48
+ */
49
+ export const eventListener = (
50
+ ctx: CustomChartContext,
51
+ ): TSToChartEventListener => {
52
+ const validEvents = Object.keys(
53
+ TSToChartEvent,
54
+ ) as (keyof TSToChartEventsPayloadMap)[];
55
+ return validEvents.reduce((acc, eventKey) => {
56
+ const eventName = eventKey as keyof TSToChartEventsPayloadMap;
57
+ const emitterKey = `setOn${eventKey}` as keyof TSToChartEventListener;
58
+
59
+ acc[emitterKey] = (
60
+ callbackFn: TSToChartEventsPayloadMap[keyof TSToChartEventsPayloadMap],
61
+ ): Promise<void> => {
62
+ if (!ctx || _.isEmpty(ctx)) {
63
+ console.log('Context is not initialized');
64
+ return Promise.reject(new Error('Context not initialized'));
65
+ }
66
+ ctx.on(eventName, callbackFn);
67
+ return Promise.resolve();
68
+ };
69
+
70
+ return acc;
71
+ }, {} as TSToChartEventListener);
72
+ };
73
+
74
+ /**
75
+ *
76
+ * @param ctx Custom Chart Context
77
+ * @returns List of event listeners
78
+ */
79
+ export const eventOffListener = (
80
+ ctx: CustomChartContext,
81
+ ): TSToChartEventOffListener => {
82
+ const validEvents = Object.keys(
83
+ TSToChartEvent,
84
+ ) as (keyof TSToChartEventsPayloadMap)[];
85
+ return validEvents.reduce((acc, eventKey) => {
86
+ const eventName = eventKey as keyof TSToChartEventsPayloadMap;
87
+ const emitterKey =
88
+ `setOff${eventKey}` as keyof TSToChartEventOffListener;
89
+
90
+ acc[emitterKey] = (): Promise<void> => {
91
+ if (!ctx || _.isEmpty(ctx)) {
92
+ console.log('Context is not initialized');
93
+ return Promise.reject(new Error('Context not initialized'));
94
+ }
95
+ ctx.off(eventName);
96
+ return Promise.resolve();
97
+ };
98
+
99
+ return acc;
100
+ }, {} as TSToChartEventOffListener);
101
+ };
@@ -0,0 +1,70 @@
1
+ import React from 'react';
2
+ import { ChartToTSEventsPayloadMap } from '../types/chart-to-ts-event.types';
3
+ import { ChartModel } from '../types/common.types';
4
+ import { TSToChartEventsPayloadMap } from '../types/ts-to-chart-event.types';
5
+
6
+ /**
7
+ * For all events that we trigger from React Chart to TS Host,
8
+ * this enum provides the trigger functions for each event.
9
+ * All the trigger functions have a prefix of emit.
10
+ */
11
+ export type ChartToTSEventEmitters = {
12
+ [key in keyof ChartToTSEventsPayloadMap as `emit${Capitalize<key>}`]: (
13
+ ...args: ChartToTSEventsPayloadMap[key]
14
+ ) => Promise<void>;
15
+ };
16
+
17
+ /**
18
+ * For all events that we trigger from TS Host to React Chart,
19
+ * this enum provides the event listener on functions for each external event listener.
20
+ * All the event listener functions have a prefix of on.
21
+ */
22
+ export type TSToChartEventListener = {
23
+ [key in keyof TSToChartEventsPayloadMap as `setOn${Capitalize<key>}`]: (
24
+ args: TSToChartEventsPayloadMap[key],
25
+ ) => Promise<void>;
26
+ };
27
+
28
+ /**
29
+ * For all events that we trigger from TS Host to React Chart,
30
+ * this enum provides the event listener on functions for each external event listener.
31
+ * All the event listener functions have a prefix of on.
32
+ */
33
+ export type TSToChartEventOffListener = {
34
+ [key in keyof TSToChartEventsPayloadMap as `setOff${Capitalize<key>}`]: () => Promise<void>;
35
+ };
36
+
37
+ export interface TSChartContextProps {
38
+ /**
39
+ * Child App which renders chart
40
+ * wrapper is used to control rendering of child app
41
+ */
42
+ children: React.ReactNode;
43
+ }
44
+
45
+ export interface ChartContextProps
46
+ extends ChartToTSEventEmitters,
47
+ TSToChartEventListener,
48
+ TSToChartEventOffListener {
49
+ /**
50
+ * decides if the chart context is initialzed
51
+ */
52
+ hasInitialized: boolean;
53
+ /**
54
+ * chart model to be used by client having
55
+ * config, data and visual props
56
+ */
57
+ chartModel: ChartModel | undefined;
58
+ /**
59
+ * For destroying current chart context
60
+ * @returns void
61
+ */
62
+ destroy: () => void;
63
+ /**
64
+ * Parent component wrapped around chart app
65
+ * for controlling re-rendering of chart
66
+ * @param children
67
+ * @returns React.JSX.Element
68
+ */
69
+ TSChartContext: ({ children }: TSChartContextProps) => React.JSX.Element;
70
+ }
@@ -40,6 +40,16 @@ export enum ChartToTSEvent {
40
40
  * Fetch data for custom query
41
41
  */
42
42
  GetDataForQuery = 'GetDataForQuery',
43
+
44
+ /**
45
+ * Show Tooltip events
46
+ */
47
+ ShowToolTip = 'ShowToolTip',
48
+
49
+ /**
50
+ * Hide Tooltip events
51
+ */
52
+ HideToolTip = 'HideToolTip',
43
53
  }
44
54
 
45
55
  /**
@@ -104,13 +114,25 @@ export interface ChartToTSEventsPayloadMap {
104
114
  * @version SDK: 0.1 | ThoughtSpot:
105
115
  */
106
116
  [ChartToTSEvent.GetDataForQuery]: [GetDataForQueryEventPayload];
117
+ /**
118
+ * Trigger to update the visual props
119
+ *
120
+ * @version SDK: 0.0.1-alpha.4 | ThoughtSpot:
121
+ */
122
+ [ChartToTSEvent.ShowToolTip]: [ShowToolTipEventPayload];
123
+ /**
124
+ * Trigger to update the visual props
125
+ *
126
+ * @version SDK: 0.0.1-alpha.4 | ThoughtSpot:
127
+ */
128
+ [ChartToTSEvent.HideToolTip]: [];
107
129
  }
108
130
 
109
131
  /**
110
132
  *
111
133
  * @group Chart to ThoughtSpot Events
112
134
  */
113
- interface UpdateVisualPropsEventPayload {
135
+ export interface UpdateVisualPropsEventPayload {
114
136
  visualProps: VisualProps;
115
137
  }
116
138
 
@@ -173,10 +195,33 @@ export interface OpenContextMenuEventPayload {
173
195
  }
174
196
  // end - open context menu payload
175
197
 
198
+ /**
199
+ * Payload for the event triggered to show a tooltip
200
+ */
201
+ export interface ShowToolTipEventPayload {
202
+ /**
203
+ * The pointer event that triggered the tooltip display
204
+ * It includes the client's X and Y coordinates.
205
+ */
206
+ event: Pick<PointerEvent, 'clientX' | 'clientY'>;
207
+ /**
208
+ * Optional custom content to display in the tooltip.
209
+ */
210
+ customTooltipContent?: string[];
211
+ /**
212
+ * Information about the data point associated
213
+ * with the tooltip
214
+ * User can also include both point and customTooltipContent
215
+ * depending upon the requirement
216
+ */
217
+ point?: Point;
218
+ }
219
+ // end - tooltip payload
220
+
176
221
  /**
177
222
  * @group Chart to ThoughtSpot Events
178
223
  */
179
- interface RenderErrorEventPayload {
224
+ export interface RenderErrorEventPayload {
180
225
  hasError: boolean;
181
226
  error: any;
182
227
  }
@@ -8,6 +8,60 @@
8
8
  * Copyright: ThoughtSpot Inc. 2023
9
9
  */
10
10
 
11
+ /**
12
+ * Configuration for input validation rules
13
+ */
14
+ export interface InputValidation {
15
+ /**
16
+ * Determines if the input is required.
17
+ *
18
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
19
+ */
20
+ required: boolean;
21
+ /**
22
+ * Error message to display when input is required but not provided.
23
+ *
24
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
25
+ */
26
+ requiredError: string;
27
+ /**
28
+ * Regular expression pattern to validate the input against.
29
+ *
30
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
31
+ */
32
+ regex: string;
33
+ /**
34
+ * Error message to display when input doesn't match the regex pattern.
35
+ *
36
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
37
+ */
38
+ regexError: string;
39
+ /**
40
+ * Minimum length required for the input.
41
+ *
42
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
43
+ */
44
+ minLength: number;
45
+ /**
46
+ * Error message to display when input length is less than the required minimum.
47
+ *
48
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
49
+ */
50
+ minLengthError: string;
51
+ /**
52
+ * Range of values allowed for the input.
53
+ *
54
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
55
+ */
56
+ range: string;
57
+ /**
58
+ * Error message to display when input value is outside the allowed range.
59
+ *
60
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
61
+ */
62
+ rangeError: string;
63
+ }
64
+
11
65
  /**
12
66
  * Text Form Element for the visual props editor
13
67
  *
@@ -53,6 +107,12 @@ export interface TextInputFormDetail {
53
107
  * @version SDK: 0.1 | ThoughtSpot:
54
108
  */
55
109
  defaultValue?: string;
110
+ /**
111
+ * inputValidation config for input field
112
+ *
113
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
114
+ */
115
+ inputValidation?: InputValidation;
56
116
  }
57
117
 
58
118
  /**
@@ -206,6 +266,14 @@ export interface Section {
206
266
  * @version SDK: 0.1 | ThoughtSpot:
207
267
  */
208
268
  alignment?: 'row' | 'column';
269
+ /**
270
+ * Defines form layout in the view for the section.
271
+ * default will be 'accordion' for first section if nothing specified
272
+ * and will be 'none' for all nested section.
273
+ *
274
+ * @version SDK: 0.0.1-alpha.3 | ThoughtSpot:
275
+ */
276
+ layoutType?: 'accordion' | 'tab' | 'none';
209
277
  }
210
278
 
211
279
  /**