feat(app): timeline rows lead with the visit's status icon and an outcome chip, with target and duration
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../pipelines/pipeline_format.dart' show formatDuration;
|
||||
import '../domain/run_models.dart';
|
||||
|
||||
/// One labelled value in the run detail's metrics block.
|
||||
@@ -17,6 +18,10 @@ typedef DetailVisit = ({
|
||||
int? sequence,
|
||||
String title,
|
||||
String subtitle,
|
||||
String status,
|
||||
String outcome,
|
||||
String target,
|
||||
String? duration,
|
||||
});
|
||||
|
||||
/// The run's primary label: the stored title, else the pipeline name, and only
|
||||
@@ -107,6 +112,10 @@ List<DetailVisit> detailTimeline(dynamic steps) {
|
||||
'${_text(step['stage'], 'Stage unavailable')} · visit '
|
||||
'${step['sequence'] is num ? (step['sequence'] as num).toInt() : 'unavailable'}',
|
||||
subtitle: _visitSubtitle(step),
|
||||
status: '${step['status'] ?? ''}'.trim(),
|
||||
outcome: '${step['outcome'] ?? ''}'.trim(),
|
||||
target: '${step['target'] ?? ''}'.trim(),
|
||||
duration: _visitDuration(step),
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -144,6 +153,15 @@ String _visitSubtitle(Map step) {
|
||||
].join(' · ');
|
||||
}
|
||||
|
||||
/// The web's `stepDuration`: finished minus started, when both are recorded.
|
||||
String? _visitDuration(Map step) {
|
||||
final started = DateTime.tryParse('${step['started_at'] ?? ''}');
|
||||
final finished = DateTime.tryParse('${step['finished_at'] ?? ''}');
|
||||
if (started == null || finished == null) return null;
|
||||
final seconds = finished.difference(started).inSeconds;
|
||||
return seconds < 0 ? null : formatDuration(seconds);
|
||||
}
|
||||
|
||||
String _text(dynamic value, String fallback) {
|
||||
final text = '${value ?? ''}'.trim();
|
||||
return text.isEmpty ? fallback : text;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/status/run_status_icon.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_detail_content.dart';
|
||||
|
||||
/// The Timeline tab's recorded visits, one native row per visit.
|
||||
@@ -82,20 +84,72 @@ class RunTimelineRow extends StatelessWidget {
|
||||
final bool cupertino;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
/// 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);
|
||||
}
|
||||
|
||||
/// One line under the title: where the visit went and how long it took.
|
||||
String get _detail => [
|
||||
if (visit.target.isNotEmpty) '→ ${visit.target}',
|
||||
?visit.duration,
|
||||
].join(' · ');
|
||||
|
||||
Widget _outcome(BuildContext context) {
|
||||
final label = visit.outcome.isNotEmpty
|
||||
? visit.outcome
|
||||
: (visit.status.isEmpty ? 'unknown' : visit.status);
|
||||
final color = 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 leading = RunStatusIcon(
|
||||
state: _state,
|
||||
label: visit.status.isEmpty ? 'Status unavailable' : visit.status,
|
||||
size: 22,
|
||||
);
|
||||
final title = Text(
|
||||
visit.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
);
|
||||
final detail = _detail;
|
||||
// The outcome chip leads the second line, so the title keeps the width.
|
||||
final subtitle = Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [_outcome(context), if (detail.isNotEmpty) Text(detail)],
|
||||
);
|
||||
if (cupertino) {
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
child: CupertinoListTile(
|
||||
leading: Icon(
|
||||
selected
|
||||
? CupertinoIcons.check_mark_circled_solid
|
||||
: CupertinoIcons.circle,
|
||||
),
|
||||
title: Text(visit.title),
|
||||
subtitle: Text(visit.subtitle),
|
||||
trailing: selected ? const Icon(CupertinoIcons.check_mark) : null,
|
||||
leading: leading,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
trailing: const CupertinoListTileChevron(),
|
||||
backgroundColor: selected
|
||||
? CupertinoDynamicColor.resolve(
|
||||
CupertinoColors.secondarySystemFill,
|
||||
@@ -108,9 +162,9 @@ class RunTimelineRow extends StatelessWidget {
|
||||
}
|
||||
return ListTile(
|
||||
selected: selected,
|
||||
leading: Icon(selected ? Icons.check_circle : Icons.circle_outlined),
|
||||
title: Text(visit.title),
|
||||
subtitle: Text(visit.subtitle),
|
||||
leading: leading,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_content.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_timeline.dart';
|
||||
import 'package:pipelines_app/ui/status/run_status_icon.dart';
|
||||
|
||||
final _steps = [
|
||||
{
|
||||
'stage': 'plan',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'target': 'build',
|
||||
'started_at': '2026-10-21T12:00:00Z',
|
||||
'finished_at': '2026-10-21T12:02:05Z',
|
||||
},
|
||||
{
|
||||
'stage': 'build',
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
'outcome': 'error',
|
||||
'target': '#failure',
|
||||
},
|
||||
{'stage': 'review', 'sequence': 3, 'status': 'running'},
|
||||
];
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('timeline rows lead with their real status '
|
||||
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
|
||||
final list = RunTimelineList(
|
||||
visits: detailTimeline(_steps),
|
||||
cupertino: cupertino,
|
||||
onSelected: (_) {},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: list))
|
||||
: MaterialApp(home: Scaffold(body: list)),
|
||||
);
|
||||
|
||||
// No placeholder circles: every row has the state's own glyph.
|
||||
expect(find.byIcon(Icons.circle_outlined), findsNothing);
|
||||
expect(find.byIcon(CupertinoIcons.circle), findsNothing);
|
||||
final states = tester
|
||||
.widgetList<RunStatusIcon>(find.byType(RunStatusIcon))
|
||||
.map((icon) => icon.state)
|
||||
.toList();
|
||||
// A completed step whose outcome is an error reads as failed.
|
||||
expect(states, ['succeeded', 'failed', 'running']);
|
||||
|
||||
expect(find.text('success'), findsOneWidget);
|
||||
expect(find.text('error'), findsOneWidget);
|
||||
expect(find.text('→ build · 2m 5s'), findsOneWidget);
|
||||
expect(find.text('→ #failure'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user