fix(sidebar): preselect clicked cloud repo when creating new task#2280
Draft
mcoll-posthog wants to merge 2 commits into
Draft
fix(sidebar): preselect clicked cloud repo when creating new task#2280mcoll-posthog wants to merge 2 commits into
mcoll-posthog wants to merge 2 commits into
Conversation
Clicking "+ new task" on a cloud-only repository row in the sidebar called navigateToTaskInput() with no arguments, so TaskInput fell back to lastUsedCloudRepository (the previously used repo) instead of the clicked one. Pass the group's repo id as initialCloudRepository when there is no local folder to pre-select the right repository. Generated-By: PostHog Code Task-Id: 0d29b421-c014-4392-adbc-fbc5b8da014e
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/features/sidebar/components/TaskListView.tsx:422-430
The `if/else` is superfluous — `navigateToTaskInput`'s parameter is already optional (`folderIdOrOptions?: string | TaskInputNavigationOptions`), so passing `undefined` is identical to calling it with no argument. This can be collapsed to a single call, satisfying the "no superfluous parts" simplicity rule.
```suggestion
navigateToTaskInput(
getNewTaskTarget({
groupFolderId,
groupId: group.id,
}),
);
```
### Issue 2 of 2
apps/code/src/renderer/features/sidebar/utils/getNewTaskTarget.test.ts:4-49
Five separate `it` blocks all drive the same function with different inputs and expected outputs — a textbook case for `it.each`. The team preference is to use parameterised tests in exactly this scenario.
```suggestion
describe("getNewTaskTarget", () => {
it.each([
{
name: "returns the folder id when the group has a matching local folder",
args: { groupFolderId: "folder-1", groupId: "posthog/code" },
expected: "folder-1",
},
{
name: "returns initialCloudRepository for a cloud-only group with no local folder",
args: { groupFolderId: undefined, groupId: "posthog/code" },
expected: { initialCloudRepository: "posthog/code" },
},
{
name: "returns undefined for the catch-all 'other' group with no folder id",
args: { groupFolderId: undefined, groupId: "other" },
expected: undefined,
},
{
name: "returns undefined when groupId is empty and no folder id is set",
args: { groupFolderId: undefined, groupId: "" },
expected: undefined,
},
{
name: "prefers the folder id even when groupId looks like a cloud repo",
args: { groupFolderId: "folder-7", groupId: "posthog/posthog" },
expected: "folder-7",
},
])("$name", ({ args, expected }) => {
expect(getNewTaskTarget(args)).toEqual(expected);
});
});
```
Reviews (1): Last reviewed commit: "fix(sidebar): preselect clicked cloud re..." | Re-trigger Greptile |
- Collapse superfluous if/else around navigateToTaskInput now that we pass the result of getNewTaskTarget through directly (the param is optional). - Convert the 5 getNewTaskTarget tests to a single it.each block to match the codebase's parameterised-test convention. Generated-By: PostHog Code Task-Id: 0d29b421-c014-4392-adbc-fbc5b8da014e
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
TaskListView.tsxcallednavigateToTaskInput()with no arguments for cloud-only groups (no matching local folder), soTaskInputfell back to the persistedlastUsedCloudRepository.getNewTaskTarget({ groupFolderId, groupId })and pass{ initialCloudRepository: group.id }when there's no local folder id.group.idis already the lowercase"org/repo"shapeTaskInputexpects.Approach (red/green TDD)
getNewTaskTarget.test.tscovering the cloud-only case (and folder-id,"other", empty-id, folder-precedence edges); failed at import (no module).TaskListView.tsx'sonNewTaskhandler, and exported the existingTaskInputNavigationOptionstype fromnavigationStore.tsfor reuse.Changes
apps/code/src/renderer/features/sidebar/utils/getNewTaskTarget.tsapps/code/src/renderer/features/sidebar/utils/getNewTaskTarget.test.ts(5 tests)apps/code/src/renderer/features/sidebar/components/TaskListView.tsxapps/code/src/renderer/stores/navigationStore.ts— exportTaskInputNavigationOptionsTest plan
pnpm --filter code test getNewTaskTarget→ 5/5 passpnpm --filter code test sidebar navigationStore→ 49/49 pass (no regressions in sidebar / navigation suites)lastUsedCloudRepository = A)Notes
pnpm typecheckis broken onmainfrom a pre-existing duplicateINBOX_VIEWEDkey inapps/code/src/shared/types/analytics.ts(introduced in f6a4c91). Unrelated to this PR.Generated-By: PostHog Code
Task-Id: 0d29b421-c014-4392-adbc-fbc5b8da014e