feat(app): add native omni-search screen over the search gateway
Pure request/parse/row logic in lib/features/search/domain, a gateway-backed repository, and Material plus Cupertino bodies. The header and rows share one scroll view, and the server's truncation, scan and cap facts stay visible even when a bounded scan returns no matches. Tests cover the exact search envelope, token parsing, stale replies, retry, truncation bounds and platform layouts. A Web-only fixture and CDP probe support rendered verification; the screen is not yet registered in the shell.
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
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';
|
||||
|
||||
/// The Cupertino search view: native search/kind controls and grouped list rows
|
||||
/// in one scroll view, with standard activity and retry controls.
|
||||
class CupertinoSearchBody extends StatelessWidget {
|
||||
const CupertinoSearchBody({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.query,
|
||||
required this.onOpen,
|
||||
required this.header,
|
||||
});
|
||||
|
||||
final OmniSearchController controller;
|
||||
final String query;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
final Widget header;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: header),
|
||||
if (controller.showProgress)
|
||||
const SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: CupertinoActivityIndicator(),
|
||||
),
|
||||
),
|
||||
..._content(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _content(BuildContext context) {
|
||||
switch (controller.bodyKind) {
|
||||
case SearchBodyKind.error:
|
||||
return [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: _CupertinoError(
|
||||
message: controller.error!,
|
||||
onRetry: controller.retry,
|
||||
),
|
||||
),
|
||||
];
|
||||
case SearchBodyKind.searching:
|
||||
return const [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: _CupertinoSearching(),
|
||||
),
|
||||
];
|
||||
case SearchBodyKind.results:
|
||||
return [
|
||||
SliverToBoxAdapter(
|
||||
child: CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
for (final hit in controller.shownResults)
|
||||
_CupertinoResult(hit: hit, query: query, onOpen: onOpen),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
case SearchBodyKind.empty:
|
||||
return [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: _CupertinoMessage(message: controller.emptyMessage!),
|
||||
),
|
||||
];
|
||||
case SearchBodyKind.idle:
|
||||
return const [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: _CupertinoMessage(
|
||||
message: 'Search pipelines, runs and artifacts.',
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _CupertinoResult extends StatelessWidget {
|
||||
const _CupertinoResult({
|
||||
required this.hit,
|
||||
required this.query,
|
||||
required this.onOpen,
|
||||
});
|
||||
|
||||
final JsonMap hit;
|
||||
final String query;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final row = searchRowView(hit, query);
|
||||
return CupertinoListTile(
|
||||
key: ValueKey('search.result.${hit['target']}'),
|
||||
leading: Icon(searchCupertinoIcon('${hit['kind'] ?? ''}')),
|
||||
title: Text(row.title),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 2,
|
||||
children: [searchRowMeta(row), searchRowSnippet(context, row)],
|
||||
),
|
||||
onTap: row.openable ? () => onOpen(hit) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CupertinoSearching extends StatelessWidget {
|
||||
const _CupertinoSearching();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 12,
|
||||
children: [CupertinoActivityIndicator(), Text('Searching…')],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _CupertinoMessage extends StatelessWidget {
|
||||
const _CupertinoMessage({required this.message});
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text(message, textAlign: TextAlign.center),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _CupertinoError extends StatelessWidget {
|
||||
const _CupertinoError({required this.message, required this.onRetry});
|
||||
|
||||
final String message;
|
||||
final Future<void> Function() onRetry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 12,
|
||||
children: [
|
||||
Text(message, textAlign: TextAlign.center),
|
||||
CupertinoButton.filled(
|
||||
key: const ValueKey('search.retry'),
|
||||
onPressed: onRetry,
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/search_controller.dart';
|
||||
import '../domain/search_row.dart';
|
||||
import 'search_result_view.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.
|
||||
class MaterialSearchBody extends StatelessWidget {
|
||||
const MaterialSearchBody({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.query,
|
||||
required this.onOpen,
|
||||
required this.header,
|
||||
});
|
||||
|
||||
final OmniSearchController controller;
|
||||
final String query;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
final Widget header;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: header),
|
||||
if (controller.showProgress)
|
||||
const SliverToBoxAdapter(child: LinearProgressIndicator()),
|
||||
..._content(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _content(BuildContext context) {
|
||||
switch (controller.bodyKind) {
|
||||
case SearchBodyKind.error:
|
||||
return [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: _SearchError(
|
||||
message: controller.error!,
|
||||
onRetry: controller.retry,
|
||||
),
|
||||
),
|
||||
];
|
||||
case SearchBodyKind.searching:
|
||||
return const [
|
||||
SliverFillRemaining(hasScrollBody: false, child: _Searching()),
|
||||
];
|
||||
case SearchBodyKind.results:
|
||||
return [
|
||||
SliverList.builder(
|
||||
itemCount: controller.shownResults.length,
|
||||
itemBuilder: (context, index) {
|
||||
final hit = controller.shownResults[index];
|
||||
return _MaterialResult(hit: hit, query: query, onOpen: onOpen);
|
||||
},
|
||||
),
|
||||
];
|
||||
case SearchBodyKind.empty:
|
||||
return [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: _SearchMessage(message: controller.emptyMessage!),
|
||||
),
|
||||
];
|
||||
case SearchBodyKind.idle:
|
||||
return const [
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: _SearchMessage(
|
||||
message: 'Search pipelines, runs and artifacts.',
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _MaterialResult extends StatelessWidget {
|
||||
const _MaterialResult({
|
||||
required this.hit,
|
||||
required this.query,
|
||||
required this.onOpen,
|
||||
});
|
||||
|
||||
final JsonMap hit;
|
||||
final String query;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final row = searchRowView(hit, query);
|
||||
return ListTile(
|
||||
key: ValueKey('search.result.${hit['target']}'),
|
||||
leading: Icon(searchMaterialIcon('${hit['kind'] ?? ''}')),
|
||||
title: Text(row.title),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 2,
|
||||
children: [searchRowMeta(row), searchRowSnippet(context, row)],
|
||||
),
|
||||
onTap: row.openable ? () => onOpen(hit) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Searching extends StatelessWidget {
|
||||
const _Searching();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 12,
|
||||
children: [CircularProgressIndicator(), Text('Searching…')],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _SearchMessage extends StatelessWidget {
|
||||
const _SearchMessage({required this.message});
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text(message, textAlign: TextAlign.center),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _SearchError extends StatelessWidget {
|
||||
const _SearchError({required this.message, required this.onRetry});
|
||||
|
||||
final String message;
|
||||
final Future<void> Function() onRetry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 12,
|
||||
children: [
|
||||
Text(message, textAlign: TextAlign.center),
|
||||
FilledButton.tonalIcon(
|
||||
key: const ValueKey('search.retry'),
|
||||
onPressed: onRetry,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('Retry'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.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),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
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) {
|
||||
'pipeline' => Icons.account_tree_outlined,
|
||||
'version' => Icons.layers_outlined,
|
||||
'run' => Icons.play_circle_outline,
|
||||
'step' => Icons.arrow_forward,
|
||||
'field' => Icons.notes,
|
||||
'artifact' => Icons.attach_file,
|
||||
_ => Icons.help_outline,
|
||||
};
|
||||
|
||||
IconData searchCupertinoIcon(String kind) => switch (kind) {
|
||||
'pipeline' => CupertinoIcons.arrow_branch,
|
||||
'version' => CupertinoIcons.square_stack_3d_up,
|
||||
'run' => CupertinoIcons.play_circle,
|
||||
'step' => CupertinoIcons.arrow_right,
|
||||
'field' => CupertinoIcons.doc_text,
|
||||
'artifact' => CupertinoIcons.paperclip,
|
||||
_ => CupertinoIcons.question_circle,
|
||||
};
|
||||
Reference in New Issue
Block a user