diff --git a/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart b/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart index 4721ac5d..7f4e2e98 100644 --- a/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart +++ b/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart @@ -8,7 +8,6 @@ import '../../../shell/destination.dart'; import '../../../shell/empty_detail_pane.dart'; import '../../../shell/shell_bar.dart'; import '../../../ui/adaptive/floating_bar_layout.dart'; -import '../../../ui/layout/reading_width.dart'; import '../../graph/domain/graph_definition.dart'; import '../../graph/widgets/stage_definition_view.dart'; import '../pipeline_models.dart'; @@ -305,20 +304,10 @@ class _PipelineDetailPanelState extends State { ); } - /// A scrolling reading body: the whole pane scrolls, the content keeps - /// [kReadingMaxWidth] from the leading edge. - Widget _scrolling(Widget child) => ListView( - children: [ - Align( - alignment: AlignmentDirectional.topStart, - child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: kReadingMaxWidth), - child: child, - ), - ), - const SizedBox(height: 24), - ], - ); + /// A scrolling reading body: the whole pane scrolls and the content fills + /// its width. + Widget _scrolling(Widget child) => + ListView(children: [child, const SizedBox(height: 24)]); Widget _withoutDetail(BuildContext context) { if (!_controller.hasSelection) { diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index 1f69fc7d..50dd8306 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -1,7 +1,6 @@ import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/segmented_bar.dart'; import '../../../ui/adaptive/top_glass_strip.dart'; -import '../../../ui/layout/reading_width.dart'; import 'dart:math' as math; import 'package:flutter/cupertino.dart'; @@ -377,15 +376,8 @@ class _RunDetailTabsState extends State { ); final body = KeyedSubtree( key: ValueKey('run-detail-body-${widget.run['id']}'), - // Reading tabs keep a readable width on a wide window; canvases, - // viewers and the gallery keep the whole pane. - child: switch (shown) { - RunDetailTab.summary || - RunDetailTab.input || - RunDetailTab.output || - RunDetailTab.timeline => ReadingWidth(child: _body(shown)), - _ => _body(shown), - }, + // Every tab fills the pane, on a phone and an unfolded foldable alike. + child: _body(shown), ); if (edge == FloatingBarEdge.top && constraints.maxWidth >= kRunDetailWideChromeMinWidth) { diff --git a/app/lib/features/runs/ui/run_detail_visit.dart b/app/lib/features/runs/ui/run_detail_visit.dart index eb8f100a..504fadbe 100644 --- a/app/lib/features/runs/ui/run_detail_visit.dart +++ b/app/lib/features/runs/ui/run_detail_visit.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../../ui/adaptive/floating_bar_layout.dart'; -import '../../../ui/layout/reading_width.dart'; import 'run_detail_content.dart'; import 'run_detail_visit_facts_view.dart'; import 'run_detail_visit_sections.dart'; @@ -73,31 +72,23 @@ class _RunVisitPaneState extends State { selected: _section, onSelected: (section) => setState(() => _section = section), ), - // Reading sections keep a readable width on a wide window; the - // gallery and the changes viewer keep the whole page. - child: _capped( - runVisitSectionBody( - section: _section, - run: widget.run, - step: widget.step, - visitIndex: widget.visitIndex, - stageKey: widget.visit.stage, - runSteps: widget.runSteps, - gateway: widget.gateway, - onRunChanged: widget.onRunChanged, - configuredEndpoint: widget.configuredEndpoint, - cupertino: widget.cupertino, - facts: RunVisitFactsView(step: widget.step), - ), + // Every section fills the page, on a phone and an unfolded foldable. + child: runVisitSectionBody( + section: _section, + run: widget.run, + step: widget.step, + visitIndex: widget.visitIndex, + stageKey: widget.visit.stage, + runSteps: widget.runSteps, + gateway: widget.gateway, + onRunChanged: widget.onRunChanged, + configuredEndpoint: widget.configuredEndpoint, + cupertino: widget.cupertino, + facts: RunVisitFactsView(step: widget.step), ), ), ); } - - Widget _capped(Widget body) => switch (_section) { - RunVisitSection.artifacts || RunVisitSection.changes => body, - _ => ReadingWidth(child: body), - }; } /// The page bar's subtitle for a recorded visit: its per-stage visit, then the run diff --git a/app/lib/ui/layout/reading_width.dart b/app/lib/ui/layout/reading_width.dart deleted file mode 100644 index 86b50800..00000000 --- a/app/lib/ui/layout/reading_width.dart +++ /dev/null @@ -1,40 +0,0 @@ -import 'dart:math' as math; - -import 'package:flutter/widgets.dart'; - -/// The widest a detail's reading body (a run or pipeline Summary, a stage -/// page's sections) grows on a wide window, so its text, trailing copy -/// buttons and facts stay within reach of the title instead of stretching -/// to the window's far edge. -const double kReadingMaxWidth = 840; - -/// Caps [child] at [maxWidth] from the leading edge, where the detail's bar -/// pieces, header strip and tabs start. It passes the full height through -/// unchanged, so a scrollable child fills the height as before; only its -/// width is capped. -class ReadingWidth extends StatelessWidget { - const ReadingWidth({ - super.key, - required this.child, - this.maxWidth = kReadingMaxWidth, - }); - - final Widget child; - final double maxWidth; - - @override - Widget build(BuildContext context) => LayoutBuilder( - // One structure at every width, so resizing across the cap never - // remounts the body (its scroll offset and open sections stay). - builder: (context, constraints) { - return Align( - alignment: AlignmentDirectional.topStart, - child: SizedBox( - width: math.min(maxWidth, constraints.maxWidth), - height: constraints.hasBoundedHeight ? constraints.maxHeight : null, - child: child, - ), - ); - }, - ); -} diff --git a/app/lib/ui/status/outcome_palette.dart b/app/lib/ui/status/outcome_palette.dart index a199d516..c940b138 100644 --- a/app/lib/ui/status/outcome_palette.dart +++ b/app/lib/ui/status/outcome_palette.dart @@ -1,28 +1,44 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -/// Colours for recorded outcome names, assigned per run by first appearance. +/// Colours for recorded outcome names within one run. /// -/// 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. +/// Well-known outcome words get a colour family that matches their meaning — +/// success-like words are green, failures red, rejections orange, retries and +/// advisories amber, skips and cancellations grey — and every other word gets +/// a distinct hue outside those families, by first appearance. The same name +/// always gets the same colour, and two different names never share one: a +/// second word of the same family takes that family's next shade. class OutcomePalette { OutcomePalette(Iterable outcomes) { + final familyUse = <_Family, int>{}; + var other = 0; for (final outcome in outcomes) { final key = _key(outcome); - if (key.isNotEmpty) _index.putIfAbsent(key, () => _index.length); + if (key.isEmpty || _swatches.containsKey(key)) continue; + final family = _familyOf(key); + if (family != null) { + final used = familyUse[family] ?? 0; + final shades = _familyShades[family]!; + if (used < shades.length) { + familyUse[family] = used + 1; + _swatches[key] = _Swatch.material(shades[used]); + continue; + } + } + _swatches[key] = other < _otherHues.length + ? _Swatch.material(_otherHues[other]) + : _Swatch.wheel(other); + other += 1; } } - final Map _index = {}; + final Map _swatches = {}; 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)]; + /// Whether [outcome] was seen (and so has a colour of its own). + bool contains(String outcome) => _swatches.containsKey(_key(outcome)); /// [outcome]'s colour for the host's brightness; an unseen or blank name /// uses the host's secondary text colour. @@ -32,37 +48,107 @@ class OutcomePalette { final brightness = cupertino ? CupertinoTheme.brightnessOf(context) : Theme.of(context).brightness; - final index = indexOf(outcome); - if (index == null) { + final swatch = _swatches[_key(outcome)]; + if (swatch == null) { return cupertino ? CupertinoColors.secondaryLabel.resolveFrom(context) : Theme.of(context).colorScheme.onSurfaceVariant; } - return outcomeColorAt(index, brightness); + return swatch.resolve(brightness); } + + /// [outcome]'s colour on a page of [brightness], or null when unseen. + Color? colorForBrightness(String outcome, Brightness brightness) => + _swatches[_key(outcome)]?.resolve(brightness); } -const List _hues = [ +enum _Family { success, failure, rejection, caution, neutral } + +/// The meaning a well-known outcome word carries, if any. +_Family? _familyOf(String key) { + final word = key.replaceAll(RegExp(r'[\s-]+'), '_'); + const success = { + 'success', + 'succeeded', + 'ok', + 'pass', + 'passed', + 'approved', + 'accepted', + 'done', + 'completed', + 'complete', + 'merged', + 'landed', + }; + const failure = {'error', 'failure', 'failed', 'fail', 'crashed', 'broken'}; + const rejection = { + 'rejected', + 'reject', + 'blocked', + 'denied', + 'declined', + 'changes_requested', + }; + const caution = { + 'retry', + 'blocked_retryable', + 'advisory', + 'warning', + 'needs_work', + 'partial', + }; + const neutral = { + 'skipped', + 'skip', + 'canceled', + 'cancelled', + 'stopped', + 'none', + }; + if (success.contains(word)) return _Family.success; + if (failure.contains(word)) return _Family.failure; + if (rejection.contains(word)) return _Family.rejection; + if (caution.contains(word)) return _Family.caution; + if (neutral.contains(word)) return _Family.neutral; + return null; +} + +/// Each family's shades, in the order successive distinct words take them. +const Map<_Family, List> _familyShades = { + _Family.success: [Colors.green, Colors.lightGreen, Colors.teal], + _Family.failure: [Colors.red, Colors.pink], + _Family.rejection: [Colors.deepOrange, Colors.orange], + _Family.caution: [Colors.amber, Colors.yellow], + _Family.neutral: [Colors.blueGrey, Colors.grey], +}; + +/// Hues for words with no family, chosen away from the family colours. +const List _otherHues = [ Colors.blue, - Colors.green, - Colors.deepOrange, Colors.purple, - Colors.teal, - Colors.pink, - Colors.amber, Colors.indigo, - Colors.brown, Colors.cyan, + Colors.brown, + Colors.deepPurple, + Colors.lightBlue, ]; -/// 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; +class _Swatch { + const _Swatch.material(MaterialColor this.color) : wheelIndex = null; + const _Swatch.wheel(int this.wheelIndex) : color = null; + + final MaterialColor? color; + final int? wheelIndex; + + Color resolve(Brightness brightness) { + final dark = brightness == Brightness.dark; + final material = color; + if (material != null) return dark ? material.shade300 : material.shade800; + // Past the named hues, continue round the wheel by the golden angle, + // starting from a blue-violet so the next words stay clear of the + // families' greens, reds, oranges and ambers. + final degrees = (230 + wheelIndex! * 137.508) % 360; + return HSLColor.fromAHSL(1, degrees, 0.55, dark ? 0.72 : 0.35).toColor(); } - 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_detail_summary_fields_test.dart b/app/test/features/runs/ui/run_detail_summary_fields_test.dart index ca702c4e..d38fd4b9 100644 --- a/app/test/features/runs/ui/run_detail_summary_fields_test.dart +++ b/app/test/features/runs/ui/run_detail_summary_fields_test.dart @@ -218,8 +218,8 @@ void main() { ); // The grid spans the Summary, and its one fact is at the start of the // line rather than a half-width block centred on the page. - // Full Summary width, up to the shared reading cap (840) on wide panes. - expect(grid.width, moreOrLessEquals(840)); + // The grid spans the whole Summary width. + expect(grid.width, moreOrLessEquals(900)); expect(stage.left, moreOrLessEquals(16)); expect(stage.center.dx, lessThan(450)); expect(find.byType(CupertinoListSection), findsNothing); diff --git a/app/test/features/runs/ui/run_detail_tabs_test.dart b/app/test/features/runs/ui/run_detail_tabs_test.dart index be44a2ac..4de353d0 100644 --- a/app/test/features/runs/ui/run_detail_tabs_test.dart +++ b/app/test/features/runs/ui/run_detail_tabs_test.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:pipelines_app/ui/layout/reading_width.dart'; import 'package:pipelines_app/features/runs/ui/run_graph_preview.dart'; import 'package:pipelines_app/features/runs/ui/run_more_menu.dart'; import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart'; @@ -114,10 +113,9 @@ void main() { expect(widePill.right, 1000 - 16); expect(widePill.bottom, 844 - 16); expect(widePill.width, lessThan(1000 * 0.6)); - // Beside the bar the content takes taps: the body spans the reading - // width from the leading edge (Summary is capped on a wide pane). + // Beside the bar the content takes taps: the body fills the pane. expect(tester.getRect(body).left, 0); - expect(tester.getRect(body).width, kReadingMaxWidth); + expect(tester.getRect(body).width, 1000); }); testWidgets('${platform.name} missing graph states the exact wording', ( diff --git a/app/test/ui/layout/reading_width_test.dart b/app/test/ui/layout/reading_width_test.dart deleted file mode 100644 index 7de8aa78..00000000 --- a/app/test/ui/layout/reading_width_test.dart +++ /dev/null @@ -1,115 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:pipelines_app/features/pipelines/pipeline_repository.dart'; -import 'package:pipelines_app/features/pipelines/pipelines_controller.dart'; -import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_panel.dart'; -import 'package:pipelines_app/features/pipelines/widgets/pipeline_summary_view.dart'; -import 'package:pipelines_app/ui/layout/reading_width.dart'; - -import '../../features/pipelines/fixtures.dart'; -import '../../features/pipelines/test_helpers.dart'; -import '../../features/runs/ui/run_detail_graph_support.dart'; -import '../../features/runs/ui/run_detail_visit_support.dart'; - -/// Reading bodies (run Summary, stage page sections, pipeline Summary) keep -/// [kReadingMaxWidth] from the leading edge on a wide window and the full -/// width on a phone. -void main() { - Future setSize(WidgetTester tester, Size size) async { - tester.view.physicalSize = size; - tester.view.devicePixelRatio = 1; - addTearDown(tester.view.reset); - } - - testWidgets('ReadingWidth caps from the leading edge and keeps its child ' - 'across the cap', (tester) async { - await setSize(tester, const Size(1200, 600)); - final scroll = ScrollController(); - addTearDown(scroll.dispose); - await tester.pumpWidget( - MaterialApp( - home: ReadingWidth( - child: ListView( - key: const Key('body'), - controller: scroll, - children: [ - for (var index = 0; index < 50; index++) - SizedBox(height: 40, child: Text('row $index')), - ], - ), - ), - ), - ); - final wide = tester.getRect(find.byKey(const Key('body'))); - expect(wide.left, 0); - expect(wide.width, kReadingMaxWidth); - expect(wide.height, 600); - scroll.jumpTo(300); - await tester.pump(); - - await setSize(tester, const Size(500, 600)); - await tester.pump(); - expect(tester.getRect(find.byKey(const Key('body'))).width, 500); - expect(scroll.offset, 300, reason: 'the body was not remounted'); - }); - - for (final platform in RunDetailTestPlatform.values) { - testWidgets('${platform.name} 1200: run Summary is capped', (tester) async { - await pumpRunDetail(tester, platform, size: const Size(1200, 800)); - final body = tester.getRect( - find.byKey(const Key('run-detail-tab-body-summary')), - ); - expect(body.left, 0); - expect(body.width, kReadingMaxWidth); - }); - - testWidgets('${platform.name} 390: run Summary keeps the full width', ( - tester, - ) async { - await pumpRunDetail(tester, platform, size: const Size(390, 844)); - final body = tester.getRect( - find.byKey(const Key('run-detail-tab-body-summary')), - ); - expect(body.width, 390); - }); - - testWidgets('${platform.name} 1200: stage page Summary is capped', ( - tester, - ) async { - await openVisit(tester, platform, size: const Size(1200, 900)); - final body = tester.getRect( - find.byKey(const Key('run-visit-body-summary')), - ); - expect(body.left, 0); - expect(body.width, kReadingMaxWidth); - // The section's trailing copy button sits within the cap. - final copy = find.byKey(const ValueKey('run-visit-copy-Input')); - expect(tester.getRect(copy).right, lessThanOrEqualTo(kReadingMaxWidth)); - }); - } - - testWidgets('1200: pipeline Summary is capped, the pane still scrolls', ( - tester, - ) async { - await setSize(tester, const Size(1200, 800)); - final gateway = gatewayFor(PipelineFixture()); - final controller = PipelinesController(PipelinesRepository(gateway)); - addTearDown(controller.dispose); - await controller.openPipeline(1); - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: PipelineDetailPanel( - controller: controller, - gateway: gateway, - showBack: false, - ), - ), - ), - ); - await tester.pumpAndSettle(); - final summary = tester.getRect(find.byType(PipelineSummaryView)); - expect(summary.left, 0); - expect(summary.width, kReadingMaxWidth); - }); -} diff --git a/app/test/ui/status/outcome_palette_test.dart b/app/test/ui/status/outcome_palette_test.dart index 20f349ee..d0b4406e 100644 --- a/app/test/ui/status/outcome_palette_test.dart +++ b/app/test/ui/status/outcome_palette_test.dart @@ -3,29 +3,62 @@ 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); - }); + for (final brightness in Brightness.values) { + Color colour(OutcomePalette palette, String name) => + palette.colorForBrightness(name, brightness)!; + final dark = brightness == Brightness.dark; + Color shade(MaterialColor c) => dark ? c.shade300 : c.shade800; - 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'); - } + test('well-known outcomes take their meaning colour ($brightness)', () { + final palette = OutcomePalette([ + 'rejected', + 'retry', + 'Success', + 'error', + 'skipped', + ]); + expect(colour(palette, 'success'), shade(Colors.green)); + expect(colour(palette, 'error'), shade(Colors.red)); + expect(colour(palette, 'rejected'), shade(Colors.deepOrange)); + expect(colour(palette, 'retry'), shade(Colors.amber)); + expect(colour(palette, 'skipped'), shade(Colors.blueGrey)); + // Case and surrounding space do not make a different outcome. + expect(colour(palette, ' SUCCESS '), shade(Colors.green)); + }); + + test('different names never share a colour ($brightness)', () { + final names = [ + 'success', + 'approved', + 'passed', + 'done', + 'error', + 'failed', + 'fail', + 'rejected', + 'blocked', + 'denied', + 'retry', + 'advisory', + 'warning', + 'skipped', + 'canceled', + 'stopped', + for (var i = 0; i < 30; i++) 'custom-$i', + ]; + final palette = OutcomePalette(names); + final colours = {for (final name in names) colour(palette, name)}; + expect(colours, hasLength(names.length)); + // Two success-like words: both green family, but distinct shades. + expect(colour(palette, 'approved'), shade(Colors.lightGreen)); + }); + } + + test('unseen or blank names have no colour of their own', () { + final palette = OutcomePalette(['success', '']); + expect(palette.contains('success'), isTrue); + expect(palette.contains(''), isFalse); + expect(palette.contains('other'), isFalse); + expect(palette.colorForBrightness('other', Brightness.light), isNull); }); }