fe24f228fe
Review r2 findings P2-4, P2-5, P3-13: a shared relative-time helper for
every list row's time, formatDuration switches to days past 24h ('9d
16h'), the stage page uses one visit numbering, drops a repeated stage
heading and fixes '1 files', and search run hits read 'Run 1'.
Implemented by pipeline run #205/#207 (Terra); its UIReview blocked on a
fixture without timestamps, verified by the manager.
375 lines
12 KiB
Dart
375 lines
12 KiB
Dart
import '../../../ui/layout/app_list_avatar.dart';
|
|
import '../../../ui/layout/app_list_row.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/floating_bar_layout.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 '../../../ui/text/relative_time.dart';
|
|
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);
|
|
}
|
|
// The notice and the applied filters lead the list, so they scroll
|
|
// behind the top bar with the runs and start below it at rest.
|
|
final header = [
|
|
if (controller.error != null) _inlineError(context),
|
|
RunsFilters(controller: controller),
|
|
];
|
|
if (controller.visibleRuns.isNotEmpty) return _groupedRuns(context, header);
|
|
return BelowTopBar(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
...header,
|
|
Expanded(
|
|
child: _state(
|
|
context,
|
|
icon: Icon(
|
|
usesCupertinoHost(context)
|
|
? CupertinoIcons.tray
|
|
: Icons.inbox_outlined,
|
|
),
|
|
title: 'No runs found.',
|
|
subtitle: 'Try changing or clearing the filters.',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _groupedRuns(BuildContext context, List<Widget> header) {
|
|
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, header),
|
|
);
|
|
}
|
|
|
|
Widget _entriesList(
|
|
List<({String? label, JsonMap? run})> entries,
|
|
List<Widget> header,
|
|
) {
|
|
// The default padding is the media padding: the first row starts below
|
|
// the top bar and the last clears the floating tab bar.
|
|
return ListView.builder(
|
|
itemCount: header.length + entries.length,
|
|
itemBuilder: (context, index) {
|
|
if (index < header.length) return header[index];
|
|
final entry = entries[index - header.length];
|
|
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),
|
|
),
|
|
);
|
|
}
|
|
// The last run of a day (before the next heading) has no divider.
|
|
final next = index - header.length + 1;
|
|
final last = next >= entries.length || entries[next].run == null;
|
|
return Arrival(
|
|
id: '${entry.run!['id']}',
|
|
child: _runTile(context, entry.run!, divider: !last),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
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, {bool divider = true}) {
|
|
final id = run['id'];
|
|
return RunListRow(
|
|
run: run,
|
|
divider: divider,
|
|
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: a status avatar, title/time, and one muted fact
|
|
/// line in the app's shared row. Its detail retains the full timestamp,
|
|
/// path, and other diagnostics.
|
|
class RunListRow extends StatelessWidget {
|
|
const RunListRow({
|
|
super.key,
|
|
required this.run,
|
|
required this.now,
|
|
this.selected = false,
|
|
this.divider = true,
|
|
this.onTap,
|
|
this.gateway,
|
|
this.onRunChanged,
|
|
this.onRunOpened,
|
|
});
|
|
|
|
final JsonMap run;
|
|
final DateTime now;
|
|
final bool selected;
|
|
|
|
/// False for the last row before a day heading or the end of the list.
|
|
final bool divider;
|
|
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 scheduled = run['scheduled'] == true;
|
|
final subtitle = [
|
|
?pipelineLabel,
|
|
if (scheduled) 'Scheduled',
|
|
?facts.duration,
|
|
?facts.progress,
|
|
].join(' · ');
|
|
// A narrow pane keeps the decision facts: the pipeline, and progress
|
|
// while executing (duration only when there is no pipeline to show).
|
|
final compactSubtitle = [
|
|
?pipelineLabel,
|
|
if (scheduled) 'Scheduled',
|
|
if (run['executing'] == true && facts.progress != null) facts.progress!,
|
|
if (pipelineLabel == null && facts.duration != null) facts.duration!,
|
|
].join(' · ');
|
|
final state = runStateOf(run['status']);
|
|
return AppListRow(
|
|
key: ValueKey('run-row-$id'),
|
|
cupertino: cupertino,
|
|
selected: selected,
|
|
divider: divider,
|
|
onTap: onTap,
|
|
leading: AppListAvatar(
|
|
foreground: runStatusColor(state).resolveFrom(context),
|
|
child: RunStatusIcon(state: state, label: runStatusLabel(run)),
|
|
),
|
|
title: Text(title),
|
|
time: formatRelativeTimestamp('${run['created_at'] ?? ''}', now: now),
|
|
subtitle: Text(subtitle),
|
|
compactSubtitle: Text(compactSubtitle),
|
|
// A narrow list pane beside the open run leaves the row no room for a
|
|
// second control; the open run's detail beside it carries the same menu.
|
|
menu: gateway != null && onRunChanged != null && showRunMoreMenu(run)
|
|
? RunMoreMenu(
|
|
run: run,
|
|
gateway: gateway!,
|
|
onRunChanged: onRunChanged!,
|
|
onRunOpened: onRunOpened,
|
|
cupertino: cupertino,
|
|
menuKey: ValueKey('run-list-more-menu-$id'),
|
|
)
|
|
: null,
|
|
);
|
|
}
|
|
}
|