-
Notifications
You must be signed in to change notification settings - Fork 8
[SCAL-284563] Added Margin value check #374
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
base: main
Are you sure you want to change the base?
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
|
SonarQube Quality Gate
See analysis details on SonarQube Fix issues before they fail your Quality Gate with |
There was a problem hiding this 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.
| 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())); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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)); | |
| }; |
| 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation logic has a few areas for improvement:
- Logging on undefined: It currently logs an error to the console even when
lazyLoadingMarginis not provided (i.e.,undefined). It's better to only log an error when an invalid value is explicitly provided. - Logging utility: The project uses a
loggerutility, which is already imported in this file. For consistency,logger.errorshould be used instead ofconsole.error. - Code Duplication: This same logic is duplicated in
src/embed/liveboard.ts. Consider extracting it into a shared utility function insrc/utils.tsto 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';
}| * 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment for DownloadAsPng seems to have been copied from another event. It incorrectly refers to 'PDF' instead of 'PNG'.
| * 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. |
| * 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment for DownloadAsPdf seems to have been copied from another event. It incorrectly refers to 'CSV' instead of 'PDF'.
| * 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. |
| * 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment for DownloadAsCsv seems to have been copied from another event. It incorrectly refers to 'XLSX' instead of 'CSV'.
| * 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. |
| * 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| * 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. |



No description provided.