import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart'; /// plan -> build -> audit with a taken path that stops at the running build and /// untaken routes to audit and both terminals. JsonMap _graph() => { 'stages': [ { 'key': 'plan', 'type': 'model', 'edges': {'success': 'build', 'error': '#'}, 'fallback_error': true, }, { 'key': 'build', 'type': 'shell', 'edges': {'success': 'audit', 'error': '#'}, }, { 'key': 'audit', 'type': 'model', 'edges': {'success': '#success', 'error': '#failure'}, }, ], }; JsonMap _runningRun() { final started = DateTime.now().toUtc().subtract( const Duration(minutes: 2, seconds: 5), ); return { 'id': 42, 'executing': true, 'current_stage': 'build', 'steps': [ { 'sequence': 1, 'stage': 'plan', 'status': 'completed', 'outcome': 'success', 'target': 'build', }, { 'sequence': 2, 'stage': 'build', 'status': 'running', 'outcome': '', 'target': '', 'started_at': started.toIso8601String(), }, ], }; } JsonMap _finishedRun() => { 'id': 42, 'executing': false, 'current_stage': '', 'steps': [ { 'sequence': 1, 'stage': 'plan', 'status': 'completed', 'outcome': 'success', 'target': 'build', }, { 'sequence': 2, 'stage': 'build', 'status': 'completed', 'outcome': 'success', 'target': 'audit', }, { 'sequence': 3, 'stage': 'audit', 'status': 'completed', 'outcome': 'success', 'target': '#', }, ], }; /// Isolated browser fixture for `RunGraphView` only. /// /// `style=cupertino` selects the Cupertino host, `dark=1` its dark theme and /// `scale=2` a real 2x text scale. `case=finished` records a resolved success /// terminal instead of the running path; `case=missing` omits the graph. A /// click reports the exact visited stage key; unvisited nodes report nothing. void main() { final parameters = Uri.base.queryParameters; runApp( _ProbeApp( cupertino: parameters['style'] == 'cupertino', dark: parameters['dark'] == '1', scale: double.tryParse(parameters['scale'] ?? '') ?? 1, fixture: parameters['case'] ?? 'running', ), ); } class _ProbeApp extends StatelessWidget { const _ProbeApp({ required this.cupertino, required this.dark, required this.scale, required this.fixture, }); final bool cupertino; final bool dark; final double scale; final String fixture; @override Widget build(BuildContext context) { final page = _ProbePage( scale: scale, graph: fixture == 'missing' ? null : _graph(), run: fixture == 'finished' ? _finishedRun() : _runningRun(), ); if (cupertino) { return CupertinoApp( theme: CupertinoThemeData( brightness: dark ? Brightness.dark : Brightness.light, ), home: CupertinoPageScaffold( navigationBar: const CupertinoNavigationBar( middle: Text('Run graph'), ), child: SafeArea(child: page), ), ); } return MaterialApp( theme: ThemeData( platform: TargetPlatform.android, brightness: Brightness.light, ), darkTheme: ThemeData( platform: TargetPlatform.android, brightness: Brightness.dark, ), themeMode: dark ? ThemeMode.dark : ThemeMode.light, home: Scaffold( appBar: AppBar(title: const Text('Run graph')), body: SafeArea(child: page), ), ); } } class _ProbePage extends StatefulWidget { const _ProbePage({ required this.scale, required this.graph, required this.run, }); final double scale; final JsonMap? graph; final JsonMap run; @override State<_ProbePage> createState() => _ProbePageState(); } class _ProbePageState extends State<_ProbePage> { String? _selected; @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('Selected: ${_selected ?? 'none'}'), const SizedBox(height: 8), Expanded( child: MediaQuery( data: MediaQuery.of( context, ).copyWith(textScaler: TextScaler.linear(widget.scale)), child: RunGraphView( graph: widget.graph, run: widget.run, selectedStage: _selected, onStageSelected: (key) => setState(() => _selected = key), ), ), ), ], ), ); } }