Skip to content
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: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@thoughtspot/visual-embed-sdk",
"version": "1.42.1",
"version": "1.42.2",
"description": "ThoughtSpot Embed SDK",
"module": "lib/src/index.js",
"main": "dist/tsembed.js",
Expand Down
2 changes: 2 additions & 0 deletions src/react/all-types-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ export {
resetCachedAuthToken,
UIPassthroughEvent,
DataPanelCustomColumnGroupsAccordionState,
CustomActionsPosition,
CustomActionTarget,
} from '../index';
22 changes: 22 additions & 0 deletions src/utils/custom-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,26 @@ describe('getCustomActions function', () => {
expect(result.errors[0]).toContain("Position 'PRIMARY' is not supported for spotter-level custom actions. Supported positions: MENU, CONTEXTMENU");
});
});

describe('Warnings', () => {
test('should warn when action name length exceeds 30 characters', () => {
// Arrange
const longName = 'A'.repeat(31);
const action: CustomAction = {
id: 'long-name-id',
name: longName,
target: CustomActionTarget.LIVEBOARD,
position: CustomActionsPosition.PRIMARY,
};

// Act
const result = getCustomActions([action]);

// Assert
expect(result.actions).toHaveLength(1);
expect(logger.warn).toHaveBeenCalledWith([
`Custom action name '${longName}' exceeds 30 characters. This may cause display or truncation issues in the UI.`
]);
});
Comment on lines +433 to +451

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and readability, it's best to avoid magic numbers. The numbers 31 and 30 should be extracted into a named constant. This makes the test's intent clearer and simplifies future updates if the length limit changes.

While this introduces some duplication with the implementation file, it's a good step. Ideally, this constant would be shared between the implementation and the test file.

        test('should warn when action name length exceeds 30 characters', () => {
            // Arrange
            const MAX_ACTION_NAME_LENGTH = 30;
            const longName = 'A'.repeat(MAX_ACTION_NAME_LENGTH + 1);
            const action: CustomAction = {
                id: 'long-name-id',
                name: longName,
                target: CustomActionTarget.LIVEBOARD,
                position: CustomActionsPosition.PRIMARY,
            };

            // Act
            const result = getCustomActions([action]);

            // Assert
            expect(result.actions).toHaveLength(1);
            expect(logger.warn).toHaveBeenCalledWith([
                `Custom action name '${longName}' exceeds ${MAX_ACTION_NAME_LENGTH} characters. This may cause display or truncation issues in the UI.`
            ]);
        });

});
});
11 changes: 11 additions & 0 deletions src/utils/custom-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CustomAction, CustomActionsPosition, CustomActionTarget } from '../type
import { arrayIncludesString } from '../utils';
import sortBy from 'lodash/sortBy';
import { CUSTOM_ACTIONS_ERROR_MESSAGE } from '../errors';
import { logger } from './logger';

export interface CustomActionsValidationResult {
actions: CustomAction[];
Expand Down Expand Up @@ -208,6 +209,16 @@ export const getCustomActions = (customActions: CustomAction[]): CustomActionsVa
}
});

// Step 4: Collect warnings for long custom action names
const MAX_ACTION_NAME_LENGTH = 30;
const warnings = finalValidActions
.filter(action => action.name.length > MAX_ACTION_NAME_LENGTH)
.map(action => `Custom action name '${action.name}' exceeds ${MAX_ACTION_NAME_LENGTH} characters. This may cause display or truncation issues in the UI.`);

if (warnings.length > 0) {
logger.warn(warnings);
}

const sortedActions = sortBy(finalValidActions, (a) => a.name.toLocaleLowerCase());

return {
Expand Down
Loading