feat(app): run rows place the run, number, pipeline, duration, time and steps in their corners
This commit is contained in:
@@ -155,6 +155,51 @@ String runRowMetaText(JsonMap run, DateTime now) {
|
||||
return parts.join(' · ');
|
||||
}
|
||||
|
||||
/// The facts a run row lays out in its corners: when it ran, for how long and
|
||||
/// how far it got. Absent facts are null, never invented.
|
||||
typedef RunRowFacts = ({String? when, String? duration, String? progress});
|
||||
|
||||
RunRowFacts runRowFacts(JsonMap run, DateTime now) {
|
||||
final created = '${run['created_at'] ?? ''}';
|
||||
final finished = '${run['finished_at'] ?? ''}';
|
||||
final start = formatLocalTimestamp(created);
|
||||
final executing = run['executing'] == true;
|
||||
String? when = start;
|
||||
int? seconds;
|
||||
if (executing) {
|
||||
final instant = parseInstant(created);
|
||||
if (instant != null) seconds = now.difference(instant).inSeconds;
|
||||
} else {
|
||||
seconds = durationSeconds(created, finished);
|
||||
final end = parseInstant(finished)?.toLocal();
|
||||
final begin = parseInstant(created)?.toLocal();
|
||||
if (start != null && end != null && begin != null) {
|
||||
// Same day: the end is just its time.
|
||||
final sameDay =
|
||||
end.year == begin.year &&
|
||||
end.month == begin.month &&
|
||||
end.day == begin.day;
|
||||
final endText = sameDay
|
||||
? '${end.hour.toString().padLeft(2, '0')}:'
|
||||
'${end.minute.toString().padLeft(2, '0')}'
|
||||
: formatLocalTimestamp(finished);
|
||||
when = '$start → $endText';
|
||||
}
|
||||
}
|
||||
final steps = run['completed_steps'];
|
||||
final stage = '${run['current_stage'] ?? ''}'.trim();
|
||||
final progress = [
|
||||
if (steps is num && steps > 0)
|
||||
steps == 1 ? '1 step' : '${steps.toInt()} steps',
|
||||
if (executing && stage.isNotEmpty) 'at $stage',
|
||||
].join(' · ');
|
||||
return (
|
||||
when: when,
|
||||
duration: seconds == null ? null : formatDuration(seconds),
|
||||
progress: progress.isEmpty ? null : progress,
|
||||
);
|
||||
}
|
||||
|
||||
String runStatusLabel(JsonMap run) {
|
||||
final status = '${run['status'] ?? ''}';
|
||||
if (!{'queued', 'running', 'waiting'}.contains(status)) {
|
||||
|
||||
@@ -172,36 +172,117 @@ class RunsList extends StatelessWidget {
|
||||
);
|
||||
|
||||
Widget _runTile(BuildContext context, JsonMap run) {
|
||||
final identity = runIdentity(run['title'], run['name']);
|
||||
final id = run['id'];
|
||||
final title = identity.label.isEmpty ? 'Run $id' : identity.label;
|
||||
// As the web's run row: the coloured status glyph leads (its tooltip and
|
||||
// accessible name are the state word), then the run, then
|
||||
// `pipeline · run N · local time · duration`.
|
||||
final meta = [
|
||||
'${run['name'] ?? 'Pipeline unavailable'}',
|
||||
runRowMetaText(run, DateTime.now()),
|
||||
if (run['scheduled'] == true) 'Scheduled',
|
||||
].join(' · ');
|
||||
final status = RunStatusIcon(
|
||||
state: runStateOf(run['status']),
|
||||
label: runStatusLabel(run),
|
||||
);
|
||||
if (usesCupertinoHost(context)) {
|
||||
return CupertinoListTile(
|
||||
leading: status,
|
||||
title: Text(title),
|
||||
subtitle: Text(meta),
|
||||
trailing: const CupertinoListTileChevron(),
|
||||
onTap: id is num ? () => onSelected(id) : null,
|
||||
);
|
||||
}
|
||||
return ListTile(
|
||||
leading: status,
|
||||
title: Text(title),
|
||||
subtitle: Text(meta),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
return RunListRow(
|
||||
run: run,
|
||||
now: DateTime.now(),
|
||||
onTap: id is num ? () => onSelected(id) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
const RunListRow({
|
||||
super.key,
|
||||
required this.run,
|
||||
required this.now,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
final DateTime now;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
@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();
|
||||
final secondary = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final base = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.bodyMedium ?? const TextStyle();
|
||||
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}) => Row(
|
||||
key: key,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
start ?? '',
|
||||
style: style,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (end != null) ...[
|
||||
const SizedBox(width: 12),
|
||||
Text(end, style: style),
|
||||
],
|
||||
],
|
||||
);
|
||||
final scheduled = run['scheduled'] == true;
|
||||
final body = 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(
|
||||
[
|
||||
if (pipeline != null)
|
||||
pipeline.isEmpty ? 'Pipeline unavailable' : pipeline,
|
||||
if (scheduled) 'Scheduled',
|
||||
].join(' · '),
|
||||
facts.duration,
|
||||
small,
|
||||
),
|
||||
line(facts.when, facts.progress, small),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
final padded = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
child: body,
|
||||
);
|
||||
return Semantics(
|
||||
button: onTap != null,
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
key: ValueKey('run-row-$id'),
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: Size.zero,
|
||||
pressedOpacity: 0.6,
|
||||
onPressed: onTap,
|
||||
child: DefaultTextStyle(style: base, child: padded),
|
||||
)
|
||||
: InkWell(key: ValueKey('run-row-$id'), onTap: onTap, child: padded),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user