fc615c69e7
# Conflicts: # app/lib/features/runs/ui/run_detail_content.dart # app/lib/features/runs/ui/run_list_row.dart # app/tool/search_selection_probe_entry.dart
177 lines
5.9 KiB
Dart
177 lines
5.9 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import '../../../ui/adaptive/floating_bar_layout.dart';
|
|
import '../../../ui/layout/app_list_avatar.dart';
|
|
import '../../../ui/layout/app_list_row.dart';
|
|
import '../../../ui/status/outcome_palette.dart';
|
|
import '../../../ui/status/run_status_icon.dart';
|
|
import '../../../ui/text/live_elapsed_builder.dart';
|
|
import '../../pipelines/pipeline_format.dart' show formatDuration;
|
|
import '../domain/run_models.dart';
|
|
import 'run_detail_content.dart';
|
|
|
|
/// The Timeline tab's recorded visits, one shared list row per visit.
|
|
///
|
|
/// The list is flat on the page on both hosts, like the runs list and the
|
|
/// Summary, with inset dividers between rows (no grouped card).
|
|
///
|
|
/// [onSelected] receives the row's index in [visits], so the caller opens
|
|
/// exactly the recorded step it was built from. [selectedSequence] highlights a
|
|
/// row when a selection is applied while the list is rendered; the current
|
|
/// flow replaces the rows with the pane, so it only matters for a defensive
|
|
/// host that keeps both visible. Only an actual recorded visit can match, so an
|
|
/// unvisited stage leaves every row unselected.
|
|
class RunTimelineList extends StatelessWidget {
|
|
const RunTimelineList({
|
|
super.key,
|
|
required this.visits,
|
|
required this.cupertino,
|
|
this.selectedSequence,
|
|
this.onSelected,
|
|
});
|
|
|
|
final List<DetailVisit> visits;
|
|
final bool cupertino;
|
|
final int? selectedSequence;
|
|
final ValueChanged<int>? onSelected;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (visits.isEmpty) {
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-timeline'),
|
|
padding: withBarClearance(context, const EdgeInsets.all(16)),
|
|
children: const [Text('No visits recorded.')],
|
|
);
|
|
}
|
|
// One colour per distinct outcome name across the whole run, so the same
|
|
// outcome reads the same on every row and different ones never match.
|
|
final palette = OutcomePalette(visits.map((visit) => visit.outcome));
|
|
return ListView(
|
|
key: const Key('run-detail-tab-body-timeline'),
|
|
padding: withBarClearance(
|
|
context,
|
|
const EdgeInsets.symmetric(vertical: 8),
|
|
),
|
|
children: [
|
|
for (var index = 0; index < visits.length; index += 1)
|
|
RunTimelineRow(
|
|
key: ValueKey(
|
|
'run-timeline-visit-${visits[index].sequence ?? index}',
|
|
),
|
|
visit: visits[index],
|
|
selected: visits[index].sequence == selectedSequence,
|
|
cupertino: cupertino,
|
|
divider: index < visits.length - 1,
|
|
palette: palette,
|
|
onTap: onSelected == null ? null : () => onSelected!(index),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// One recorded visit. [selected] marks the row an applied selection identifies;
|
|
/// the current flow opens the pane instead of leaving a highlighted row. It is
|
|
/// never true for a stage with no recorded visit.
|
|
class RunTimelineRow extends StatelessWidget {
|
|
const RunTimelineRow({
|
|
super.key,
|
|
required this.visit,
|
|
required this.selected,
|
|
required this.cupertino,
|
|
this.divider = false,
|
|
this.onTap,
|
|
this.palette,
|
|
});
|
|
|
|
final DetailVisit visit;
|
|
final bool selected;
|
|
final bool cupertino;
|
|
final bool divider;
|
|
final VoidCallback? onTap;
|
|
|
|
/// The run's outcome colours; without one the row colours its own outcome
|
|
/// as the first (and only) name.
|
|
final OutcomePalette? palette;
|
|
|
|
/// The visit's state for its glyph: the outcome when it has one (a completed
|
|
/// step can still have failed), else the step status.
|
|
String get _state {
|
|
final outcome = visit.outcome.toLowerCase();
|
|
if (outcome == 'error' || outcome == 'failed' || outcome == 'failure') {
|
|
return 'failed';
|
|
}
|
|
return runStateOf(visit.status);
|
|
}
|
|
|
|
Widget _outcome(BuildContext context) {
|
|
final label = visit.outcome.isNotEmpty
|
|
? visit.outcome
|
|
: (visit.status.isEmpty ? 'unknown' : visit.status);
|
|
// An outcome is coloured by its name (no word is wired to a colour); a
|
|
// visit with no outcome yet keeps its status colour.
|
|
final color = visit.outcome.isNotEmpty
|
|
? (palette ?? OutcomePalette([visit.outcome])).colorFor(
|
|
context,
|
|
visit.outcome,
|
|
)
|
|
: runStatusColor(_state).resolveFrom(context);
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: 0.14),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Text(
|
|
label,
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = _state;
|
|
// The outcome chip leads the second line, then where the visit went and
|
|
// the tokens it reported; the duration is the row's time.
|
|
return AppListRow(
|
|
cupertino: cupertino,
|
|
selected: selected,
|
|
divider: divider,
|
|
onTap: onTap,
|
|
leading: AppListAvatar(
|
|
foreground: runStatusColor(state).resolveFrom(context),
|
|
child: RunStatusIcon(
|
|
state: state,
|
|
label: visit.status.isEmpty ? 'Status unavailable' : visit.status,
|
|
),
|
|
),
|
|
title: Text(visit.title),
|
|
time: visit.duration,
|
|
// A running visit's elapsed time ticks; only that label rebuilds.
|
|
timeWidget: visit.runningSince == null
|
|
? null
|
|
: LiveElapsedBuilder(
|
|
since: visit.runningSince,
|
|
builder: (context, now) => Text(
|
|
formatDuration(now.difference(visit.runningSince!).inSeconds),
|
|
),
|
|
),
|
|
subtitleLeading: _outcome(context),
|
|
subtitle: visit.target.isEmpty && visit.tokens == null
|
|
? null
|
|
: Text(
|
|
[
|
|
if (visit.target.isNotEmpty) '→ ${visit.target}',
|
|
?visit.tokens,
|
|
].join(' · '),
|
|
),
|
|
);
|
|
}
|
|
}
|