-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr_bar.dart
More file actions
474 lines (443 loc) · 16.3 KB
/
Copy pathpr_bar.dart
File metadata and controls
474 lines (443 loc) · 16.3 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
import '../../app/theme.dart';
import '../../store/models.dart';
import '../../store/store.dart';
import '../../ui/widgets/icon_glyph.dart';
import '../../ui/widgets/pr_detail.dart';
import '../../ui/widgets/pr_signals.dart';
import '../../ui/widgets/pr_tone.dart';
import '../../ui/widgets/wrap_up.dart';
/// The sentence — dot, identity, loud fact. Keyed so a test can measure or read
/// *this* widget instead of `find.byType(Text).first`, which is whatever comes
/// first depth-first: the layout assertions here check a left bound and a minimum
/// gap, so a wrongly-picked `Text` would most likely still satisfy them and the
/// test would quietly stop guarding the invariant it exists for.
const Key kPrBarSentenceKey = ValueKey('pr-bar-sentence');
/// Tooltip on a stale bar. Names *why* the data is dimmed — a refresh that could
/// not complete against GitHub's quota — so the user can tell last-known data
/// from current data instead of guessing at the dimming.
const kStalePrTooltip =
'Last known state — could not refresh (GitHub quota). '
'Retrying automatically.';
/// The row directly above the docked composer: **one sentence about the
/// worktree, and the one action that moves it forward.**
///
/// `<dot> #142 · 2 checks failing +2 more [ Fix ▾ ]`
///
/// Replaces the old two-zone bar (a `PR #42` pill plus a general-purpose
/// six-prompt split button), whose two halves secretly depended on each other:
/// the pill's neighbouring chip is what set the button's default action, and
/// nothing on screen said so. Here the sentence *is* the reason for the button,
/// read left to right.
///
/// What it shows comes entirely from [PrStatus] — the shared derivation the
/// mobile row and sheet also read, so the three surfaces cannot disagree about
/// whether a PR is failing. This widget only decides how much of it fits: the
/// loud fact in full, the rest as a `+n more` disclosure onto [showPrDetail].
class PrComposerBar extends ConsumerWidget {
const PrComposerBar({
super.key,
required this.status,
required this.onInsertPrompt,
this.pr,
this.projectId,
this.worktreePath,
this.branch,
this.uncommittedFiles = 0,
});
/// The derived facts + the call to action. See [prStatusFor].
final PrStatus status;
/// The PR itself, for the detail sheet's check list and its web link. Null
/// when the worktree has none.
final PullRequest? pr;
/// Identity for the direct operations (wrap up / discard). When either is
/// null those actions are unavailable — there is nothing safe to act on.
final String? projectId;
final String? worktreePath;
/// The worktree's branch, for the confirm dialog's "delete the local branch"
/// step. Not derivable from [status] — its identity is the PR number by then.
final String? branch;
/// Files with uncommitted changes, for the confirm's data-loss warning. Passed
/// rather than parsed back out of a signal label.
final int uncommittedFiles;
/// Insert a resolved canned prompt into the composer (does not send).
final void Function(String prompt) onInsertPrompt;
@override
Widget build(BuildContext context, WidgetRef ref) {
// No padding of its own: it is handed to `Composer(header:)`, which owns the
// insets between the composer's box edge and its hairline.
return Row(
children: [
// The sentence group takes the row and keeps the free space *before* the
// button, so the CTA hugs the right edge instead of trailing the text
// wherever it happens to end (the mockup's `flex:1` spacer).
//
// Expanded + an inner Row, not `Flexible` + `Spacer`: two flex children
// in one Row would split the free space evenly, so the sentence would
// elide at half the width while the spacer sat on the rest. Here the
// non-flex `+n more` is measured first and `_Reason` gets what is left.
Expanded(
child: Row(
children: [
Flexible(
child: _Reason(
key: kPrBarSentenceKey,
status: status,
onOpen: () => _openDetail(context, ref),
),
),
if (status.more > 0) ...[
const SizedBox(width: kSpace8),
_MoreLink(
count: status.more,
onTap: () => _openDetail(context, ref),
),
],
],
),
),
const SizedBox(width: kSpace10),
PrCtaButton(
status: status,
// Home 1: the caret menu's "This worktree" group needs an identity to
// name; without one the group is simply absent.
projectId: projectId,
worktreePath: worktreePath,
onRun: (remedy) => _run(context, ref, remedy),
),
],
);
}
void _openDetail(BuildContext context, WidgetRef ref) => showPrDetail(
context,
status: status,
pr: pr,
// Identity, so the sheet re-derives rather than freezing its facts.
projectId: projectId,
worktreePath: worktreePath,
onRun: (remedy) => _run(context, ref, remedy),
);
Future<void> _run(
BuildContext context,
WidgetRef ref,
PrRemedy remedy,
) async {
// Re-derive from the snapshot at call time: the in-dialog "Lands in" picker
// can change the PR base (and the derived facts) while the dialog is open, so
// a remedy must act on today's target, not the build-time `status`/`pr`.
// Guard `context.mounted` first — the bar can be torn down by a snapshot and
// reading `ref` on a defunct element throws. Falls back to open-time values
// when the row is gone from the snapshot.
if (!context.mounted) return;
final at = ref.read(reposProvider).locateWorktree(worktreePath);
await runPrRemedy(
context,
ref,
remedy: remedy,
status: at == null ? status : prStatusFor(at),
pr: at == null ? pr : at.worktree.pr,
projectId: projectId,
worktreePath: worktreePath,
branch: at == null ? branch : at.worktree.branch,
uncommittedFiles: at == null
? uncommittedFiles
: at.worktree.uncommittedFiles,
onInsertPrompt: onInsertPrompt,
);
}
}
/// The sentence: a status dot, the PR number (or branch), and the loud fact.
/// Truncates with an ellipsis rather than growing the row — the composer's width
/// is not negotiable, and a bar that reflows as CI churns is worse than one that
/// elides.
class _Reason extends StatelessWidget {
const _Reason({super.key, required this.status, required this.onOpen});
final PrStatus status;
final VoidCallback onOpen;
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
// The label, not the dot: `kCheckFail`/`kCheckPending` are dot tokens that
// print at 3.2:1 and 2.4:1 on the light theme's surface.
final tone = prToneTextColor(cs, status.tone);
final base = Theme.of(context).textTheme.bodySmall ?? const TextStyle();
// Only the *derived* half dims when stale. The PR number never goes stale,
// so dimming it too (as the old pill did, wholesale) hid the one fact that
// was still reliable.
final dim = status.stale ? 0.55 : 1.0;
final sentence = Text.rich(
TextSpan(
children: [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsets.only(right: kSpace6),
child: PrToneDot(
tone: status.tone,
dot: status.dot,
progress: status.checkProgress,
),
),
),
TextSpan(
text: status.identity,
style: base.copyWith(
color: cs.onSurface,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: ' · ',
// Not `outlineVariant`: that is the hairline token, and at 1.07:1 on
// the composer's box the separator simply was not there. The mockup
// gives text separators their own mid-grey (§3).
style: base.copyWith(color: cs.outline.withValues(alpha: 0.55)),
),
TextSpan(
text: status.loud.label,
style: base.copyWith(color: tone.withValues(alpha: dim)),
),
if (status.stale)
TextSpan(
text: ' · last known',
style: base.copyWith(color: cs.outline, fontSize: 11),
),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
);
return Tooltip(
message: status.stale ? kStalePrTooltip : 'Show detail',
child: InkWell(
onTap: onOpen,
borderRadius: BorderRadius.circular(kRadius6),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: kSpace4,
vertical: kSpace2,
),
child: sentence,
),
),
);
}
}
/// `+2 more` — the disclosure onto the full fact list.
class _MoreLink extends StatelessWidget {
const _MoreLink({required this.count, required this.onTap});
final int count;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
return Tooltip(
message: 'Show the other $count',
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(kRadius6),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: kSpace4,
vertical: kSpace2,
),
child: Text(
'+$count more',
style: Theme.of(context).textTheme.labelXs?.copyWith(
color: cs.outline,
decoration: TextDecoration.underline,
decorationStyle: TextDecorationStyle.dotted,
// The label's own colour, not the hairline token: at 1.07:1 the
// underline was invisible, and it is the only thing on the row that
// says this text can be tapped.
decorationColor: cs.outline,
),
),
),
),
);
}
}
/// The call to action: the remedy for the loud fact, plus a caret onto the full
/// menu ([showPrActionMenu]).
///
/// Three visual registers, so "ask the agent to try" and "delete this worktree
/// now" can never be confused for each other:
/// * **idle** — nothing pressing: a quiet outline, and the main segment opens
/// the menu rather than pretending one of six prompts is the obvious step,
/// * **agent prompt** — tonal fill in the fact's tone; inserts text,
/// * **direct op** — solid fill; runs now (behind a confirm when destructive).
class PrCtaButton extends ConsumerWidget {
const PrCtaButton({
super.key,
required this.status,
required this.onRun,
this.projectId,
this.worktreePath,
});
final PrStatus status;
/// Identity for the menu's "Lands in" entry (Home 1). Optional: a surface with
/// no resolvable worktree just does not show the group.
final String? projectId;
final String? worktreePath;
/// Every action — prompt or direct — goes through here; [runPrRemedy] decides
/// what each one means. This widget deliberately knows nothing about composers.
final void Function(PrRemedy remedy) onRun;
@override
Widget build(BuildContext context, WidgetRef ref) {
final cs = Theme.of(context).colorScheme;
final cta = status.cta;
final tone = prToneTextColor(cs, cta.tone);
final remedy = cta.remedy;
final direct = remedy is DirectRemedy;
// A solid fill, and a muted one for the op that deletes things — see
// [prDirectCtaFill].
final fill = prDirectCtaFill(
cs,
cta.tone,
destructive: direct && remedy.op == PrDirectOp.discardWorktree,
);
final (Color bg, Color fg, Color? border) = switch (cta) {
PrCta(remedy: null) => (
Colors.transparent,
cs.onSurfaceVariant,
cs.outlineVariant,
),
_ when direct => (fill.bg, fill.fg, null),
_ => (
Color.alphaBlend(
prToneColor(cs, cta.tone).withValues(alpha: 0.18),
cs.surfaceContainerHigh,
),
tone,
null,
),
};
return MenuAnchor(
alignmentOffset: const Offset(0, 4),
menuChildren: buildPrActionMenu(
context,
ref,
status: status,
onRun: onRun,
projectId: projectId,
// Resolved from the snapshot rather than passed in, so the inline value is
// whatever the latest broadcast says.
worktree: ref
.watch(reposProvider)
.locateWorktree(worktreePath)
?.worktree,
),
builder: (context, controller, _) => _SplitButton(
label: cta.label,
icon: prRemedyIcon(remedy),
background: bg,
foreground: fg,
border: border,
menuOpen: controller.isOpen,
// Idle has no verb to run, so its main segment opens the menu too —
// otherwise it would be a button that does nothing.
onAction: remedy == null
? () => controller.isOpen ? controller.close() : controller.open()
: () => onRun(remedy),
onToggleMenu: () =>
controller.isOpen ? controller.close() : controller.open(),
),
);
}
}
/// A compact labelled split button: a leading action segment (icon + label) and
/// a trailing caret segment that toggles the menu, separated by a hairline.
/// Mirrors the M3 split-button idiom already used by `open_in_ide.dart`.
class _SplitButton extends StatelessWidget {
const _SplitButton({
required this.label,
required this.icon,
required this.background,
required this.foreground,
required this.border,
required this.menuOpen,
required this.onAction,
required this.onToggleMenu,
});
final String label;
final IconGlyph icon;
final Color background;
final Color foreground;
final Color? border;
final bool menuOpen;
final VoidCallback onAction;
final VoidCallback onToggleMenu;
static const double _height = 28;
@override
Widget build(BuildContext context) {
return Material(
color: background,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(kRadius8),
side: border == null ? BorderSide.none : BorderSide(color: border!),
),
clipBehavior: Clip.antiAlias,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Tooltip(
message: label,
child: InkWell(
onTap: onAction,
child: SizedBox(
height: _height,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: kSpace12),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
icon.build(size: 13, color: foreground),
const SizedBox(width: kSpace6),
Text(
label,
style: Theme.of(context).textTheme.labelXs?.copyWith(
color: foreground,
fontWeight: FontWeight.w700,
),
),
],
),
),
),
),
),
// A plain 1px box, not a VerticalDivider: that keeps the button out of
// VerticalDivider type-finders used elsewhere (e.g. pane dividers).
Container(
width: 1,
height: _height,
color: foreground.withValues(alpha: 0.20),
),
Tooltip(
message: 'PR actions',
child: InkWell(
onTap: onToggleMenu,
child: SizedBox(
height: _height,
width: _height,
child: AnimatedRotation(
turns: menuOpen ? 0.5 : 0,
duration: const Duration(milliseconds: 150),
child: Icon(
PhosphorIconsLight.caretDown,
size: 12,
color: foreground,
),
),
),
),
),
],
),
);
}
}