From 1bf2ae41c4cb99d5f5db87cab7b0a537c1d8d522 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 31 Oct 2026 12:28:54 +0000 Subject: [PATCH] fix(runs): colour timeline outcomes by name, not by status A completed step's outcome chip took the success colour, so 'rejected' read green beside 'success'. Outcome chips now get one colour per distinct outcome name in the run (assigned by first appearance, from a well-separated hue list that continues by the golden angle), so equal names match and different names never share a colour. No outcome word is wired to a colour; the status glyph still shows the step's state. --- .../features/runs/ui/run_detail_timeline.dart | 19 +++++- app/lib/ui/status/outcome_palette.dart | 68 +++++++++++++++++++ .../runs/ui/run_timeline_row_test.dart | 36 ++++++++++ app/test/ui/status/outcome_palette_test.dart | 31 +++++++++ 4 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 app/lib/ui/status/outcome_palette.dart create mode 100644 app/test/ui/status/outcome_palette_test.dart diff --git a/app/lib/features/runs/ui/run_detail_timeline.dart b/app/lib/features/runs/ui/run_detail_timeline.dart index 779bd72c..e7ac986d 100644 --- a/app/lib/features/runs/ui/run_detail_timeline.dart +++ b/app/lib/features/runs/ui/run_detail_timeline.dart @@ -2,6 +2,7 @@ import '../../../ui/theme/app_theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../ui/status/outcome_palette.dart'; import '../../../ui/status/run_status_icon.dart'; import '../domain/run_models.dart'; import 'run_detail_content.dart'; @@ -38,6 +39,9 @@ class RunTimelineList extends StatelessWidget { 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)); final rows = [ for (var index = 0; index < visits.length; index += 1) RunTimelineRow( @@ -47,6 +51,7 @@ class RunTimelineList extends StatelessWidget { visit: visits[index], selected: visits[index].sequence == selectedSequence, cupertino: cupertino, + palette: palette, onTap: onSelected == null ? null : () => onSelected!(index), ), ]; @@ -83,6 +88,7 @@ class RunTimelineRow extends StatelessWidget { required this.selected, required this.cupertino, this.onTap, + this.palette, }); final DetailVisit visit; @@ -90,6 +96,10 @@ class RunTimelineRow extends StatelessWidget { final bool cupertino; 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 { @@ -110,7 +120,14 @@ class RunTimelineRow extends StatelessWidget { final label = visit.outcome.isNotEmpty ? visit.outcome : (visit.status.isEmpty ? 'unknown' : visit.status); - final color = runStatusColor(_state).resolveFrom(context); + // 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( diff --git a/app/lib/ui/status/outcome_palette.dart b/app/lib/ui/status/outcome_palette.dart new file mode 100644 index 00000000..a199d516 --- /dev/null +++ b/app/lib/ui/status/outcome_palette.dart @@ -0,0 +1,68 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +/// Colours for recorded outcome names, assigned per run by first appearance. +/// +/// Outcome words are pipeline-defined ('approved', 'rejected', 'retry', …), so +/// no name is hard-wired to a colour: the same name always gets the same +/// colour within a run and two different names never share one. The first +/// [_hues] names use well-separated hues; later ones continue around the +/// colour wheel by the golden angle so they stay distinct. +class OutcomePalette { + OutcomePalette(Iterable outcomes) { + for (final outcome in outcomes) { + final key = _key(outcome); + if (key.isNotEmpty) _index.putIfAbsent(key, () => _index.length); + } + } + + final Map _index = {}; + + static String _key(String outcome) => outcome.trim().toLowerCase(); + + /// The position [outcome] was first seen at, or null for a blank or unseen + /// name. + int? indexOf(String outcome) => _index[_key(outcome)]; + + /// [outcome]'s colour for the host's brightness; an unseen or blank name + /// uses the host's secondary text colour. + Color colorFor(BuildContext context, String outcome) { + final cupertino = + context.findAncestorWidgetOfExactType() == null; + final brightness = cupertino + ? CupertinoTheme.brightnessOf(context) + : Theme.of(context).brightness; + final index = indexOf(outcome); + if (index == null) { + return cupertino + ? CupertinoColors.secondaryLabel.resolveFrom(context) + : Theme.of(context).colorScheme.onSurfaceVariant; + } + return outcomeColorAt(index, brightness); + } +} + +const List _hues = [ + Colors.blue, + Colors.green, + Colors.deepOrange, + Colors.purple, + Colors.teal, + Colors.pink, + Colors.amber, + Colors.indigo, + Colors.brown, + Colors.cyan, +]; + +/// The colour for the [index]th distinct outcome, readable on the page in +/// [brightness] (darker shades on light pages, lighter on dark). +Color outcomeColorAt(int index, Brightness brightness) { + final dark = brightness == Brightness.dark; + if (index < _hues.length) { + final hue = _hues[index]; + return dark ? hue.shade300 : hue.shade800; + } + final degrees = (index * 137.508) % 360; + return HSLColor.fromAHSL(1, degrees, 0.6, dark ? 0.7 : 0.35).toColor(); +} diff --git a/app/test/features/runs/ui/run_timeline_row_test.dart b/app/test/features/runs/ui/run_timeline_row_test.dart index d5bca773..3f949b28 100644 --- a/app/test/features/runs/ui/run_timeline_row_test.dart +++ b/app/test/features/runs/ui/run_timeline_row_test.dart @@ -56,4 +56,40 @@ void main() { expect(find.text('→ #failure'), findsOneWidget); }); } + + for (final cupertino in [false, true]) { + testWidgets('outcome chips are coloured by name, not by status ' + '(${cupertino ? 'cupertino' : 'material'})', (tester) async { + // Every step completed: before, all three chips were the success colour. + final steps = [ + for (final (i, outcome) in [ + 'success', + 'rejected', + 'success', + 'approved', + ].indexed) + { + 'stage': 'stage$i', + 'sequence': i + 1, + 'status': 'completed', + 'outcome': outcome, + }, + ]; + final list = RunTimelineList( + visits: detailTimeline(steps), + cupertino: cupertino, + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: list)) + : MaterialApp(home: Scaffold(body: list)), + ); + Color chip(String text, [int at = 0]) => + tester.widget(find.text(text).at(at)).style!.color!; + expect(chip('success'), chip('success', 1)); + expect(chip('rejected'), isNot(chip('success'))); + expect(chip('approved'), isNot(chip('success'))); + expect(chip('approved'), isNot(chip('rejected'))); + }); + } } diff --git a/app/test/ui/status/outcome_palette_test.dart b/app/test/ui/status/outcome_palette_test.dart new file mode 100644 index 00000000..20f349ee --- /dev/null +++ b/app/test/ui/status/outcome_palette_test.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/status/outcome_palette.dart'; + +void main() { + test('same outcome names share a colour; different names never do', () { + final palette = OutcomePalette([ + 'success', + 'rejected', + 'Success', + 'approved', + '', + 'rejected ', + ]); + expect(palette.indexOf('success'), 0); + expect(palette.indexOf('SUCCESS'), 0); + expect(palette.indexOf('rejected'), 1); + expect(palette.indexOf('approved'), 2); + expect(palette.indexOf(''), isNull); + expect(palette.indexOf('never seen'), isNull); + }); + + test('the first fifty outcome colours are all distinct in both themes', () { + for (final brightness in Brightness.values) { + final colours = { + for (var i = 0; i < 50; i++) outcomeColorAt(i, brightness).toARGB32(), + }; + expect(colours, hasLength(50), reason: '$brightness'); + } + }); +}