Files
pipelines/app/lib/features/runs/ui/runs_list.dart
T
alan 2542791a82 fix(app): keep the polished run and pipeline lists usable in narrow panes
Run #196 landed list polish that broke a 640px window: the list pane is
~127px there, so the new pipeline icon overflowed, the run row's centre
landed on its new actions menu (a tap opened the menu instead of the
run), and the new loading/empty states overflowed short panes. Narrow
pipeline rows drop the icon and chevron, run rows show their menu only
from 280px (the detail carries it), and the state blocks scroll.
2026-10-31 01:03:47 +00:00

453 lines
15 KiB
Dart

import '../../../ui/layout/section_heading.dart';
import '../../../ui/motion/motion.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/status/run_status_icon.dart';
import '../../attention/notify/notification_controller.dart';
import '../../attention/runtime/attention_controller.dart';
import '../../attention/runtime/attention_store.dart';
import '../../attention/ui/needs_you_runs_heading.dart';
import '../domain/run_models.dart';
import '../../../shell/shell_bar.dart';
import 'run_path_mini.dart';
import 'run_more_menu.dart';
import 'runs_controller.dart';
import 'runs_stats_page.dart';
import 'runs_filters.dart';
class RunsList extends StatelessWidget {
const RunsList({
super.key,
required this.controller,
required this.onSelected,
this.syncToken = 0,
this.attentionStore = const SharedPreferencesAttentionStore(),
this.attentionNow,
this.notifications,
this.attention,
this.active = true,
});
/// False while a run detail covers the list; the bar is then the run's.
final bool active;
final RunsController controller;
final ValueChanged<num> onSelected;
/// Advances when the shared socket is replaced, so the attention detector
/// rebaselines instead of replaying a transition from before the gap.
final int syncToken;
/// Test and fixture seam for the persisted attention dismissals.
final AttentionStore attentionStore;
/// Deterministic local-day clock for the attention window.
final DateTime Function()? attentionNow;
/// App-level notification delivery; absent in list-only fixtures.
final NotificationController? notifications;
/// The app's shared attention controller; absent in list-only fixtures.
final AttentionController? attention;
@override
Widget build(BuildContext context) {
final actions = [
// The Needs-you bell sits with the other actions, freeing the row.
NeedsYouRunsHeading(
rows: controller.runs,
frames: controller.repository.gateway.frames,
onOpen: (entry) => onSelected(entry.runId),
syncToken: syncToken,
store: attentionStore,
now: attentionNow,
notifications: notifications,
attention: attention,
),
...RunsBarActions(
controller,
).build(context, onStats: () => openRunsStats(context, controller)),
];
// Outside the app shell (the list on its own) the actions head the list.
if (!ShellBar.available(context)) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(8, 4, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: actions,
),
),
Expanded(child: _list(context)),
],
);
}
return ShellBar(
active: active,
actions: actions,
// The Runs tab counts runs still executing.
child: ShellBadge(
kind: ShellBadgeKind.running,
count: controller.runs.where((run) => run['executing'] == true).length,
child: _list(context),
),
);
}
Widget _list(BuildContext context) {
if (controller.loading && controller.runs.isEmpty) {
return _state(
context,
icon: usesCupertinoHost(context)
? const CupertinoActivityIndicator()
: const CircularProgressIndicator(),
title: 'Loading runs…',
);
}
if (controller.error != null && controller.runs.isEmpty) {
return _emptyError(context);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (controller.error != null) _inlineError(context),
RunsFilters(controller: controller),
Expanded(
child: controller.visibleRuns.isEmpty
? _state(
context,
icon: Icon(
usesCupertinoHost(context)
? CupertinoIcons.tray
: Icons.inbox_outlined,
),
title: 'No runs found.',
subtitle: 'Try changing or clearing the filters.',
)
: _groupedRuns(context),
),
],
);
}
Widget _groupedRuns(BuildContext context) {
final groups = groupRunsByDay(controller.visibleRuns, DateTime.now());
final entries = <({String? label, JsonMap? run})>[];
for (final group in groups) {
entries.add((label: group.label, run: null));
entries.addAll(group.runs.map((run) => (label: null, run: run)));
}
// Runs that start while the list is open enter with a short fade.
return ArrivalScope(
ids: [for (final run in controller.visibleRuns) '${run['id']}'],
child: _entriesList(entries),
);
}
Widget _entriesList(List<({String? label, JsonMap? run})> entries) {
return ListView.builder(
itemCount: entries.length,
itemBuilder: (context, index) {
final entry = entries[index];
if (entry.label case final label?) {
// A day heading reads as a divider between groups of runs.
return Padding(
padding: const EdgeInsets.only(top: 8),
child: Semantics(
header: true,
child: SectionHeading(title: label, minHeight: 32),
),
);
}
return Arrival(
id: '${entry.run!['id']}',
child: _runTile(context, entry.run!),
);
},
);
}
Widget _emptyError(BuildContext context) => Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
usesCupertinoHost(context)
? CupertinoIcons.exclamationmark_triangle
: Icons.error_outline,
),
const SizedBox(height: 8),
Text(controller.error!),
const SizedBox(height: 8),
usesCupertinoHost(context)
? CupertinoButton(
onPressed: controller.load,
child: const Text('Retry'),
)
: FilledButton(
onPressed: controller.load,
child: const Text('Retry'),
),
],
),
),
);
Widget _state(
BuildContext context, {
required Widget icon,
required String title,
String? subtitle,
}) => Center(
// A short pane (a list beside a detail, or the keyboard up) scrolls the
// state instead of overflowing it.
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
icon,
const SizedBox(height: 12),
Text(title, textAlign: TextAlign.center),
if (subtitle != null) ...[
const SizedBox(height: 4),
Text(
subtitle,
textAlign: TextAlign.center,
style: TextStyle(
color: usesCupertinoHost(context)
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
],
),
),
);
Widget _inlineError(BuildContext context) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
Expanded(child: Text(controller.error!)),
if (usesCupertinoHost(context))
CupertinoButton(
onPressed: controller.load,
child: const Text('Retry'),
)
else
TextButton(onPressed: controller.load, child: const Text('Retry')),
],
),
);
Widget _runTile(BuildContext context, JsonMap run) {
final id = run['id'];
return RunListRow(
run: run,
selected: id == controller.selectedRunId,
now: DateTime.now(),
onTap: id is num ? () => onSelected(id) : null,
gateway: controller.repository.gateway,
onRunChanged: controller.acceptRunDetail,
onRunOpened: onSelected,
);
}
}
/// One run in the list with its facts in the row's corners: the run and its
/// number on top, the pipeline and duration below, then when it ran and how
/// far it got.
class RunListRow extends StatelessWidget {
/// The narrowest row that still shows its own actions menu.
static const double _menuMinRowWidth = 280;
const RunListRow({
super.key,
required this.run,
required this.now,
this.selected = false,
this.onTap,
this.gateway,
this.onRunChanged,
this.onRunOpened,
});
final JsonMap run;
final DateTime now;
final bool selected;
final VoidCallback? onTap;
final ApiGateway? gateway;
final ValueChanged<JsonMap>? onRunChanged;
final ValueChanged<num>? onRunOpened;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final identity = runIdentity(run['title'], run['name']);
final id = run['id'];
final title = identity.label.isEmpty ? 'Run $id' : identity.label;
final facts = runRowFacts(run, now);
// A run without its own title is named by its pipeline, so the pipeline
// line does not repeat it.
final pipeline = identity.pipeline?.trim();
// With no stored title, `name` is already the row title; repeating it as
// a subtitle adds no identity. A titled run with an empty name genuinely
// lacks its pipeline, so make that absence explicit.
final pipelineLabel = pipeline == null
? null
: pipeline.isEmpty
? 'Pipeline unavailable'
: pipeline;
final secondary = cupertino
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
final nativeStyle = cupertino
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodyMedium ?? const TextStyle();
final base = !cupertino && selected
? nativeStyle.copyWith(
color: Theme.of(context).colorScheme.onSecondaryContainer,
)
: nativeStyle;
final titleStyle = base.copyWith(fontWeight: FontWeight.w600);
final small = base.copyWith(
color: secondary,
fontSize: (base.fontSize ?? 14) - 1,
);
Widget line(String? start, String? end, TextStyle style, {Key? key}) =>
LayoutBuilder(
key: key,
builder: (context, constraints) {
Widget text(String value) => Text(
value,
style: style,
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
if (end == null) return text(start ?? '');
final measure = TextPainter(
text: TextSpan(text: end, style: style),
textDirection: Directionality.of(context),
textScaler: MediaQuery.textScalerOf(context),
)..layout();
final fits = measure.width + 12 < constraints.maxWidth;
measure.dispose();
if (!fits) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
text(start ?? ''),
Align(
alignment: AlignmentDirectional.centerEnd,
child: text(end),
),
],
);
}
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: text(start ?? '')),
const SizedBox(width: 12),
text(end),
],
);
},
);
final scheduled = run['scheduled'] == true;
Widget body(bool withMenu) => Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 2, right: 12),
child: RunStatusIcon(
state: runStateOf(run['status']),
label: runStatusLabel(run),
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
line(title, id == null ? null : '#$id', titleStyle),
const SizedBox(height: 2),
line(
[?pipelineLabel, if (scheduled) 'Scheduled'].join(' · '),
facts.duration,
small,
),
line(facts.when, facts.progress, small),
// The run's path, each stage in its own result colour.
Padding(
padding: const EdgeInsets.only(top: 4),
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: RunPathMini(run: run),
),
),
],
),
),
if (withMenu &&
gateway != null &&
onRunChanged != null &&
showRunMoreMenu(run))
RunMoreMenu(
run: run,
gateway: gateway!,
onRunChanged: onRunChanged!,
onRunOpened: onRunOpened,
cupertino: cupertino,
menuKey: ValueKey('run-list-more-menu-$id'),
),
],
);
// A narrow list pane beside the open run leaves the row no room for a
// second control (a tap on its centre would land on the menu); the open
// run's detail beside it carries the same menu.
final padded = Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: LayoutBuilder(
builder: (context, constraints) =>
body(constraints.maxWidth >= _menuMinRowWidth),
),
);
return Semantics(
selected: selected,
button: onTap != null,
child: cupertino
? CupertinoButton(
key: ValueKey('run-row-$id'),
color: selected
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: null,
padding: EdgeInsets.zero,
minimumSize: Size.zero,
pressedOpacity: 0.6,
onPressed: onTap,
child: DefaultTextStyle(style: base, child: padded),
)
: Material(
key: ValueKey('run-row-surface-$id'),
color: selected
? Theme.of(context).colorScheme.secondaryContainer
: Colors.transparent,
child: InkWell(
key: ValueKey('run-row-$id'),
onTap: onTap,
child: padded,
),
),
);
}
}