-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat(YDBSyntaxHighlighter): separate component, load languages on demand #2004
Conversation
f44fbc9
to
6ca078b
Compare
} | ||
|
||
/** SyntaxHighlighter with just YQL for sync load */ | ||
export function YqlHighlighter({children, className}: YqlHighlighterProps) { |
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.
Previous YqlHighlighter
with little changes to render queries in tables and overview. The reason - we load a lot of other languages in YDBSyntaxHighlighter
, so it's loaded with lazy load. However, in tables lazy load works not very good, since there are may loaders and row height changes. So to make it lazy in tables we need first create some loader for queries - it should display query with proper size but without highlight
withCopy?: boolean; | ||
}; | ||
|
||
export function YDBSyntaxHighlighter({ |
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.
Named it YDBSyntaxHighlighter
to prevent names collision with SyntaxHighlighter
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
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.
I just don't like warnings
There is no proper types for this lib - there are any
types in DT
transparentBackground?: boolean; | ||
withCopy?: boolean; |
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.
Added these props to make component customisable
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.
PR Overview
This PR refactors syntax highlighting components to create a separate reusable YDBSyntaxHighlighter and update existing components to use the new highlighter. The changes include:
- Introducing new components for syntax highlighting (YDBSyntaxHighlighter, lazy-loaded variant, themes, and types).
- Refactoring file imports and selectors to align with the new naming convention.
- Removing legacy highlighter components and updating tests and UI components accordingly.
Reviewed Changes
File | Description |
---|---|
src/components/SyntaxHighlighter/YqlHighlighter.tsx | New synchronous highlighter component with updated CSS class names. |
src/components/SyntaxHighlighter/types.ts | Added 'yql' to the Language type definition. |
src/components/SyntaxHighlighter/i18n/index.ts | New i18n registration for syntax highlighter component. |
src/components/SyntaxHighlighter/YDBSyntaxHighlighter.tsx | Main highlighter component with lazy copy button support and multi-language registration. |
src/components/SyntaxHighlighter/shared.ts | Utility file for consistent CSS class name generation. |
src/components/SyntaxHighlighter/lazy.ts | Lazy-load helper for the new highlighter component. |
src/components/SyntaxHighlighter/themes.ts | Theme definitions and style hooks for syntax highlighter. |
src/components/ConnectToDB/ConnectToDBDialog.tsx | Updated to use the lazy-loaded YDBSyntaxHighlighter. |
tests/suites/tenant/queryHistory/models/QueriesHistoryTable.ts | Updated CSS selectors to match new highlighter component. |
src/containers/Tenant/Info/View/View.ts | Updated import location for YqlHighlighter. |
src/components/TruncatedQuery/TruncatedQuery.tsx | Updated import location for YqlHighlighter. |
src/containers/Tenant/Diagnostics/Overview/TransferInfo/TransferInfo.tsx | Updated import location for YqlHighlighter. |
src/components/SyntaxHighlighter/yql.ts | Removed legacy theme definitions in favor of centralized theming. |
src/containers/Tenant/Diagnostics/TopQueries/columns/columns.tsx | Updated import location for YqlHighlighter. |
src/components/YqlHighlighter/YqlHighlighter.tsx | Removed legacy YqlHighlighter component. |
src/components/ConnectToDB/ConnectToDBSyntaxHighlighter/lazy.ts | Removed legacy lazy loader for ConnectToDB highlighter. |
src/components/ConnectToDB/ConnectToDBSyntaxHighlighter/ConnectToDBSyntaxHighlighter.tsx | Removed legacy ConnectToDB syntax highlighter component. |
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
src/components/SyntaxHighlighter/YqlHighlighter.tsx:15
- [nitpick] The component is still named 'YqlHighlighter' while its styling is set with the BEM block 'ydb-syntax-highlighter', which might create confusion with the new YDBSyntaxHighlighter component. Consider renaming the component or adding documentation to clarify its specific role.
export function YqlHighlighter({children, className}: YqlHighlighterProps) {
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.
Could you please provide more detailed description of what is to be achieved with these changes?
I suppose that they are for some future changes (db connection highlighting or like that)?
Or the goal is fixing some performance issues?
ReactSyntaxHighlighter.registerLanguage('javascript', javascript); | ||
ReactSyntaxHighlighter.registerLanguage('php', php); | ||
ReactSyntaxHighlighter.registerLanguage('python', python); | ||
ReactSyntaxHighlighter.registerLanguage('yql', yql); |
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.
Maybe its possible to register needed language on demand inside components? Or its library requirement to register on top level?
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.
Updated component, now it registers languages on render
I want to use this component internally (with ydb-embedded-ui as a package), so I made it a components with some customization via props. These changes are not connected with any changes in this package |
React.useEffect(() => { | ||
async function registerLangAndUpdateKey() { | ||
await registerLanguage(language); | ||
setHighlighterKey(nanoid()); |
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.
Without component update syntax won't be highlighted
Stand: https://nda.ya.ru/t/TMvWvEJo7Cczh9
CI Results
Test Status:⚠️ FLAKY
📊 Full Report
Test Changes Summary ⏭️1
⏭️ Skipped Tests (1)
Bundle Size: 🔺
Current: 83.30 MB | Main: 80.81 MB
Diff: +2.49 MB (3.08%)
ℹ️ CI Information