diff --git a/app/lib/application/schedules_destination.dart b/app/lib/application/schedules_destination.dart index d667fc2b..d249102e 100644 --- a/app/lib/application/schedules_destination.dart +++ b/app/lib/application/schedules_destination.dart @@ -6,11 +6,16 @@ import 'package:flutter/material.dart'; import '../features/schedules/data/schedules_repository.dart'; import '../features/schedules/ui/list/schedule_list_controller.dart'; +import '../features/schedules/ui/list/schedule_list_toolbar.dart' + show ScheduleRefreshAction; import '../features/schedules/ui/list/schedule_list_view.dart'; import '../ui/adaptive/host.dart'; import 'app_session.dart'; import 'server_endpoint.dart'; +/// The Back control of the app-level Schedules page. +const schedulesPageBackKey = ValueKey('schedules-page-back'); + /// The saved-schedule list above Settings. /// /// It is read-only: opening a row asks the composition to show the owning @@ -101,30 +106,33 @@ class _SchedulesDestinationState extends State { Widget _page(bool cupertino) { final body = _body(cupertino); + // The round Back closes the page; Refresh sits in the actions pill. + final bar = SegmentedBar( + cupertino: cupertino, + leading: SegmentedBackButton( + key: schedulesPageBackKey, + cupertino: cupertino, + onPressed: widget.onBack, + ), + title: 'Schedules', + actions: [ + if (widget.session.everConnected) + ScheduleRefreshAction( + controller: _controller, + cupertino: cupertino, + onRefresh: () => unawaited(_controller.refresh()), + ), + ], + ); if (cupertino) { return CupertinoPageScaffold( - navigationBar: SegmentedBar( - cupertino: true, - leading: CupertinoButton( - padding: EdgeInsets.zero, - onPressed: widget.onBack, - child: const Icon(CupertinoIcons.back, semanticLabel: 'Back'), - ), - title: 'Schedules', - ), + navigationBar: bar, child: SafeArea(child: body), ); } return Scaffold( extendBodyBehindAppBar: true, - appBar: SegmentedBar( - cupertino: false, - leading: IconButton( - onPressed: widget.onBack, - icon: const Icon(Icons.arrow_back, semanticLabel: 'Back'), - ), - title: 'Schedules', - ), + appBar: bar, body: SafeArea(left: false, right: false, bottom: false, child: body), ); } @@ -145,6 +153,7 @@ class _SchedulesDestinationState extends State { if (id != null) widget.onOpenPipeline(id); }, onRefresh: () => _controller.refresh(), + refreshInToolbar: false, ); } } diff --git a/app/lib/application/templates_destination.dart b/app/lib/application/templates_destination.dart index 94d86168..736d6d54 100644 --- a/app/lib/application/templates_destination.dart +++ b/app/lib/application/templates_destination.dart @@ -1,10 +1,14 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../ui/adaptive/segmented_bar.dart'; import '../core/api_gateway.dart'; import '../features/templates/screen.dart'; +import '../features/templates/ui/template_detail.dart' + show templateDetailBackKey; +import '../shell/destination.dart'; +import '../shell/shell_bar.dart'; import '../ui/adaptive/host.dart'; +import '../ui/adaptive/segmented_bar.dart'; import 'app_session.dart'; import 'connection_status.dart'; import 'server_endpoint.dart'; @@ -14,15 +18,17 @@ const templatesPageBackKey = ValueKey('templates-page-back'); /// The Templates destination: the landed gallery over the app's shared gateway. /// -/// The gallery is rendered in embedded mode, so the shell owns navigation; this -/// destination contributes the page's one native bar (Back + Templates) and the -/// same honest connection states as the other destinations. No socket is opened +/// The gallery is rendered in embedded mode and publishes its controls to +/// this page's one segmented bar (through a [ShellBarScope] the page owns): +/// the round Back closes the page from the gallery and returns to the gallery +/// from an open template, and Refresh sits in the actions pill. The same +/// honest connection states as the other destinations. No socket is opened /// here: [session] owns the only connection, and a template read, validate or /// create request travels over it. /// /// [onCreated] forwards the server-confirmed detail once, so the caller can /// invalidate the Pipelines list. This screen never inserts a row itself. -class TemplatesDestination extends StatelessWidget { +class TemplatesDestination extends StatefulWidget { const TemplatesDestination({ super.key, required this.session, @@ -42,24 +48,74 @@ class TemplatesDestination extends StatelessWidget { /// The template detail the route names, or null for the gallery. final String? initialKey; + @override + State createState() => _TemplatesDestinationState(); +} + +class _TemplatesDestinationState extends State { + final ShellBarRegistry _bar = ShellBarRegistry(); + + @override + void dispose() { + _bar.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { final cupertino = usesCupertinoHost(context); - return AnimatedBuilder( - animation: session, - builder: (context, _) => _TemplatesPage( - cupertino: cupertino, - onBack: onBack, - child: _body(cupertino), + final body = ShellBarScope( + registry: _bar, + destination: AppDestination.settings, + child: AnimatedBuilder( + animation: widget.session, + builder: (context, _) => _body(cupertino), ), ); + final bar = ListenableBuilder( + listenable: _bar, + builder: (context, _) => _segmentedBar(cupertino), + ); + if (cupertino) { + return CupertinoPageScaffold( + navigationBar: _BarSlot(cupertino: true, child: bar), + child: SafeArea(child: body), + ); + } + return Scaffold( + extendBodyBehindAppBar: true, + appBar: _BarSlot(cupertino: false, child: bar), + body: SafeArea(child: body), + ); + } + + SegmentedBar _segmentedBar(bool cupertino) { + final spec = _bar.specFor(AppDestination.settings); + final onDetailBack = spec?.onBack; + return SegmentedBar( + cupertino: cupertino, + leading: onDetailBack != null + ? SegmentedBackButton( + key: templateDetailBackKey, + cupertino: cupertino, + onPressed: onDetailBack, + ) + : SegmentedBackButton( + key: templatesPageBackKey, + cupertino: cupertino, + onPressed: widget.onBack, + ), + title: spec?.title ?? 'Templates', + actions: spec?.actions ?? const [], + ); } Widget _body(bool cupertino) { + final session = widget.session; if (!session.everConnected) { return ConnectionGate( session: session, - server: server, + server: widget.server, cupertino: cupertino, ); } @@ -71,8 +127,8 @@ class TemplatesDestination extends StatelessWidget { child: TemplatesScreen( gateway: session.gateway, embedded: true, - onCreated: onCreated, - initialKey: initialKey, + onCreated: widget.onCreated, + initialKey: widget.initialKey, ), ), ], @@ -80,52 +136,22 @@ class TemplatesDestination extends StatelessWidget { } } -/// The page's standard native bar. Back is named explicitly so it cannot be -/// confused with the gallery's own Back-to-gallery control. -class _TemplatesPage extends StatelessWidget { - const _TemplatesPage({ - required this.cupertino, - required this.onBack, - required this.child, - }); +/// Gives the scaffold a [SegmentedBar]'s size and obstruction while the bar +/// itself is rebuilt from the published controls. +class _BarSlot extends StatelessWidget + implements ObstructingPreferredSizeWidget { + const _BarSlot({required this.cupertino, required this.child}); final bool cupertino; - final VoidCallback onBack; final Widget child; @override - Widget build(BuildContext context) { - if (cupertino) { - return CupertinoPageScaffold( - navigationBar: SegmentedBar( - cupertino: true, - leading: CupertinoButton( - key: templatesPageBackKey, - padding: EdgeInsets.zero, - onPressed: onBack, - child: const Icon( - CupertinoIcons.back, - semanticLabel: 'Back to Settings', - ), - ), - title: 'Templates', - ), - child: SafeArea(child: child), - ); - } - return Scaffold( - extendBodyBehindAppBar: true, - appBar: SegmentedBar( - cupertino: false, - leading: IconButton( - key: templatesPageBackKey, - tooltip: 'Back to Settings', - onPressed: onBack, - icon: const Icon(Icons.arrow_back), - ), - title: 'Templates', - ), - body: SafeArea(child: child), - ); - } + Size get preferredSize => + SegmentedBar(cupertino: cupertino, title: '').preferredSize; + + @override + bool shouldFullyObstruct(BuildContext context) => false; + + @override + Widget build(BuildContext context) => child; } diff --git a/app/lib/features/attention/ui/needs_you_bell.dart b/app/lib/features/attention/ui/needs_you_bell.dart index af177c14..036ec199 100644 --- a/app/lib/features/attention/ui/needs_you_bell.dart +++ b/app/lib/features/attention/ui/needs_you_bell.dart @@ -185,9 +185,12 @@ class _NeedsYouBellState extends State { Widget _cupertino(BuildContext context) { final theme = CupertinoTheme.of(context); + // The whole 44pt target and no extra padding, like every bar action. return CupertinoButton( key: attentionBellKey, focusNode: _focus, + padding: EdgeInsets.zero, + minimumSize: const Size.square(kMinInteractiveDimensionCupertino), onPressed: _open, child: _badged( context, diff --git a/app/lib/features/pipelines/widgets/pipeline_controls.dart b/app/lib/features/pipelines/widgets/pipeline_controls.dart index b417668f..550ecdc8 100644 --- a/app/lib/features/pipelines/widgets/pipeline_controls.dart +++ b/app/lib/features/pipelines/widgets/pipeline_controls.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/adaptive/host.dart'; +import '../../../ui/adaptive/segmented_bar.dart'; import '../pipeline_query.dart'; @@ -59,23 +60,16 @@ class PipelineBackButton extends StatelessWidget { final VoidCallback onPressed; + /// The same round Back as every page's segmented bar. @override Widget build(BuildContext context) { - if (useCupertinoControls(context)) { - return Semantics( - button: true, - label: 'Back to pipelines', - child: CupertinoButton( - padding: EdgeInsets.zero, - onPressed: onPressed, - child: const Icon(CupertinoIcons.back), - ), - ); - } - return IconButton( - tooltip: 'Back to pipelines', - onPressed: onPressed, - icon: const Icon(Icons.arrow_back), + final cupertino = useCupertinoControls(context); + return Semantics( + label: 'Back to pipelines', + child: SegmentedPill( + cupertino: cupertino, + child: SegmentedBackButton(cupertino: cupertino, onPressed: onPressed), + ), ); } } @@ -105,9 +99,10 @@ class PipelineSortButton extends StatelessWidget { label: icon ? 'Sort pipelines: ${sort.label}' : null, excludeSemantics: icon, child: CupertinoButton( - padding: icon - ? const EdgeInsets.symmetric(horizontal: 6) - : EdgeInsets.zero, + padding: EdgeInsets.zero, + minimumSize: icon + ? const Size.square(kMinInteractiveDimensionCupertino) + : null, onPressed: () => _showCupertinoSheet(context), child: icon ? const Icon(CupertinoIcons.arrow_up_arrow_down) diff --git a/app/lib/features/pipelines/widgets/pipeline_list_panel.dart b/app/lib/features/pipelines/widgets/pipeline_list_panel.dart index ff4040dc..1bbdd1b5 100644 --- a/app/lib/features/pipelines/widgets/pipeline_list_panel.dart +++ b/app/lib/features/pipelines/widgets/pipeline_list_panel.dart @@ -441,7 +441,8 @@ List pipelineListActions( excludeSemantics: true, child: CupertinoButton( key: const Key('pipeline-filter'), - padding: const EdgeInsets.symmetric(horizontal: 6), + padding: EdgeInsets.zero, + minimumSize: const Size.square(kMinInteractiveDimensionCupertino), onPressed: openFilters, child: Icon( filters.count > 0 diff --git a/app/lib/features/runs/ui/runs_filters.dart b/app/lib/features/runs/ui/runs_filters.dart index 36eebedb..a42607b9 100644 --- a/app/lib/features/runs/ui/runs_filters.dart +++ b/app/lib/features/runs/ui/runs_filters.dart @@ -1,3 +1,4 @@ +import '../../../ui/input/app_search_field.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -211,8 +212,10 @@ class RunsBarActions { excludeSemantics: true, child: CupertinoButton( key: key, - padding: const EdgeInsets.symmetric(horizontal: 6), - minimumSize: Size.zero, + // The whole 44pt target and no extra padding, like every bar + // action, so the icons are evenly spaced inside the pill. + padding: EdgeInsets.zero, + minimumSize: const Size.square(kMinInteractiveDimensionCupertino), onPressed: onPressed, child: Icon(ios), ), @@ -372,23 +375,13 @@ class _RunsFilterSheetState extends State<_RunsFilterSheet> { @override Widget build(BuildContext context) { final controller = widget.controller; - final field = widget.cupertino - ? CupertinoSearchTextField( - key: const ValueKey('runs.filter.query'), - controller: _text, - placeholder: 'Filter runs', - onChanged: controller.setQuery, - ) - : TextField( - key: const ValueKey('runs.filter.query'), - controller: _text, - decoration: const InputDecoration( - hintText: 'Filter runs', - prefixIcon: Icon(Icons.search), - isDense: true, - ), - onChanged: controller.setQuery, - ); + final field = AppSearchField( + fieldKey: const ValueKey('runs.filter.query'), + controller: _text, + cupertino: widget.cupertino, + placeholder: 'Filter runs', + onChanged: controller.setQuery, + ); return ListenableBuilder( listenable: controller, builder: (context, _) => ConstrainedBox( diff --git a/app/lib/features/schedules/ui/list/schedule_list_toolbar.dart b/app/lib/features/schedules/ui/list/schedule_list_toolbar.dart index 4e01c4fb..50f1f1df 100644 --- a/app/lib/features/schedules/ui/list/schedule_list_toolbar.dart +++ b/app/lib/features/schedules/ui/list/schedule_list_toolbar.dart @@ -1,26 +1,56 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../../ui/input/app_search_field.dart'; +import '../../../../ui/navigation/bar_icon_button.dart'; import 'schedule_list_controller.dart'; const scheduleSearchFieldKey = ValueKey('schedule-search-field'); const scheduleFilterKey = ValueKey('schedule-filter'); const scheduleRefreshKey = ValueKey('schedule-refresh'); -/// Search, enabled filter and the read-only refresh control. +/// Refresh for the list, as a bar action: the platform's activity indicator +/// in the same touch target while a read is in flight. +class ScheduleRefreshAction extends StatelessWidget { + const ScheduleRefreshAction({ + super.key, + required this.controller, + required this.cupertino, + required this.onRefresh, + }); + + final SchedulesController controller; + final bool cupertino; + final VoidCallback onRefresh; + + @override + Widget build(BuildContext context) => BarIconButton( + key: controller.isLoading ? null : scheduleRefreshKey, + cupertino: cupertino, + icon: Icons.refresh, + cupertinoIcon: CupertinoIcons.refresh, + label: 'Refresh schedules', + busy: controller.isLoading, + busyLabel: 'Refreshing schedules', + onPressed: onRefresh, + ); +} + +/// Search and the enabled filter; the refresh control too when no bar above +/// carries it ([onRefresh] null leaves it to the bar). class ScheduleListToolbar extends StatelessWidget { const ScheduleListToolbar({ super.key, required this.controller, required this.searchController, required this.cupertino, - required this.onRefresh, + this.onRefresh, }); final SchedulesController controller; final TextEditingController searchController; final bool cupertino; - final VoidCallback onRefresh; + final VoidCallback? onRefresh; @override Widget build(BuildContext context) { @@ -44,8 +74,14 @@ class ScheduleListToolbar extends StatelessWidget { ), ), ), - const SizedBox(width: 8), - _refresh(context), + if (onRefresh case final refresh?) ...[ + const SizedBox(width: 8), + ScheduleRefreshAction( + controller: controller, + cupertino: cupertino, + onRefresh: refresh, + ), + ], ], ), ), @@ -67,40 +103,14 @@ class ScheduleListToolbar extends StatelessWidget { ); } - Widget _search(BuildContext context) { - if (cupertino) { - return CupertinoSearchTextField( - key: scheduleSearchFieldKey, - controller: searchController, - placeholder: 'Search schedules', - onChanged: controller.setQuery, - onSuffixTap: () { - searchController.clear(); - controller.clearQuery(); - }, - ); - } - return TextField( - key: scheduleSearchFieldKey, - controller: searchController, - onChanged: controller.setQuery, - textInputAction: TextInputAction.search, - decoration: InputDecoration( - hintText: 'Search schedules', - prefixIcon: const Icon(Icons.search), - suffixIcon: controller.query.isEmpty - ? null - : IconButton( - tooltip: 'Clear search', - icon: const Icon(Icons.clear), - onPressed: () { - searchController.clear(); - controller.clearQuery(); - }, - ), - ), - ); - } + Widget _search(BuildContext context) => AppSearchField( + fieldKey: scheduleSearchFieldKey, + controller: searchController, + cupertino: cupertino, + placeholder: 'Search schedules', + onChanged: controller.setQuery, + onCleared: controller.clearQuery, + ); Widget _filter(BuildContext context) { if (cupertino) { @@ -136,38 +146,6 @@ class ScheduleListToolbar extends StatelessWidget { ); } - Widget _refresh(BuildContext context) { - if (controller.isLoading) { - return Semantics( - label: 'Refreshing schedules', - liveRegion: true, - child: Padding( - padding: const EdgeInsets.all(12), - child: cupertino - ? const CupertinoActivityIndicator() - : const CircularProgressIndicator(strokeWidth: 2), - ), - ); - } - if (cupertino) { - return Semantics( - label: 'Refresh schedules', - child: CupertinoButton( - key: scheduleRefreshKey, - padding: EdgeInsets.zero, - onPressed: onRefresh, - child: const Icon(CupertinoIcons.refresh), - ), - ); - } - return IconButton( - key: scheduleRefreshKey, - tooltip: 'Refresh schedules', - onPressed: onRefresh, - icon: const Icon(Icons.refresh), - ); - } - TextStyle? _metaStyle(BuildContext context) => cupertino ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith( color: CupertinoColors.secondaryLabel.resolveFrom(context), diff --git a/app/lib/features/schedules/ui/list/schedule_list_view.dart b/app/lib/features/schedules/ui/list/schedule_list_view.dart index 0ca34236..e3b82cc5 100644 --- a/app/lib/features/schedules/ui/list/schedule_list_view.dart +++ b/app/lib/features/schedules/ui/list/schedule_list_view.dart @@ -20,6 +20,7 @@ class SchedulesListView extends StatelessWidget { required this.cupertino, required this.onOpen, required this.onRefresh, + this.refreshInToolbar = true, }); final SchedulesController controller; @@ -29,6 +30,9 @@ class SchedulesListView extends StatelessWidget { final ValueChanged onOpen; final VoidCallback onRefresh; + /// False when the page's bar carries Refresh instead. + final bool refreshInToolbar; + @override Widget build(BuildContext context) { return Column( @@ -37,7 +41,7 @@ class SchedulesListView extends StatelessWidget { controller: controller, searchController: searchController, cupertino: cupertino, - onRefresh: onRefresh, + onRefresh: refreshInToolbar ? onRefresh : null, ), Expanded(child: _body(context)), ], diff --git a/app/lib/features/search/search_screen.dart b/app/lib/features/search/search_screen.dart index 375fa005..39295491 100644 --- a/app/lib/features/search/search_screen.dart +++ b/app/lib/features/search/search_screen.dart @@ -1,20 +1,23 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../ui/adaptive/segmented_bar.dart'; import '../../core/api_gateway.dart'; +import '../../shell/shell_bar.dart'; import '../../ui/adaptive/host.dart'; +import '../../ui/adaptive/segmented_bar.dart'; import 'data/search_repository.dart'; import 'domain/search_controller.dart'; -import 'domain/search_models.dart'; import 'ui/cupertino_search_body.dart'; -import 'ui/search_result_view.dart'; import 'ui/material_search_body.dart'; +import 'ui/search_bar_controls.dart'; +import 'ui/search_bounds_note.dart'; +import 'ui/search_result_view.dart'; -/// Native omni-search over the Pipelines server: a standard search field, an -/// explicit kind selector, and a flat result list whose rows open the server's -/// own target through [onOpen]. The screen never mutates server state and never -/// guesses a route for an unknown or targetless hit. +/// Native omni-search over the Pipelines server: the search field, a compact +/// kind menu and the syntax help in the top bar's actions pill, and a flat +/// result list whose rows open the server's own target through [onOpen]. The +/// screen never mutates server state and never guesses a route for an unknown +/// or targetless hit. class SearchScreen extends StatefulWidget { const SearchScreen({ super.key, @@ -31,7 +34,7 @@ class SearchScreen extends StatefulWidget { /// Cupertino controls and every other platform uses Material. final bool? cupertino; - /// True as the Search tab: the shell's bar names it, so no page bar. + /// True as the Search tab: the controls go into the shell's bar. final bool embedded; @override @@ -68,35 +71,6 @@ class _SearchScreenState extends State { _controller.updateQuery(''); } - void _selectKind(SearchKind kind) => _controller.selectKind(kind); - - bool get _showHint { - final body = _controller.bodyKind; - return body == SearchBodyKind.idle || body == SearchBodyKind.empty; - } - - Future _pickKind(BuildContext context) async { - final selected = await showCupertinoModalPopup( - context: context, - builder: (context) => CupertinoActionSheet( - title: const Text('Kind'), - actions: [ - for (final kind in SearchKind.values) - CupertinoActionSheetAction( - onPressed: () => Navigator.pop(context, kind), - isDefaultAction: kind == _controller.parsed.kind, - child: Text(kind.label), - ), - ], - cancelButton: CupertinoActionSheetAction( - onPressed: () => Navigator.pop(context), - child: const Text('Cancel'), - ), - ), - ); - if (selected != null) _selectKind(selected); - } - @override void dispose() { _controller.removeListener(_onState); @@ -115,143 +89,78 @@ class _SearchScreenState extends State { (usesCupertinoHost(context) || Theme.of(context).platform == TargetPlatform.iOS || Theme.of(context).platform == TargetPlatform.macOS); - return cupertino ? _cupertinoScreen() : _materialScreen(); - } - - Widget _materialScreen() { - // Results scroll behind a floating tab bar; the list clears it itself. - final body = SafeArea( - bottom: false, - child: SearchArtifactScope( - gateway: widget.gateway, - onOpen: widget.onOpen, - child: MaterialSearchBody( - controller: _controller, - query: _controller.parsed.query, - onOpen: widget.onOpen, - header: _materialHeader(), - ), - ), + if (widget.embedded) { + // The shell's bar carries the controls; without a shell (a bare embed) + // they lead the results instead. + if (!ShellBar.available(context)) { + return _body(cupertino, controls: _controls(cupertino)); + } + return ShellBar(actions: [_controls(cupertino)], child: _body(cupertino)); + } + final bar = SegmentedBar( + cupertino: cupertino, + title: 'Search', + actions: [_controls(cupertino)], ); - if (widget.embedded) return body; + if (cupertino) { + return CupertinoPageScaffold(navigationBar: bar, child: _body(cupertino)); + } return Scaffold( extendBodyBehindAppBar: true, - appBar: const SegmentedBar(cupertino: false, title: 'Search'), - body: body, + appBar: bar, + body: _body(cupertino), ); } - Widget _materialHeader() => Padding( - padding: const EdgeInsets.fromLTRB(16, 12, 16, 8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - spacing: 8, - children: [ - SearchBar( - key: const ValueKey('search.field'), - controller: _text, - autoFocus: true, - hintText: 'Search pipelines, runs and artifacts', - leading: const Icon(Icons.search), - trailing: [ - if (_text.text.isNotEmpty) - IconButton( - key: const ValueKey('search.clear'), - onPressed: _clear, - tooltip: 'Clear search', - icon: const Icon(Icons.close), - ), - ], - textInputAction: TextInputAction.search, - onChanged: _controller.updateQuery, - onSubmitted: (_) => _controller.submit(), - ), - InputDecorator( - decoration: const InputDecoration( - labelText: 'Kind', - border: OutlineInputBorder(), - ), - child: DropdownButtonHideUnderline( - child: DropdownButton( - key: const ValueKey('search.kind'), - value: _controller.parsed.kind, - isExpanded: true, - onChanged: (kind) { - if (kind != null) _selectKind(kind); - }, - items: [ - for (final kind in SearchKind.values) - DropdownMenuItem(value: kind, child: Text(kind.label)), - ], - ), - ), - ), - if (_showHint) const Text(_tokenHint), - if (_controller.boundsText case final bounds?) Text(bounds), - ], - ), + Widget _controls(bool cupertino) => SearchBarControls( + cupertino: cupertino, + text: _text, + kind: _controller.parsed.kind, + onChanged: _controller.updateQuery, + onSubmitted: _controller.submit, + onCleared: _clear, + onKind: _controller.selectKind, ); - Widget _cupertinoScreen() { - final body = SafeArea( - bottom: false, - child: SearchArtifactScope( - gateway: widget.gateway, - onOpen: widget.onOpen, - child: CupertinoSearchBody( - controller: _controller, - query: _controller.parsed.query, - onOpen: widget.onOpen, - header: _cupertinoHeader(context), - ), + /// The server's result and scan bounds, only when they cut the answer + /// short: a complete answer needs no statistics. + Widget _header({Widget? controls}) { + final bounds = _controller.truncated ? _controller.boundsText : null; + if (bounds == null && controls == null) return const SizedBox.shrink(); + return Padding( + padding: const EdgeInsets.symmetric(vertical: 4), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + spacing: 8, + children: [ + ?controls, + if (bounds != null) + SearchBoundsNote(key: searchBoundsKey, text: bounds), + ], ), ); - if (widget.embedded) return body; - return CupertinoPageScaffold( - navigationBar: const SegmentedBar(cupertino: true, title: 'Search'), - child: body, - ); } - Widget _cupertinoHeader(BuildContext context) => Padding( - padding: const EdgeInsets.fromLTRB(16, 12, 16, 8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - spacing: 8, - children: [ - CupertinoSearchTextField( - key: const ValueKey('search.field'), - controller: _text, - autofocus: true, - placeholder: 'Search pipelines, runs and artifacts', - onChanged: _controller.updateQuery, - onSubmitted: (_) => _controller.submit(), - onSuffixTap: _clear, - ), - Align( - alignment: AlignmentDirectional.centerStart, - child: CupertinoButton( - key: const ValueKey('search.kind'), - padding: EdgeInsets.zero, - onPressed: () => _pickKind(context), - child: Row( - mainAxisSize: MainAxisSize.max, - spacing: 6, - children: [ - Expanded(child: Text('Kind: ${_controller.parsed.kind.label}')), - const Icon(CupertinoIcons.chevron_down), - ], + /// No top safe area: the results run behind the floating bar and the + /// scroll view starts them below it. + Widget _body(bool cupertino, {Widget? controls}) { + final header = _header(controls: controls); + return SearchArtifactScope( + gateway: widget.gateway, + onOpen: widget.onOpen, + child: cupertino + ? CupertinoSearchBody( + controller: _controller, + query: _controller.parsed.query, + onOpen: widget.onOpen, + header: header, + ) + : MaterialSearchBody( + controller: _controller, + query: _controller.parsed.query, + onOpen: widget.onOpen, + header: header, ), - ), - ), - if (_showHint) const Text(_tokenHint), - if (_controller.boundsText case final bounds?) Text(bounds), - ], - ), - ); + ); + } } - -const _tokenHint = - 'Filter with t:pipeline or type:artifact (pipeline, run, step, field, ' - 'artifact, version). Last type wins; choosing Kind replaces it. Quote ' - 'tokens to search literally.'; diff --git a/app/lib/features/search/ui/cupertino_search_body.dart b/app/lib/features/search/ui/cupertino_search_body.dart index 42555218..f27d2e8b 100644 --- a/app/lib/features/search/ui/cupertino_search_body.dart +++ b/app/lib/features/search/ui/cupertino_search_body.dart @@ -1,14 +1,14 @@ -import '../../../ui/theme/app_theme.dart'; import 'package:flutter/cupertino.dart'; import '../../../core/api_gateway.dart'; import '../domain/search_controller.dart'; import '../domain/search_row.dart'; import 'search_result_view.dart'; -import '../../../ui/adaptive/floating_bar_layout.dart'; +import 'search_layout.dart'; -/// The Cupertino search view: native search/kind controls and grouped list rows -/// in one scroll view, with standard activity and retry controls. +/// The Cupertino search view: an optional status header and inset-grouped +/// rows in one scroll view that runs behind the top bar, with standard +/// activity and retry controls. class CupertinoSearchBody extends StatelessWidget { const CupertinoSearchBody({ super.key, @@ -25,7 +25,7 @@ class CupertinoSearchBody extends StatelessWidget { @override Widget build(BuildContext context) { - return CustomScrollView( + return SearchScrollView( slivers: [ SliverToBoxAdapter(child: header), if (controller.showProgress) @@ -36,7 +36,6 @@ class CupertinoSearchBody extends StatelessWidget { ), ), ..._content(context), - const SliverFloatingBarClearance(), ], ); } @@ -64,7 +63,16 @@ class CupertinoSearchBody extends StatelessWidget { return [ SliverToBoxAdapter( child: CupertinoListSection.insetGrouped( - backgroundColor: AppColors.groupedBackground, + // The section sits on the page's own background (the shell's + // is not the grouped one), so it takes the bar pills' grey + // rather than a white card framed by a grey band. + backgroundColor: const Color(0x00000000), + decoration: BoxDecoration( + color: CupertinoColors.systemGrey6.resolveFrom(context), + borderRadius: const BorderRadius.all(Radius.circular(10)), + ), + // The column already keeps the bar's inset. + margin: const EdgeInsets.symmetric(vertical: 8), children: [ for (final hit in controller.shownResults) _CupertinoResult(hit: hit, query: query, onOpen: onOpen), @@ -112,13 +120,8 @@ class _CupertinoResult extends StatelessWidget { Icon(searchCupertinoIcon('${hit['kind'] ?? ''}')), leadingSize: 44, trailing: searchArtifactActions(context, hit), - title: Text(row.title), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - spacing: 2, - children: [searchRowMeta(row), searchRowSnippet(context, row)], - ), + title: searchRowTitle(context, row), + subtitle: searchRowLine(context, row), onTap: row.openable ? () => onOpen(hit) : null, ); } diff --git a/app/lib/features/search/ui/material_search_body.dart b/app/lib/features/search/ui/material_search_body.dart index 2caf31b2..9681b270 100644 --- a/app/lib/features/search/ui/material_search_body.dart +++ b/app/lib/features/search/ui/material_search_body.dart @@ -4,10 +4,10 @@ import '../../../core/api_gateway.dart'; import '../domain/search_controller.dart'; import '../domain/search_row.dart'; import 'search_result_view.dart'; -import '../../../ui/adaptive/floating_bar_layout.dart'; +import 'search_layout.dart'; -/// The Material search view: the controls header and a flat native result list -/// in one scroll view, so text scaling can never clip the controls or a row. +/// The Material search view: an optional status header and a flat native +/// result list in one scroll view that runs behind the top bar. class MaterialSearchBody extends StatelessWidget { const MaterialSearchBody({ super.key, @@ -24,13 +24,12 @@ class MaterialSearchBody extends StatelessWidget { @override Widget build(BuildContext context) { - return CustomScrollView( + return SearchScrollView( slivers: [ SliverToBoxAdapter(child: header), if (controller.showProgress) const SliverToBoxAdapter(child: LinearProgressIndicator()), ..._content(context), - const SliverFloatingBarClearance(), ], ); } @@ -100,13 +99,8 @@ class _MaterialResult extends StatelessWidget { searchArtifactThumbnail(context, hit) ?? Icon(searchMaterialIcon('${hit['kind'] ?? ''}')), trailing: searchArtifactActions(context, hit), - title: Text(row.title), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - spacing: 2, - children: [searchRowMeta(row), searchRowSnippet(context, row)], - ), + title: searchRowTitle(context, row), + subtitle: searchRowLine(context, row), onTap: row.openable ? () => onOpen(hit) : null, ); } diff --git a/app/lib/features/search/ui/search_bar_controls.dart b/app/lib/features/search/ui/search_bar_controls.dart new file mode 100644 index 00000000..2d805437 --- /dev/null +++ b/app/lib/features/search/ui/search_bar_controls.dart @@ -0,0 +1,211 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../../ui/input/app_search_field.dart'; +import '../../../ui/navigation/bar_icon_button.dart'; +import '../domain/search_models.dart'; + +const searchFieldKey = ValueKey('search.field'); +const searchKindKey = ValueKey('search.kind'); +const searchHelpKey = ValueKey('search.help'); +const searchBarControlsKey = ValueKey('search.bar'); + +/// The widest the search pill grows on a wide window. +const double kSearchPillMaxWidth = 560; + +const searchTokenHint = + 'Filter with t:pipeline or type:artifact (pipeline, run, step, field, ' + 'artifact, version). Last type wins; choosing Kind replaces it. Quote ' + 'tokens to search literally.'; + +/// Search's controls as one piece of the top bar's actions pill: the search +/// field, a compact Kind menu and the query-syntax help behind an info button. +class SearchBarControls extends StatelessWidget { + const SearchBarControls({ + super.key, + required this.cupertino, + required this.text, + required this.kind, + required this.onChanged, + required this.onSubmitted, + required this.onCleared, + required this.onKind, + this.autofocus = true, + }); + + final bool cupertino; + final TextEditingController text; + final SearchKind kind; + final ValueChanged onChanged; + final VoidCallback onSubmitted; + final VoidCallback onCleared; + final ValueChanged onKind; + final bool autofocus; + + @override + Widget build(BuildContext context) => ConstrainedBox( + key: searchBarControlsKey, + constraints: const BoxConstraints(maxWidth: kSearchPillMaxWidth), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Flexible( + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 4), + child: AppSearchField( + fieldKey: searchFieldKey, + clearKey: const ValueKey('search.clear'), + controller: text, + autofocus: autofocus, + inBar: true, + cupertino: cupertino, + placeholder: 'Search pipelines, runs and artifacts', + onChanged: onChanged, + onSubmitted: (_) => onSubmitted(), + onCleared: onCleared, + ), + ), + ), + SearchKindButton(cupertino: cupertino, kind: kind, onSelected: onKind), + BarIconButton( + key: searchHelpKey, + cupertino: cupertino, + icon: Icons.info_outline, + cupertinoIcon: CupertinoIcons.info_circle, + label: 'Search syntax', + onPressed: () => showSearchHelp(context, cupertino: cupertino), + ), + ], + ), + ); +} + +/// Kind as a compact menu: a filter icon while every kind is searched, the +/// chosen kind's name once narrowed. +class SearchKindButton extends StatelessWidget { + const SearchKindButton({ + super.key, + required this.cupertino, + required this.kind, + required this.onSelected, + }); + + final bool cupertino; + final SearchKind kind; + final ValueChanged onSelected; + + String get _label => 'Kind: ${kind.label}'; + + @override + Widget build(BuildContext context) { + final narrowed = kind != SearchKind.all; + if (cupertino) { + final icon = Icon( + narrowed + ? CupertinoIcons.line_horizontal_3_decrease_circle_fill + : CupertinoIcons.line_horizontal_3_decrease_circle, + ); + return Semantics( + button: true, + label: _label, + excludeSemantics: true, + child: CupertinoButton( + key: searchKindKey, + padding: EdgeInsets.symmetric(horizontal: narrowed ? 8 : 0), + minimumSize: const Size.square(kMinInteractiveDimensionCupertino), + onPressed: () => _pickCupertino(context), + child: narrowed + ? Row( + mainAxisSize: MainAxisSize.min, + spacing: 4, + children: [icon, Text(kind.label)], + ) + : icon, + ), + ); + } + return PopupMenuButton( + key: searchKindKey, + tooltip: _label, + initialValue: kind, + onSelected: onSelected, + itemBuilder: (_) => [ + for (final value in SearchKind.values) + CheckedPopupMenuItem( + value: value, + checked: value == kind, + child: Text(value.label), + ), + ], + child: narrowed + ? Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: Chip( + avatar: const Icon(Icons.filter_list), + label: Text(kind.label), + visualDensity: VisualDensity.compact, + ), + ) + : const SizedBox.square( + dimension: kMinInteractiveDimension, + child: Icon(Icons.filter_list), + ), + ); + } + + Future _pickCupertino(BuildContext context) async { + final selected = await showCupertinoModalPopup( + context: context, + builder: (context) => CupertinoActionSheet( + title: const Text('Kind'), + actions: [ + for (final value in SearchKind.values) + CupertinoActionSheetAction( + onPressed: () => Navigator.pop(context, value), + isDefaultAction: value == kind, + child: Text(value.label), + ), + ], + cancelButton: CupertinoActionSheetAction( + onPressed: () => Navigator.pop(context), + child: const Text('Cancel'), + ), + ), + ); + if (selected != null) onSelected(selected); + } +} + +/// The query syntax, on demand instead of a paragraph above the results. +Future showSearchHelp(BuildContext context, {required bool cupertino}) { + if (cupertino) { + return showCupertinoDialog( + context: context, + barrierDismissible: true, + builder: (context) => CupertinoAlertDialog( + title: const Text('Search syntax'), + content: const Text(searchTokenHint), + actions: [ + CupertinoDialogAction( + isDefaultAction: true, + onPressed: () => Navigator.pop(context), + child: const Text('OK'), + ), + ], + ), + ); + } + return showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Search syntax'), + content: const Text(searchTokenHint), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('OK'), + ), + ], + ), + ); +} diff --git a/app/lib/features/search/ui/search_bounds_note.dart b/app/lib/features/search/ui/search_bounds_note.dart new file mode 100644 index 00000000..baac9213 --- /dev/null +++ b/app/lib/features/search/ui/search_bounds_note.dart @@ -0,0 +1,45 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../../ui/adaptive/host.dart'; + +const searchBoundsKey = ValueKey('search.bounds'); + +/// The server's note that a result set was cut short, in the host's muted +/// caption style with an info icon. +class SearchBoundsNote extends StatelessWidget { + const SearchBoundsNote({super.key, required this.text}); + + final String text; + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoHost(context); + final TextStyle? style; + final IconData icon; + if (cupertino) { + icon = CupertinoIcons.info_circle; + style = CupertinoTheme.of(context).textTheme.textStyle.copyWith( + fontSize: 13, + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ); + } else { + icon = Icons.info_outline; + final theme = Theme.of(context); + style = theme.textTheme.bodySmall?.copyWith( + color: theme.colorScheme.onSurfaceVariant, + ); + } + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + spacing: 8, + children: [ + Icon(icon, size: 16, color: style?.color), + Expanded(child: Text(text, style: style)), + ], + ), + ); + } +} diff --git a/app/lib/features/search/ui/search_layout.dart b/app/lib/features/search/ui/search_layout.dart new file mode 100644 index 00000000..e7a79f53 --- /dev/null +++ b/app/lib/features/search/ui/search_layout.dart @@ -0,0 +1,41 @@ +import 'package:flutter/widgets.dart'; + +import '../../../ui/adaptive/floating_bar_layout.dart'; + +/// The widest the result column grows on a wide window. +const double kSearchContentMaxWidth = 840; + +/// The bar's own side inset, so the column starts under the title pill. +const double kSearchContentInset = 12; + +/// Search's scroll view: it runs behind the floating top bar (the first item +/// starts below the bar's height, read from the media padding), ends clear of +/// a floating tab bar, and keeps each sliver to a start-aligned column no +/// wider than [kSearchContentMaxWidth]. +class SearchScrollView extends StatelessWidget { + const SearchScrollView({super.key, required this.slivers}); + + final List slivers; + + @override + Widget build(BuildContext context) { + final padding = MediaQuery.paddingOf(context); + return CustomScrollView( + slivers: [ + SliverToBoxAdapter(child: SizedBox(height: padding.top + 4)), + for (final sliver in slivers) + SliverPadding( + padding: EdgeInsetsDirectional.only( + start: kSearchContentInset + padding.left, + end: kSearchContentInset + padding.right, + ), + sliver: SliverConstrainedCrossAxis( + maxExtent: kSearchContentMaxWidth, + sliver: sliver, + ), + ), + const SliverFloatingBarClearance(), + ], + ); + } +} diff --git a/app/lib/features/search/ui/search_result_view.dart b/app/lib/features/search/ui/search_result_view.dart index 1d23851f..030068c5 100644 --- a/app/lib/features/search/ui/search_result_view.dart +++ b/app/lib/features/search/ui/search_result_view.dart @@ -11,39 +11,87 @@ import '../../artifacts/ui/artifact_tile.dart'; import '../../artifacts/ui/artifact_viewer_fetch.dart'; import '../domain/search_row.dart'; -/// Kind, recency and read-only affordance for one row. Deliberately unstyled -/// beyond weight so Material and Cupertino inherit their own system typography -/// and colours, including dark mode and text scaling. -Widget searchRowMeta(SearchRowView row) { - final parts = [row.kindLabel, if (row.recency != null) row.recency!]; - return Text( - parts.join(' · '), - style: const TextStyle(fontWeight: FontWeight.w600), +/// A row's title line: the bold title and, at its trailing edge, a small tag +/// naming the kind. +Widget searchRowTitle(BuildContext context, SearchRowView row) => Row( + crossAxisAlignment: CrossAxisAlignment.start, + spacing: 8, + children: [ + Expanded( + child: Text( + row.title, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: const TextStyle(fontWeight: FontWeight.w600), + ), + ), + SearchKindTag(label: row.kindLabel), + ], +); + +/// A row's one muted line: recency, then the snippet (its first query +/// occurrence emphasised by weight, never by parsing server text as markup) +/// or, without one, the kind's own facts. +Widget searchRowLine(BuildContext context, SearchRowView row) { + final snippet = row.snippet; + final lead = row.recency == null ? '' : '${row.recency} · '; + final spans = [ + if (snippet == null) + TextSpan(text: '$lead${row.secondary}') + else ...[ + if (lead.isNotEmpty) TextSpan(text: lead), + for (final span in row.snippetSpans) + TextSpan( + text: span.text, + style: span.matched + ? const TextStyle(fontWeight: FontWeight.bold) + : null, + ), + ], + ]; + return Text.rich( + TextSpan(children: spans), + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: TextStyle(color: _muted(context)), ); } -/// The snippet with the first query occurrence emphasised by weight, never by -/// parsing server text as markup or by a bespoke colour. -Widget searchRowSnippet(BuildContext context, SearchRowView row) { - final snippet = row.snippet; - if (snippet == null) { - return row.secondary.isEmpty - ? const SizedBox.shrink() - : Text(row.secondary); +Color _muted(BuildContext context) => usesCupertinoHost(context) + ? CupertinoColors.secondaryLabel.resolveFrom(context) + : Theme.of(context).colorScheme.onSurfaceVariant; + +/// The result's kind as a small tinted capsule. +class SearchKindTag extends StatelessWidget { + const SearchKindTag({super.key, required this.label}); + + final String label; + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoHost(context); + final Color fill; + final TextStyle? style; + if (cupertino) { + fill = CupertinoColors.tertiarySystemFill.resolveFrom(context); + style = CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith( + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ); + } else { + final theme = Theme.of(context); + fill = theme.colorScheme.surfaceContainerHighest; + style = theme.textTheme.labelSmall?.copyWith( + color: theme.colorScheme.onSurfaceVariant, + ); + } + return DecoratedBox( + decoration: ShapeDecoration(color: fill, shape: const StadiumBorder()), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), + child: Text(label, style: style), + ), + ); } - return Text.rich( - TextSpan( - children: [ - for (final span in row.snippetSpans) - TextSpan( - text: span.text, - style: span.matched - ? const TextStyle(fontWeight: FontWeight.bold) - : null, - ), - ], - ), - ); } IconData searchMaterialIcon(String kind) => switch (kind) { diff --git a/app/lib/features/templates/screen.dart b/app/lib/features/templates/screen.dart index 8410a495..566cb7c6 100644 --- a/app/lib/features/templates/screen.dart +++ b/app/lib/features/templates/screen.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import '../../core/api_gateway.dart'; +import '../../shell/shell_bar.dart'; import '../../ui/adaptive/host.dart'; import 'data/template_repository.dart'; import 'domain/template_entry.dart'; @@ -189,7 +190,7 @@ class _TemplatesScreenState extends State { ) : TemplateDetail( entry: selected, - showBack: widget.embedded, + showBack: widget.embedded && !ShellBar.available(context), onBack: _back, onCreate: () => _openCreate(selected), ); diff --git a/app/lib/features/templates/ui/template_detail.dart b/app/lib/features/templates/ui/template_detail.dart index 97c4b204..a60a09a5 100644 --- a/app/lib/features/templates/ui/template_detail.dart +++ b/app/lib/features/templates/ui/template_detail.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/adaptive/host.dart'; +import '../../../ui/adaptive/segmented_bar.dart'; import '../domain/template_entry.dart'; /// Browser wording for the gallery and the selected template, kept verbatim. @@ -112,20 +113,21 @@ class TemplateDetail extends StatelessWidget { } Widget _backRow(BuildContext context, bool cupertino) { - final back = cupertino - ? CupertinoButton( - key: templateDetailBackKey, - padding: EdgeInsets.zero, - onPressed: onBack, - child: const Icon(CupertinoIcons.back, semanticLabel: 'Back'), - ) - : BackButton(key: templateDetailBackKey, onPressed: onBack); + // Only without a bar above: the same round Back the bar would show. + final back = SegmentedPill( + cupertino: cupertino, + child: SegmentedBackButton( + key: templateDetailBackKey, + cupertino: cupertino, + onPressed: onBack, + ), + ); return Padding( - padding: const EdgeInsets.fromLTRB(4, 4, 16, 0), + padding: const EdgeInsets.fromLTRB(12, 8, 16, 0), child: Row( children: [ back, - const SizedBox(width: 4), + const SizedBox(width: 8), Expanded( child: Text('Templates', style: templateSectionStyle(context)), ), diff --git a/app/lib/features/templates/ui/templates_frame.dart b/app/lib/features/templates/ui/templates_frame.dart index c58e35dc..3e6d2250 100644 --- a/app/lib/features/templates/ui/templates_frame.dart +++ b/app/lib/features/templates/ui/templates_frame.dart @@ -1,17 +1,21 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import '../../../ui/adaptive/segmented_bar.dart'; +import '../../../shell/shell_bar.dart'; import '../../../ui/adaptive/host.dart'; +import '../../../ui/adaptive/segmented_bar.dart'; +import '../../../ui/navigation/bar_icon_button.dart'; const templatesRefreshKey = ValueKey('templates-refresh'); const templatesBackKey = ValueKey('templates-back'); /// The screen's native chrome. /// -/// Standalone use keeps the host's own app bar with Back and Refresh. A shell -/// that already owns navigation passes [embedded], which drops the bar and -/// keeps Refresh at the top of the body. +/// Standalone use draws the segmented bar: the round Back (back to the +/// gallery from a template, otherwise the route's own) and Refresh in the +/// actions pill. A page that already owns a bar passes [embedded]; the +/// screen then publishes its Back and Refresh to that bar through +/// [ShellBar]. Only with no bar above at all does Refresh sit atop the body. class TemplatesFrame extends StatelessWidget { const TemplatesFrame({ super.key, @@ -32,77 +36,60 @@ class TemplatesFrame extends StatelessWidget { @override Widget build(BuildContext context) { - if (embedded) return _embedded(context); - return usesCupertinoHost(context) - ? _cupertino(context) - : _material(context); - } - - Widget _embedded(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Align( - alignment: AlignmentDirectional.centerEnd, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8), - child: _refreshButton(context), + final cupertino = usesCupertinoHost(context); + if (embedded) { + if (ShellBar.available(context)) { + return ShellBar( + title: 'Templates', + onBack: canGoBack ? onBack : null, + actions: [_refreshButton()], + child: body, + ); + } + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Align( + alignment: AlignmentDirectional.centerEnd, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: _refreshButton(), + ), ), - ), - Expanded(child: body), - ], + Expanded(child: body), + ], + ); + } + final bar = SegmentedBar( + cupertino: cupertino, + leading: canGoBack + ? SegmentedBackButton( + key: templatesBackKey, + cupertino: cupertino, + onPressed: onBack, + ) + : null, + title: 'Templates', + actions: [_refreshButton()], ); - } - - Widget _cupertino(BuildContext context) { - return CupertinoPageScaffold( - navigationBar: SegmentedBar( - cupertino: true, - leading: canGoBack - ? CupertinoButton( - key: templatesBackKey, - padding: EdgeInsets.zero, - onPressed: onBack, - child: const Icon(CupertinoIcons.back, semanticLabel: 'Back'), - ) - : null, - title: 'Templates', - actions: [_refreshButton(context)], - ), - child: SafeArea(child: body), - ); - } - - Widget _material(BuildContext context) { + if (cupertino) { + return CupertinoPageScaffold( + navigationBar: bar, + child: SafeArea(child: body), + ); + } return Scaffold( extendBodyBehindAppBar: true, - appBar: SegmentedBar( - cupertino: false, - title: 'Templates', - leading: canGoBack - ? BackButton(key: templatesBackKey, onPressed: onBack) - : null, - actions: [_refreshButton(context)], - ), + appBar: bar, body: SafeArea(child: body), ); } - Widget _refreshButton(BuildContext context) { - final onPressed = refreshing ? null : onRefresh; - if (usesCupertinoHost(context)) { - return CupertinoButton( - key: templatesRefreshKey, - padding: EdgeInsets.zero, - onPressed: onPressed, - child: const Icon(CupertinoIcons.refresh, semanticLabel: 'Refresh'), - ); - } - return IconButton( - key: templatesRefreshKey, - tooltip: 'Refresh', - onPressed: onPressed, - icon: const Icon(Icons.refresh), - ); - } + Widget _refreshButton() => BarIconButton( + key: templatesRefreshKey, + icon: Icons.refresh, + cupertinoIcon: CupertinoIcons.refresh, + label: 'Refresh', + onPressed: refreshing ? null : onRefresh, + ); } diff --git a/app/lib/ui/input/app_search_field.dart b/app/lib/ui/input/app_search_field.dart new file mode 100644 index 00000000..e2c16ee6 --- /dev/null +++ b/app/lib/ui/input/app_search_field.dart @@ -0,0 +1,116 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../adaptive/host.dart'; + +/// The app's one search field per platform. +/// +/// Cupertino uses the stock [CupertinoSearchTextField]. Material uses a +/// [TextField] shaped like it: a stadium with a leading search icon, a clear +/// button once there is text, no underline and no elevation. On a page it is +/// filled with the host's raised surface; [inBar] drops the fill (and the +/// Cupertino grey) because a bar's glass pill is already its background. +class AppSearchField extends StatelessWidget { + const AppSearchField({ + super.key, + required this.controller, + required this.placeholder, + this.fieldKey, + this.clearKey, + this.onChanged, + this.onSubmitted, + this.onCleared, + this.autofocus = false, + this.focusNode, + this.inBar = false, + this.cupertino, + }); + + final TextEditingController controller; + final String placeholder; + + /// The key of the text field itself, for finders. + final Key? fieldKey; + + /// The key of Material's clear button. + final Key? clearKey; + final ValueChanged? onChanged; + final ValueChanged? onSubmitted; + + /// Runs after the clear control emptied the field; without it the clear + /// reports an empty [onChanged]. + final VoidCallback? onCleared; + final bool autofocus; + final FocusNode? focusNode; + final bool inBar; + final bool? cupertino; + + void _clear() { + controller.clear(); + if (onCleared case final cleared?) { + cleared(); + } else { + onChanged?.call(''); + } + } + + @override + Widget build(BuildContext context) { + if (cupertino ?? usesCupertinoHost(context)) { + return CupertinoSearchTextField( + key: fieldKey, + controller: controller, + focusNode: focusNode, + autofocus: autofocus, + placeholder: placeholder, + backgroundColor: inBar ? const Color(0x00000000) : null, + onChanged: onChanged, + onSubmitted: onSubmitted, + onSuffixTap: _clear, + ); + } + final scheme = Theme.of(context).colorScheme; + const radius = BorderRadius.all(Radius.circular(28)); + const stadium = OutlineInputBorder( + borderRadius: radius, + borderSide: BorderSide.none, + ); + return ValueListenableBuilder( + valueListenable: controller, + builder: (context, value, _) => TextField( + key: fieldKey, + controller: controller, + focusNode: focusNode, + autofocus: autofocus, + textInputAction: TextInputAction.search, + onChanged: onChanged, + onSubmitted: onSubmitted, + decoration: InputDecoration( + hintText: placeholder, + prefixIcon: const Icon(Icons.search), + suffixIcon: value.text.isEmpty + ? null + : IconButton( + key: clearKey, + tooltip: 'Clear search', + onPressed: _clear, + icon: const Icon(Icons.close), + ), + filled: !inBar, + fillColor: scheme.surfaceContainerHigh, + isDense: true, + border: stadium, + enabledBorder: stadium, + // In the bar the pill is the field's outline; on a page the focused + // field shows the host's focus ring. + focusedBorder: inBar + ? stadium + : OutlineInputBorder( + borderRadius: radius, + borderSide: BorderSide(color: scheme.primary, width: 2), + ), + ), + ), + ); + } +} diff --git a/app/lib/ui/navigation/bar_icon_button.dart b/app/lib/ui/navigation/bar_icon_button.dart new file mode 100644 index 00000000..1c33e8a1 --- /dev/null +++ b/app/lib/ui/navigation/bar_icon_button.dart @@ -0,0 +1,87 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../adaptive/host.dart'; + +/// One icon action of a segmented bar's actions pill (or any toolbar row). +/// +/// Every action gets the platform's whole touch target and no extra padding, +/// so a row of them is evenly spaced and the last one never touches the +/// pill's edge: Material's [IconButton] (48dp, with its tooltip), Cupertino's +/// [CupertinoButton] at [kMinInteractiveDimensionCupertino] (44pt) square. +/// While [busy] the action shows the platform's activity indicator in the +/// same box and takes no taps. +class BarIconButton extends StatelessWidget { + const BarIconButton({ + super.key, + required this.icon, + required this.cupertinoIcon, + required this.label, + required this.onPressed, + this.selected = false, + this.busy = false, + this.busyLabel, + this.cupertino, + }); + + final IconData icon; + final IconData cupertinoIcon; + + /// The tooltip and accessible name. + final String label; + final VoidCallback? onPressed; + + /// Material shows a toggled-on action as selected. + final bool selected; + final bool busy; + + /// The accessible name while [busy]; defaults to [label]. + final String? busyLabel; + + /// The control family; defaults to the host's. + final bool? cupertino; + + @override + Widget build(BuildContext context) { + final native = cupertino ?? usesCupertinoHost(context); + if (busy) { + final side = native + ? kMinInteractiveDimensionCupertino + : kMinInteractiveDimension; + return Semantics( + label: busyLabel ?? label, + liveRegion: true, + child: SizedBox.square( + dimension: side, + child: Center( + child: native + ? const CupertinoActivityIndicator() + : const SizedBox.square( + dimension: 20, + child: CircularProgressIndicator(strokeWidth: 2), + ), + ), + ), + ); + } + if (native) { + return Semantics( + button: true, + label: label, + excludeSemantics: true, + child: CupertinoButton( + padding: EdgeInsets.zero, + minimumSize: const Size.square(kMinInteractiveDimensionCupertino), + onPressed: onPressed, + child: Icon(cupertinoIcon), + ), + ); + } + return IconButton( + tooltip: label, + isSelected: selected, + onPressed: onPressed, + icon: Icon(icon), + ); + } +} diff --git a/app/notes/pages-fixes.md b/app/notes/pages-fixes.md new file mode 100644 index 00000000..1f745aa2 --- /dev/null +++ b/app/notes/pages-fixes.md @@ -0,0 +1,150 @@ +# Search, Settings and page-chrome fixes (style review batch C) + +Fixes from the whole-app style review (`/tmp/app-style-review/report.md`): +F8/F28 Search, F9 Settings, F10 refresh placement, F11 back/close, F20 +Cupertino action spacing, and F1 for Search and Settings. + +## Shared pieces + +- `lib/ui/input/app_search_field.dart` — `AppSearchField`, the one search field + per platform: Cupertino's stock `CupertinoSearchTextField`; on Material a + stadium `TextField` (leading search icon, clear button once there is text, + no underline, no elevation). It is filled with `surfaceContainerHigh` on a + page; `inBar` drops the fill (Cupertino: the grey) inside a bar's glass pill. + It is used by Search, the Schedules toolbar and the Runs filter sheet. The + chat search fields were left alone because chat belongs to another lane. +- `lib/ui/navigation/bar_icon_button.dart` — `BarIconButton`, one icon action + of an actions pill. Material uses an `IconButton` (48dp, tooltip). Cupertino + uses a `CupertinoButton` with no padding and a 44pt square minimum. `busy` + shows the platform activity indicator in the same box. + +## Search (F8, F28, F1) + +- The bar is the shell's title pill (Search) plus one actions pill holding + `SearchBarControls` (`features/search/ui/search_bar_controls.dart`): the + field, a compact Kind menu, and an info button for the query syntax. + - Kind is a filter icon while every kind is searched, and a small chip once + the search is narrowed. Material uses a `PopupMenuButton` of + `CheckedPopupMenuItem`s; Cupertino uses an action sheet. + - The info button opens the syntax help in a dialog. + - As the shell's tab the screen publishes the controls through `ShellBar`. + Standalone, it gives them to its own `SegmentedBar`. + - The pill is at most 560 wide (`kSearchPillMaxWidth`). + - `SegmentedBar` keeps a 25% title share and right-aligns its actions, and + `lib/shell` and `lib/ui/adaptive` were out of scope. So the field sits + beside the Search title rather than replacing it. +- The bounds line (`N results · cap · scanned …`) now appears only when the + server truncated the answer. It is a muted note with an info icon + (`search_bounds_note.dart`, key `search.bounds`). +- Result rows: a bold title (up to 2 lines), a small kind tag at the trailing + edge (`SearchKindTag`), and one muted line: recency, then the snippet (match + in bold) or the kind's facts. The old bold kind line between title and + metadata is gone. +- `SearchScrollView` (`search_layout.dart`): + - There is no top `SafeArea`. The scroll view reaches the top edge and starts + its content below the bar's media padding. + - Each sliver is start-aligned at the bar's 12px inset, at most 840 wide. + - The view ends with the floating tab bar's clearance. + - Cupertino results are one inset section filled with `systemGrey6`, the + same grey as the bar pills, instead of a white card framed by a grey band + on the shell's white page. +- Keys kept: `search.field`, `search.kind`, `search.clear`, `search.retry`, + `search.result.`. New keys: `search.help`, `search.bar`, + `search.bounds`. + +## Settings (F9, F1) + +Done in a separate worktree and fast-forwarded here (commit `3ec580c2`). + +- Flat grouped sections: + - `SettingsGroup`/`SettingsGroupItem`: a Material primary header over a flat + `surfaceContainer` group with dividers; Cupertino + `CupertinoListSection.insetGrouped`. + - `SettingsRow` and `SettingsStatusRow` rows. + - Server rows show a check mark, the address and a trailing + Use/Edit/Remove menu (key `settings.server..menu`), plus an Add server + row. + - Templates and Schedules are chevron rows in a "Library" group. + - The ntfy rows use a `CupertinoSwitch` on Cupertino. + - The disabled Save workspace is a `FilledButton.tonal`. +- No elevated cards: `SettingsCard` was removed. +- Helper copy is shorter, and the trust warning is a section footer. +- `SettingsPageBody`: no top `SafeArea`. The page pads by the bar's height, + and its column is start-aligned at x=12 with a maximum width of 720. + +## Refresh and Back (F10, F11) + +- Templates: + - `TemplatesFrame` puts Refresh in the bar's actions pill. Standalone, it + draws its own `SegmentedBar`. Embedded, it publishes Back and Refresh + through `ShellBar`. + - `TemplatesDestination` owns a `ShellBarRegistry`/`ShellBarScope` for its + page and builds its one `SegmentedBar` from what the gallery publishes. + - The round leading piece is the page Back (`templates-page-back`) on the + gallery and the detail Back (`template-detail-back`) on an open template, + so there is only ever one Back. The body back row in `TemplateDetail` + remains only with no bar above, as a `SegmentedPill` + + `SegmentedBackButton`. +- Schedules: `SchedulesDestination` uses `SegmentedBackButton` (new key + `schedules-page-back`) and puts `ScheduleRefreshAction` in the actions pill. + The toolbar shows Refresh only when no bar carries it + (`SchedulesListView.refreshInToolbar`; the standalone `SchedulesScreen` + still shows it in the body). +- `PipelineBackButton` is now the round `SegmentedPill` + `SegmentedBackButton` + (semantics "Back to pipelines" kept). + +## Cupertino action spacing (F20) + +The Runs stats/filter/sort actions, the Needs-you bell, and the Pipelines +filter and sort icons all use no padding and a 44pt square target. They are +evenly spaced, and the last one no longer touches the pill's edge. + +## Tests + +- New: + - `test/features/search/search_bar_layout_test.dart`, on both hosts: + - the controls are in the bar, with no SearchBar or dropdown + - the help is hidden until the info button is tapped + - stats show only when truncated + - rows have a kind tag and one line + - at 1200 the scroll view reaches y=0, rows start below the bar inside + the 12 inset and the 840 cap, and the pill is no wider than 560 + - `test/ui/navigation/bar_icon_button_test.dart`: 44/48 targets that abut; + one stadium search field with a clear button; no Material under Cupertino. +- Updated: + - `search_screen_test.dart` and `search_screen_states_test.dart` + (`TextField` instead of `SearchBar`, the Kind menu item) + - `templates_wiring_test.dart` (Refresh and the single Back are in the bar; + one extra frame for the bar to hand Back back) + - `schedules_destination_test.dart` (Back and Refresh are bar pieces) + - the Settings tests listed in commit `3ec580c2` + +## Evidence + +The captures are in `/tmp/fix-c-evidence/`. + +- Setup: + - Web build of `tool/templates_wiring_probe_entry.dart` (the real app with + `?host=cupertino`). + - Served by a copy of `tool/runs_probe_server.mjs` in `/tmp/fix-c-tools/`. + The copy adds fixture `list_templates`/`list_schedules` replies and marks + a search containing "many" as truncated. + - Driven by `/tmp/fix-c-tools/shoot.mjs` (headless Chrome). +- Files: `{m,c}-{search,settings,templates,schedules}-{560,1200}-{light,dark}`, + `{m,c}-search-560-{idle,truncated}`, `{m,c}-runs-560-light`, + `{m,c}-settings-560-scrolled`. +- The Settings worktree's own captures are `settings-app-*` and + `settings-probe-*`. + +## Known gaps + +- In the shell, Search and Settings content still stops below the bar: the + shell wraps each tab in a top `SafeArea` (`lib/shell`, out of scope). Both + pages already pad by the media padding, so they will run behind the bar once + the shell stops consuming it. A standalone `SearchScreen` (not mounted by + the app, only by tests) already runs behind its own bar. +- The Search field shares the bar with the Search title pill. Making it fill + the whole bar needs a `SegmentedBar`/shell change. +- The Cupertino Templates gallery still draws white rows in a grey band on the + white page (gallery styling was not part of this batch). +- No device run: Android and iOS are unverified. diff --git a/app/test/application/schedules_destination_test.dart b/app/test/application/schedules_destination_test.dart index b919db30..6ad3b265 100644 --- a/app/test/application/schedules_destination_test.dart +++ b/app/test/application/schedules_destination_test.dart @@ -6,6 +6,8 @@ import 'package:pipelines_app/application/app_session.dart'; import 'package:pipelines_app/application/schedules_destination.dart'; import 'package:pipelines_app/application/server_endpoint.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart'; +import 'package:pipelines_app/features/schedules/ui/list/schedule_list_toolbar.dart'; +import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; import '../core/transport/pipelines_client_test.dart' show FakeChannel; @@ -67,5 +69,15 @@ void main() { await tester.pump(); await tester.pump(); expect(find.text('Nightly review'), findsOneWidget); + + // Back and Refresh are bar pieces; the body has neither. + Finder inBar(Key key) => find.descendant( + of: find.byType(SegmentedBar), + matching: find.byKey(key), + ); + expect(inBar(schedulesPageBackKey), findsOneWidget); + expect(inBar(scheduleRefreshKey), findsOneWidget); + expect(find.byKey(scheduleRefreshKey), findsOneWidget); + expect(find.byType(SegmentedBackButton), findsOneWidget); }); } diff --git a/app/test/application/templates_wiring_test.dart b/app/test/application/templates_wiring_test.dart index 3d0a238d..7aaf2aac 100644 --- a/app/test/application/templates_wiring_test.dart +++ b/app/test/application/templates_wiring_test.dart @@ -211,14 +211,31 @@ void main() { expect(sockets, 1); expect(requestsOf(channel, 'list_templates'), hasLength(1)); + // Refresh sits in the bar's actions pill, not in the body. + Finder inBar(Key key) => find.descendant( + of: find.byType(SegmentedBar), + matching: find.byKey(key), + ); + expect(inBar(templatesRefreshKey), findsOneWidget); + expect(find.byKey(templatesRefreshKey), findsOneWidget); + expect(inBar(templatesPageBackKey), findsOneWidget); + await tester.tap(find.byKey(templateRowKey('release'))); await tester.pump(); + await tester.pump(); expect(find.text('Definition source'), findsOneWidget); + // One Back at a time, in the bar's round leading piece: the open + // template's Back replaces the page's. + expect(inBar(templateDetailBackKey), findsOneWidget); + expect(find.byKey(templateDetailBackKey), findsOneWidget); + expect(find.byKey(templatesPageBackKey), findsNothing); // Detail Back returns to the gallery, then the page Back restores the // same Settings state. await tester.tap(find.byKey(templateDetailBackKey)); await tester.pump(); + // The gallery hands the bar back to the page's Back on the next frame. + await tester.pump(); await tester.tap(find.byKey(templatesPageBackKey)); await tester.pumpAndSettle(); @@ -333,6 +350,8 @@ void main() { await tester.pump(); await tester.tap(find.byKey(templateDetailBackKey)); await tester.pump(); + // The gallery hands the bar back to the page's Back on the next frame. + await tester.pump(); await tester.tap(find.byKey(templatesPageBackKey)); await tester.pumpAndSettle(); await tester.tap(find.text('Pipelines').last); diff --git a/app/test/features/search/search_bar_layout_test.dart b/app/test/features/search/search_bar_layout_test.dart new file mode 100644 index 00000000..1755044a --- /dev/null +++ b/app/test/features/search/search_bar_layout_test.dart @@ -0,0 +1,157 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/search/search_screen.dart'; +import 'package:pipelines_app/features/search/ui/search_bar_controls.dart'; +import 'package:pipelines_app/features/search/ui/search_bounds_note.dart'; +import 'package:pipelines_app/features/search/ui/search_layout.dart'; +import 'package:pipelines_app/features/search/ui/search_result_view.dart'; +import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; + +import 'search_screen_test.dart' + show ImmediateGateway, field, pipeline, response; + +void _size(WidgetTester tester, double width) { + tester.view.physicalSize = Size(width, 800); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); +} + +Future _search(WidgetTester tester, String query) async { + await tester.enterText(find.byKey(searchFieldKey), query); + await tester.pump(const Duration(milliseconds: 300)); + await tester.pumpAndSettle(); +} + +Widget _app(bool cupertino, Widget child) => + cupertino ? CupertinoApp(home: child) : MaterialApp(home: child); + +void main() { + for (final cupertino in [false, true]) { + final host = cupertino ? 'Cupertino' : 'Material'; + + testWidgets('$host: the field, Kind and help live in the bar pill', ( + tester, + ) async { + _size(tester, 390); + final gateway = ImmediateGateway((_, _) => response([pipeline])); + await tester.pumpWidget( + _app( + cupertino, + SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino), + ), + ); + + for (final key in [searchFieldKey, searchKindKey, searchHelpKey]) { + expect( + find.descendant( + of: find.byType(SegmentedBar), + matching: find.byKey(key), + ), + findsOneWidget, + reason: '$key is in the bar', + ); + } + // One field per platform: no elevated SearchBar, no dropdown. + expect(find.byType(SearchBar), findsNothing); + expect(find.byType(DropdownButton), findsNothing); + expect( + find.byType(CupertinoSearchTextField), + cupertino ? findsOneWidget : findsNothing, + ); + // The syntax help is behind the info button, not on the page. + expect(find.text(searchTokenHint), findsNothing); + await tester.tap(find.byKey(searchHelpKey)); + await tester.pumpAndSettle(); + expect(find.text(searchTokenHint), findsOneWidget); + }); + + testWidgets('$host: stats appear only for a truncated answer', ( + tester, + ) async { + _size(tester, 390); + var truncated = false; + final gateway = ImmediateGateway((_, _) { + final reply = response([pipeline]); + (reply['search_results'] as Map)['truncated'] = truncated; + return reply; + }); + await tester.pumpWidget( + _app( + cupertino, + SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino), + ), + ); + + await _search(tester, 'release'); + expect(find.text('Release planner'), findsOneWidget); + expect(find.byKey(searchBoundsKey), findsNothing); + expect(find.textContaining('scanned'), findsNothing); + + truncated = true; + await _search(tester, 'releases'); + expect(find.byKey(searchBoundsKey), findsOneWidget); + expect(find.textContaining('Results truncated'), findsOneWidget); + }); + + testWidgets('$host: rows show a bold title, a kind tag and one line', ( + tester, + ) async { + _size(tester, 390); + final gateway = ImmediateGateway((_, _) => response([field])); + await tester.pumpWidget( + _app( + cupertino, + SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino), + ), + ); + await _search(tester, 'release'); + + final row = find.byKey(const ValueKey('search.result.run:11:4:output')); + expect(row, findsOneWidget); + expect( + find.descendant(of: row, matching: find.byType(SearchKindTag)), + findsOneWidget, + ); + expect( + find.descendant( + of: row, + matching: find.textContaining('the release is ready'), + ), + findsOneWidget, + ); + }); + + testWidgets('$host: results run behind the bar in a capped column', ( + tester, + ) async { + _size(tester, 1200); + final gateway = ImmediateGateway((_, _) => response([pipeline])); + await tester.pumpWidget( + _app( + cupertino, + SearchScreen(gateway: gateway, onOpen: (_) {}, cupertino: cupertino), + ), + ); + await _search(tester, 'release'); + + // The scroll view reaches the top edge; its first row starts below + // the floating bar. + final scroll = find.byType(CustomScrollView); + expect(tester.getTopLeft(scroll).dy, 0); + final barBottom = tester.getBottomLeft(find.byType(SegmentedBar)).dy; + final row = find.byKey(const ValueKey('search.result.pipeline:7')); + expect(tester.getTopLeft(row).dy, greaterThanOrEqualTo(barBottom - 8)); + // Start-aligned under the bar's inset, no wider than the cap. + final rect = tester.getRect(row); + expect(rect.left, greaterThanOrEqualTo(kSearchContentInset)); + expect(rect.right, lessThanOrEqualTo(kSearchContentInset + 840)); + // The search pill keeps to its own cap on a wide window. + expect( + tester.getSize(find.byKey(searchBarControlsKey)).width, + lessThanOrEqualTo(kSearchPillMaxWidth), + ); + }); + } +} diff --git a/app/test/features/search/search_screen_states_test.dart b/app/test/features/search/search_screen_states_test.dart index a42a4ced..6bf5c5cb 100644 --- a/app/test/features/search/search_screen_states_test.dart +++ b/app/test/features/search/search_screen_states_test.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/search/domain/search_models.dart'; import 'package:pipelines_app/features/search/search_screen.dart'; class RecordingGateway implements ApiGateway { @@ -135,10 +136,15 @@ void main() { await tester.tap(find.byKey(const ValueKey('search.kind'))); await tester.pumpAndSettle(); - await tester.tap(find.text('Pipelines').last); + await tester.tap( + find.ancestor( + of: find.text('Pipelines').last, + matching: find.byType(CheckedPopupMenuItem), + ), + ); await tester.pumpAndSettle(); - final field = tester.widget( + final field = tester.widget( find.byKey(const ValueKey('search.field')), ); expect(field.controller!.text.trim(), 'plan'); diff --git a/app/test/features/search/search_screen_test.dart b/app/test/features/search/search_screen_test.dart index 7c1b7eeb..5e866264 100644 --- a/app/test/features/search/search_screen_test.dart +++ b/app/test/features/search/search_screen_test.dart @@ -2,7 +2,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; -import 'package:pipelines_app/features/search/domain/search_models.dart'; import 'package:pipelines_app/features/search/search_screen.dart'; class ImmediateGateway implements ApiGateway { @@ -116,9 +115,10 @@ void main() { ), ); - expect(find.byType(SearchBar), findsOneWidget); - expect(find.byType(DropdownButton), findsOneWidget); - expect(find.text('All kinds'), findsOneWidget); + expect(find.byType(SearchBar), findsNothing); + expect(find.byType(TextField), findsOneWidget); + expect(find.byKey(const ValueKey('search.kind')), findsOneWidget); + expect(find.byTooltip('Kind: All kinds'), findsOneWidget); expect(gateway.calls, isEmpty); await search(tester, 'release'); diff --git a/app/test/ui/navigation/bar_icon_button_test.dart b/app/test/ui/navigation/bar_icon_button_test.dart new file mode 100644 index 00000000..8f9a110b --- /dev/null +++ b/app/test/ui/navigation/bar_icon_button_test.dart @@ -0,0 +1,95 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/input/app_search_field.dart'; +import 'package:pipelines_app/ui/navigation/bar_icon_button.dart'; + +Widget _row(bool cupertino, List children) { + final row = Center( + child: Row(mainAxisSize: MainAxisSize.min, children: children), + ); + return cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: row)) + : MaterialApp(home: Scaffold(body: row)); +} + +BarIconButton _action(Key key, {bool busy = false}) => BarIconButton( + key: key, + icon: Icons.refresh, + cupertinoIcon: CupertinoIcons.refresh, + label: 'Refresh', + busy: busy, + onPressed: () {}, +); + +void main() { + for (final cupertino in [false, true]) { + final host = cupertino ? 'Cupertino' : 'Material'; + final side = cupertino + ? kMinInteractiveDimensionCupertino + : kMinInteractiveDimension; + + testWidgets('$host bar actions are whole, evenly sized touch targets', ( + tester, + ) async { + await tester.pumpWidget( + _row(cupertino, [ + _action(const ValueKey('a')), + _action(const ValueKey('b')), + _action(const ValueKey('c'), busy: true), + ]), + ); + for (final key in const ['a', 'b', 'c']) { + expect(tester.getSize(find.byKey(ValueKey(key))), Size(side, side)); + } + // Adjacent actions abut: the spacing is the targets', not padding. + expect( + tester.getTopLeft(find.byKey(const ValueKey('b'))).dx - + tester.getTopLeft(find.byKey(const ValueKey('a'))).dx, + side, + ); + if (cupertino) expect(find.byType(Material), findsNothing); + expect(find.bySemanticsLabel('Refresh'), findsWidgets); + }); + + testWidgets('$host search field is one stadium field with a clear', ( + tester, + ) async { + final text = TextEditingController(); + addTearDown(text.dispose); + var cleared = false; + await tester.pumpWidget( + _row(cupertino, [ + SizedBox( + width: 300, + child: AppSearchField( + fieldKey: const ValueKey('field'), + controller: text, + placeholder: 'Search', + onCleared: () => cleared = true, + ), + ), + ]), + ); + if (cupertino) { + expect(find.byType(CupertinoSearchTextField), findsOneWidget); + expect(find.byType(Material), findsNothing); + return; + } + final field = tester.widget( + find.byKey(const ValueKey('field')), + ); + final border = field.decoration!.enabledBorder! as OutlineInputBorder; + expect(border.borderSide, BorderSide.none); + expect(field.decoration!.filled, isTrue); + expect(find.byTooltip('Clear search'), findsNothing); + + await tester.enterText(find.byKey(const ValueKey('field')), 'abc'); + await tester.pump(); + await tester.tap(find.byTooltip('Clear search')); + await tester.pump(); + expect(text.text, isEmpty); + expect(cleared, isTrue); + }); + } +}