Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { PullRequestStackMembership } from "@t3tools/contracts";
import { useGT } from "gt-react-native";
import { Pressable, View } from "react-native";

import { AppText as Text } from "../../components/ui/AppText";
import { SymbolView } from "../../components/ui/AppSymbol";
import { cn } from "../../lib/cn";
import { PullRequestGlyph } from "./pullRequestGlyphs";

/** Heads two or more PRs from one stack; tapping folds them. */
export function PullRequestStackHeaderRow(props: {
readonly membership: PullRequestStackMembership;
readonly shown: number;
readonly open: boolean;
readonly sidebar: boolean;
readonly onToggle: () => void;
/** Opens a PR in the stack, whose page lists every layer. */
readonly onShowAll: () => void;
}) {
const gt = useGT();
const muted = props.sidebar ? "text-drawer-foreground-muted" : "text-foreground-muted";
const tint = props.sidebar ? "accent-drawer-foreground-muted" : "accent-foreground-muted";
const hidden = props.membership.size - props.shown;
return (
<View
className={cn(
"flex-row items-center gap-2 pt-3 pb-1",
props.sidebar ? "bg-drawer px-3" : "px-4",
)}
>
<Pressable
accessibilityRole="button"
accessibilityState={{ expanded: props.open }}
accessibilityLabel={gt("Stack into {base}, {shown} of {size} here", {
base: props.membership.base,
shown: props.shown,
size: props.membership.size,
})}
onPress={props.onToggle}
className="min-w-0 flex-1 flex-row items-center gap-1.5"
>
<SymbolView
name={props.open ? "chevron.down" : "chevron.right"}
size={11}
tintColorClassName={tint}
/>
<SymbolView name={PullRequestGlyph.stack} size={13} tintColorClassName={tint} />
<Text className={cn("min-w-0 shrink text-xs font-medium", muted)} numberOfLines={1}>
{gt("Stack into {base}", { base: props.membership.base })}
</Text>
<Text className={cn("text-xs tabular-nums", muted)}>
{gt("{shown} of {size} here", { shown: props.shown, size: props.membership.size })}
</Text>
</Pressable>
{hidden > 0 ? (
<Pressable
accessibilityRole="button"
accessibilityLabel={gt("Show the {count} other layers of this stack", { count: hidden })}
onPress={props.onShowAll}
hitSlop={8}
>
<Text className={cn("text-xs tabular-nums", muted)}>
{gt("+{count} more", { count: hidden })}
</Text>
</Pressable>
) : null}
</View>
);
}
85 changes: 67 additions & 18 deletions apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { LegendList, type LegendListRef } from "@legendapp/list/react-native";
import { useNavigation } from "@react-navigation/native";
import { useGT } from "gt-react-native";
import { use, useMemo, useRef, useState, type ReactNode } from "react";
import { useAtomValue } from "@effect/atom-react";
import { useAtomSet, useAtomValue } from "@effect/atom-react";
import { AsyncResult } from "effect/reactivity";
import { Keyboard, Platform, Pressable, View } from "react-native";
import { RefreshControl } from "../../components/ui/RefreshControl";
import { NativeScrollView } from "../../native/NativeScrollViewMarker";
Expand All @@ -25,6 +26,15 @@ import { useWorkspaceState } from "../../state/workspace";
import { useProjects } from "../../state/entities";
import { environmentServerConfigsAtom } from "../../state/server";
import { PullRequestListRow } from "./PullRequestListRow";
import { PullRequestStackHeaderRow } from "./PullRequestStackHeaderRow";
import {
pullRequestListItemEntries,
pullRequestListItemKey,
pullRequestListItems,
pullRequestListItemsAreEqual,
type PullRequestListItem,
} from "./pullRequestStackItems";
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
import { liveReviewKey, useLiveReviews } from "./review/useLiveReviews";
import {
PullRequestListFilters,
Expand All @@ -40,7 +50,6 @@ import {
filterPullRequestList,
pullRequestListFacets,
pullRequestListInput,
pullRequestListRowsAreEqual,
scopedPullRequestListKey as pullRequestKey,
type EnvironmentPullRequestListEntry,
withoutScratchProjectScope,
Expand Down Expand Up @@ -103,6 +112,8 @@ export function PullRequestsScreen(
const workspace = useWorkspaceTabs()!;
const { environments } = useWorkspaceState();
const configs = useAtomValue(environmentServerConfigsAtom);
const preferencesResult = useAtomValue(mobilePreferencesAtom);
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
const insets = useSafeAreaInsets();
const contentTopInset = useContentTopInset();
// UIKit insets the list by its column's safe area, which this context can report as 0.
Expand Down Expand Up @@ -269,32 +280,70 @@ export function PullRequestsScreen(
labelColors,
}),
});
const renderPullRequest = ({ item }: { readonly item: EnvironmentPullRequestListEntry }) => (
<PullRequestListRow
item={item}
onSelect={selectPullRequest}
getActions={actions}
onAction={select}
busy={busyKey === pullRequestKey(item)}
selected={selectedKey === pullRequestKey(item)}
sidebar={sidebar}
reviewWaiting={reviewWaiting(item)}
/>
);
const collapsedStackList = AsyncResult.isSuccess(preferencesResult)
? (preferencesResult.value.pullRequestCollapsedStacks ?? [])
: [];
const listItems = pullRequestListItems(entries, new Set(collapsedStackList), selectedKey);
// Builds from the stored list, not this render's, like Home's folded projects.
const toggleStack = (stackKey: string) =>
savePreferences({
transform: (current) => {
const next = new Set(current.pullRequestCollapsedStacks ?? []);
if (!next.delete(stackKey)) next.add(stackKey);
return { pullRequestCollapsedStacks: [...next].slice(-200) };
},
});
const renderPullRequest = ({ item: row }: { readonly item: PullRequestListItem }) => {
if (row.kind === "stack") {
return (
<PullRequestStackHeaderRow
membership={row.membership}
shown={row.entries.length}
open={row.open}
sidebar={sidebar}
onToggle={() => toggleStack(row.key)}
onShowAll={() => selectPullRequest(row.entries[0]!)}
/>
);
}
const item = row.entry;
const pullRequestRow = (
<PullRequestListRow
item={item}
onSelect={selectPullRequest}
getActions={actions}
onAction={select}
busy={busyKey === pullRequestKey(item)}
selected={selectedKey === pullRequestKey(item)}
sidebar={sidebar}
reviewWaiting={reviewWaiting(item)}
/>
);
return row.nested ? <View className="ps-4">{pullRequestRow}</View> : pullRequestRow;
};
const list = (
<View className={sidebar ? "flex-1 bg-drawer" : "flex-1 bg-screen"}>
<LegendList
ref={listRef}
data={entries}
data={listItems}
extraData={`${selectedKey}:${busyKey}:${waitingKeys}`}
keyExtractor={pullRequestKey}
itemsAreEqual={pullRequestListRowsAreEqual}
keyExtractor={pullRequestListItemKey}
itemsAreEqual={pullRequestListItemsAreEqual}
estimatedItemSize={88}
drawDistance={1_000}
maintainVisibleContentPosition={result.continued ? maintainVisiblePosition : false}
onEndReached={() => void result.loadMore()}
onEndReachedThreshold={0.5}
onViewableItemsChanged={result.onViewableItemsChanged}
onViewableItemsChanged={({ viewableItems }) =>
result.onViewableItemsChanged({
viewableItems: viewableItems.flatMap((token) =>
pullRequestListItemEntries(token.item).map((item) => ({
item,
isViewable: token.isViewable,
})),
),
})
}
refreshControl={
<RefreshControl
refreshing={result.refreshing}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, expect, it } from "vite-plus/test";

import { scopedPullRequestListKey, type EnvironmentPullRequestListEntry } from "./pullRequestList";
import { pullRequestListItems } from "./pullRequestStackItems";

const entry = (number: number, position?: number) =>
({
environmentId: "env-1",
projectId: "project-1",
host: "github.com",
repository: "acme/app",
number,
...(position === undefined ? {} : { stack: { number: 7, position, size: 4, base: "main" } }),
}) as unknown as EnvironmentPullRequestListEntry;

const shape = (items: ReturnType<typeof pullRequestListItems>) =>
items.map((item) =>
item.kind === "stack"
? `stack:${item.open ? "open" : "folded"}`
: `${item.nested ? " " : ""}#${item.entry.number}`,
);

describe("pullRequestListItems", () => {
const entries = [entry(12, 2), entry(5), entry(11, 1)];
const stackKey = "env-1|github.com|acme/app|7";

it("puts a stack's PRs under one open header at the first one's spot", () => {
expect(shape(pullRequestListItems(entries, new Set(), undefined))).toEqual([
"stack:open",
" #11",
" #12",
"#5",
]);
});

it("keeps only the header of a folded stack", () => {
expect(shape(pullRequestListItems(entries, new Set([stackKey]), undefined))).toEqual([
"stack:folded",
"#5",
]);
});

it("opens a folded stack that holds the selected PR", () => {
const selected = scopedPullRequestListKey(entries[0]!);
expect(shape(pullRequestListItems(entries, new Set([stackKey]), selected))).toEqual([
"stack:open",
" #11",
" #12",
"#5",
]);
});
});
74 changes: 74 additions & 0 deletions apps/mobile/src/features/pull-requests/pullRequestStackItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { nestPullRequestStacks } from "@t3tools/client-runtime/pull-request-stack-nesting";
import type { PullRequestStackMembership } from "@t3tools/contracts";

import {
pullRequestListRowsAreEqual,
scopedPullRequestListKey,
type EnvironmentPullRequestListEntry,
} from "./pullRequestList";

/** One row of the PR list: a PR, or the header of two or more PRs from one stack. */
export type PullRequestListItem =
| {
readonly kind: "entry";
readonly entry: EnvironmentPullRequestListEntry;
/** Shown under a stack header. */
readonly nested: boolean;
}
| {
readonly kind: "stack";
readonly key: string;
readonly membership: PullRequestStackMembership;
/** Bottom layer first. */
readonly entries: ReadonlyArray<EnvironmentPullRequestListEntry>;
readonly open: boolean;
};

/** Flattens nested stacks for a flat list; a folded stack keeps only its header. */
export function pullRequestListItems(
entries: ReadonlyArray<EnvironmentPullRequestListEntry>,
collapsedStacks: ReadonlySet<string>,
selectedKey: string | null | undefined,
): ReadonlyArray<PullRequestListItem> {
return nestPullRequestStacks(entries).flatMap((row): PullRequestListItem[] => {
if (row.kind === "entry") return [{ kind: "entry", entry: row.entry, nested: false }];
// The selected PR never hides inside a folded stack.
const open =
!collapsedStacks.has(row.key) ||
row.entries.some((entry) => scopedPullRequestListKey(entry) === selectedKey);
return [
{ kind: "stack", key: row.key, membership: row.membership, entries: row.entries, open },
...(open
? row.entries.map((entry) => ({ kind: "entry" as const, entry, nested: true }))
: []),
];
});
}

export const pullRequestListItemKey = (item: PullRequestListItem) =>
item.kind === "stack" ? `stack:${item.key}` : scopedPullRequestListKey(item.entry);

export function pullRequestListItemsAreEqual(
previous: PullRequestListItem,
next: PullRequestListItem,
): boolean {
if (previous.kind === "entry" && next.kind === "entry") {
return (
previous.nested === next.nested && pullRequestListRowsAreEqual(previous.entry, next.entry)
);
}
if (previous.kind === "stack" && next.kind === "stack") {
return (
previous.key === next.key &&
previous.open === next.open &&
previous.membership.size === next.membership.size &&
previous.membership.base === next.membership.base &&
previous.entries.length === next.entries.length
);
}
return false;
}

/** The PRs a list row shows, for visibility tracking. */
export const pullRequestListItemEntries = (item: PullRequestListItem) =>
item.kind === "entry" ? [item.entry] : [];
5 changes: 5 additions & 0 deletions apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2912,6 +2912,11 @@
},
". Öffne eine Ebene, um sie zu prüfen oder den Stack bis zu dieser Ebene zu mergen."
],
"7bbdd8496e6dbd8a": "Stack into {base}, {shown} of {size} here",
"f003c65939c9c8f0": "Stack into {base}",
"0034f65ef4b6491d": "{shown} of {size} here",
"e31342b1da7c0627": "Show the {count} other layers of this stack",
"98515f1201b25dcc": "+{count} more",
"7d50c5c18ba726fa": "{term, select, mr {Status des Merge Requests, {status}} cr {Status der Änderungsanfrage, {status}} other {Status des Pull Requests, {status}}}",
"25019c947d3082dc": "{term, select, mr {Status des Merge Requests} cr {Status der Änderungsanfrage} other {Status des Pull Requests}}",
"cdfe7771384370e8": "{term, select, mr {Einen neuen Merge Request öffnen, der diese Änderungen rückgängig macht?} cr {Eine neue Änderungsanfrage öffnen, die diese Änderungen rückgängig macht?} other {Einen neuen Pull Request öffnen, der diese Änderungen rückgängig macht?}}",
Expand Down
5 changes: 5 additions & 0 deletions apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,11 @@
},
". Open a layer to review it or merge the stack through that layer."
],
"7bbdd8496e6dbd8a": "Stack into {base}, {shown} of {size} here",
"f003c65939c9c8f0": "Stack into {base}",
"0034f65ef4b6491d": "{shown} of {size} here",
"e31342b1da7c0627": "Show the {count} other layers of this stack",
"98515f1201b25dcc": "+{count} more",
"7d50c5c18ba726fa": "{term, select, mr {Merge request} cr {Change request} other {Pull request}} status, {status}",
"25019c947d3082dc": "{term, select, mr {Merge request} cr {Change request} other {Pull request}} status",
"cdfe7771384370e8": "Open a new {term, select, mr {merge request} cr {change request} other {pull request}} that reverses these changes?",
Expand Down
5 changes: 5 additions & 0 deletions apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,11 @@
},
". Abre una capa para revisarla o fusionar la pila hasta esa capa."
],
"7bbdd8496e6dbd8a": "Stack into {base}, {shown} of {size} here",
"f003c65939c9c8f0": "Stack into {base}",
"0034f65ef4b6491d": "{shown} of {size} here",
"e31342b1da7c0627": "Show the {count} other layers of this stack",
"98515f1201b25dcc": "+{count} more",
"7d50c5c18ba726fa": "Estado de la {term, select, mr {merge request} cr {solicitud de cambios} other {pull request}}, {status}",
"25019c947d3082dc": "Estado de la {term, select, mr {merge request} cr {solicitud de cambios} other {pull request}}",
"cdfe7771384370e8": "¿Abrir una {term, select, mr {merge request} cr {solicitud de cambios} other {pull request}} nueva que revierta estos cambios?",
Expand Down
5 changes: 5 additions & 0 deletions apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,11 @@
},
". Ouvrez une couche pour la relire ou fusionner la pile jusqu’à cette couche."
],
"7bbdd8496e6dbd8a": "Stack into {base}, {shown} of {size} here",
"f003c65939c9c8f0": "Stack into {base}",
"0034f65ef4b6491d": "{shown} of {size} here",
"e31342b1da7c0627": "Show the {count} other layers of this stack",
"98515f1201b25dcc": "+{count} more",
"7d50c5c18ba726fa": "Statut de la {term, select, mr {merge request} cr {demande de modification} other {pull request}}, {status}",
"25019c947d3082dc": "Statut de la {term, select, mr {merge request} cr {demande de modification} other {pull request}}",
"cdfe7771384370e8": "Ouvrir une nouvelle {term, select, mr {merge request} cr {demande de modification} other {pull request}} qui annule ces modifications ?",
Expand Down
5 changes: 5 additions & 0 deletions apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -2905,6 +2905,11 @@
},
"。レイヤーを開いてレビューするか、そのレイヤーまでスタックをマージしてください。"
],
"7bbdd8496e6dbd8a": "Stack into {base}, {shown} of {size} here",
"f003c65939c9c8f0": "Stack into {base}",
"0034f65ef4b6491d": "{shown} of {size} here",
"e31342b1da7c0627": "Show the {count} other layers of this stack",
"98515f1201b25dcc": "+{count} more",
"7d50c5c18ba726fa": "{term, select, mr {マージリクエストのステータス、{status}} cr {変更リクエストのステータス、{status}} other {プルリクエストのステータス、{status}}}",
"25019c947d3082dc": "{term, select, mr {マージリクエストのステータス} cr {変更リクエストのステータス} other {プルリクエストのステータス}}",
"cdfe7771384370e8": "{term, select, mr {これらの変更を元に戻す新しいマージリクエストを開きますか?} cr {これらの変更を元に戻す新しい変更リクエストを開きますか?} other {これらの変更を元に戻す新しいプルリクエストを開きますか?}}",
Expand Down
5 changes: 5 additions & 0 deletions apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -2909,6 +2909,11 @@
},
". 레이어를 열어 검토하거나 해당 레이어까지 스택을 병합하세요."
],
"7bbdd8496e6dbd8a": "Stack into {base}, {shown} of {size} here",
"f003c65939c9c8f0": "Stack into {base}",
"0034f65ef4b6491d": "{shown} of {size} here",
"e31342b1da7c0627": "Show the {count} other layers of this stack",
"98515f1201b25dcc": "+{count} more",
"7d50c5c18ba726fa": "{term, select, mr {병합 요청} cr {변경 요청} other {풀 리퀘스트}} 상태, {status}",
"25019c947d3082dc": "{term, select, mr {병합 요청} cr {변경 요청} other {풀 리퀘스트}} 상태",
"cdfe7771384370e8": "이 변경 사항을 되돌리는 새 {term, select, mr {병합 요청을} cr {변경 요청을} other {풀 리퀘스트를}} 열까요?",
Expand Down
Loading
Loading