Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic AllowedConfiguration #30

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/custom-chart-context.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ describe('CustomChartContext', () => {
defaultChartConfig: undefined,
chartConfigEditorDefinition: undefined,
visualPropEditorDefinition: undefined,
allowedConfigurations: {
allowColumnNumberFormatting: false,
allowColumnConditionalFormatting: false,
},
});
expect(mockPostMessage).toHaveBeenCalled();
expect(mockPostMessageToHost).not.toHaveBeenCalled();
Expand Down
14 changes: 14 additions & 0 deletions src/main/custom-chart-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import _ from 'lodash';
import {

Check warning on line 10 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ./ts-to-chart-event.types:6
AxisMenuActionHandler,
ChartToTSEvent,
ChartToTSEventsPayloadMap,
Expand Down Expand Up @@ -47,6 +47,11 @@

let isInitialized = false;

export type AllowedConfigurations = {
allowColumnNumberFormatting: boolean;
allowColumnConditionalFormatting: boolean;
};

export type CustomChartContextProps = {
/**
* Generate the default axis configuration for rendering the chart on first load.
Expand Down Expand Up @@ -121,6 +126,9 @@
* @version SDK: 0.1 | ThoughtSpot:
*/
visualPropEditorDefinition?: VisualPropEditorDefinition;

// Whether user wants thoughtspot default number and conditional formatting
allowedConfigurations?: AllowedConfigurations;
};

/**
Expand All @@ -130,6 +138,10 @@
validateConfig: () => ({ isValid: true }),
validateVisualProps: () => ({ isValid: true }),
chartConfigEditorDefinition: undefined,
allowedConfigurations: {
allowColumnNumberFormatting: false,
allowColumnConditionalFormatting: false,
},
};

export class CustomChartContext {
Expand Down Expand Up @@ -244,7 +256,7 @@
* @version SDK: 0.1 | ThoughtSpot:
*/
public initialize = (): Promise<void> => {
console.log('Chart Context: initialization start');

Check warning on line 259 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
return this.hasInitializedPromise;
};

Expand Down Expand Up @@ -276,7 +288,7 @@
*/
public off<T extends keyof TSToChartEventsPayloadMap>(eventType: T): void {
if (_.isNil(this.eventListeners[eventType])) {
console.log('No event listener found to remove');

Check warning on line 291 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
this.eventListeners[eventType] = [];
return;
}
Expand Down Expand Up @@ -433,7 +445,7 @@
...eventPayload: ChartToTSEventsPayloadMap[T]
): Promise<any> {
if (!isInitialized) {
console.log(

Check warning on line 448 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'Chart Context: not initialized the context, something went wrong',
);
return Promise.reject(new Error('Context not initialized'));
Expand All @@ -456,7 +468,7 @@
*/
private registerEventProcessor = () => {
if (isInitialized) {
console.error(

Check warning on line 471 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'The context is already initialized. you cannot have multiple contexts',
);
throw new Error(ErrorType.MultipleContextsNotSupported);
Expand All @@ -476,7 +488,7 @@
return;
}

console.log(

Check warning on line 491 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'Chart Context: message received:',
event.data.eventType,
event.data,
Expand Down Expand Up @@ -619,7 +631,7 @@
isValid: true,
};
} catch (error: unknown) {
console.log(

Check warning on line 634 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'ContextMenuCustomAction: payload recieved:',
payload,
'CustomActionCallbackStore:',
Expand Down Expand Up @@ -662,7 +674,7 @@
isValid: true,
};
} catch (error: unknown) {
console.log(

Check warning on line 677 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'AxisMenuCustomAction: payload recieved:',
payload,
'CustomActionCallbackStore:',
Expand Down Expand Up @@ -787,6 +799,8 @@
this.chartContextProps.chartConfigEditorDefinition,
visualPropEditorDefinition:
this.chartContextProps.visualPropEditorDefinition,
allowedConfigurations:
this.chartContextProps.allowedConfigurations,
};
};

Expand Down Expand Up @@ -814,7 +828,7 @@
};
}

console.log(

Check warning on line 831 in src/main/custom-chart-context.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
'ChartContext: Response:',
event.data.eventType,
response,
Expand Down
7 changes: 7 additions & 0 deletions src/types/ts-to-chart-event.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AllowedConfigurations } from '../main/custom-chart-context';
import { ChartColumn } from './answer-column.types';
import { Point } from './chart-to-ts-event.types';
import {
Expand Down Expand Up @@ -191,6 +192,12 @@ export interface InitializeEventResponsePayload {
* @version SDK: 0.1 | ThoughtSpot:
*/
visualPropEditorDefinition?: VisualPropEditorDefinition;
/**
* Toggle native configurations supported by TS UI. Ex: column level number and conditional formatting.
*
* @version SDK: 0.1 | ThoughtSpot:
*/
allowedConfigurations?: AllowedConfigurations;
}

/**
Expand Down
Loading