merge(app): land graph colour and route order

This commit is contained in:
2026-10-23 18:51:00 +01:00
4 changed files with 129 additions and 7 deletions
@@ -19,8 +19,20 @@ class RunGraphState {
required this.currentStage,
required this.executing,
required this.currentStageStartedAt,
Map<String, List<int>> routeOrders = const {},
}) : visitedStages = List.unmodifiable(visitedStages),
takenRoutes = List.unmodifiable(takenRoutes);
takenRoutes = List.unmodifiable(takenRoutes),
_routeOrders = Map.unmodifiable(routeOrders);
final Map<String, List<int>> _routeOrders;
/// Where in the run each pass over a taken route came: 1 for the first
/// route the run took, 2 for the next, and so on; a loop has several.
List<int> routeOrder(String source, String outcome, String target) {
final resolved = resolveTarget(outcome, target);
if (resolved == null || resolved.isEmpty) return const [];
return _routeOrders['$source\u0000$outcome\u0000$resolved'] ?? const [];
}
/// Visited stage keys in first-appearance order, without duplicates.
final List<String> visitedStages;
@@ -74,6 +86,8 @@ RunGraphState runGraphState(dynamic run) {
final seenStages = <String>{};
final takenRoutes = <String>[];
final seenRoutes = <String>{};
final routeOrders = <String, List<int>>{};
var ordinal = 0;
void visit(String? key) {
if (key == null || key.isEmpty || !seenStages.add(key)) return;
@@ -92,6 +106,7 @@ RunGraphState runGraphState(dynamic run) {
if (resolved == null || resolved.isEmpty) continue;
final route = '$stage\u0000$outcome\u0000$resolved';
if (seenRoutes.add(route)) takenRoutes.add(route);
routeOrders.putIfAbsent(route, () => []).add(++ordinal);
if (isTerminalTarget(resolved)) visit(resolved);
}
@@ -120,5 +135,6 @@ RunGraphState runGraphState(dynamic run) {
currentStage: currentStage,
executing: executing,
currentStageStartedAt: currentStageStartedAt,
routeOrders: routeOrders,
);
}
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/status/run_status_icon.dart';
import '../domain/graph_definition.dart';
/// One content-sized stage node as an ordinary native control.
@@ -53,7 +54,7 @@ class GraphStageNode extends StatelessWidget {
@override
Widget build(BuildContext context) {
final content = ExcludeSemantics(child: _content());
final content = ExcludeSemantics(child: _content(context));
void onPressed() => onSelected(node.key);
final control = MergeSemantics(
child: Semantics(
@@ -111,14 +112,41 @@ class GraphStageNode extends StatelessWidget {
? CupertinoButton.filled(onPressed: onPressed, child: content)
: CupertinoButton.tinted(onPressed: onPressed, child: content);
Widget _content() {
Widget _content(BuildContext context) {
final status = _status;
// The recorded status reads apart from the name: a coloured dot and
// coloured, smaller text in the status's own hue.
final color = status == null
? null
: runStatusColor(graphStatusState(status)).resolveFrom(context);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(_breakable(node.label), softWrap: true),
if (status != null) Text(_breakable(status), softWrap: true),
if (status != null)
Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 8,
height: 8,
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
),
const SizedBox(width: 6),
Flexible(
child: Text(
_breakable(status),
softWrap: true,
style: TextStyle(
color: color,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
),
],
),
],
);
}
@@ -246,3 +274,17 @@ class StageActivityHaloPainter extends CustomPainter {
bool shouldRepaint(StageActivityHaloPainter oldDelegate) =>
oldDelegate.color != color || oldDelegate.progress != progress;
}
/// The run state a recorded step status colours as: done is green, an error or
/// a block is red, running is blue, waiting teal, anything else grey.
String graphStatusState(String status) {
final word = status.trim().split(RegExp(r'[\s·]+')).first.toLowerCase();
return switch (word) {
'completed' || 'succeeded' || 'success' || 'done' => 'succeeded',
'failed' || 'error' || 'blocked' => 'failed',
'running' || 'active' => 'running',
'waiting' || 'queued' => 'waiting',
'interrupted' || 'canceled' || 'cancelled' => 'interrupted',
_ => 'unknown',
};
}
@@ -240,9 +240,9 @@ class RunGraphCanvas extends StatelessWidget {
Positioned(
left: label.x,
top: label.y,
child: Text(
routing.routeFor(label.edgeId)!.label,
style: style.labelStyle,
child: _takenLabel(
routing.routeFor(label.edgeId)!,
executedColor,
),
),
],
@@ -250,6 +250,39 @@ class RunGraphCanvas extends StatelessWidget {
}
}
/// A taken route's label led by its place in the run (`2`, or `2, 5` for a
/// loop), so the path reads in order.
extension on RunGraphCanvas {
Widget _takenLabel(EdgeRoute route, Color color) {
final order = state.routeOrder(route.source, route.outcome, route.target);
final text = Text(route.label, style: style.labelStyle);
if (order.isEmpty) return text;
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
key: ValueKey('run-route-order:${route.id}'),
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(8),
),
child: Text(
order.join(', '),
style: const TextStyle(
color: Color(0xFFFFFFFF),
fontSize: 10,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(width: 4),
text,
],
);
}
}
/// One placed run node. A visited stage is the native control with its recorded
/// status; an unvisited node and a terminal are labels with no tap target or
/// button semantics, because neither owns a recorded visit to open. [active]
@@ -0,0 +1,31 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/domain/run_graph_state.dart';
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
import 'package:pipelines_app/ui/status/run_status_icon.dart';
void main() {
test('taken routes carry their place in the run, loops every pass', () {
final state = runGraphState({
'steps': [
{'stage': 'plan', 'outcome': 'success', 'target': 'build'},
{'stage': 'build', 'outcome': 'retry', 'target': 'build'},
{'stage': 'build', 'outcome': 'retry', 'target': 'build'},
{'stage': 'build', 'outcome': 'success', 'target': '#success'},
],
});
expect(state.routeOrder('plan', 'success', 'build'), [1]);
expect(state.routeOrder('build', 'retry', 'build'), [2, 3]);
expect(state.routeOrder('build', 'success', '#success'), [4]);
expect(state.routeOrder('plan', 'error', '#failure'), isEmpty);
});
test('a recorded status colours by what it means', () {
expect(graphStatusState('completed'), 'succeeded');
expect(graphStatusState('blocked'), 'failed');
expect(graphStatusState('running · 2m'), 'running');
expect(graphStatusState('waiting'), 'waiting');
expect(graphStatusState('mystery'), 'unknown');
expect(runStatusColor('succeeded'), CupertinoColors.systemGreen);
});
}