-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(sidebar): show repository context on pinned tasks #76471
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6bca0b5
feat(sidebar): show repository context on pinned tasks
haacked b3b7952
fix(sidebar): make TaskItem story timestamps deterministic under Mock…
haacked 7dce69e
chore(sidebar): use neutral fixtures in TaskItem story, add PR screen…
haacked f8501db
chore: drop the PR screenshot PNGs from the tree
haacked a07576d
refactor(sidebar): share the groupable-folder shape, drop the pinned-…
haacked 2a97d9b
chore(visual): update storybook baselines
posthog[bot] bda57f5
chore: add before/after screenshots for the PR description
haacked 69fa1ce
chore: drop the PR screenshot PNGs from the tree
haacked 3c421f6
fix(sidebar): tooltip the truncated context line, correct its label c…
haacked 1dba34a
chore(sidebar): remove redundant comments
charlesvien 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
116 changes: 116 additions & 0 deletions
116
products/desktop/packages/core/src/sidebar/taskContext.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,116 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| formatTaskContext, | ||
| type TaskContextFolder, | ||
| type TaskContextTask, | ||
| } from "./taskContext"; | ||
|
|
||
| const CODE_REPO = { | ||
| fullPath: "posthog/code", | ||
| name: "code", | ||
| organization: "PostHog", | ||
| }; | ||
|
|
||
| function task(overrides: Partial<TaskContextTask> = {}): TaskContextTask { | ||
| return { | ||
| repository: CODE_REPO, | ||
| workspaceMode: "local", | ||
| branchName: null, | ||
| linkedBranch: null, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| const mainClone: TaskContextFolder = { | ||
| name: "PostHog Desktop", | ||
| path: "/repos/code", | ||
| remoteUrl: "posthog/code", | ||
| mainRepoPath: null, | ||
| }; | ||
|
|
||
| describe("formatTaskContext", () => { | ||
| it.each<{ name: string; task: TaskContextTask; expected: string | null }>([ | ||
| { | ||
| name: "repository only when the task has no branch of its own", | ||
| task: task(), | ||
| expected: "code", | ||
| }, | ||
| { | ||
| name: "repository and linked branch", | ||
| task: task({ linkedBranch: "posthog-code/fix-login" }), | ||
| expected: "code · posthog-code/fix-login", | ||
| }, | ||
| { | ||
| name: "the worktree's checked-out branch when no branch is linked yet", | ||
| task: task({ workspaceMode: "worktree", branchName: "wt/parser" }), | ||
| expected: "code · wt/parser", | ||
| }, | ||
| { | ||
| name: "the linked branch in preference to the checked-out branch", | ||
| task: task({ | ||
| workspaceMode: "worktree", | ||
| branchName: "wt/parser", | ||
| linkedBranch: "posthog-code/parser", | ||
| }), | ||
| expected: "code · posthog-code/parser", | ||
| }, | ||
| { | ||
| name: "no branch for a local task sitting on the default branch", | ||
| task: task({ workspaceMode: "local", branchName: "main" }), | ||
| expected: "code", | ||
| }, | ||
| { | ||
| name: "repository only for a cloud task with no linked branch", | ||
| task: task({ workspaceMode: "cloud" }), | ||
| expected: "code", | ||
| }, | ||
| { | ||
| name: "the custom-images group name for image-builder tasks", | ||
| task: task({ repository: null, originProduct: "image_builder" }), | ||
| expected: "Custom images", | ||
| }, | ||
| { | ||
| name: "the branch alone when the task has no repository", | ||
| task: task({ repository: null, linkedBranch: "posthog-code/orphan" }), | ||
| expected: "posthog-code/orphan", | ||
| }, | ||
| { | ||
| name: "null when there is neither a repository nor a branch", | ||
| task: task({ repository: null }), | ||
| expected: null, | ||
| }, | ||
| ])("renders $name", ({ task: subject, expected }) => { | ||
| expect(formatTaskContext(subject)).toBe(expected); | ||
| }); | ||
|
|
||
| it("labels the repository with the registered folder's name", () => { | ||
| expect(formatTaskContext(task(), [mainClone])).toBe("PostHog Desktop"); | ||
| }); | ||
|
|
||
| it("labels a worktree task with its main checkout's folder name", () => { | ||
| const worktree: TaskContextFolder = { | ||
| name: "code-wt", | ||
| path: "/repos/code-wt", | ||
| remoteUrl: "posthog/code", | ||
| mainRepoPath: "/repos/code", | ||
| }; | ||
|
|
||
| expect( | ||
| formatTaskContext( | ||
| task({ workspaceMode: "worktree", branchName: "wt/parser" }), | ||
| [worktree, mainClone], | ||
| ), | ||
| ).toBe("PostHog Desktop · wt/parser"); | ||
| }); | ||
|
|
||
| it("falls back to the repository name when no folder is registered", () => { | ||
| const unrelated: TaskContextFolder = { | ||
| name: "posthog", | ||
| path: "/repos/posthog", | ||
| remoteUrl: "posthog/posthog", | ||
| mainRepoPath: null, | ||
| }; | ||
|
|
||
| expect(formatTaskContext(task(), [unrelated])).toBe("code"); | ||
| }); | ||
| }); |
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 @@ | ||
| import { | ||
| CUSTOM_IMAGES_GROUP_NAME, | ||
| findGroupFolder, | ||
| type GroupableFolder, | ||
| } from "./groupTasks"; | ||
| import type { TaskData } from "./sidebarData.types"; | ||
|
|
||
| export type TaskContextTask = Pick< | ||
| TaskData, | ||
| | "repository" | ||
| | "originProduct" | ||
| | "workspaceMode" | ||
| | "branchName" | ||
| | "linkedBranch" | ||
| >; | ||
|
|
||
| export interface TaskContextFolder extends GroupableFolder { | ||
| name: string; | ||
| } | ||
|
|
||
| function repositoryLabel( | ||
| task: TaskContextTask, | ||
| folders: TaskContextFolder[], | ||
| ): string | null { | ||
| if (task.originProduct === "image_builder") return CUSTOM_IMAGES_GROUP_NAME; | ||
| const repository = task.repository; | ||
| if (!repository) return null; | ||
| // The registered folder's name is what the group header shows. No collision | ||
| // prefix here: pinned tasks are partitioned out before groups are built. | ||
| return findGroupFolder(folders, repository.fullPath)?.name ?? repository.name; | ||
| } | ||
|
|
||
| function branchLabel(task: TaskContextTask): string | null { | ||
| // `linkedBranch` stays unset while a task sits on the repo's default branch, | ||
| // so rows never all repeat "· main". Worktrees fall back to their checkout. | ||
| if (task.linkedBranch) return task.linkedBranch; | ||
| return task.workspaceMode === "worktree" ? task.branchName : null; | ||
| } | ||
|
|
||
| /** | ||
| * `<repository> · <branch>` line for a row rendered outside its repository | ||
| * group (the pinned section), where no group header supplies the context. | ||
| */ | ||
| export function formatTaskContext( | ||
| task: TaskContextTask, | ||
| folders: TaskContextFolder[] = [], | ||
| ): string | null { | ||
| const repository = repositoryLabel(task, folders); | ||
| const branch = branchLabel(task); | ||
| if (repository && branch) return `${repository} · ${branch}`; | ||
| return repository ?? branch; | ||
| } |
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
Oops, something went wrong.
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.
🟦 Nice-to-have
I wonder if this should belong in a reusable hook