diff --git a/app/lib/features/pipelines/pipeline_models.dart b/app/lib/features/pipelines/pipeline_models.dart index 40dfb344..ed1c6ad8 100644 --- a/app/lib/features/pipelines/pipeline_models.dart +++ b/app/lib/features/pipelines/pipeline_models.dart @@ -24,6 +24,7 @@ class PipelineSummary { required this.enabledScheduleCount, this.recordedStages, this.flowStages, + this.shape, }); factory PipelineSummary.fromJson(PipelineJson json) { @@ -45,6 +46,7 @@ class PipelineSummary { scheduled: scheduled is bool ? scheduled : null, scheduleCount: scheduleCount, enabledScheduleCount: _optionalInt(json['enabled_schedule_count']), + shape: _jsonObject(json['shape']), ); } @@ -68,6 +70,13 @@ class PipelineSummary { /// The stage count recorded by the current version's optional `shape` flow. final int? flowStages; + /// The current version's recorded flow, when the summary carries one. + /// + /// Raw JSON like a detail's graph: the row's miniature draws it without + /// normalising, fetching or inventing a stage. Null is "not recorded", not an + /// empty flow. + final PipelineJson? shape; + /// The list row's stage count from recorded values only: the summary's own /// count, else the recorded flow's count, else its plain [stages] field. /// Zero only when none was recorded, which is the web row's own fallback. @@ -136,13 +145,13 @@ class PipelineDetail extends PipelineSummary { required super.enabledScheduleCount, super.recordedStages, super.flowStages, + super.shape, required this.latestVersion, required this.versionCreatedAt, required this.contentHash, required this.source, required this.versions, this.graph, - this.shape, }); factory PipelineDetail.fromJson(PipelineJson json) { @@ -160,6 +169,7 @@ class PipelineDetail extends PipelineSummary { enabledScheduleCount: summary.enabledScheduleCount, recordedStages: summary.recordedStages, flowStages: summary.flowStages, + shape: summary.shape, latestVersion: _int(json['latest_version']), versionCreatedAt: _string(json['version_created_at']), contentHash: _string(json['content_hash']), @@ -174,7 +184,6 @@ class PipelineDetail extends PipelineSummary { ) : const [], graph: _jsonObject(json['graph']), - shape: _jsonObject(json['shape']), ); } @@ -190,9 +199,6 @@ class PipelineDetail extends PipelineSummary { /// carried no graph, which is not the same as a definition with no stages. final PipelineJson? graph; - /// The optional compact graph summary some replies add, kept verbatim. - final PipelineJson? shape; - /// The concrete version this detail describes. A request for version 0 asks /// for latest, so the reply's own `version` is authoritative for display. int get resolvedVersion => version > 0 ? version : latestVersion; diff --git a/app/lib/features/pipelines/widgets/pipeline_list_panel.dart b/app/lib/features/pipelines/widgets/pipeline_list_panel.dart index cbdbe2f6..2820f605 100644 --- a/app/lib/features/pipelines/widgets/pipeline_list_panel.dart +++ b/app/lib/features/pipelines/widgets/pipeline_list_panel.dart @@ -1,6 +1,14 @@ +import 'dart:math' as math; + import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../graph/domain/graph_definition.dart'; +import '../../graph/layout/graph_node_layout.dart'; +import '../../graph/layout/layout_models.dart'; +import '../../graph/routing/graph_edge_routing.dart'; +import '../../graph/routing/route_models.dart'; +import '../../graph/widgets/graph_canvas_style.dart'; import '../pipeline_format.dart'; import '../pipeline_models.dart'; import '../pipeline_query.dart'; @@ -152,7 +160,7 @@ class PipelineListPanel extends StatelessWidget { selected: controller.selectedId == pipeline.id, onTap: () => controller.openPipeline(pipeline.id, version: pipeline.version), - title: Text(pipeline.displayName), + title: _rowTitle(context, pipeline), subtitle: _subtitle(context, pipeline, now), ); }, @@ -169,7 +177,7 @@ class PipelineListPanel extends StatelessWidget { for (final pipeline in items) CupertinoListTile( key: Key('pipeline-row-${pipeline.id}'), - title: Text(pipeline.displayName), + title: _rowTitle(context, pipeline), subtitle: _subtitle(context, pipeline, now), trailing: const CupertinoListTileChevron(), onTap: () => controller.openPipeline( @@ -183,6 +191,22 @@ class PipelineListPanel extends StatelessWidget { ); } + /// The row's name plus its recorded miniature, when the reply carried one. + /// The trailing cue never replaces or fills in any metadata line. + Widget _rowTitle(BuildContext context, PipelineSummary pipeline) { + final shape = pipeline.shape; + return Row( + children: [ + Expanded(child: Text(pipeline.displayName)), + if (shape != null) + PipelineMiniGraph( + key: Key('pipeline-mini-${pipeline.id}'), + shape: shape, + ), + ], + ); + } + Widget _subtitle( BuildContext context, PipelineSummary pipeline, @@ -218,3 +242,176 @@ class PipelineListPanel extends StatelessWidget { ); } } + +/// The row's recorded flow cue: label-free stage boxes and their routes. +/// +/// Mirrors `web/src/miniGraph.js` and `.pipeline-mini`: stage nodes only (no +/// terminals, labels or placeholder), drawn from the shared graph layout and +/// routing. Nothing is fetched and no node is invented, so a summary without a +/// recorded `shape` draws no cue. +class PipelineMiniGraph extends StatelessWidget { + const PipelineMiniGraph({super.key, required this.shape}); + + /// The summary's recorded flow (`shape`), verbatim. + final PipelineJson shape; + + // The cue's graph coordinates, matching the web miniature's own metrics. + // These are drawing coordinates for a graph, not row/control dimensions. + static const double _nodeWidth = 26; + static const double _nodeHeight = 12; + static const double _columnGap = 12; + static const double _rowGap = 8; + static const double _padding = 2; + static const double _maxWidth = 180; + static const double _maxHeight = 22; + + @override + Widget build(BuildContext context) { + final flow = _miniatureFlow(shape); + if (flow == null) return const SizedBox.shrink(); + final nodes = graphNodes(flow); + final edges = graphEdges(flow); + final layout = layoutGraphNodes( + nodes: nodes, + edges: edges, + extents: { + for (final node in nodes) + node.key: NodeExtent(width: _nodeWidth, height: _nodeHeight), + }, + config: GraphLayoutConfig( + columnGap: _columnGap, + rowGap: _rowGap, + padding: _padding, + ), + ); + final routing = routeGraphEdges( + layout: layout, + edges: edges, + labelExtents: { + // The cue is deliberately label-free, like the web miniature. + for (final edge in edges) edge.id: LabelExtent(width: 0, height: 0), + }, + config: RoutingConfig( + nodeClearance: 2, + laneSpacing: 6, + corridorSpacing: 4, + portSpacing: 3, + labelGap: 0, + boundsPadding: 2, + ), + ); + final style = GraphCanvasStyle.of(context); + final size = Size(math.max(routing.width, 1), math.max(routing.height, 1)); + return ExcludeSemantics( + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 8), + child: ConstrainedBox( + constraints: const BoxConstraints( + maxWidth: _maxWidth, + maxHeight: _maxHeight, + ), + child: FittedBox( + fit: BoxFit.contain, + alignment: AlignmentDirectional.centerEnd, + child: SizedBox( + width: size.width, + height: size.height, + child: CustomPaint( + painter: _MiniGraphPainter( + layout: layout, + routes: routing.routes, + color: style.edgeColor, + strokeWidth: style.edgeWidth, + ), + ), + ), + ), + ), + ), + ); + } + + /// The recorded stages with edges kept only between declared stage keys. + /// + /// This is the web miniature's own filter: terminal routes (`#success`/ + /// `#failure`) and unknown targets are not drawn as cue nodes, and a shape + /// with no declared stage key yields no cue. + Map? _miniatureFlow(PipelineJson raw) { + final stages = raw['stages']; + if (stages is! List) return null; + final recorded = >[]; + final keys = {}; + for (final entry in stages) { + if (entry is! Map) continue; + final stage = Map.from(entry); + final key = '${stage['key'] ?? ''}'; + if (key.isEmpty) continue; + recorded.add(stage); + keys.add(key); + } + if (recorded.isEmpty) return null; + for (final stage in recorded) { + final edges = stage['edges']; + if (edges is! Map) continue; + stage['edges'] = { + for (final edge in edges.entries) + if (keys.contains('${edge.value}')) '${edge.key}': edge.value, + }; + } + return {'stages': recorded}; + } +} + +/// Paints the miniature's routed edges and rounded stage boxes in graph space. +class _MiniGraphPainter extends CustomPainter { + _MiniGraphPainter({ + required this.layout, + required this.routes, + required this.color, + required this.strokeWidth, + }); + + final GraphLayout layout; + final List routes; + final Color color; + final double strokeWidth; + + @override + void paint(Canvas canvas, Size size) { + canvas.save(); + canvas.clipRect(Offset.zero & size); + final edgePaint = Paint() + ..color = color.withValues(alpha: 0.5) + ..strokeWidth = strokeWidth + ..style = PaintingStyle.stroke + ..strokeJoin = StrokeJoin.round; + for (final route in routes) { + if (route.points.length < 2) continue; + final path = Path()..moveTo(route.points.first.x, route.points.first.y); + for (var index = 1; index < route.points.length; index += 1) { + path.lineTo(route.points[index].x, route.points[index].y); + } + canvas.drawPath(path, edgePaint); + } + final nodePaint = Paint() + ..color = color.withValues(alpha: 0.55) + ..style = PaintingStyle.fill; + for (final box in layout.nodes) { + canvas.drawRRect( + RRect.fromRectAndRadius( + Rect.fromLTWH(box.x, box.y, box.width, box.height), + const Radius.circular(3), + ), + nodePaint, + ); + } + canvas.restore(); + } + + @override + bool shouldRepaint(covariant _MiniGraphPainter oldDelegate) => + oldDelegate.color != color || + oldDelegate.strokeWidth != strokeWidth || + !identical(oldDelegate.layout, layout) || + !identical(oldDelegate.routes, routes); +} diff --git a/app/test/features/pipelines/pipeline_row_miniature_test.dart b/app/test/features/pipelines/pipeline_row_miniature_test.dart new file mode 100644 index 00000000..176ef6dc --- /dev/null +++ b/app/test/features/pipelines/pipeline_row_miniature_test.dart @@ -0,0 +1,72 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/pipelines/widgets/pipeline_list_panel.dart'; + +import 'fixtures.dart'; +import 'test_helpers.dart'; + +/// The list row's recorded flow cue: the reply's `shape` is drawn through the +/// shared graph layout, and nothing is invented or fetched when it is absent. +void main() { + group('pipeline row miniature', () { + testWidgets('a recorded shape draws the row miniature', (tester) async { + final fixture = PipelineFixture(); + final gateway = gatewayFor( + fixture, + summaries: [ + pipelineSummary(id: 7, name: 'Shape', stages: 2) + ..['shape'] = reviewGraph(), + ], + ); + + await pumpWide(tester, gateway); + + expect(find.byKey(const Key('pipeline-mini-7')), findsOneWidget); + // The cue is additive: the recorded metadata line is unchanged. + expect(find.text('id 7 · v1 · 2 stages'), findsOneWidget); + }); + + testWidgets('a summary without a shape draws no miniature', (tester) async { + final fixture = PipelineFixture(); + final gateway = gatewayFor( + fixture, + summaries: [pipelineSummary(id: 8, name: 'Bare')], + ); + + await pumpWide(tester, gateway); + + expect(find.byType(PipelineMiniGraph), findsNothing); + expect(find.byKey(const Key('pipeline-mini-8')), findsNothing); + expect(find.text('id 8 · v1 · 1 stage'), findsOneWidget); + }); + + testWidgets('a miniature never fetches another origin or pipeline detail', ( + tester, + ) async { + final fixture = PipelineFixture(); + final shape = reviewGraph(); + final stage = (shape['stages'] as List).first as Map; + // A recorded external preview must be ignored: the row draws only the + // recorded flow and never requests another origin. + stage['preview'] = 'https://images.example.test/mini.png'; + stage['url'] = 'https://images.example.test/mini.png'; + final gateway = gatewayFor( + fixture, + summaries: [ + pipelineSummary(id: 9, name: 'Remote', stages: 2)..['shape'] = shape, + ], + ); + + await pumpWide(tester, gateway); + + expect(find.byKey(const Key('pipeline-mini-9')), findsOneWidget); + expect(find.byType(Image), findsNothing); + expect(gateway.callsOf('get_pipeline'), isEmpty); + expect( + gateway.calls.map((call) => call.type), + everyElement(isIn(['list_pipelines', 'list_runs'])), + ); + expect(find.text('id 9 · v1 · 2 stages'), findsOneWidget); + }); + }); +}