Merge branch 'main' into worktree-agent-aab11f4f1fe3dff6b
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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<String> outcomes) {
|
||||
for (final outcome in outcomes) {
|
||||
final key = _key(outcome);
|
||||
if (key.isNotEmpty) _index.putIfAbsent(key, () => _index.length);
|
||||
}
|
||||
}
|
||||
|
||||
final Map<String, int> _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<MaterialApp>() == 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<MaterialColor> _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();
|
||||
}
|
||||
@@ -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<Text>(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')));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user