95 lines
3.3 KiB
Dart
95 lines
3.3 KiB
Dart
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),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|