Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 78 additions & 49 deletions apps/web/src/components/issue/IssuesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
type HeldIssuePage,
} from "@t3tools/client-runtime/issue-list";
import { issueTrackerDetailText } from "@t3tools/client-runtime/state/issue-trackers";
import { issueEntryKey } from "@t3tools/client-runtime/state/issues";
import { issueEntryKey, type MergedIssueList } from "@t3tools/client-runtime/state/issues";
import type { EnvironmentProject } from "@t3tools/client-runtime/state/models";
import type {
EnvironmentId,
IssueInvolvement,
Expand Down Expand Up @@ -80,6 +81,7 @@ import { SidebarInset } from "~/components/ui/sidebar";
import { isCommandPaletteOpen } from "~/commandPaletteBus";
import { isElectron } from "~/env";
import { useLiveRefresh } from "~/hooks/useLiveRefresh";
import { useStableCallback } from "~/hooks/useStableCallback";
import { resolveShortcutCommand, shortcutLabelForCommand } from "~/keybindings";
import { isTerminalFocused } from "~/lib/terminalFocus";
import { usePanelAnimationSettings, usePanelPresence } from "~/panelAnimations";
Expand Down Expand Up @@ -188,11 +190,75 @@ function hostOptionsFor(
];
}

// A change of selection should not rebuild the rows for the current list and filters.
function useIssueGroups({
answers,
chosenHost,
hidden,
query,
projects,
order,
}: {
answers: MergedIssueList["answers"];
chosenHost: string | undefined;
hidden: IssuesSearch["hideProjects"];
query: string;
projects: ReadonlyArray<EnvironmentProject>;
order: IssueListSort;
}) {
const [pages, setPages] = useState<ReadonlyMap<EnvironmentId, HeldIssuePage>>(new Map());
const held = holdIssuePages(answers, pages);
const hiddenProjects = issueProjectKeys(hidden);
// Rows grouped per tracker account, so a tracker that cannot be read says so where its rows
// would be, and each tracker's rows carry on from their own cursors.
// The server names every tracker so the menu can switch hosts, but reads only the chosen one.
// A server older than `excludeProjectIds` still answers for hidden projects.
const shown =
chosenHost || hiddenProjects.size > 0
? new Map(
[...held].map(([environmentId, page]) => [
environmentId,
{
...page,
entries: page.entries.filter(
(entry) =>
!hiddenProjects.has(
pullRequestProjectKey({ environmentId, id: entry.projectId }),
),
),
errors: page.errors.filter(
(error) =>
!hiddenProjects.has(
pullRequestProjectKey({ environmentId, id: error.projectId }),
),
),
answer: {
...page.answer,
scopes: page.answer.scopes?.filter(
(scope) =>
!hiddenProjects.has(
pullRequestProjectKey({ environmentId, id: scope.projectId }),
),
),
trackers: chosenHost
? page.answer.trackers.filter(
(tracker) => tracker.host.toLowerCase() === chosenHost,
)
: page.answer.trackers,
},
},
]),
)
: held;
const groups = groupIssues(shown, query, projects, order);
return { held, shown, groups, setPages };
}

export function IssuesPage() {
const gt = useGT();
const resolve = useMessages();
const navigate = useNavigate({ from: "/issues" });
const search = useSearch({ from: "/_chat/issues" });
const search = useSearch({ from: "/_chat/issues", structuralSharing: true });
const { environments } = useEnvironments();
const projects = useProjects();
const issuesSupported = useIssuesSupported();
Expand Down Expand Up @@ -241,8 +307,14 @@ export function IssuesPage() {
{ key: JSON.stringify(targets) },
);

const [pages, setPages] = useState<ReadonlyMap<EnvironmentId, HeldIssuePage>>(new Map());
const held = holdIssuePages(list.answers, pages);
const { held, shown, groups, setPages } = useIssueGroups({
answers: list.answers,
chosenHost: search.host?.toLowerCase(),
hidden: search.hideProjects,
query: debouncedQuery,
projects,
order: search.order ?? "updated",
});
const loadPage = useAtomCommand(issueEnvironment.listPage, { reportFailure: false });
const [loadingMore, setLoadingMore] = useState<string | null>(null);
// One tracker group's button carries on that tracker's scopes only.
Expand Down Expand Up @@ -275,49 +347,6 @@ export function IssuesPage() {
});
};

// Rows grouped per tracker account, so a tracker that cannot be read says so where its rows
// would be, and each tracker's rows carry on from their own cursors.
// The server names every tracker so the menu can switch hosts, but reads only the chosen one.
const chosenHost = search.host?.toLowerCase();
// A server older than `excludeProjectIds` still answers for hidden projects.
const shown =
chosenHost || hiddenProjects.size > 0
? new Map(
[...held].map(([environmentId, page]) => [
environmentId,
{
...page,
entries: page.entries.filter(
(entry) =>
!hiddenProjects.has(
pullRequestProjectKey({ environmentId, id: entry.projectId }),
),
),
errors: page.errors.filter(
(error) =>
!hiddenProjects.has(
pullRequestProjectKey({ environmentId, id: error.projectId }),
),
),
answer: {
...page.answer,
scopes: page.answer.scopes?.filter(
(scope) =>
!hiddenProjects.has(
pullRequestProjectKey({ environmentId, id: scope.projectId }),
),
),
trackers: chosenHost
? page.answer.trackers.filter(
(tracker) => tracker.host.toLowerCase() === chosenHost,
)
: page.answer.trackers,
},
},
]),
)
: held;
const groups = groupIssues(shown, debouncedQuery, projects, search.order ?? "updated");
const filterScopes = issueFilterScopes(
shown,
projects.filter((project) => !hiddenProjects.has(pullRequestProjectKey(project))),
Expand Down Expand Up @@ -418,7 +447,7 @@ export function IssuesPage() {
: clearedSelection,
);

const selectEntry = (entry: IssueRowTarget) => {
const selectEntry = useStableCallback((entry: IssueRowTarget) => {
if (rightPanelRef === null) return;
useRightPanelStore.getState().openIssue(rightPanelRef, entry);
updateSearch({
Expand All @@ -429,7 +458,7 @@ export function IssuesPage() {
scope: entry.scope,
key: entry.key,
});
};
});

// A link into the page names an issue before any row was pressed.
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- opens the URL-linked issue in the right panel store
Expand Down
Loading