Repository navigation
Expand file tree
/
Copy pathPullRequestStackCard.tsx
More file actions
88 lines (87 loc) · 3.37 KB
/
Copy pathPullRequestStackCard.tsx
File metadata and controls
88 lines (87 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { useState } from "react";
import { View } from "react-native";
import { useOpenWorkspaceDetail } from "../layout/useOpenWorkspaceDetail";
import { AppText as Text } from "../../components/ui/AppText";
import { PullRequestCardGroup, PullRequestCardRow } from "./PullRequestControls";
import { pullRequestLayerParams } from "./pullRequestStack";
import { pullRequestStatus } from "./pullRequestStatus";
import type { PullRequestParams } from "./usePullRequestDiff";
import type { PullRequestStackState } from "./usePullRequestStack";
import { PullRequestGlyph } from "./pullRequestGlyphs";
import { withKnownPullRequestSummary } from "../../state/use-thread-pr";
export function PullRequestStackCard(props: {
readonly params: PullRequestParams;
readonly state: PullRequestStackState;
}) {
const openDetail = useOpenWorkspaceDetail();
const [expanded, setExpanded] = useState(false);
const stack = props.state.stack;
if (!stack) {
const summary =
props.params.initialSummary?.number === props.params.number
? props.params.initialSummary.stack
: undefined;
if (!summary) return null;
return (
<PullRequestCardGroup>
<PullRequestCardRow
title="Stack"
icon={PullRequestGlyph.stack}
value={`${summary.position} of ${summary.size}`}
last
/>
</PullRequestCardGroup>
);
}
const position = stack.layers.findIndex((layer) => layer.number === props.params.number) + 1;
return (
<PullRequestCardGroup>
<PullRequestCardRow
title="Stack"
icon={PullRequestGlyph.stack}
value={`${position} of ${stack.layers.length}`}
accessibilityLabel={`Stack, ${position} of ${stack.layers.length}${props.state.isFresh ? "" : ", showing saved stack"}`}
expanded={expanded}
onPress={() => setExpanded(!expanded)}
last={!expanded}
/>
{expanded ? (
<View>
{stack.layers.map((layer, index) => {
const selected = layer.number === props.params.number;
const status = pullRequestStatus({
state: layer.state,
isDraft: layer.isDraft === true,
});
return (
<View key={layer.number} className={selected ? "bg-thread-selected" : undefined}>
<PullRequestCardRow
title={layer.title ?? layer.headBranch}
icon={status.icon}
tint={status.tint}
value={selected ? "Current" : status.label}
detail={`#${layer.number} · ${index + 1} of ${stack.layers.length}`}
onPress={
selected
? undefined
: () =>
openDetail({
name: "PullRequest",
params: withKnownPullRequestSummary(
pullRequestLayerParams(props.params, layer.number),
),
})
}
last={index === stack.layers.length - 1}
/>
</View>
);
})}
<Text className="px-4 py-3 text-xs text-foreground-muted">
Base: {stack.base}. Open a layer to review it or merge the stack through that layer.
</Text>
</View>
) : null}
</PullRequestCardGroup>
);
}