Files
pipelines/app/lib/features/runs/ui/runs_list.dart
T
alan ea0f22dfc7 fix(app): keep round-3 run rows within narrow large-text widths
The trailing relative time could not shrink, so a 320px row at 2x text
overflowed; it now keeps at most 40% of the title line and ellipsises.
Update the pipelines screen test for rows that no longer show the run
number or a no-runs line.
2026-10-31 02:19:02 +00:00

493 lines
16 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 '../../pipelines/pipeline_format.dart' show formatRanAgo;
import '../domain/run_models.dart';
import '../../../shell/shell_bar.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 a status avatar, title/time, and one muted fact
/// line. Its detail retains the full timestamp, path, and other diagnostics.
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,
);
final scheduled = run['scheduled'] == true;
final subtitle = [
?pipelineLabel,
if (scheduled) 'Scheduled',
?facts.duration,
?facts.progress,
].join(' · ');
final relativeTime = formatRanAgo('${run['created_at'] ?? ''}', now);
Widget body(bool withMenu, bool compact) => Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsetsDirectional.only(end: 12),
child: _RunStatusAvatar(
state: runStateOf(run['status']),
label: runStatusLabel(run),
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: compact
? [
Text(
title,
style: titleStyle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 2),
Text(
// The stored pipeline name is a fallback when the API
// has no human-readable pipeline title. Avoid repeating
// it if it already supplies the row title.
[
?pipelineLabel,
if (scheduled) 'Scheduled',
if (run['executing'] == true && facts.progress != null)
facts.progress!,
if (pipelineLabel == null && facts.duration != null)
facts.duration!,
].join(' · '),
style: small,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
]
: [
// The time keeps at most 40% of the line, so very large
// text in a narrow row ellipsises instead of overflowing.
LayoutBuilder(
builder: (context, constraints) => Row(
children: [
Expanded(
child: Text(
title,
style: titleStyle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
if (relativeTime != null)
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: constraints.maxWidth * 0.4,
),
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: 8,
),
child: Text(
relativeTime,
style: small,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
],
),
),
const SizedBox(height: 2),
Text(
subtitle,
style: small,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
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) {
final compact = constraints.maxWidth < _menuMinRowWidth;
return body(!compact, compact);
},
),
);
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,
),
),
);
}
}
class _RunStatusAvatar extends StatelessWidget {
const _RunStatusAvatar({required this.state, required this.label});
final String state;
final String label;
@override
Widget build(BuildContext context) {
final color = runStatusColor(state).resolveFrom(context);
return Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: color.withValues(alpha: 0.14),
shape: BoxShape.circle,
),
alignment: Alignment.center,
child: RunStatusIcon(state: state, label: label),
);
}
}