From 480f8843ebae8ba2255d39956fcbbc0ee72de317 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 31 Oct 2026 06:02:02 +0000 Subject: [PATCH 1/2] Polish adaptive app chrome --- .../changes/widgets/changes_viewer.dart | 8 ++- .../chat/conversation/chat_mode_control.dart | 41 ++++++++++++--- .../graph/viewport/graph_expanded_view.dart | 52 ++++++++++++++----- .../graph/viewport/graph_viewport.dart | 48 +++++++++-------- .../graph/widgets/stage_definition_view.dart | 12 +++-- app/lib/ui/adaptive/segmented_bar.dart | 4 +- app/lib/ui/adaptive/segmented_bar_pieces.dart | 3 +- app/lib/ui/layout/sticky_section.dart | 2 +- .../features/changes/changes_viewer_test.dart | 5 ++ .../chat_floating_chrome_test.dart | 40 ++++++++++++++ .../viewport/graph_expanded_view_test.dart | 51 ++++++++++++++++-- .../widgets/stage_definition_view_test.dart | 10 ++++ .../pipelines/pipeline_graph_expand_test.dart | 4 +- app/test/ui/layout/sticky_section_test.dart | 1 + 14 files changed, 228 insertions(+), 53 deletions(-) diff --git a/app/lib/features/changes/widgets/changes_viewer.dart b/app/lib/features/changes/widgets/changes_viewer.dart index 3d6a6a56..49c22eb4 100644 --- a/app/lib/features/changes/widgets/changes_viewer.dart +++ b/app/lib/features/changes/widgets/changes_viewer.dart @@ -230,9 +230,15 @@ class _ChangesViewerState extends State { bar: Align( alignment: AlignmentDirectional.centerEnd, heightFactor: 1, + widthFactor: 1, child: Padding( padding: const EdgeInsets.all(8), - child: GlassPill(cupertino: usesCupertinoHost(context), child: pager), + child: IntrinsicWidth( + child: GlassPill( + cupertino: usesCupertinoHost(context), + child: pager, + ), + ), ), ), child: content, diff --git a/app/lib/features/chat/conversation/chat_mode_control.dart b/app/lib/features/chat/conversation/chat_mode_control.dart index d38a16b1..75355793 100644 --- a/app/lib/features/chat/conversation/chat_mode_control.dart +++ b/app/lib/features/chat/conversation/chat_mode_control.dart @@ -60,6 +60,7 @@ class _ChatModeControlState extends State { final picker = _ChatModePicker( load: () => repository.modes(widget.sessionId), current: _mode, + currentName: _name, cupertino: cupertino, choose: (mode) async { final applied = await repository.selectMode(widget.sessionId, mode.id); @@ -95,6 +96,9 @@ class _ChatModeControlState extends State { final cupertino = chatControlsStyleOf(context) == ChatControlsStyle.cupertino; final label = _name; + // At phone widths the title and a named mode cannot both remain useful. + // Keep the mode's shield, whose semantic label and picker still name it. + final iconOnly = cupertino && MediaQuery.sizeOf(context).width < 600; final content = Row( mainAxisSize: MainAxisSize.min, children: [ @@ -103,8 +107,10 @@ class _ChatModeControlState extends State { ? CupertinoIcons.shield_lefthalf_fill : Icons.shield_outlined, ), - const SizedBox(width: 4), - Flexible(child: Text(label, overflow: TextOverflow.ellipsis)), + if (!iconOnly) ...[ + const SizedBox(width: 4), + Flexible(child: Text(label, overflow: TextOverflow.ellipsis)), + ], ], ); const key = Key('chat-mode'); @@ -146,12 +152,14 @@ class _ChatModePicker extends StatefulWidget { const _ChatModePicker({ required this.load, required this.current, + required this.currentName, required this.cupertino, required this.choose, }); final Future<({List modes, String current})> Function() load; final String current; + final String currentName; final bool cupertino; final Future Function(_Mode mode) choose; @@ -165,6 +173,23 @@ class _ChatModePickerState extends State<_ChatModePicker> { bool _busy = false; String? _error; + /// The session row has already named the selected mode. Some harnesses do + /// not return a catalog, so retain that known value in the picker rather + /// than opening an action sheet with no visible mode. + List<_Mode> get _visibleModes { + final modes = _modes; + if (modes == null || + _current.isEmpty || + widget.currentName.isEmpty || + modes.any((mode) => mode.id == _current)) { + return modes ?? const []; + } + return [ + ...modes, + (id: _current, name: widget.currentName, description: ''), + ]; + } + @override void initState() { super.initState(); @@ -230,7 +255,8 @@ class _ChatModePickerState extends State<_ChatModePicker> { Widget _materialSheet(BuildContext context) { final theme = Theme.of(context); - final modes = _modes; + final modes = _visibleModes; + final loaded = _modes != null; return SafeArea( child: ListView( key: const Key('chat-mode-sheet'), @@ -248,7 +274,7 @@ class _ChatModePickerState extends State<_ChatModePicker> { style: TextStyle(color: theme.colorScheme.error), ), ), - if (modes == null) + if (!loaded) const Padding( padding: EdgeInsets.all(16), child: Center(child: CircularProgressIndicator()), @@ -274,7 +300,8 @@ class _ChatModePickerState extends State<_ChatModePicker> { Widget _cupertinoSheet(BuildContext context) { final secondary = CupertinoColors.secondaryLabel.resolveFrom(context); - final modes = _modes; + final modes = _visibleModes; + final loaded = _modes != null; return CupertinoActionSheet( key: const Key('chat-mode-sheet'), title: const Text('Mode'), @@ -285,11 +312,11 @@ class _ChatModePickerState extends State<_ChatModePicker> { color: CupertinoColors.systemRed.resolveFrom(context), ), ) - : modes == null + : !loaded ? const CupertinoActivityIndicator() : null, actions: [ - for (final mode in modes ?? const <_Mode>[]) + for (final mode in modes) CupertinoActionSheetAction( key: ValueKey('chat-mode-option-${mode.id}'), onPressed: () => _choose(mode), diff --git a/app/lib/features/graph/viewport/graph_expanded_view.dart b/app/lib/features/graph/viewport/graph_expanded_view.dart index e1c56300..9efa09bc 100644 --- a/app/lib/features/graph/viewport/graph_expanded_view.dart +++ b/app/lib/features/graph/viewport/graph_expanded_view.dart @@ -7,9 +7,6 @@ import '../../../ui/adaptive/floating_bar_layout.dart'; import 'graph_viewport.dart'; import 'graph_viewport_controller.dart'; -/// The expanded presentation's close wording (`Close`). -const String graphExpandedClose = 'Close'; - /// Builds the same canvas for another viewport, with the selection that /// presentation is showing. typedef GraphExpandedCanvasBuilder = @@ -88,6 +85,7 @@ class _GraphExpandedViewState extends State { key: const Key('graph-expanded-viewport'), controller: _controller, contentSize: widget.contentSize, + showControls: false, // The larger box fits the whole graph, as the web does when its panel // expands; a later resize re-fits until the reader pans or zooms, then // only clamps. @@ -107,13 +105,12 @@ class _GraphExpandedViewState extends State { navigationBar: SegmentedBar( cupertino: true, automaticallyImplyLeading: false, + leading: SegmentedBackButton(cupertino: true, onPressed: _close), title: widget.title, actions: [ - CupertinoButton( - key: const Key('graph-expanded-close'), - padding: const EdgeInsets.symmetric(horizontal: 16), - onPressed: _close, - child: const Text(graphExpandedClose), + _GraphFitButton( + cupertino: true, + onPressed: _controller.fitToViewport, ), ], ), @@ -126,11 +123,11 @@ class _GraphExpandedViewState extends State { cupertino: false, title: widget.title, automaticallyImplyLeading: false, + leading: SegmentedBackButton(cupertino: false, onPressed: _close), actions: [ - TextButton( - key: const Key('graph-expanded-close'), - onPressed: _close, - child: const Text(graphExpandedClose), + _GraphFitButton( + cupertino: false, + onPressed: _controller.fitToViewport, ), ], ), @@ -139,6 +136,37 @@ class _GraphExpandedViewState extends State { } } +class _GraphFitButton extends StatelessWidget { + const _GraphFitButton({required this.cupertino, required this.onPressed}); + + final bool cupertino; + final VoidCallback onPressed; + + @override + Widget build(BuildContext context) => MergeSemantics( + child: Semantics( + button: true, + label: graphFitLabel, + child: cupertino + ? CupertinoButton( + key: const Key('graph-fit'), + padding: const EdgeInsets.all(8), + onPressed: onPressed, + child: const ExcludeSemantics(child: Icon(CupertinoIcons.resize)), + ) + : Tooltip( + message: graphFitLabel, + excludeFromSemantics: true, + child: IconButton( + key: const Key('graph-fit'), + onPressed: onPressed, + icon: const ExcludeSemantics(child: Icon(Icons.fit_screen)), + ), + ), + ), + ); +} + /// Pushes [GraphExpandedView] with the host's native full-screen transition. /// /// This is the seam a Graph tab or run detail can call: pass the measured diff --git a/app/lib/features/graph/viewport/graph_viewport.dart b/app/lib/features/graph/viewport/graph_viewport.dart index 3751a7ae..071b432d 100644 --- a/app/lib/features/graph/viewport/graph_viewport.dart +++ b/app/lib/features/graph/viewport/graph_viewport.dart @@ -25,6 +25,7 @@ class GraphViewport extends StatefulWidget { required this.contentSize, required this.child, this.onExpand, + this.showControls = true, }); final GraphViewportController controller; @@ -38,6 +39,10 @@ class GraphViewport extends StatefulWidget { /// Opens the expanded presentation. Null hides the expand control. final VoidCallback? onExpand; + /// Whether this canvas draws its own fit/expand pill. Full-screen graph + /// views place Fit in their top-bar actions instead. + final bool showControls; + @override State createState() => _GraphViewportState(); } @@ -111,31 +116,32 @@ class _GraphViewportState extends State { ), ), ), - PositionedDirectional( - top: 8, - end: 8, - child: GlassPill( - cupertino: usesCupertinoHost(context), - child: Wrap( - spacing: 2, - children: [ - _ViewportButton( - buttonKey: const Key('graph-fit'), - icon: _fitIcon(context), - label: graphFitLabel, - onPressed: widget.controller.fitToViewport, - ), - if (widget.onExpand != null) + if (widget.showControls) + PositionedDirectional( + top: 8, + end: 8, + child: GlassPill( + cupertino: usesCupertinoHost(context), + child: Wrap( + spacing: 2, + children: [ _ViewportButton( - buttonKey: const Key('graph-expand'), - icon: _expandIcon(context), - label: graphExpandLabel, - onPressed: widget.onExpand, + buttonKey: const Key('graph-fit'), + icon: _fitIcon(context), + label: graphFitLabel, + onPressed: widget.controller.fitToViewport, ), - ], + if (widget.onExpand != null) + _ViewportButton( + buttonKey: const Key('graph-expand'), + icon: _expandIcon(context), + label: graphExpandLabel, + onPressed: widget.onExpand, + ), + ], + ), ), ), - ), ], ); }, diff --git a/app/lib/features/graph/widgets/stage_definition_view.dart b/app/lib/features/graph/widgets/stage_definition_view.dart index 6f69a648..3244d9e9 100644 --- a/app/lib/features/graph/widgets/stage_definition_view.dart +++ b/app/lib/features/graph/widgets/stage_definition_view.dart @@ -93,9 +93,15 @@ class _StageDefinitionViewState extends State { const SizedBox(height: 16), ], if (fields.any((field) => field.block)) ...[ - MarkdownModeSwitch( - raw: _raw, - onChanged: (raw) => setState(() => _raw = raw), + Align( + alignment: AlignmentDirectional.centerStart, + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 220), + child: MarkdownModeSwitch( + raw: _raw, + onChanged: (raw) => setState(() => _raw = raw), + ), + ), ), const SizedBox(height: 16), ], diff --git a/app/lib/ui/adaptive/segmented_bar.dart b/app/lib/ui/adaptive/segmented_bar.dart index fd3556a9..c1247e6d 100644 --- a/app/lib/ui/adaptive/segmented_bar.dart +++ b/app/lib/ui/adaptive/segmented_bar.dart @@ -254,10 +254,10 @@ class SegmentedBar extends StatelessWidget end: Alignment.bottomCenter, colors: [ background, - background.withValues(alpha: background.a * 0.85), + background.withValues(alpha: background.a * 0.95), background.withValues(alpha: 0), ], - stops: const [0, 0.45, 1], + stops: const [0, 0.5, 1], ), ), ), diff --git a/app/lib/ui/adaptive/segmented_bar_pieces.dart b/app/lib/ui/adaptive/segmented_bar_pieces.dart index 6056c628..1dc46c36 100644 --- a/app/lib/ui/adaptive/segmented_bar_pieces.dart +++ b/app/lib/ui/adaptive/segmented_bar_pieces.dart @@ -120,7 +120,8 @@ class SegmentedTitlePill extends StatelessWidget { fontWeight: FontWeight.w600, color: foreground, ); - subtitleStyle = text.tabLabelTextStyle.copyWith( + subtitleStyle = text.textStyle.copyWith( + fontSize: 13, color: foreground ?? CupertinoColors.secondaryLabel.resolveFrom(context), ); diff --git a/app/lib/ui/layout/sticky_section.dart b/app/lib/ui/layout/sticky_section.dart index 42fe49e2..e6a8e61c 100644 --- a/app/lib/ui/layout/sticky_section.dart +++ b/app/lib/ui/layout/sticky_section.dart @@ -111,7 +111,7 @@ class StickySectionTitle extends StatelessWidget { ), ); final row = Padding( - padding: const EdgeInsetsDirectional.only(start: 13, end: 8), + padding: const EdgeInsetsDirectional.only(start: 16, end: 8), child: Row( children: [ Expanded( diff --git a/app/test/features/changes/changes_viewer_test.dart b/app/test/features/changes/changes_viewer_test.dart index 74e55fa4..387164cd 100644 --- a/app/test/features/changes/changes_viewer_test.dart +++ b/app/test/features/changes/changes_viewer_test.dart @@ -147,6 +147,11 @@ void main() { ), findsOneWidget, ); + final pagerPill = find.ancestor( + of: find.byKey(ChangesVisitPager.nextKey), + matching: find.byType(GlassPill), + ); + expect(tester.getRect(pagerPill).width, lessThan(400)); await tester.tap(find.byKey(ChangesVisitPager.nextKey)); await tester.pump(); diff --git a/app/test/features/chat/conversation/chat_floating_chrome_test.dart b/app/test/features/chat/conversation/chat_floating_chrome_test.dart index 25a56f44..805a0cd4 100644 --- a/app/test/features/chat/conversation/chat_floating_chrome_test.dart +++ b/app/test/features/chat/conversation/chat_floating_chrome_test.dart @@ -206,5 +206,45 @@ void main() { ); } }); + + testWidgets('Cupertino mode is icon-only below 600px', (tester) async { + if (!cupertino) return; + final semantics = tester.ensureSemantics(); + _size(tester, const Size(560, 800)); + await _pump( + tester, + cupertino: true, + messages: 1, + session: const { + 'id': 's', + 'backend': 'opencode', + 'model': 'p/sonnet-4-5', + 'mode': 'default', + 'mode_name': 'Ask for permission', + }, + ); + + final mode = find.byKey(const Key('chat-mode')); + expect(mode, findsOneWidget); + expect( + find.descendant(of: mode, matching: find.text('Ask for permission')), + findsNothing, + ); + expect( + tester.getSemantics(mode).label, + contains('Change mode, currently Ask for permission'), + ); + await tester.tap(mode); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('chat-mode-sheet')), findsOneWidget); + // The fixture has no chat_modes catalog, but the recorded session mode + // remains visible in the sheet. + expect( + find.byKey(const ValueKey('chat-mode-option-default')), + findsOneWidget, + ); + expect(find.text('Ask for permission'), findsOneWidget); + semantics.dispose(); + }); } } diff --git a/app/test/features/graph/viewport/graph_expanded_view_test.dart b/app/test/features/graph/viewport/graph_expanded_view_test.dart index 06a55856..a1a7d077 100644 --- a/app/test/features/graph/viewport/graph_expanded_view_test.dart +++ b/app/test/features/graph/viewport/graph_expanded_view_test.dart @@ -1,9 +1,11 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/semantics.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/graph/viewport/graph_expanded_view.dart'; +import 'package:pipelines_app/features/graph/viewport/graph_viewport.dart'; import 'package:pipelines_app/features/graph/viewport/graph_viewport_math.dart'; import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart'; import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart'; @@ -103,7 +105,7 @@ void main() { isTrue, ); - await tester.tap(find.byKey(const Key('graph-expanded-close'))); + await tester.tap(find.byType(BackButton)); await tester.pumpAndSettle(); expect(find.byType(GraphExpandedView), findsNothing); @@ -195,14 +197,18 @@ void main() { await tester.tap(find.byKey(const Key('graph-expand'))); await tester.pumpAndSettle(); expect(find.byType(GraphExpandedView), findsOneWidget); - expect(_inExpanded(find.text(graphExpandedClose)), findsOneWidget); + expect( + _inExpanded(find.byType(CupertinoNavigationBarBackButton)), + findsOneWidget, + ); + expect(_inExpanded(find.byKey(const Key('graph-fit'))), findsOneWidget); expect( tester.widget(_inExpanded(_node('build'))).selected, isTrue, ); expect(tester.takeException(), isNull); - await tester.tap(find.byKey(const Key('graph-expanded-close'))); + await tester.tap(find.byType(CupertinoNavigationBarBackButton)); await tester.pumpAndSettle(); expect(find.byType(GraphExpandedView), findsNothing); expect(tester.widget(_node('build')).selected, isTrue); @@ -210,4 +216,43 @@ void main() { expect(picked, isEmpty); expect(tester.takeException(), isNull); }); + + testWidgets('expanded Fit is an activatable labelled button on both hosts', ( + tester, + ) async { + for (final cupertino in [false, true]) { + final host = cupertino ? 'Cupertino' : 'Material'; + await tester.pumpWidget( + cupertino + ? CupertinoApp( + home: CupertinoPageScaffold( + child: DefinitionGraphView( + graph: linearGraph(), + selectedStage: 'build', + onSelected: (_) {}, + ), + ), + ) + : _materialHost( + graph: linearGraph(), + selected: 'build', + onSelected: (_) {}, + ), + ); + await _settle(tester); + await tester.tap(find.byKey(const Key('graph-expand'))); + await tester.pumpAndSettle(); + + final fit = tester + .getSemantics(_inExpanded(find.byKey(const Key('graph-fit')))) + .getSemanticsData(); + expect(fit.label, graphFitLabel, reason: '$host Fit must be labelled'); + expect(fit.flagsCollection.isButton, isTrue); + expect( + fit.hasAction(SemanticsAction.tap), + isTrue, + reason: '$host Fit must expose its tap action on the labelled node', + ); + } + }); } diff --git a/app/test/features/graph/widgets/stage_definition_view_test.dart b/app/test/features/graph/widgets/stage_definition_view_test.dart index 53ce57fa..115d89ed 100644 --- a/app/test/features/graph/widgets/stage_definition_view_test.dart +++ b/app/test/features/graph/widgets/stage_definition_view_test.dart @@ -82,6 +82,16 @@ void main() { expect(_text('error'), findsOneWidget); }); + testWidgets('the rendered/raw control remains compact', (tester) async { + tester.view.physicalSize = const Size(800, 700); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget(_material(_view())); + + final control = find.byKey(const Key('markdown-source-mode')); + expect(tester.getRect(control).width, lessThan(221)); + }); + testWidgets('the raw section keeps unknown fields exact and selectable', ( tester, ) async { diff --git a/app/test/features/pipelines/pipeline_graph_expand_test.dart b/app/test/features/pipelines/pipeline_graph_expand_test.dart index 43c91555..1c33dfde 100644 --- a/app/test/features/pipelines/pipeline_graph_expand_test.dart +++ b/app/test/features/pipelines/pipeline_graph_expand_test.dart @@ -128,7 +128,7 @@ void main() { isTrue, ); - await tester.tap(find.byKey(const Key('graph-expanded-close'))); + await tester.tap(find.byType(BackButton)); await tester.pumpAndSettle(); expect(find.byType(GraphExpandedView), findsNothing); @@ -149,7 +149,7 @@ void main() { await tester.tap(find.byKey(const Key('graph-expand'))); await tester.pumpAndSettle(); - await tester.tap(find.byKey(const Key('graph-expanded-close'))); + await tester.tap(find.byType(BackButton)); await tester.pumpAndSettle(); expect(find.byType(GraphExpandedView), findsNothing); diff --git a/app/test/ui/layout/sticky_section_test.dart b/app/test/ui/layout/sticky_section_test.dart index 0a6b66ca..7b9c600f 100644 --- a/app/test/ui/layout/sticky_section_test.dart +++ b/app/test/ui/layout/sticky_section_test.dart @@ -55,6 +55,7 @@ void main() { tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); await tester.pumpWidget(const MaterialApp(home: Scaffold(body: _Host()))); + expect(tester.getTopLeft(find.text('Input')).dx, 16); expect(find.text('line 0'), findsOneWidget); // Empty space well right of the short title, left of the chevron. final strip = tester.getRect(find.byType(StickySectionTitle)); From 1bf2ae41c4cb99d5f5db87cab7b0a537c1d8d522 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 31 Oct 2026 12:28:54 +0000 Subject: [PATCH 2/2] 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'); + } + }); +}