Repository navigation
ENG-2256 Implement new relation menu empty state #1491
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
Merged
trangdoan982
merged 3 commits into
main
from
eng-2256-implement-new-relation-menu-empty-state
Oct 2, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
apps/obsidian/src/components/canvas/utils/__tests__/menuPlacement.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { clampMenuCentre } from "~/components/canvas/utils/menuPlacement"; | ||
|
|
||
| const menu = { width: 160, height: 128 }; | ||
| const viewport = { width: 1000, height: 800 }; | ||
| const place = (x: number, y: number, flyoutWidth = 0) => | ||
| clampMenuCentre({ | ||
| anchor: { x, y }, | ||
| menu, | ||
| flyoutWidth, | ||
| viewport, | ||
| margin: 8, | ||
| }); | ||
|
|
||
| describe("clampMenuCentre", () => { | ||
| it("keeps the anchor when the menu fits", () => { | ||
| expect(place(500, 400)).toEqual({ x: 500, y: 400 }); | ||
| }); | ||
|
|
||
| it("moves the menu inside the top and left edges", () => { | ||
| expect(place(10, 10)).toEqual({ x: 88, y: 72 }); | ||
| }); | ||
|
|
||
| it("moves the menu inside the bottom and right edges", () => { | ||
| expect(place(995, 795)).toEqual({ x: 912, y: 728 }); | ||
| }); | ||
|
|
||
| it("leaves room for an open flyout on the right", () => { | ||
| expect(place(900, 400, 132)).toEqual({ x: 780, y: 400 }); | ||
| }); | ||
|
|
||
| it("keeps the left edge visible when the menu is wider than the viewport", () => { | ||
| const narrow = clampMenuCentre({ | ||
| anchor: { x: 50, y: 400 }, | ||
| menu, | ||
| flyoutWidth: 132, | ||
| viewport: { width: 300, height: 800 }, | ||
| margin: 8, | ||
| }); | ||
| expect(narrow.x).toBe(88); | ||
| }); | ||
| }); |
52 changes: 52 additions & 0 deletions
52
apps/obsidian/src/components/canvas/utils/menuPlacement.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| type Point = { x: number; y: number }; | ||
| type Size = { width: number; height: number }; | ||
|
|
||
| const clampAxis = ({ | ||
| centre, | ||
| before, | ||
| after, | ||
| length, | ||
| margin, | ||
| }: { | ||
| centre: number; | ||
| before: number; | ||
| after: number; | ||
| length: number; | ||
| margin: number; | ||
| }): number => { | ||
| const min = margin + before; | ||
| const max = length - margin - after; | ||
| // Too big to fit: keep the start edge visible, where the header and + are. | ||
| if (max < min) return min; | ||
| return Math.min(Math.max(centre, min), max); | ||
| }; | ||
|
|
||
| /** Centre of a centred menu, moved just enough to keep it and a right-side flyout inside the viewport. */ | ||
| export const clampMenuCentre = ({ | ||
| anchor, | ||
| menu, | ||
| flyoutWidth, | ||
| viewport, | ||
| margin, | ||
| }: { | ||
| anchor: Point; | ||
| menu: Size; | ||
| flyoutWidth: number; | ||
| viewport: Size; | ||
| margin: number; | ||
| }): Point => ({ | ||
| x: clampAxis({ | ||
| centre: anchor.x, | ||
| before: menu.width / 2, | ||
| after: menu.width / 2 + flyoutWidth, | ||
| length: viewport.width, | ||
| margin, | ||
| }), | ||
| y: clampAxis({ | ||
| centre: anchor.y, | ||
| before: menu.height / 2, | ||
| after: menu.height / 2, | ||
| length: viewport.height, | ||
| margin, | ||
| }), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why can't we remove the arrow based on the action, whether you click away from the canvas or unfocus or something? Why do we have to catch it on the next canvas load?