Skip to content

Chore(UI): Improve relation traverse functionality in knowledge graph#27883

Open
aniketkatkar97 wants to merge 2 commits intomainfrom
knowledge-graph-improvements
Open

Chore(UI): Improve relation traverse functionality in knowledge graph#27883
aniketkatkar97 wants to merge 2 commits intomainfrom
knowledge-graph-improvements

Conversation

@aniketkatkar97
Copy link
Copy Markdown
Member

This pull request adds interactive edge tooltips and enhanced edge interaction handling to the Knowledge Graph component. Users can now hover over edges to see contextual information about relationships, and click edges to navigate between connected nodes. The changes include updates to the component logic, event handling, styles, and tests.

Edge interaction and tooltip enhancements:

  • Added a new EdgeTooltipState type and extended the GraphInteractionCtx to support edge tooltips and canvas references, enabling the display of contextual tooltips on edge hover. (KnowledgeGraph.interface.ts openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.interface.tsR64-R75)
  • Implemented logic in KnowledgeGraph.tsx to manage tooltip state and render a styled tooltip with relationship labels and direction when hovering over an edge. (KnowledgeGraph.tsx [1] [2]
  • Updated KnowledgeGraph.utils.ts to register new event handlers for edge:pointerover, edge:pointerleave, and edge:click, supporting tooltip display, edge/node highlighting, and navigation between connected nodes. (KnowledgeGraph.utils.ts [1] [2]
  • Improved event handling so that edge hover highlights both the edge and its endpoints, and clicking an edge focuses the unselected endpoint node. (KnowledgeGraph.utils.ts openmetadata-ui/src/main/resources/ui/src/utils/KnowledgeGraph.utils.tsR904-R1032)

Styling and accessibility:

Testing:

  • Expanded unit tests in KnowledgeGraph.utils.test.ts to cover edge hover, leave, and click events, verifying tooltip state, highlighting, and navigation behaviors. (KnowledgeGraph.utils.test.ts [1] [2] [3]

Other improvements:

@aniketkatkar97 aniketkatkar97 self-assigned this May 4, 2026
Copilot AI review requested due to automatic review settings May 4, 2026 10:06
@aniketkatkar97 aniketkatkar97 requested a review from a team as a code owner May 4, 2026 10:06
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs UI UI specific issues labels May 4, 2026
Comment on lines 76 to 79
for (let i = 0; i < type.length; i++) {
// codePointAt instead of charCodeAt to handle multi-byte Unicode (emoji, CJK)
hash = (hash * 31 + (type.codePointAt(i) ?? 0)) >>> 0;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Bug: codePointAt in index-based loop mishandles surrogate pairs

The comment on line 77 says codePointAt is used to handle multi-byte Unicode (emoji, CJK), but the loop still iterates with a simple i++ over type.length (which counts UTF-16 code units, not code points). For characters outside the BMP (e.g. emojis like 🔥 which occupy 2 code units), codePointAt(i) correctly returns the full code point on the high surrogate index, but on the next iteration (i+1) it processes the low surrogate separately, yielding a different hash than intended.

CJK characters are in the BMP so they work fine with either approach — the real impact is limited to emoji-containing type strings, which are likely rare. Still, the comment is misleading about what it fixes.

Use for...of to iterate by code point, or skip the low surrogate by advancing i when the code point is > 0xFFFF.

Suggested fix:

let hash = 0;
for (const ch of type) {
  hash = (hash * 31 + (ch.codePointAt(0) ?? 0)) >>> 0;
}

Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion

top: edgeTooltip.y + 12,
}}>
<div className="kg-edge-tooltip__direction">
{`${edgeTooltip.sourceLabel} → ${edgeTooltip.targetLabel}`}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: Hardcoded strings in edge tooltip instead of i18n

The edge tooltip in KnowledgeGraph.tsx line 747 uses a template literal with a hardcoded arrow character to display the direction. Per project conventions, user-visible strings should use the useTranslation hook. The character is fine as a symbol, but the overall pattern of constructing display strings inline (rather than through t()) may not align with the project's i18n requirements if localization of the direction label format is needed.

Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion

z-index: 1200;
pointer-events: none;
background: @white;
border: 1px solid rgba(0, 0, 0, 0.12);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: Hardcoded colors in tooltip styles violate theming guidelines

The new .kg-edge-tooltip styles in KnowledgeGraph.style.less use hardcoded rgba(0, 0, 0, ...) values for text colors, borders, and shadows (lines 128, 137, 145, 131). Per the project's frontend architecture guidelines, semantic CSS custom properties (--color-*, --shadow-*) should be used instead of hardcoded color values to ensure consistency with the theme system.

Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion

@gitar-bot
Copy link
Copy Markdown

gitar-bot Bot commented May 4, 2026

Code Review 👍 Approved with suggestions 0 resolved / 3 findings

Enhances Knowledge Graph edge interactions with hover-based tooltips and navigation functionality. Consider using i18n for tooltip labels, standardizing colors to follow theme guidelines, and ensuring proper iteration for surrogate pairs in the hash calculation.

💡 Bug: codePointAt in index-based loop mishandles surrogate pairs

📄 openmetadata-ui/src/main/resources/ui/src/utils/KnowledgeGraph.utils.ts:76-79

The comment on line 77 says codePointAt is used to handle multi-byte Unicode (emoji, CJK), but the loop still iterates with a simple i++ over type.length (which counts UTF-16 code units, not code points). For characters outside the BMP (e.g. emojis like 🔥 which occupy 2 code units), codePointAt(i) correctly returns the full code point on the high surrogate index, but on the next iteration (i+1) it processes the low surrogate separately, yielding a different hash than intended.

CJK characters are in the BMP so they work fine with either approach — the real impact is limited to emoji-containing type strings, which are likely rare. Still, the comment is misleading about what it fixes.

Use for...of to iterate by code point, or skip the low surrogate by advancing i when the code point is > 0xFFFF.

Suggested fix
let hash = 0;
for (const ch of type) {
  hash = (hash * 31 + (ch.codePointAt(0) ?? 0)) >>> 0;
}
💡 Quality: Hardcoded strings in edge tooltip instead of i18n

📄 openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.tsx:747

The edge tooltip in KnowledgeGraph.tsx line 747 uses a template literal with a hardcoded arrow character to display the direction. Per project conventions, user-visible strings should use the useTranslation hook. The character is fine as a symbol, but the overall pattern of constructing display strings inline (rather than through t()) may not align with the project's i18n requirements if localization of the direction label format is needed.

💡 Quality: Hardcoded colors in tooltip styles violate theming guidelines

📄 openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less:128 📄 openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less:131 📄 openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less:137 📄 openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less:145

The new .kg-edge-tooltip styles in KnowledgeGraph.style.less use hardcoded rgba(0, 0, 0, ...) values for text colors, borders, and shadows (lines 128, 137, 145, 131). Per the project's frontend architecture guidelines, semantic CSS custom properties (--color-*, --shadow-*) should be used instead of hardcoded color values to ensure consistency with the theme system.

🤖 Prompt for agents
Code Review: Enhances Knowledge Graph edge interactions with hover-based tooltips and navigation functionality. Consider using i18n for tooltip labels, standardizing colors to follow theme guidelines, and ensuring proper iteration for surrogate pairs in the hash calculation.

1. 💡 Bug: codePointAt in index-based loop mishandles surrogate pairs
   Files: openmetadata-ui/src/main/resources/ui/src/utils/KnowledgeGraph.utils.ts:76-79

   The comment on line 77 says `codePointAt` is used to handle multi-byte Unicode (emoji, CJK), but the loop still iterates with a simple `i++` over `type.length` (which counts UTF-16 code units, not code points). For characters outside the BMP (e.g. emojis like 🔥 which occupy 2 code units), `codePointAt(i)` correctly returns the full code point on the high surrogate index, but on the next iteration (`i+1`) it processes the low surrogate separately, yielding a different hash than intended.
   
   CJK characters are in the BMP so they work fine with either approach — the real impact is limited to emoji-containing type strings, which are likely rare. Still, the comment is misleading about what it fixes.
   
   Use `for...of` to iterate by code point, or skip the low surrogate by advancing `i` when the code point is > 0xFFFF.

   Suggested fix:
   let hash = 0;
   for (const ch of type) {
     hash = (hash * 31 + (ch.codePointAt(0) ?? 0)) >>> 0;
   }

2. 💡 Quality: Hardcoded strings in edge tooltip instead of i18n
   Files: openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.tsx:747

   The edge tooltip in KnowledgeGraph.tsx line 747 uses a template literal with a hardcoded `→` arrow character to display the direction. Per project conventions, user-visible strings should use the `useTranslation` hook. The `→` character is fine as a symbol, but the overall pattern of constructing display strings inline (rather than through `t()`) may not align with the project's i18n requirements if localization of the direction label format is needed.

3. 💡 Quality: Hardcoded colors in tooltip styles violate theming guidelines
   Files: openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less:128, openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less:131, openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less:137, openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less:145

   The new `.kg-edge-tooltip` styles in `KnowledgeGraph.style.less` use hardcoded `rgba(0, 0, 0, ...)` values for text colors, borders, and shadows (lines 128, 137, 145, 131). Per the project's frontend architecture guidelines, semantic CSS custom properties (`--color-*`, `--shadow-*`) should be used instead of hardcoded color values to ensure consistency with the theme system.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the Knowledge Graph UI interactions by adding edge hover tooltips (showing relationship context) and improving edge click behavior to traverse between connected nodes, alongside a couple of robustness tweaks (UUID suffix matching and Unicode-safe-ish hashing).

Changes:

  • Added edge hover/leave/click event handling in G6 to support edge tooltips, cursor changes, and endpoint highlighting.
  • Rendered a fixed-position edge tooltip UI and introduced supporting types/styles.
  • Expanded unit tests for the new edge interaction handlers.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
openmetadata-ui/src/main/resources/ui/src/utils/KnowledgeGraph.utils.ts Registers new edge event handlers, manages tooltip state, and tweaks hashing for Unicode.
openmetadata-ui/src/main/resources/ui/src/utils/KnowledgeGraph.utils.test.ts Adds coverage for edge hover/leave/click behaviors and updates handler count expectations.
openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.tsx Adds tooltip state, renders tooltip UI, and improves focus node ID matching.
openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.style.less Adds styling for the new edge tooltip.
openmetadata-ui/src/main/resources/ui/src/components/KnowledgeGraph/KnowledgeGraph.interface.ts Extends interaction context and introduces EdgeTooltipState.
openmetadata-ui/src/main/resources/ui/src/assets/svg/ic-schema.svg Updates the schema icon SVG asset.

Comment on lines 76 to 78
for (let i = 0; i < type.length; i++) {
// codePointAt instead of charCodeAt to handle multi-byte Unicode (emoji, CJK)
hash = (hash * 31 + (type.codePointAt(i) ?? 0)) >>> 0;
Comment on lines +917 to +919
const labels: string[] = Array.isArray(rawLabels)
? (rawLabels as string[])
: [String(edge.data?.['label'] ?? '')];
Comment on lines +1024 to +1030
: tgtId;

void graph.focusElement(farId, {
duration: ZOOM_DURATION_MS,
easing: ZOOM_EASING,
});
selectedNodeIdRef.current = farId;
top: edgeTooltip.y + 12,
}}>
<div className="kg-edge-tooltip__direction">
{`${edgeTooltip.sourceLabel} → ${edgeTooltip.targetLabel}`}
Comment on lines +749 to +750
{edgeTooltip.labels.map((label) => (
<div className="kg-edge-tooltip__label" key={label}>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 62%
62.46% (62983/100824) 42.79% (33959/79347) 45.79% (10045/21934)

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🟡 Playwright Results — all passed (14 flaky)

✅ 3984 passed · ❌ 0 failed · 🟡 14 flaky · ⏭️ 86 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 1 298 0 1 4
🟡 Shard 2 750 0 4 8
🟡 Shard 3 743 0 3 7
🟡 Shard 4 773 0 2 18
✅ Shard 5 687 0 0 41
🟡 Shard 6 733 0 4 8
🟡 14 flaky test(s) (passed on retry)
  • Pages/AuditLogs.spec.ts › should apply both User and EntityType filters simultaneously (shard 1, 1 retry)
  • Features/ActivityAPI.spec.ts › Activity event is created when description is updated (shard 2, 1 retry)
  • Features/ActivityAPI.spec.ts › Activity event shows the actor who made the change (shard 2, 1 retry)
  • Features/BulkImport.spec.ts › Database service (shard 2, 1 retry)
  • Features/Glossary/GlossaryWorkflow.spec.ts › should display correct status badge color and icon (shard 2, 1 retry)
  • Features/RTL.spec.ts › Verify Following widget functionality (shard 3, 1 retry)
  • Features/Table.spec.ts › Tags term should be consistent for search (shard 3, 1 retry)
  • Flow/AddRoleAndAssignToUser.spec.ts › Verify assigned role to new user (shard 3, 1 retry)
  • Pages/CustomProperties.spec.ts › Should clear search and show all properties for apiCollection in right panel (shard 4, 1 retry)
  • Pages/DataContractsSemanticRules.spec.ts › Validate Description Rule Is_Not_Set (shard 4, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • Pages/Lineage/LineageRightPanel.spec.ts › Verify custom properties tab IS visible for supported type: searchIndex (shard 6, 1 retry)
  • Pages/ODCSImportExport.spec.ts › Multi-object ODCS contract - object selector shows all schema objects (shard 6, 1 retry)
  • Pages/UserDetails.spec.ts › Create team with domain and verify visibility of inherited domain in user profile after team removal (shard 6, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

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

Labels

safe to test Add this label to run secure Github workflows on PRs UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants