Skip to content

Conversation

@ruchI9897
Copy link
Contributor

No description provided.

@ruchI9897 ruchI9897 requested a review from a team as a code owner December 10, 2025 05:17
@mnk-blr
Copy link
Collaborator

mnk-blr commented Dec 10, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ruchI9897, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing the robustness and clarity of the embedding SDK. It introduces a new validation mechanism for CSS margin values, specifically for lazy loading configurations, ensuring that only valid CSS strings are applied. This prevents potential UI issues arising from malformed margin inputs. Additionally, the PR improves the documentation for several EmbedEvent types, providing clearer guidance on how to subscribe to the start or end of specific actions, which will aid developers in more precise event handling.

Highlights

  • CSS Margin Validation Utility: A new utility function, isValidCssMargin, has been introduced to rigorously validate CSS margin string values, ensuring they adhere to expected formats like "10px" or "1em".
  • Lazy Loading Margin Enforcement: Implemented checks within AppEmbed and LiveboardEmbed to validate the lazyLoadingMargin configuration. If an invalid CSS margin string is provided, an error is logged, and the margin defaults to "0px" to prevent incorrect styling.
  • Improved Event Documentation: Clarifying comments have been added to several EmbedEvent types in src/types.ts, detailing the usage of start:true and end:true options for subscribing to the initiation or completion of various actions like saving, downloading, or deleting.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sonar-prod-ts
Copy link

sonar-prod-ts bot commented Dec 10, 2025

SonarQube Quality Gate

Quality Gate failed

Failed condition B Maintainability Rating on New Code (is worse than A)

See analysis details on SonarQube

Fix issues before they fail your Quality Gate with SonarLint SonarLint in your IDE.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces validation for the lazyLoadingMargin configuration option. My review focuses on improving the robustness of the new validation logic, addressing code duplication, and fixing several documentation errors in the type definitions. I've provided suggestions to make the CSS margin validation more comprehensive, refactor the duplicated validation logic for better maintainability, and correct misleading comments in src/types.ts.

Comment on lines +140 to +150
export const isValidCssMargin = (value: string): boolean => {
if (typeof value !== 'string' || value.trim() === '') {
return false;
}

// Check for CSS length values (e.g., "10px", "1em", "50%")
const cssLengthPattern = /^\d+(\.\d+)?(px|em|rem|%|vh|vw)$/i;
const parts = value.trim().split(/\s+/);

return parts.length <= 4 && parts.every(part => cssLengthPattern.test(part.trim()));
};
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The CSS margin validation can be improved to support negative values and unitless zero, which are valid in CSS. For example, margin: -10px and margin: 0 are both valid.

I've also removed a redundant empty line for better code style.

Suggested change
export const isValidCssMargin = (value: string): boolean => {
if (typeof value !== 'string' || value.trim() === '') {
return false;
}
// Check for CSS length values (e.g., "10px", "1em", "50%")
const cssLengthPattern = /^\d+(\.\d+)?(px|em|rem|%|vh|vw)$/i;
const parts = value.trim().split(/\s+/);
return parts.length <= 4 && parts.every(part => cssLengthPattern.test(part.trim()));
};
export const isValidCssMargin = (value: string): boolean => {
if (typeof value !== 'string' || value.trim() === '') {
return false;
}
// Check for CSS length values (e.g., "10px", "1em", "50%", "-10px").
// Also allows for unitless 0.
const cssLengthPattern = /^-?\d+(\.\d+)?(px|em|rem|%|vh|vw)$/i;
const parts = value.trim().split(/\s+/);
return parts.length <= 4 && parts.every(part => part === '0' || cssLengthPattern.test(part));
};

Comment on lines +764 to +770
if(typeof this.viewConfig.lazyLoadingMargin !== 'string' || !isValidCssMargin(this.viewConfig.lazyLoadingMargin)) {
console.error('lazyLoadingMargin must be a valid CSS margin string value (e.g., "10px"). Defaulting to "0px".');
params[Param.RootMarginForLazyLoad] = '0px';
}
else {
params[Param.RootMarginForLazyLoad] = this.viewConfig.lazyLoadingMargin;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This validation logic has a few areas for improvement:

  1. Logging on undefined: It currently logs an error to the console even when lazyLoadingMargin is not provided (i.e., undefined). It's better to only log an error when an invalid value is explicitly provided.
  2. Logging utility: The project uses a logger utility, which is already imported in this file. For consistency, logger.error should be used instead of console.error.
  3. Code Duplication: This same logic is duplicated in src/embed/liveboard.ts. Consider extracting it into a shared utility function in src/utils.ts to improve maintainability.

Here's a suggested refactoring that addresses these points.

                const { lazyLoadingMargin } = this.viewConfig;
                if (typeof lazyLoadingMargin === 'string' && isValidCssMargin(lazyLoadingMargin)) {
                    params[Param.RootMarginForLazyLoad] = lazyLoadingMargin;
                } else {
                    if (lazyLoadingMargin != null) {
                        logger.error('lazyLoadingMargin must be a valid CSS margin string value (e.g., "10px"). Defaulting to "0px".');
                    }
                    params[Param.RootMarginForLazyLoad] = '0px';
                }

Comment on lines 2300 to +2301
* Emitted when the Download as PDF action is triggered on an Answer
* Use start:true to subscribe to when download as PDF is initiated, or end:true to subscribe to when download as PDF is completed. Default is end:true.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment for DownloadAsPng seems to have been copied from another event. It incorrectly refers to 'PDF' instead of 'PNG'.

Suggested change
* Emitted when the Download as PDF action is triggered on an Answer
* Use start:true to subscribe to when download as PDF is initiated, or end:true to subscribe to when download as PDF is completed. Default is end:true.
* Emitted when the Download as PNG action is triggered on an Answer
* Use start:true to subscribe to when download as PNG is initiated, or end:true to subscribe to when download as PNG is completed. Default is end:true.

Comment on lines 2315 to +2316
* Emitted when the Download as CSV action is triggered on an Answer.
* Use start:true to subscribe to when download as CSV is initiated, or end:true to subscribe to when download as CSV is completed. Default is end:true.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment for DownloadAsPdf seems to have been copied from another event. It incorrectly refers to 'CSV' instead of 'PDF'.

Suggested change
* Emitted when the Download as CSV action is triggered on an Answer.
* Use start:true to subscribe to when download as CSV is initiated, or end:true to subscribe to when download as CSV is completed. Default is end:true.
* Emitted when the Download as PDF action is triggered on an Answer.
* Use start:true to subscribe to when download as PDF is initiated, or end:true to subscribe to when download as PDF is completed. Default is end:true.

Comment on lines 2330 to +2331
* Emitted when the Download as XLSX action is triggered on an Answer.
* Use start:true to subscribe to when download as XLSX is initiated, or end:true to subscribe to when download as XLSX is completed. Default is end:true.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment for DownloadAsCsv seems to have been copied from another event. It incorrectly refers to 'XLSX' instead of 'CSV'.

Suggested change
* Emitted when the Download as XLSX action is triggered on an Answer.
* Use start:true to subscribe to when download as XLSX is initiated, or end:true to subscribe to when download as XLSX is completed. Default is end:true.
* Emitted when the Download as CSV action is triggered on an Answer.
* Use start:true to subscribe to when download as CSV is initiated, or end:true to subscribe to when download as CSV is completed. Default is end:true.

Comment on lines 2512 to +2513
* Emitted when the user creates a copy of an Answer.
* Use start:true to subscribe to when copy and edit is initiated, or end:true to subscribe to when copy and edit is completed. Default is end:true.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment for SaveAsView seems to be incorrect. It describes creating a copy, which is likely intended for the CopyAEdit event. The comment should describe the 'Save as View' action.

Suggested change
* Emitted when the user creates a copy of an Answer.
* Use start:true to subscribe to when copy and edit is initiated, or end:true to subscribe to when copy and edit is completed. Default is end:true.
* Emitted when an Answer is saved as a View.
* Use start:true to subscribe to when save as view is initiated, or end:true to subscribe to when save as view is completed. Default is end:true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants