feat(app): run rows show the run's path as a small coloured miniature
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/status/run_status_icon.dart';
|
||||
import '../../graph/widgets/graph_stage_node.dart' show graphStatusState;
|
||||
|
||||
/// One stage on a run's path: its key and the state its latest visit left.
|
||||
typedef RunPathStage = ({String key, String state});
|
||||
|
||||
/// The stages a run visited, in first-visit order, each with the state of its
|
||||
/// latest visit, plus the end it reached (`#success`/`#failure`) if any. Read
|
||||
/// from the run's recorded steps or the list row's `graph_evidence`.
|
||||
({List<RunPathStage> stages, String? end}) runPath(JsonMap run) {
|
||||
final raw = run['steps'] is List
|
||||
? run['steps'] as List
|
||||
: (run['graph_evidence'] is Map
|
||||
? (run['graph_evidence'] as Map)['visits'] as List? ?? const []
|
||||
: const []);
|
||||
final order = <String>[];
|
||||
final states = <String, String>{};
|
||||
String? end;
|
||||
for (final entry in raw) {
|
||||
if (entry is! Map) continue;
|
||||
final key = '${entry['stage'] ?? ''}'.trim();
|
||||
if (key.isEmpty) continue;
|
||||
if (!states.containsKey(key)) order.add(key);
|
||||
final target = '${entry['target'] ?? ''}'.trim();
|
||||
final outcome = '${entry['outcome'] ?? ''}'.trim();
|
||||
final status = '${entry['status'] ?? ''}'.trim();
|
||||
states[key] = target == '#failure' || outcome == 'error'
|
||||
? 'failed'
|
||||
: graphStatusState(status.isEmpty ? outcome : status);
|
||||
if (target == '#success' || target == '#failure') end = target;
|
||||
}
|
||||
return (
|
||||
stages: [for (final key in order) (key: key, state: states[key]!)],
|
||||
end: end,
|
||||
);
|
||||
}
|
||||
|
||||
/// A run's path as a small picture: one coloured box per visited stage,
|
||||
/// joined in order, and a dot for the end it reached.
|
||||
class RunPathMini extends StatelessWidget {
|
||||
const RunPathMini({super.key, required this.run, this.maxStages = 6});
|
||||
|
||||
final JsonMap run;
|
||||
final int maxStages;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final path = runPath(run);
|
||||
if (path.stages.isEmpty) return const SizedBox.shrink();
|
||||
// A long path keeps its latest stages.
|
||||
final stages = path.stages.length > maxStages
|
||||
? path.stages.sublist(path.stages.length - maxStages)
|
||||
: path.stages;
|
||||
final line = CupertinoColors.separator.resolveFrom(context);
|
||||
Widget box(RunPathStage stage) => Container(
|
||||
width: 14,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: runStatusColor(stage.state).resolveFrom(context),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
);
|
||||
Widget join() => Container(width: 5, height: 1.5, color: line);
|
||||
final end = path.end;
|
||||
return ExcludeSemantics(
|
||||
child: Row(
|
||||
key: const Key('run-path-mini'),
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (var index = 0; index < stages.length; index += 1) ...[
|
||||
if (index > 0) join(),
|
||||
box(stages[index]),
|
||||
],
|
||||
if (end != null) ...[
|
||||
join(),
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: runStatusColor(
|
||||
end == '#success' ? 'succeeded' : 'failed',
|
||||
).resolveFrom(context),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import '../../attention/runtime/attention_store.dart';
|
||||
import '../../attention/ui/needs_you_runs_heading.dart';
|
||||
import '../domain/run_models.dart';
|
||||
import '../../../shell/shell_bar.dart';
|
||||
import 'run_path_mini.dart';
|
||||
import 'runs_controller.dart';
|
||||
import 'runs_stats_page.dart';
|
||||
import 'runs_filters.dart';
|
||||
@@ -262,6 +263,14 @@ class RunListRow extends StatelessWidget {
|
||||
small,
|
||||
),
|
||||
line(facts.when, facts.progress, small),
|
||||
// The run's path, each stage in its own result colour.
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
child: RunPathMini(run: run),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_path_mini.dart';
|
||||
|
||||
void main() {
|
||||
final run = {
|
||||
'graph_evidence': {
|
||||
'complete': true,
|
||||
'visits': [
|
||||
{'stage': 'plan', 'status': 'completed', 'outcome': 'success'},
|
||||
{'stage': 'build', 'status': 'completed', 'outcome': 'retry'},
|
||||
{
|
||||
'stage': 'build',
|
||||
'status': 'completed',
|
||||
'outcome': 'error',
|
||||
'target': '#failure',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
test('the path keeps first-visit order and each stage latest state', () {
|
||||
final path = runPath(run);
|
||||
expect(path.stages.map((stage) => stage.key), ['plan', 'build']);
|
||||
expect(path.stages.map((stage) => stage.state), ['succeeded', 'failed']);
|
||||
expect(path.end, '#failure');
|
||||
expect(runPath({}).stages, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('the miniature colours each stage by its result', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(child: RunPathMini(run: run)),
|
||||
),
|
||||
),
|
||||
);
|
||||
final colors = tester
|
||||
.widgetList<Container>(find.byType(Container))
|
||||
.map((box) => (box.decoration as BoxDecoration?)?.color)
|
||||
.whereType<Color>()
|
||||
.map((color) => color.toARGB32())
|
||||
.toList();
|
||||
expect(colors, contains(CupertinoColors.systemGreen.color.toARGB32()));
|
||||
expect(colors, contains(CupertinoColors.systemRed.color.toARGB32()));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user