Skip to content

Commit 715ecc0

Browse files
committed
refactor(web): move sidebar, pull request page and update pill fork code to fork files
ForkSidebar.tsx holds the owner filter menu, notice and group tabs of the sidebar header. usePullRequestOwnerFilter.ts holds the owner filter of the pull request page. ForkSidebarUpdate.tsx holds the fork changelog and the pingdotgg#192 hooks of the update pill. The thread card layout stays in SidebarThreadRow on purpose. Plan: _shared/fork-isolation-plan-2026-10-16.md, item 8.
1 parent c87a33d commit 715ecc0

7 files changed

Lines changed: 283 additions & 167 deletions

File tree

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,7 @@ import {
303303
import { SidebarContent, SidebarGroup, useSidebar } from "./ui/sidebar";
304304
import { SidebarChromeFooter, SidebarChromeHeader } from "./sidebar/SidebarChrome";
305305
import { SidebarHeaderIconButton, SidebarThreadHeader } from "./sidebar/SidebarThreadHeader";
306-
import { SidebarOwnerFilterMenu, SidebarOwnerFilterNotice } from "./sidebar/SidebarOwnerFilter";
307-
import { useSidebarOwnerFilter } from "./sidebar/useSidebarOwnerFilter";
308-
import { SidebarGroupTabs } from "./sidebar/SidebarGroupTabs";
309-
import { useSidebarGroups } from "./sidebar/useSidebarGroups";
306+
import * as ForkSidebar from "./sidebar/ForkSidebar";
310307
import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuShortcut, MenuTrigger } from "./ui/menu";
311308
import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
312309
import { MiddleTruncate } from "./ui/middle-truncate";
@@ -2417,22 +2414,13 @@ export default function Sidebar() {
24172414
projectGroupsRef.current = projectGroups;
24182415
// Fork: the owner filter shows only or hides the projects of the selected repository owners.
24192416
// The project scope offers only the projects that it shows.
2420-
const {
2421-
repositoryOwnerFiltersEnabled,
2422-
savedOwnerFilter,
2423-
ownerFilter,
2424-
ownerOptions,
2425-
ownerVisibleProjectKeys,
2426-
visibleProjectGroups,
2427-
ownerHiddenProjectCount,
2428-
ownerHiddenThreadsNeedingUser,
2429-
setOwnerFilter,
2430-
} = useSidebarOwnerFilter({
2417+
const owner = ForkSidebar.useSidebarOwnerFilter({
24312418
unsortedProjectGroups,
24322419
projectGroups,
24332420
projectGroupingSettings,
24342421
threads,
24352422
});
2423+
const { ownerFilter, ownerVisibleProjectKeys, visibleProjectGroups } = owner;
24362424
// Threads on non-primary environments (T3 Connect, hosted) resolve their
24372425
// provider entry from their own environment's config: default instance ids
24382426
// are driver slugs, so a flat map would collide across environments.
@@ -2648,7 +2636,7 @@ export default function Sidebar() {
26482636
const [threadSearchQuery, setThreadSearchQuery] = useState("");
26492637
const isSearchingThreads = threadSearchQuery.trim().length > 0;
26502638
// Fork: thread groups as tabs. The list shows the threads of the open tab.
2651-
const sidebarGroups = useSidebarGroups({
2639+
const sidebarGroups = ForkSidebar.useSidebarGroups({
26522640
threads,
26532641
ownerVisibleProjectKeys,
26542642
scopedProjectKeys,
@@ -4716,15 +4704,7 @@ export default function Sidebar() {
47164704
<SidebarThreadHeader
47174705
searchFieldRef={headerSearchRef}
47184706
hasProjects={projectGroups.length > 0}
4719-
ownerFilter={
4720-
repositoryOwnerFiltersEnabled ? (
4721-
<SidebarOwnerFilterMenu
4722-
options={ownerOptions}
4723-
filter={savedOwnerFilter}
4724-
onChange={setOwnerFilter}
4725-
/>
4726-
) : null
4727-
}
4707+
ownerFilter={<ForkSidebar.OwnerFilterMenu owner={owner} />}
47284708
projectScope={
47294709
<Combobox
47304710
items={projectScopeItems}
@@ -4867,27 +4847,18 @@ export default function Sidebar() {
48674847
activeSearchResultIndex={activeSearchResultIndex}
48684848
onClearSearch={clearThreadSearch}
48694849
/>
4870-
{ownerFilter !== null ? (
4871-
<SidebarOwnerFilterNotice
4872-
filter={savedOwnerFilter}
4873-
hiddenProjectCount={ownerHiddenProjectCount}
4874-
hiddenThreadsNeedingUser={ownerHiddenThreadsNeedingUser}
4875-
onChange={setOwnerFilter}
4876-
/>
4877-
) : null}
4878-
{sidebarGroups.enabled ? (
4879-
<SidebarGroupTabs
4880-
groups={sidebarGroups}
4881-
dragging={dragState !== null}
4882-
routeThreadKey={routeThreadKey}
4883-
projectFor={(thread) =>
4884-
projectByKey.get(`${thread.environmentId}:${thread.projectId}`) ?? null
4885-
}
4886-
onOpenThread={(thread) =>
4887-
navigateToThread(scopeThreadRef(thread.environmentId, thread.id))
4888-
}
4889-
/>
4890-
) : null}
4850+
<ForkSidebar.HeaderFilterRows
4851+
owner={owner}
4852+
groups={sidebarGroups}
4853+
dragging={dragState !== null}
4854+
routeThreadKey={routeThreadKey}
4855+
projectFor={(thread) =>
4856+
projectByKey.get(`${thread.environmentId}:${thread.projectId}`) ?? null
4857+
}
4858+
onOpenThread={(thread) =>
4859+
navigateToThread(scopeThreadRef(thread.environmentId, thread.id))
4860+
}
4861+
/>
48914862
</SidebarGroup>
48924863
}
48934864
>

‎apps/web/src/components/pullRequest/pullRequestOwnerFilter.logic.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { FilterOperator } from "../filters/FilterChip";
1313
import { pullRequestProjectKey } from "./PullRequestListFilters";
1414

1515
/** Fork: the part of a project that the repository owner filter reads. */
16-
interface OwnedProject {
16+
export interface OwnedProject {
1717
readonly id: ProjectId;
1818
readonly environmentId: EnvironmentId;
1919
readonly repositoryIdentity?: RepositoryIdentity | null | undefined;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* Fork: the repository owner filter and filter chip parts of the pull request page
3+
* (`routes/_chat.pull-requests.tsx`). The route calls this module and keeps one line per hook.
4+
*/
5+
import type { ClientSettings, EnvironmentId, ProjectId } from "@t3tools/contracts";
6+
import { useMemo } from "react";
7+
8+
import type { FilterOperator } from "../filters/FilterChip";
9+
import type { PullRequestFilterChip } from "./pullRequestFilterChips.logic";
10+
import {
11+
MAX_PULL_REQUEST_LIST_OWNERS,
12+
type PullRequestListPreferencePatch,
13+
type PullRequestListPreferences,
14+
} from "./pullRequestListPreferences";
15+
import {
16+
type OwnedProject,
17+
type PullRequestOwnerFilter,
18+
projectsOfOwners,
19+
pullRequestMenuOwnerFilter,
20+
pullRequestOwnerRowFilter,
21+
} from "./pullRequestOwnerFilter.logic";
22+
23+
/** Owners are read like labels, then lowercased to match `repositoryOwnerOf`. */
24+
export function pullRequestSearchOwners(labels: {
25+
readonly labels?: ReadonlyArray<string>;
26+
}): Partial<Pick<PullRequestListPreferences, "owners">> {
27+
const owners = labels.labels
28+
?.map((owner) => owner.toLowerCase())
29+
.slice(0, MAX_PULL_REQUEST_LIST_OWNERS);
30+
return owners === undefined ? {} : { owners };
31+
}
32+
33+
export const selectRepositoryOwnerFilters = (settings: ClientSettings) =>
34+
settings.repositoryOwnerFilters;
35+
const NO_OWNERS: ReadonlyArray<string> = [];
36+
export const selectPullRequestFilterChips = (settings: ClientSettings) =>
37+
settings.pullRequestFilterChips;
38+
export const NO_FILTER_CHIPS: ReadonlyArray<PullRequestFilterChip> = [];
39+
40+
/** The search patch of an owner menu change. */
41+
export const ownerMenuPatch = (
42+
owners: ReadonlyArray<string>,
43+
operator: FilterOperator,
44+
): PullRequestListPreferencePatch => ({
45+
owners: owners.length === 0 ? undefined : owners,
46+
ownerOperator: operator === "is_not" ? operator : undefined,
47+
});
48+
49+
export function usePullRequestOwnerFilter<Project extends OwnedProject>(input: {
50+
/** The `repositoryOwnerFilters` setting. */
51+
readonly enabled: boolean;
52+
readonly search: Pick<PullRequestListPreferences, "owners" | "ownerOperator"> & {
53+
readonly projectId?: ProjectId | undefined;
54+
readonly environmentId?: EnvironmentId | undefined;
55+
};
56+
readonly projects: ReadonlyArray<Project>;
57+
/** The owners of the typed and of the sent search text. */
58+
readonly typedOwners: PullRequestOwnerFilter | undefined;
59+
readonly sentOwners: PullRequestOwnerFilter | undefined;
60+
}) {
61+
const { enabled, search, projects, typedOwners, sentOwners } = input;
62+
// The repository owners that narrow the list. A typed `org:` or `-org:` wins over the menu,
63+
// the same way the other typed qualifiers win. The request reads the sent text, and the rows
64+
// on screen read the typed text at once.
65+
const menuOwners = enabled ? (search.owners ?? NO_OWNERS) : NO_OWNERS;
66+
const menuOwnerOperator: FilterOperator = search.ownerOperator ?? "is";
67+
const menuOwnerFilter = useMemo(
68+
() => pullRequestMenuOwnerFilter(menuOwners, menuOwnerOperator),
69+
[menuOwnerOperator, menuOwners],
70+
);
71+
const requestOwners = sentOwners ?? menuOwnerFilter;
72+
const localOwners = typedOwners ?? menuOwnerFilter;
73+
// The projects that the list asks about. The project scope, the project menu and the
74+
// per-server split read these. The selection reads every project, because a link can open a
75+
// pull request from any owner.
76+
const listProjects = useMemo(
77+
() => projectsOfOwners(projects, requestOwners),
78+
[projects, requestOwners],
79+
);
80+
const keepRequestOwnerRow = useMemo(
81+
() => pullRequestOwnerRowFilter(projects, requestOwners),
82+
[projects, requestOwners],
83+
);
84+
const keepLocalOwnerRow = useMemo(
85+
() =>
86+
localOwners === requestOwners
87+
? keepRequestOwnerRow
88+
: pullRequestOwnerRowFilter(projects, localOwners),
89+
[keepRequestOwnerRow, localOwners, projects, requestOwners],
90+
);
91+
// An owner change that leaves the scoped project out drops the project scope too, the same
92+
// way picking another server does. The owner menu and the owner chip both pass here.
93+
const withOwnerScope = (
94+
patch: PullRequestListPreferencePatch,
95+
): PullRequestListPreferencePatch => {
96+
if (!("owners" in patch) && !("ownerOperator" in patch)) return patch;
97+
const owners = "owners" in patch ? (patch.owners ?? NO_OWNERS) : menuOwners;
98+
const operator = "ownerOperator" in patch ? (patch.ownerOperator ?? "is") : menuOwnerOperator;
99+
const kept = projectsOfOwners(projects, pullRequestMenuOwnerFilter(owners, operator));
100+
const keepsScope =
101+
search.projectId === undefined ||
102+
kept.some(
103+
(project) =>
104+
project.id === search.projectId &&
105+
(search.environmentId === undefined || project.environmentId === search.environmentId),
106+
);
107+
return keepsScope ? patch : { ...patch, projectId: undefined };
108+
};
109+
return {
110+
menuOwners,
111+
menuOwnerOperator,
112+
listProjects,
113+
keepRequestOwnerRow,
114+
keepLocalOwnerRow,
115+
withOwnerScope,
116+
};
117+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Fork parts of the sidebar thread list header (`Sidebar.tsx`): the repository owner filter and
3+
* the thread group tabs. The sidebar imports this module once and keeps one line per hook.
4+
*/
5+
import type { ComponentProps } from "react";
6+
7+
import { SidebarGroupTabs } from "./SidebarGroupTabs";
8+
import { SidebarOwnerFilterMenu, SidebarOwnerFilterNotice } from "./SidebarOwnerFilter";
9+
import type { useSidebarOwnerFilter } from "./useSidebarOwnerFilter";
10+
11+
export { useSidebarGroups } from "./useSidebarGroups";
12+
export { useSidebarOwnerFilter } from "./useSidebarOwnerFilter";
13+
14+
type OwnerFilterState = Pick<
15+
ReturnType<typeof useSidebarOwnerFilter>,
16+
| "repositoryOwnerFiltersEnabled"
17+
| "ownerOptions"
18+
| "savedOwnerFilter"
19+
| "ownerFilter"
20+
| "ownerHiddenProjectCount"
21+
| "ownerHiddenThreadsNeedingUser"
22+
| "setOwnerFilter"
23+
>;
24+
25+
/** The owner menu in the header, while `repositoryOwnerFilters` is on. */
26+
export function OwnerFilterMenu({ owner }: { readonly owner: OwnerFilterState }) {
27+
return owner.repositoryOwnerFiltersEnabled ? (
28+
<SidebarOwnerFilterMenu
29+
options={owner.ownerOptions}
30+
filter={owner.savedOwnerFilter}
31+
onChange={owner.setOwnerFilter}
32+
/>
33+
) : null;
34+
}
35+
36+
/** Below the header: the owner filter notice and the group tabs. */
37+
export function HeaderFilterRows({
38+
owner,
39+
...tabs
40+
}: { readonly owner: OwnerFilterState } & ComponentProps<typeof SidebarGroupTabs>) {
41+
return (
42+
<>
43+
{owner.ownerFilter !== null ? (
44+
<SidebarOwnerFilterNotice
45+
filter={owner.savedOwnerFilter}
46+
hiddenProjectCount={owner.ownerHiddenProjectCount}
47+
hiddenThreadsNeedingUser={owner.ownerHiddenThreadsNeedingUser}
48+
onChange={owner.setOwnerFilter}
49+
/>
50+
) : null}
51+
{tabs.groups.enabled ? <SidebarGroupTabs {...tabs} /> : null}
52+
</>
53+
);
54+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Fork parts of the sidebar update button (`SidebarUpdatePill.tsx`): the fork changelog in the
3+
* update popover, the idle install prompt and the newer-update check before install.
4+
*/
5+
import type { ClientSettings, DesktopUpdateState } from "@t3tools/contracts";
6+
import { useState } from "react";
7+
8+
import { useClientSettings } from "../../hooks/useSettings";
9+
import { ForkChangelogDialog } from "../forkChangelog/ForkChangelogDialog";
10+
import { ForkUpdateChanges } from "../forkChangelog/ForkUpdateChanges";
11+
import { Button } from "../ui/button";
12+
13+
export {
14+
openIdleInstallPromptIfAgentsRun,
15+
useIdleInstallArmed,
16+
} from "../desktop/DesktopUpdateIdleInstall";
17+
export { prepareNewestUpdateInstall } from "../desktop/DesktopUpdateNewerCheck";
18+
19+
const selectForkChangelogEnabled = (settings: ClientSettings) => settings.forkChangelogEnabled;
20+
21+
/** With the changelog on, the popover opens even when no update is available. */
22+
export function useForkChangelog() {
23+
const enabled = useClientSettings(selectForkChangelogEnabled);
24+
const [open, setOpen] = useState(false);
25+
return { enabled, open, setOpen };
26+
}
27+
type ForkChangelog = ReturnType<typeof useForkChangelog>;
28+
29+
/** The popover body while the fork changelog is on: the release changes and "Open changelog". */
30+
export function ForkUpdatePopoverChanges(props: {
31+
readonly changelog: ForkChangelog;
32+
readonly popover: { readonly close: () => void };
33+
readonly state: DesktopUpdateState;
34+
readonly tooltip: string;
35+
}) {
36+
return (
37+
<>
38+
<ForkUpdateChanges state={props.state} tooltip={props.tooltip} />
39+
<div className="mt-2 px-1">
40+
<Button
41+
size="xs"
42+
variant="outline"
43+
onClick={() => {
44+
props.popover.close();
45+
props.changelog.setOpen(true);
46+
}}
47+
>
48+
Open changelog
49+
</Button>
50+
</div>
51+
</>
52+
);
53+
}
54+
55+
export function ForkChangelogDialogHost({ changelog }: { readonly changelog: ForkChangelog }) {
56+
return changelog.enabled ? (
57+
<ForkChangelogDialog open={changelog.open} onOpenChange={changelog.setOpen} />
58+
) : null;
59+
}

0 commit comments

Comments
 (0)