From dd324d1f92e01b844ce1daec8b3e4500d2d4dc98 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 22:43:35 +0100 Subject: [PATCH 1/2] feat(app): artifact viewer actions are bottom icons; swipe pages; native download, share and open in browser --- app/android/app/src/main/AndroidManifest.xml | 9 + .../actions/artifact_file_actions.dart | 96 +++++++++- .../artifacts/actions/artifact_transfer.dart | 1 + .../actions/artifact_transfer_io.dart | 56 ++++++ .../artifacts/ui/artifact_external_open.dart | 1 + .../ui/artifact_external_open_io.dart | 11 ++ .../artifacts/ui/artifact_viewer_body.dart | 155 ++++++++-------- app/pubspec.lock | 168 ++++++++++++++++++ app/pubspec.yaml | 3 + .../actions/artifact_file_actions_test.dart | 24 ++- .../ui/artifact_gallery_page_test.dart | 5 +- .../ui/artifact_viewer_page_test.dart | 44 ++++- 12 files changed, 476 insertions(+), 97 deletions(-) create mode 100644 app/lib/features/artifacts/actions/artifact_transfer_io.dart create mode 100644 app/lib/features/artifacts/ui/artifact_external_open_io.dart diff --git a/app/android/app/src/main/AndroidManifest.xml b/app/android/app/src/main/AndroidManifest.xml index dce5eb9a..53f7c6c9 100644 --- a/app/android/app/src/main/AndroidManifest.xml +++ b/app/android/app/src/main/AndroidManifest.xml @@ -56,5 +56,14 @@ + + + + + + + + + diff --git a/app/lib/features/artifacts/actions/artifact_file_actions.dart b/app/lib/features/artifacts/actions/artifact_file_actions.dart index 39fa72b7..1000980a 100644 --- a/app/lib/features/artifacts/actions/artifact_file_actions.dart +++ b/app/lib/features/artifacts/actions/artifact_file_actions.dart @@ -23,8 +23,12 @@ class ArtifactFileActions extends StatefulWidget { required this.resolved, this.fetch = fetchArtifact, this.bridge = const ArtifactFileBridge(), + this.compact = false, }); + /// Icon buttons only (a viewer's bottom bar): no labels and no notices. + final bool compact; + final ArtifactRecord artifact; final ResolvedArtifactUrl resolved; final ArtifactFetch fetch; @@ -74,10 +78,12 @@ class _ArtifactFileActionsState extends State { Widget build(BuildContext context) { return ListenableBuilder( listenable: _controller, - builder: (context, _) => _ActionBar( - controller: _controller, - cupertino: usesCupertinoHost(context), - ), + builder: (context, _) => widget.compact + ? _IconActions(controller: _controller) + : _ActionBar( + controller: _controller, + cupertino: usesCupertinoHost(context), + ), ); } } @@ -185,3 +191,85 @@ class _ActionBar extends StatelessWidget { ); } } + +/// Download and Share as icon buttons; a spinner stands in for the one in +/// progress. A host that cannot download or share simply has no button. +class _IconActions extends StatelessWidget { + const _IconActions({required this.controller}); + + final ArtifactFileActionsController controller; + + @override + Widget build(BuildContext context) { + final busy = controller.busy; + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (controller.canDownload) + ArtifactIconAction( + key: const Key('artifact-download'), + label: 'Download', + icon: Icons.download_outlined, + cupertinoIcon: CupertinoIcons.arrow_down_to_line, + busy: busy, + onPressed: busy ? null : controller.download, + ), + if (controller.canShare) + ArtifactIconAction( + key: const Key('artifact-share'), + label: 'Share', + icon: Icons.share_outlined, + cupertinoIcon: CupertinoIcons.share, + onPressed: busy ? null : controller.share, + ), + ], + ); + } +} + +/// One icon-only viewer action with its name as tooltip and accessible label. +class ArtifactIconAction extends StatelessWidget { + const ArtifactIconAction({ + super.key, + required this.label, + required this.icon, + required this.cupertinoIcon, + required this.onPressed, + this.busy = false, + }); + + final String label; + final IconData icon; + final IconData cupertinoIcon; + final VoidCallback? onPressed; + final bool busy; + + @override + Widget build(BuildContext context) { + if (usesCupertinoHost(context)) { + return Semantics( + button: true, + label: label, + child: CupertinoButton( + padding: const EdgeInsets.all(8), + onPressed: onPressed, + child: busy + ? const CupertinoActivityIndicator(radius: 9) + : Icon(cupertinoIcon), + ), + ); + } + return IconButton( + tooltip: label, + visualDensity: VisualDensity.compact, + onPressed: onPressed, + icon: busy + ? const SizedBox( + width: 18, + height: 18, + child: CircularProgressIndicator(strokeWidth: 2), + ) + : Icon(icon), + ); + } +} diff --git a/app/lib/features/artifacts/actions/artifact_transfer.dart b/app/lib/features/artifacts/actions/artifact_transfer.dart index bc99bbf3..f27d65c1 100644 --- a/app/lib/features/artifacts/actions/artifact_transfer.dart +++ b/app/lib/features/artifacts/actions/artifact_transfer.dart @@ -1,6 +1,7 @@ import 'artifact_file.dart'; import 'artifact_transfer_stub.dart' if (dart.library.js_interop) 'artifact_transfer_web.dart' + if (dart.library.io) 'artifact_transfer_io.dart' as impl; /// The outcome of a host file transfer. diff --git a/app/lib/features/artifacts/actions/artifact_transfer_io.dart b/app/lib/features/artifacts/actions/artifact_transfer_io.dart new file mode 100644 index 00000000..5fb3ccb9 --- /dev/null +++ b/app/lib/features/artifacts/actions/artifact_transfer_io.dart @@ -0,0 +1,56 @@ +import 'package:file_picker/file_picker.dart'; +import 'package:share_plus/share_plus.dart'; + +import 'artifact_file.dart'; +import 'artifact_transfer.dart'; + +/// Phones and desktops: Download asks where to save the exact bytes (the +/// system "Save as"), Share hands the named file to the share sheet. +bool get artifactDownloadSupported => true; + +bool get artifactShareSupported => true; + +String get artifactDownloadUnsupportedMessage => ''; + +String get artifactShareUnsupportedMessage => ''; + +Future saveArtifactFile(ArtifactFile file) async { + try { + final saved = await FilePicker.saveFile( + fileName: file.name, + bytes: file.bytes, + mimeType: file.mimeType, + ); + if (saved == null) { + return const ArtifactTransferResult(ArtifactTransferState.canceled, ''); + } + return ArtifactTransferResult( + ArtifactTransferState.saved, + 'Saved ${file.name}.', + ); + } catch (error) { + return ArtifactTransferResult( + ArtifactTransferState.failed, + 'Could not save ${file.name}: $error', + ); + } +} + +Future shareArtifactFile(ArtifactFile file) async { + try { + final result = await SharePlus.instance.share( + ShareParams( + files: [XFile.fromData(file.bytes, mimeType: file.mimeType)], + fileNameOverrides: [file.name], + ), + ); + return result.status == ShareResultStatus.dismissed + ? const ArtifactTransferResult(ArtifactTransferState.canceled, '') + : const ArtifactTransferResult(ArtifactTransferState.shared, ''); + } catch (error) { + return ArtifactTransferResult( + ArtifactTransferState.failed, + 'Could not share ${file.name}: $error', + ); + } +} diff --git a/app/lib/features/artifacts/ui/artifact_external_open.dart b/app/lib/features/artifacts/ui/artifact_external_open.dart index 15ae4180..4a4a4f81 100644 --- a/app/lib/features/artifacts/ui/artifact_external_open.dart +++ b/app/lib/features/artifacts/ui/artifact_external_open.dart @@ -1,6 +1,7 @@ import '../domain/artifact_url.dart'; import 'artifact_external_open_stub.dart' if (dart.library.js_interop) 'artifact_external_open_web.dart' + if (dart.library.io) 'artifact_external_open_io.dart' as impl; /// Opens an already validated artifact url with the host's external handler. diff --git a/app/lib/features/artifacts/ui/artifact_external_open_io.dart b/app/lib/features/artifacts/ui/artifact_external_open_io.dart new file mode 100644 index 00000000..88a8a0d3 --- /dev/null +++ b/app/lib/features/artifacts/ui/artifact_external_open_io.dart @@ -0,0 +1,11 @@ +import 'package:url_launcher/url_launcher.dart'; + +/// Phones and desktops: the link opens in the system browser, which renders +/// what it can and offers to download the rest. +Future openArtifactExternally(Uri uri) async { + try { + return await launchUrl(uri, mode: LaunchMode.externalApplication); + } catch (_) { + return false; + } +} diff --git a/app/lib/features/artifacts/ui/artifact_viewer_body.dart b/app/lib/features/artifacts/ui/artifact_viewer_body.dart index f2fc1922..3772f4cb 100644 --- a/app/lib/features/artifacts/ui/artifact_viewer_body.dart +++ b/app/lib/features/artifacts/ui/artifact_viewer_body.dart @@ -62,27 +62,10 @@ class ArtifactViewerBody extends StatelessWidget { @override Widget build(BuildContext context) { final resolved = plan.resolved; - final controls = [ - if (resolved != null && !resolved.external) - ArtifactFileActions( - key: ValueKey( - 'viewer-files-${page.group.stageKey}\u0000' - '${page.group.visit}\u0000${page.artifact.url}', - ), - artifact: page.artifact, - resolved: resolved, - fetch: fetch, - bridge: fileBridge, - ), - if (resolved != null) - _Actions(resolved: resolved, onOpen: onOpen, onCopy: onCopy), - ]; final content = SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - // Room for the controls bar, so it never covers the first line. - if (controls.isNotEmpty) const SizedBox(height: 56), Padding( padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4), child: ArtifactSelectionFacts( @@ -102,11 +85,6 @@ class ArtifactViewerBody extends StatelessWidget { ), ), ), - if (status != null) - Padding( - padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4), - child: Semantics(liveRegion: true, child: Text(status!)), - ), ArtifactPreviewBody( plan: plan, loading: loading, @@ -118,23 +96,60 @@ class ArtifactViewerBody extends StatelessWidget { ], ), ); + final hasPrevious = pagedIndex(index, -1, count) != index; + final hasNext = pagedIndex(index, 1, count) != index; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Expanded( - child: controls.isEmpty - ? content - : ArtifactControlsOverlay( - key: ValueKey('viewer-overlay-${page.artifact.url}'), - controls: controls, - child: content, - ), + // A horizontal swipe moves to the previous or next artifact. + child: GestureDetector( + key: const Key('artifact-viewer-swipe'), + behavior: HitTestBehavior.translucent, + onHorizontalDragEnd: (details) { + final velocity = details.primaryVelocity ?? 0; + if (velocity < -250 && hasNext) onNext(); + if (velocity > 250 && hasPrevious) onPrevious(); + }, + child: content, + ), ), - _Pager( - index: index, - count: count, - onPrevious: onPrevious, - onNext: onNext, + // Every action as an icon at the bottom, beside the pager. + SafeArea( + top: false, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: Row( + key: const Key('artifact-viewer-actions'), + children: [ + if (resolved != null && !resolved.external) + ArtifactFileActions( + key: ValueKey( + 'viewer-files-${page.group.stageKey}\u0000' + '${page.group.visit}\u0000${page.artifact.url}', + ), + artifact: page.artifact, + resolved: resolved, + fetch: fetch, + bridge: fileBridge, + compact: true, + ), + if (resolved != null) + _Actions(resolved: resolved, onOpen: onOpen, onCopy: onCopy), + Expanded( + child: Align( + alignment: AlignmentDirectional.centerEnd, + child: _Pager( + index: index, + count: count, + onPrevious: onPrevious, + onNext: onNext, + ), + ), + ), + ], + ), + ), ), ], ); @@ -263,40 +278,25 @@ class _Actions extends StatelessWidget { final VoidCallback onCopy; @override - Widget build(BuildContext context) { - if (usesCupertinoHost(context)) { - return SafeArea( - top: false, - child: Wrap( - alignment: WrapAlignment.center, - spacing: 8, - children: [ - CupertinoButton(onPressed: onOpen, child: const Text('Open')), - CupertinoButton(onPressed: onCopy, child: const Text('Copy link')), - ], - ), - ); - } - return SafeArea( - top: false, - child: Wrap( - alignment: WrapAlignment.center, - spacing: 8, - children: [ - TextButton.icon( - onPressed: onOpen, - icon: const Icon(Icons.open_in_new), - label: const Text('Open'), - ), - TextButton.icon( - onPressed: onCopy, - icon: const Icon(Icons.content_copy), - label: const Text('Copy link'), - ), - ], + Widget build(BuildContext context) => Row( + mainAxisSize: MainAxisSize.min, + children: [ + ArtifactIconAction( + key: const Key('artifact-open'), + label: 'Open', + icon: Icons.open_in_new, + cupertinoIcon: CupertinoIcons.arrow_up_right_square, + onPressed: onOpen, ), - ); - } + ArtifactIconAction( + key: const Key('artifact-copy-link'), + label: 'Copy link', + icon: Icons.link, + cupertinoIcon: CupertinoIcons.link, + onPressed: onCopy, + ), + ], + ); } const artifactPreviousKey = ValueKey('artifact-previous'); @@ -320,18 +320,15 @@ class _Pager extends StatelessWidget { if (count <= 1) return const SizedBox.shrink(); final hasPrevious = pagedIndex(index, -1, count) != index; final hasNext = pagedIndex(index, 1, count) != index; - return SafeArea( - top: false, - child: ChevronPager( - index: index, - count: count, - previousLabel: 'Previous artifact', - nextLabel: 'Next artifact', - previousKey: artifactPreviousKey, - nextKey: artifactNextKey, - onPrevious: hasPrevious ? onPrevious : null, - onNext: hasNext ? onNext : null, - ), + return ChevronPager( + index: index, + count: count, + previousLabel: 'Previous artifact', + nextLabel: 'Next artifact', + previousKey: artifactPreviousKey, + nextKey: artifactNextKey, + onPrevious: hasPrevious ? onPrevious : null, + onNext: hasNext ? onNext : null, ); } } diff --git a/app/pubspec.lock b/app/pubspec.lock index 9d7f55c5..ed2a34ae 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + android_file_picker: + dependency: transitive + description: + name: android_file_picker + sha256: e94229cc41c4bb5fb6a2254146340a8b650664c99b5c93b9001f66c3375d0060 + url: "https://pub.dev" + source: hosted + version: "2.1.1" args: dependency: transitive description: @@ -57,6 +65,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.19.1" + cross_file: + dependency: transitive + description: + name: cross_file + sha256: f141ea4f277af142a0356955707f6556f37b03947d39d55585981a06ca437bd6 + url: "https://pub.dev" + source: hosted + version: "0.3.5+5" crypto: dependency: transitive description: @@ -121,6 +137,54 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.1" + file_picker: + dependency: "direct main" + description: + name: file_picker + sha256: "98c0b156b6380ba55bc767a14e2e6b3feb246e713ad40092424596fa79005bea" + url: "https://pub.dev" + source: hosted + version: "13.1.0" + file_picker_darwin: + dependency: transitive + description: + name: file_picker_darwin + sha256: ca2918264c453400c80ef0d69ca3f8b816f894db6144bebac73064ad64927e0e + url: "https://pub.dev" + source: hosted + version: "2.3.3" + file_picker_linux: + dependency: transitive + description: + name: file_picker_linux + sha256: c6562fc7d426db2fb85ea66fe2627953d2709932df5584ceaacf0aa5e39cf4da + url: "https://pub.dev" + source: hosted + version: "2.0.2" + file_picker_platform_interface: + dependency: transitive + description: + name: file_picker_platform_interface + sha256: "336e7168306834a2b68e6168ed768e00d3fabeac23154d5793e277ca9f97cf20" + url: "https://pub.dev" + source: hosted + version: "4.2.0" + file_picker_web: + dependency: transitive + description: + name: file_picker_web + sha256: a2288008280aabe371aff029466b3405e60838e0a1d714767488c59b926c8b8c + url: "https://pub.dev" + source: hosted + version: "4.2.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be + url: "https://pub.dev" + source: hosted + version: "1.1.1" flutter: dependency: "direct main" description: flutter @@ -304,6 +368,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" + mime: + dependency: transitive + description: + name: mime + sha256: bd47de35f07e27267e69c8c8b22edf9473bfee170a60d60fcc93730c5144b7f6 + url: "https://pub.dev" + source: hosted + version: "2.1.0" objective_c: dependency: transitive description: @@ -440,6 +512,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.0" + share_plus: + dependency: "direct main" + description: + name: share_plus + sha256: db40767f130189d53f3ae8a6393c217ff4a492da1baff718a9873679c0c00224 + url: "https://pub.dev" + source: hosted + version: "13.3.1" + share_plus_platform_interface: + dependency: transitive + description: + name: share_plus_platform_interface + sha256: "365ef7379fc22507256adda3385152942ffce08935452bc972c2e52a0bebae41" + url: "https://pub.dev" + source: hosted + version: "7.2.0" shared_preferences: dependency: "direct main" description: @@ -565,6 +653,78 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.0" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + sha256: e8cc955c97e06df9879140a1fe301f3d493f01b7c62dec7f46834be31d7e9fda + url: "https://pub.dev" + source: hosted + version: "6.3.3" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + sha256: "611e87fb320b70d1dd721dc46af89c98aceccea9b31fde49e084591414e0c610" + url: "https://pub.dev" + source: hosted + version: "6.3.33" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + sha256: "8faa1aab294f1ab4040b43660c887b0418d5fa4f0cffef76a484e6aa1092eb4a" + url: "https://pub.dev" + source: hosted + version: "6.4.2" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + sha256: "10f86fef4c2c43563fa6c211ff9cf757adf4d3ab762c56bd430664a947d70cd0" + url: "https://pub.dev" + source: hosted + version: "3.2.3" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + sha256: "5e835a3b869c2d70325349c81c5a45c28e20791265b67b2669da6b08c5cd5201" + url: "https://pub.dev" + source: hosted + version: "3.2.6" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + sha256: "85c81589622fbc87c1c683aaea164d3604a7777495a79d91e39ffcdec39ddb34" + url: "https://pub.dev" + source: hosted + version: "2.4.3" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + sha256: "6c5ad3f22cd4c38e089b81963b3cd7bb83b111b2df5dce008bb066162f42e429" + url: "https://pub.dev" + source: hosted + version: "3.1.6" + uuid: + dependency: transitive + description: + name: uuid + sha256: "9b129329f58692f6e6578329498a8fe9fbe98f090beb764ffbb8ee2eadd01dcd" + url: "https://pub.dev" + source: hosted + version: "4.6.0" vector_math: dependency: transitive description: @@ -685,6 +845,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.4.0" + windows_file_picker: + dependency: transitive + description: + name: windows_file_picker + sha256: "18452aa293de3b6961c6d05b0e71b4be7bb90c67635abdd3aa5c4e75dd875072" + url: "https://pub.dev" + source: hosted + version: "2.0.1" xdg_directories: dependency: transitive description: diff --git a/app/pubspec.yaml b/app/pubspec.yaml index b10798d7..1afec5e9 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -45,6 +45,9 @@ dependencies: package_info_plus: ^10.2.2 path_provider: ^2.1.6 open_filex: ^5.0.0 + share_plus: ^13.3.1 + file_picker: ^13.1.0 + url_launcher: ^6.3.3 dev_dependencies: flutter_test: diff --git a/app/test/features/artifacts/actions/artifact_file_actions_test.dart b/app/test/features/artifacts/actions/artifact_file_actions_test.dart index 27b48ccd..83360640 100644 --- a/app/test/features/artifacts/actions/artifact_file_actions_test.dart +++ b/app/test/features/artifacts/actions/artifact_file_actions_test.dart @@ -223,7 +223,11 @@ void main() { stage: 'review', visit: 1, artifacts: [ - artifact('report.zip', contentType: 'application/zip', sizeBytes: 3), + artifact( + 'report.zip', + contentType: 'application/zip', + sizeBytes: 3, + ), ], ), ], @@ -262,6 +266,14 @@ void main() { artifact: _record, resolved: resolveArtifactUrl(_endpoint, _record.url)!, fetch: _fetch, + bridge: const ArtifactFileBridge( + downloadSupported: false, + shareSupported: false, + downloadUnsupportedMessage: + 'Downloading files is not supported on this platform yet.', + shareUnsupportedMessage: + 'File sharing is not supported on this platform yet.', + ), ), ), ), @@ -374,8 +386,8 @@ void main() { ); await tester.pumpAndSettle(); - expect(find.text('Download'), findsOneWidget); - expect(find.text('Share'), findsOneWidget); + expect(find.byKey(const Key('artifact-download')), findsOneWidget); + expect(find.byKey(const Key('artifact-share')), findsOneWidget); final externalGroup = visitGroup(artifacts: [external]); await tester.pumpWidget( @@ -395,9 +407,9 @@ void main() { ); await tester.pumpAndSettle(); - expect(find.text('Download'), findsNothing); - expect(find.text('Share'), findsNothing); - expect(find.text('Open'), findsOneWidget); + expect(find.byKey(const Key('artifact-download')), findsNothing); + expect(find.byKey(const Key('artifact-share')), findsNothing); + expect(find.byKey(const Key('artifact-open')), findsOneWidget); }, ); } diff --git a/app/test/features/artifacts/ui/artifact_gallery_page_test.dart b/app/test/features/artifacts/ui/artifact_gallery_page_test.dart index 88778988..4cdb0030 100644 --- a/app/test/features/artifacts/ui/artifact_gallery_page_test.dart +++ b/app/test/features/artifacts/ui/artifact_gallery_page_test.dart @@ -466,7 +466,10 @@ void main() { ); expect(tester.takeException(), isNull); - expect(tester.getSize(find.byType(CustomScrollView)).height, greaterThan(0)); + expect( + tester.getSize(find.byType(CustomScrollView)).height, + greaterThan(0), + ); expect( find.text('12 files excluded from artifact capture.'), findsOneWidget, diff --git a/app/test/features/artifacts/ui/artifact_viewer_page_test.dart b/app/test/features/artifacts/ui/artifact_viewer_page_test.dart index 6c14d079..2a9110de 100644 --- a/app/test/features/artifacts/ui/artifact_viewer_page_test.dart +++ b/app/test/features/artifacts/ui/artifact_viewer_page_test.dart @@ -150,10 +150,9 @@ void main() { expect(find.byType(ArtifactViewerPage), findsOneWidget); // The gallery's thumbnail and the viewer read the same recorded file. expect(fetched, isNotEmpty); - expect( - fetched.toSet(), - {Uri.parse('http://127.0.0.1:8081/artifacts/1/1/shot.png')}, - ); + expect(fetched.toSet(), { + Uri.parse('http://127.0.0.1:8081/artifacts/1/1/shot.png'), + }); expect(find.byType(Image), findsOneWidget); expect(find.text('1 of 1 · image/png'), findsOneWidget); expect(find.text('image/png · 1.0\u00a0KiB'), findsOneWidget); @@ -247,7 +246,7 @@ void main() { ); expect(fetched, isEmpty); expect(find.byType(Image), findsNothing); - await tester.tap(find.text('Open')); + await tester.tap(find.byKey(const Key('artifact-open'))); await tester.pumpAndSettle(); expect(opened, [Uri.parse('https://elsewhere.test/shot.png')]); }); @@ -320,8 +319,8 @@ void main() { // The player streams the url itself; the viewer never fetches its bytes. expect(find.byType(ArtifactVideoPlayer), findsOneWidget); expect(find.text('This file type cannot be previewed here.'), findsNothing); - expect(find.text('Open'), findsOneWidget); - expect(find.text('Copy link'), findsOneWidget); + expect(find.byKey(const Key('artifact-open')), findsOneWidget); + expect(find.byKey(const Key('artifact-copy-link')), findsOneWidget); expect(fetches, 0); }); @@ -523,6 +522,37 @@ void main() { expect(find.byType(Material), findsNothing); }); + testWidgets('a swipe moves to the next and previous artifact', ( + tester, + ) async { + final first = recordedArtifact( + 'a.png', + url: '/artifacts/1/1/a.png', + contentType: 'image/png', + ); + final second = recordedArtifact( + 'b.png', + url: '/artifacts/1/2/b.png', + contentType: 'image/png', + ); + final groups = [ + _group([first], visit: 1), + _group([second], visit: 2), + ]; + await _pumpViewer( + tester, + groups: groups, + selected: artifactVisitIdentity(groups[0], first), + ); + final swipe = find.byKey(const Key('artifact-viewer-swipe')); + await tester.fling(swipe, const Offset(-300, 0), 1000); + await tester.pumpAndSettle(); + expect(find.textContaining('2 of 2'), findsWidgets); + await tester.fling(swipe, const Offset(300, 0), 1000); + await tester.pumpAndSettle(); + expect(find.textContaining('1 of 2'), findsWidgets); + }); + testWidgets('Material paging stays inside 320px at 2x text', (tester) async { tester.view.physicalSize = const Size(640, 1200); tester.view.devicePixelRatio = 2; From 0e6db03903b320c32dc239e7c916b1ace7641c62 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 22:49:21 +0100 Subject: [PATCH 2/2] feat(app): an open pipeline, run or chat fills a phone screen; Back steps up one level; stage tabs end with Session --- app/lib/application/app_router.dart | 21 ++++++- app/lib/application/pipelines_app.dart | 4 ++ .../runs/ui/run_detail_visit_sections.dart | 63 ++----------------- app/lib/shell/adaptive_shell.dart | 32 ++++++---- app/test/application/app_router_test.dart | 28 +++++++++ app/test/application/search_wiring_test.dart | 7 ++- .../ui/run_detail_visit_sections_test.dart | 24 ++----- .../runs/ui/run_detail_visit_support.dart | 14 +---- app/test/shell/shell_bar_test.dart | 19 ++++++ 9 files changed, 104 insertions(+), 108 deletions(-) diff --git a/app/lib/application/app_router.dart b/app/lib/application/app_router.dart index ba7c5aa8..b7f726c8 100644 --- a/app/lib/application/app_router.dart +++ b/app/lib/application/app_router.dart @@ -213,8 +213,13 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { notifyListeners(); } + /// Back (Android's button, the browser's): close whatever page sits on top + /// first, then step up one level — a stage to its run or pipeline, a run, + /// pipeline or chat to its list — and only leave the app from a list. @override Future popRoute() async { + final navigator = _navigatorKey.currentState; + if (navigator != null && await navigator.maybePop()) return true; if (searchOpen) { closeSearch(); return true; @@ -227,10 +232,24 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { closeTemplates(); return true; } - if (_route.runId != null) { + final runId = _route.runId; + if (runId != null && _route.stageKey != null) { + goTo(AppRoute.run(runId)); + return true; + } + if (runId != null) { onPopToRuns(); return true; } + final pipelineId = _route.pipelineId; + if (_route.kind == AppRouteKind.pipelines && pipelineId != null) { + goTo( + _route.stageKey != null + ? AppRoute.pipeline(pipelineId, version: _route.version) + : AppRoute.pipelines, + ); + return true; + } if (_route.chatSessionId != null) { onPopToChat(); return true; diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 40bb013b..26cc6e3f 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -410,6 +410,10 @@ class _PipelinesAppState extends State final chatRoute = tab(AppDestination.chat); return AdaptiveShell( attentionCount: attentionCount, + detailOpen: + route.runId != null || + route.chatSessionId != null || + (route.kind == AppRouteKind.pipelines && route.pipelineId != null), cupertino: _cupertino, destination: _destinationOf(route.kind), onDestinationSelected: _selectDestination, diff --git a/app/lib/features/runs/ui/run_detail_visit_sections.dart b/app/lib/features/runs/ui/run_detail_visit_sections.dart index 56e26b5e..689d23a1 100644 --- a/app/lib/features/runs/ui/run_detail_visit_sections.dart +++ b/app/lib/features/runs/ui/run_detail_visit_sections.dart @@ -128,18 +128,19 @@ class RunVisitSectionStrip extends StatelessWidget { } /// The stage page's tabs: Summary (Input and Output), Artifacts, Changes and -/// More (Session and Definition). The finer sections stay addressable. +/// Session. The finer sections stay addressable. const shownVisitSections = [ RunVisitSection.summary, RunVisitSection.artifacts, RunVisitSection.changes, - RunVisitSection.more, + RunVisitSection.session, ]; /// The tab that shows [section]. RunVisitSection visitTabFor(RunVisitSection section) => switch (section) { RunVisitSection.input || RunVisitSection.output => RunVisitSection.summary, - RunVisitSection.session || RunVisitSection.definition => RunVisitSection.more, + // The stage's definition lives on the pipeline, not on a run's visit. + RunVisitSection.more || RunVisitSection.definition => RunVisitSection.session, _ => section, }; @@ -178,10 +179,7 @@ Widget runVisitSectionBody({ cupertino: cupertino, ); case RunVisitSection.more: - return _MoreSection( - session: body(RunVisitSection.session), - definition: body(RunVisitSection.definition), - ); + return body(RunVisitSection.session); case RunVisitSection.input: return runDetailFieldTab( tabKey: 'visit-input', @@ -230,57 +228,6 @@ Widget runVisitSectionBody({ } } -/// Session and Definition behind one tab, with a small switch between them. -class _MoreSection extends StatefulWidget { - const _MoreSection({required this.session, required this.definition}); - - final Widget session; - final Widget definition; - - @override - State<_MoreSection> createState() => _MoreSectionState(); -} - -class _MoreSectionState extends State<_MoreSection> { - var _definition = false; - - @override - Widget build(BuildContext context) { - final cupertino = usesCupertinoHost(context); - final control = cupertino - ? CupertinoSlidingSegmentedControl( - key: const Key('run-visit-more-switch'), - groupValue: _definition, - onValueChanged: (value) => - setState(() => _definition = value ?? false), - children: const {false: Text('Session'), true: Text('Definition')}, - ) - : SegmentedButton( - key: const Key('run-visit-more-switch'), - showSelectedIcon: false, - segments: const [ - ButtonSegment(value: false, label: Text('Session')), - ButtonSegment(value: true, label: Text('Definition')), - ], - selected: {_definition}, - onSelectionChanged: (value) => - setState(() => _definition = value.single), - ); - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), - child: control, - ), - Expanded(child: _definition ? widget.definition : widget.session), - ], - ); - } -} - -/// The stage's Input and Output as sticky collapsibles, each with a copy -/// button for its recorded text. class _VisitSummary extends StatefulWidget { const _VisitSummary({ super.key, diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index 0851e56f..9c80322a 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -15,6 +15,7 @@ class AdaptiveShell extends StatefulWidget { this.onDestinationSelected, this.onSearch, this.attentionCount = 0, + this.detailOpen = false, }); final Map destinationBodies; @@ -33,6 +34,10 @@ class AdaptiveShell extends StatefulWidget { /// so it stays visible from any destination. Zero shows no badge. final int attentionCount; + /// A pipeline, run or chat is open: on a phone it takes the whole screen, + /// like its own page, and the destination bar steps aside until Back. + final bool detailOpen; + @override State createState() => _AdaptiveShellState(); } @@ -183,18 +188,19 @@ class _AdaptiveShellState extends State { : Column( children: [ Expanded(child: _destinationStack(contents, index)), - CupertinoTabBar( - currentIndex: index, - onTap: (value) => - _select(AppDestination.values[value]), - items: _items((destination) { - final item = destinationDetails(destination); - return BottomNavigationBarItem( - icon: _icon(destination, item.cupertinoIcon), - label: item.label, - ); - }), - ), + if (!widget.detailOpen) + CupertinoTabBar( + currentIndex: index, + onTap: (value) => + _select(AppDestination.values[value]), + items: _items((destination) { + final item = destinationDetails(destination); + return BottomNavigationBarItem( + icon: _icon(destination, item.cupertinoIcon), + label: item.label, + ); + }), + ), ], ), ), @@ -250,7 +256,7 @@ class _AdaptiveShellState extends State { Expanded(child: _destinationStack(contents, index)), ], ), - bottomNavigationBar: wide + bottomNavigationBar: wide || widget.detailOpen ? null : NavigationBar( selectedIndex: index, diff --git a/app/test/application/app_router_test.dart b/app/test/application/app_router_test.dart index 5f0c1f33..51f2409f 100644 --- a/app/test/application/app_router_test.dart +++ b/app/test/application/app_router_test.dart @@ -13,6 +13,7 @@ AppRouterDelegate delegate(AppRoute initial, {void Function()? onChat}) => ); void main() { + TestWidgetsFlutterBinding.ensureInitialized(); test('system Back leaves one chat session for the chat list', () async { var left = 0; final router = delegate(AppRoute.chatSession('s1'), onChat: () => left++); @@ -22,6 +23,33 @@ void main() { expect(left, 1); }); + test('system Back steps up one level at a time', () async { + var runs = 0; + final router = AppRouterDelegate( + builder: (context, route) => const SizedBox.shrink(), + onPopToRuns: () => runs++, + onPopToChat: () {}, + cupertino: false, + initial: AppRoute.run.stage(77, 'plan', visit: 0), + ); + addTearDown(router.dispose); + + // A stage returns to its run, then the run to the Runs list. + expect(await router.popRoute(), isTrue); + expect(router.route, AppRoute.run(77)); + expect(await router.popRoute(), isTrue); + expect(runs, 1); + + // A pipeline stage returns to its pipeline, then to the list, and the + // list leaves Back to the platform. + router.goTo(AppRoute.pipelineStage(4, 'plan', version: 2)); + expect(await router.popRoute(), isTrue); + expect(router.route, AppRoute.pipeline(4, version: 2)); + expect(await router.popRoute(), isTrue); + expect(router.route, AppRoute.pipelines); + expect(await router.popRoute(), isFalse); + }); + test('system Back on a list destination stays with the platform', () async { final router = delegate(AppRoute.chat); addTearDown(router.dispose); diff --git a/app/test/application/search_wiring_test.dart b/app/test/application/search_wiring_test.dart index bcd8c33e..f0e20723 100644 --- a/app/test/application/search_wiring_test.dart +++ b/app/test/application/search_wiring_test.dart @@ -268,7 +268,7 @@ void main() { testWidgets( 'the Search tab opens focused and the Runs tab keeps the open run', (tester) async { - tester.view.physicalSize = const Size(390, 844); + tester.view.physicalSize = const Size(900, 1000); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); @@ -295,7 +295,8 @@ void main() { ); await replyRunList(tester, channel); await replyRunDetail(tester, channel, 2); - expect(find.byKey(const ValueKey('shell.back')), findsOneWidget); + // On a phone an open run fills the screen and the tabs step aside, so + // switching tabs with a run open is a wide-window move. // Search is the fifth tab. await tapTab(tester, 'Search'); @@ -337,7 +338,7 @@ void main() { testWidgets('a result opens through the existing run route over one socket', ( tester, ) async { - tester.view.physicalSize = const Size(390, 844); + tester.view.physicalSize = const Size(900, 1000); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); diff --git a/app/test/features/runs/ui/run_detail_visit_sections_test.dart b/app/test/features/runs/ui/run_detail_visit_sections_test.dart index c6eb84b1..edd92d48 100644 --- a/app/test/features/runs/ui/run_detail_visit_sections_test.dart +++ b/app/test/features/runs/ui/run_detail_visit_sections_test.dart @@ -21,12 +21,12 @@ void main() { expect(find.text('Back'), findsNothing); // The page bar's own Back is the only one. expect(find.byKey(const Key('run-visit-back')), findsOneWidget); - // Four tabs: Summary, Artifacts, Changes, More. + // Four tabs: Summary, Artifacts, Changes, Session. expect(shownVisitSections, [ RunVisitSection.summary, RunVisitSection.artifacts, RunVisitSection.changes, - RunVisitSection.more, + RunVisitSection.session, ]); // Summary holds both Input and Output. expect(find.text('Input'), findsOneWidget); @@ -73,9 +73,8 @@ void main() { expect(find.text('sess-1'), findsOneWidget); expect(find.text('Open session.html'), findsOneWidget); - await openVisitTab(tester, RunVisitSection.definition); - expect(find.byType(StageDefinitionView), findsOneWidget); - expect(find.text('Draft the plan.'), findsOneWidget); + // The stage's definition belongs to the pipeline, not to a visit. + expect(find.byType(StageDefinitionView), findsNothing); }); testWidgets('${platform.name} artifacts tab reports the capture state', ( @@ -178,21 +177,6 @@ void main() { expect(find.byType(ArtifactGalleryPage), findsOneWidget); }); - testWidgets('${platform.name} missing definition uses exact wording', ( - tester, - ) async { - await openVisit( - tester, - platform, - run: visitRunFixture(declareStage: false), - ); - await openVisitTab(tester, RunVisitSection.definition); - - expect(find.byType(StageDefinitionView), findsNothing); - expect(find.text(unknownStageDefinition), findsOneWidget); - expect(find.text('Draft the plan.'), findsNothing); - }); - testWidgets('${platform.name} visit sections at 320 with 2x dark text', ( tester, ) async { diff --git a/app/test/features/runs/ui/run_detail_visit_support.dart b/app/test/features/runs/ui/run_detail_visit_support.dart index caed4dd4..d1ac587a 100644 --- a/app/test/features/runs/ui/run_detail_visit_support.dart +++ b/app/test/features/runs/ui/run_detail_visit_support.dart @@ -115,8 +115,7 @@ Future openVisit( await tester.pumpAndSettle(); } -/// Opens the tab showing [section]: Input and Output are on Summary, Session -/// and Definition behind More's switch. +/// Opens the tab showing [section]: Input and Output are on Summary. Future openVisitTab(WidgetTester tester, RunVisitSection section) async { final shown = visitTabFor(section); final tab = find.byKey(ValueKey('run-visit-tab-${shown.name}')); @@ -124,15 +123,4 @@ Future openVisitTab(WidgetTester tester, RunVisitSection section) async { await tester.pumpAndSettle(); await tester.tap(tab); await tester.pumpAndSettle(); - if (section == RunVisitSection.session || - section == RunVisitSection.definition) { - final choice = find.descendant( - of: find.byKey(const Key('run-visit-more-switch')), - matching: find.text( - section == RunVisitSection.session ? 'Session' : 'Definition', - ), - ); - await tester.tap(choice); - await tester.pumpAndSettle(); - } } diff --git a/app/test/shell/shell_bar_test.dart b/app/test/shell/shell_bar_test.dart index d9734edb..329decdf 100644 --- a/app/test/shell/shell_bar_test.dart +++ b/app/test/shell/shell_bar_test.dart @@ -99,4 +99,23 @@ void main() { findsNothing, ); }); + + testWidgets('an open detail fills a phone screen without the tab bar', ( + tester, + ) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + Widget shell({required bool detail}) => MaterialApp( + home: AdaptiveShell( + destination: AppDestination.runs, + detailOpen: detail, + destinationBodies: {AppDestination.runs: (_) => const Text('runs')}, + ), + ); + await tester.pumpWidget(shell(detail: false)); + expect(find.byType(NavigationBar), findsOneWidget); + await tester.pumpWidget(shell(detail: true)); + expect(find.byType(NavigationBar), findsNothing); + }); }