Skip to content

Commit ee36595

Browse files
committed
chore: merge main into issue-watch/26076
2 parents 56ecb81 + 1854e14 commit ee36595

25 files changed

Lines changed: 1418 additions & 150 deletions
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import { RegistryContext } from "@effect/atom-react";
2+
import {
3+
EnvironmentId,
4+
type PullRequestListInput,
5+
type PullRequestListResult,
6+
} from "@t3tools/contracts";
7+
import { AtomRegistry } from "effect/reactivity";
8+
import { act, useLayoutEffect } from "react";
9+
import { createRoot } from "react-dom/client";
10+
import { expect, it, vi } from "vite-plus/test";
11+
12+
const mocks = vi.hoisted(() => ({ failPage: false }));
13+
14+
vi.mock("../../connection/catalog", async () => {
15+
const { Atom } = await import("effect/reactivity");
16+
return {
17+
environmentCatalog: {
18+
sessionGenerationAtom: Atom.family((_environmentId: string) => Atom.make(0)),
19+
},
20+
};
21+
});
22+
23+
vi.mock("../../state/pull-requests", async () => {
24+
const { AsyncResult, Atom } = await import("effect/reactivity");
25+
const Effect = await import("effect/Effect");
26+
const page = (nextCursors: PullRequestListResult["nextCursors"]): PullRequestListResult => ({
27+
entries: [],
28+
nextCursors,
29+
truncated: false,
30+
viewers: {},
31+
providers: [],
32+
errors: [],
33+
});
34+
const list = Atom.family((key: string) => {
35+
const target: { environmentId: string; input: PullRequestListInput } = JSON.parse(key);
36+
const response = page(target.input.cursors ? {} : { "github.com org/repo": "next" });
37+
return Atom.make(
38+
Effect.suspend(() => {
39+
if (target.environmentId === "offline")
40+
return Effect.fail(new Error("Environment is not connected."));
41+
if (target.input.cursors && mocks.failPage) return Effect.fail(new Error("Page failed."));
42+
return Effect.succeed(response);
43+
}),
44+
);
45+
});
46+
const { pullRequestListHead } = await import("./pullRequestList");
47+
const pages = Atom.family((_key: string) =>
48+
Atom.make<ReturnType<typeof pullRequestListHead> | null>(null),
49+
);
50+
return {
51+
pullRequestListPagesKey: (target: unknown) => JSON.stringify(target),
52+
pullRequestListPagesFamily: pages,
53+
pullRequestListStatsFamily: Atom.family((_key: string) => Atom.make(new Map())),
54+
composerPullRequests: {
55+
list: (target: unknown) => list(JSON.stringify(target)),
56+
listStats: Atom.family(() => Atom.make(AsyncResult.success({ stats: [] }))),
57+
invalidate: {
58+
run: async () => AsyncResult.success({}),
59+
},
60+
},
61+
};
62+
});
63+
64+
import { usePullRequestList } from "./usePullRequestList";
65+
66+
function setup(ids: readonly string[]) {
67+
mocks.failPage = false;
68+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
69+
const registry = AtomRegistry.make();
70+
const targets = ids.map((id) => ({
71+
environmentId: EnvironmentId.make(id),
72+
input: { state: "open" as const },
73+
}));
74+
let latest: ReturnType<typeof usePullRequestList>;
75+
function Probe() {
76+
const result = usePullRequestList(targets);
77+
useLayoutEffect(() => {
78+
latest = result;
79+
});
80+
return null;
81+
}
82+
const root = createRoot(document.createElement("div"));
83+
act(() => {
84+
root.render(
85+
<RegistryContext.Provider value={registry}>
86+
<Probe />
87+
</RegistryContext.Provider>,
88+
);
89+
});
90+
return {
91+
get latest() {
92+
return latest;
93+
},
94+
[Symbol.dispose]() {
95+
act(() => root.unmount());
96+
registry.dispose();
97+
},
98+
};
99+
}
100+
101+
it("keeps a refresh failure in the source errors and allows healthy pagination", async () => {
102+
using probe = setup(["healthy", "offline"]);
103+
await act(async () => probe.latest.onRefresh());
104+
expect(probe.latest.data.errors.map((error) => error.message)).toEqual([
105+
"Environment is not connected.",
106+
]);
107+
expect(probe.latest.refreshing).toBe(false);
108+
expect(probe.latest.loadMoreError).toBeNull();
109+
110+
await act(async () => probe.latest.loadMore());
111+
expect(probe.latest.continued).toBe(true);
112+
expect(probe.latest.hasMore).toBe(false);
113+
expect(probe.latest.loadMoreError).toBeNull();
114+
});
115+
116+
it("keeps load-more failures retryable", async () => {
117+
using probe = setup(["healthy"]);
118+
await act(async () => probe.latest.onRefresh());
119+
mocks.failPage = true;
120+
await act(async () => probe.latest.loadMore());
121+
expect(probe.latest.loadMoreError).toBe("Page failed.");
122+
expect(probe.latest.hasMore).toBe(true);
123+
expect(probe.latest.continued).toBe(false);
124+
125+
mocks.failPage = false;
126+
await act(async () => probe.latest.loadMore(true));
127+
expect(probe.latest.loadMoreError).toBeNull();
128+
expect(probe.latest.hasMore).toBe(false);
129+
expect(probe.latest.continued).toBe(true);
130+
});

‎apps/mobile/src/features/pull-requests/usePullRequestList.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ export function usePullRequestList(targets: readonly ListTarget[]) {
162162
const refreshAtom = refreshLoadFamily(scopeKey);
163163
const page = useAtomValue(pageAtom);
164164
const refresh = useAtomValue(refreshAtom);
165-
// Starting one kind of load clears the other, so at most one holds an error.
166-
const loadError = settledError(refresh) ?? settledError(page);
165+
const loadError = settledError(page);
167166

168167
// A page or refresh asked for while an environment was unreachable fails at once, and its
169168
// error stops loading on scroll. Once it is back, ask for the page again; a refresh's error is
@@ -184,7 +183,7 @@ export function usePullRequestList(targets: readonly ListTarget[]) {
184183
const pageResult = registry.get(pageAtom);
185184
const refreshResult = registry.get(refreshAtom);
186185
if (pageResult.waiting || refreshResult.waiting) return;
187-
if (!retry && (settledError(refreshResult) ?? settledError(pageResult))) return;
186+
if (!retry && settledError(pageResult)) return;
188187
if (!continuations(registry, targets).length) return;
189188
registry.set(refreshAtom, Atom.Reset);
190189
registry.set(pageAtom, retry);

‎apps/mobile/src/features/workspace/WorkspaceRootScreen.android.tsx‎

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,64 +33,45 @@ export function WorkspaceRootScreen() {
3333
const floating = floatingTabsMetrics(enabled.length + 1, scale, fabSize, window.width);
3434
const context = {
3535
...workspace,
36-
bottomClearance: floatingTabsEnabled
37-
? insets.bottom +
38-
FLOATING_TABS.bottom +
39-
FLOATING_TABS.edge +
40-
Math.max(
41-
floating.height,
42-
workspace.state.selectedTab === "threads" ? floating.fabOffset + fabSize : 0,
43-
)
44-
: workspace.state.selectedTab === "threads"
45-
? fabClearance + 16
46-
: 16,
36+
bottomClearance: layout.usesSplitView
37+
? workspace.bottomClearance
38+
: floatingTabsEnabled
39+
? insets.bottom +
40+
FLOATING_TABS.bottom +
41+
FLOATING_TABS.edge +
42+
Math.max(
43+
floating.height,
44+
workspace.state.selectedTab === "threads" ? floating.fabOffset + fabSize : 0,
45+
)
46+
: workspace.state.selectedTab === "threads"
47+
? fabClearance + 16
48+
: 16,
4749
};
4850
const tab = workspace.state.selectedTab;
4951

50-
if (layout.usesSplitView) {
51-
if (enabled.length === 0) return <View className="flex-1 bg-screen" />;
52-
return (
53-
<WorkspaceTabPanes
54-
tabs={TABS}
55-
selected={tab}
56-
renderTab={(tab) =>
57-
tab === "threads" ? (
58-
<HomeRouteScreen />
59-
) : tab !== "pullRequests" ? (
60-
<WorkspaceExtraTab tab={tab} />
61-
) : (
62-
<>
63-
<NativeStackScreenOptions options={{ headerShown: false }} />
64-
<AndroidScreenHeader title="Pull requests" />
65-
<View className="flex-1 items-center justify-center px-10">
66-
<EmptyState
67-
title="Select a pull request"
68-
detail="Choose a pull request from the sidebar to review it."
69-
variant="plain"
70-
/>
71-
</View>
72-
</>
73-
)
74-
}
75-
/>
76-
);
77-
}
78-
7952
return (
8053
<WorkspaceTabsContext value={context}>
81-
<View className="flex-1 bg-header">
82-
<NativeStackScreenOptions options={{ headerShown: false }} />
54+
<View className={layout.usesSplitView ? "flex-1 bg-screen" : "flex-1 bg-header"}>
55+
{!layout.usesSplitView ? (
56+
<NativeStackScreenOptions options={{ headerShown: false }} />
57+
) : null}
8358
<SafeAreaInsetsContext
8459
value={
85-
floatingTabsEnabled
86-
? tab === "usage"
87-
? { ...insets, bottom: context.bottomClearance }
88-
: insets
89-
: { ...insets, bottom: 0 }
60+
layout.usesSplitView
61+
? insets
62+
: floatingTabsEnabled
63+
? tab === "usage"
64+
? { ...insets, bottom: context.bottomClearance }
65+
: insets
66+
: { ...insets, bottom: 0 }
9067
}
9168
>
9269
{enabled.length === 0 ? (
93-
<WorkspaceNoTabs />
70+
layout.usesSplitView ? (
71+
<View className="flex-1 bg-screen" />
72+
) : (
73+
<WorkspaceNoTabs />
74+
)
9475
) : (
9576
<WorkspaceTabPanes
9677
tabs={TABS}
@@ -100,6 +81,18 @@ export function WorkspaceRootScreen() {
10081
<HomeRouteScreen />
10182
) : tab !== "pullRequests" ? (
10283
<WorkspaceExtraTab tab={tab} />
84+
) : layout.usesSplitView ? (
85+
<>
86+
<NativeStackScreenOptions options={{ headerShown: false }} />
87+
<AndroidScreenHeader title="Pull requests" />
88+
<View className="flex-1 items-center justify-center px-10">
89+
<EmptyState
90+
title="Select a pull request"
91+
detail="Choose a pull request from the sidebar to review it."
92+
variant="plain"
93+
/>
94+
</View>
95+
</>
10396
) : (
10497
<PullRequestsScreen
10598
renderFrame={(filters, list) => (
@@ -114,7 +107,7 @@ export function WorkspaceRootScreen() {
114107
/>
115108
)}
116109
</SafeAreaInsetsContext>
117-
{floatingTabsEnabled ? (
110+
{layout.usesSplitView ? null : floatingTabsEnabled ? (
118111
<FloatingWorkspaceTabs fillWidth onNewThread={startNewTask} />
119112
) : (
120113
<AndroidWorkspaceNavigation onNewThread={startNewTask} />

‎apps/mobile/src/features/workspace/workspace-tabs-state.test.ts‎

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { describe, expect, it } from "vite-plus/test";
1+
import { describe, expect, it, vi } from "vite-plus/test";
2+
import { act, createElement, createContext, useState, type ReactNode } from "react";
3+
import { createRoot } from "react-dom/client";
4+
import { WorkspaceRootScreen } from "./WorkspaceRootScreen.android";
25
import {
36
initialWorkspaceTabsState,
47
workspaceTabsReducer,
@@ -161,3 +164,91 @@ describe("workspace root navigation", () => {
161164
expect(workspaceTabForNativeSlot(order, "removed")).toBeNull();
162165
});
163166
});
167+
168+
const mocks = vi.hoisted(() => ({ split: false, floating: false }));
169+
170+
vi.mock("../settings/appearance/AppearancePreferencesProvider", () => ({
171+
useAndroidFloatingTabs: () => mocks.floating,
172+
}));
173+
vi.mock("react-native", () => ({
174+
useWindowDimensions: () => ({ width: 400, height: 800 }),
175+
View: ({ children }: { children: ReactNode }) => createElement("div", null, children),
176+
}));
177+
vi.mock("react-native-safe-area-context", () => ({
178+
SafeAreaInsetsContext: createContext({ top: 0, right: 0, bottom: 24, left: 0 }),
179+
useSafeAreaInsets: () => ({ top: 0, right: 0, bottom: 24, left: 0 }),
180+
}));
181+
vi.mock("../layout/AdaptiveWorkspaceLayout", () => ({
182+
useAdaptiveWorkspaceLayout: () => ({
183+
layout: { usesSplitView: mocks.split },
184+
startNewTask: () => undefined,
185+
}),
186+
}));
187+
vi.mock("./navigation-tabs", () => ({
188+
useEnabledNavigationTabs: () => ["threads", "pullRequests", "usage"],
189+
}));
190+
vi.mock("./WorkspaceTabsContext", () => ({
191+
WorkspaceTabsContext: createContext(null),
192+
useWorkspaceTabs: () => ({ state: { selectedTab: "usage" } }),
193+
}));
194+
vi.mock("./WorkspaceExtraTab", () => ({
195+
WorkspaceExtraTab: function UsageProbe() {
196+
const [tab, setTab] = useState("Limits");
197+
return createElement("button", { onClick: () => setTab("Usage") }, tab);
198+
},
199+
}));
200+
vi.mock("../../native/StackHeader", () => ({ NativeStackScreenOptions: () => null }));
201+
vi.mock("../../components/ui/AndroidScreenHeader", () => ({ AndroidScreenHeader: () => null }));
202+
vi.mock("../../components/ui/EmptyState", () => ({ EmptyState: () => null }));
203+
vi.mock("../../components/ui/ScreenContent", () => ({
204+
ScreenContent: ({ children }: { children: ReactNode }) => createElement("div", null, children),
205+
}));
206+
vi.mock("../../components/ui/useAndroidControlSizing", () => ({
207+
useAndroidControlSizing: () => ({ fabClearance: 64, scale: 1, fabSize: 56 }),
208+
}));
209+
vi.mock("../home/HomeRouteScreen", () => ({ HomeRouteScreen: () => null }));
210+
vi.mock("../pull-requests/PullRequestFilterMenuContext", () => ({
211+
PullRequestFilterMenuProvider: ({ children }: { children: ReactNode }) =>
212+
createElement("div", null, children),
213+
}));
214+
vi.mock("../pull-requests/PullRequestsScreen", () => ({ PullRequestsScreen: () => null }));
215+
vi.mock("../pull-requests/PullRequestToolbar.android", () => ({ PullRequestToolbar: () => null }));
216+
vi.mock("./AndroidWorkspaceNavigation", () => ({
217+
AndroidWorkspaceNavigation: () => null,
218+
FloatingWorkspaceTabs: () => null,
219+
}));
220+
vi.mock("./WorkspaceNoTabs", () => ({ WorkspaceNoTabs: () => null }));
221+
222+
function setup(split: boolean, floating: boolean) {
223+
mocks.split = split;
224+
mocks.floating = floating;
225+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
226+
return { [Symbol.dispose]: () => vi.unstubAllGlobals() };
227+
}
228+
229+
it.each([
230+
[false, false],
231+
[true, false],
232+
[false, true],
233+
[true, true],
234+
])(
235+
"keeps the Usage page mounted through layout transitions (split: %s, floating: %s)",
236+
async (split, floating) => {
237+
using _actEnvironment = setup(split, floating);
238+
const container = document.createElement("div");
239+
const root = createRoot(container);
240+
using _root = { [Symbol.dispose]: () => act(() => root.unmount()) };
241+
await act(async () => root.render(createElement(WorkspaceRootScreen)));
242+
243+
const button = container.querySelector("button")!;
244+
await act(async () => button.click());
245+
expect(button.textContent).toBe("Usage");
246+
247+
for (const nextSplit of [!split, split, !split, split]) {
248+
mocks.split = nextSplit;
249+
await act(async () => root.render(createElement(WorkspaceRootScreen)));
250+
expect(container.querySelector("button")?.textContent).toBe("Usage");
251+
expect(container.querySelector("button")).toBe(button);
252+
}
253+
},
254+
);

0 commit comments

Comments
 (0)