Files
pipelines/app/lib/features/search/ui/material_search_body.dart
T
alan ccc80a9a8d Add keyboard navigation to search results
Keep the search field focused while selecting results with Control or arrow keys, and open the selected result with Enter. Document the field-scoped shortcuts and cover navigation, reset, submission, and typing behavior with regression tests.
2026-11-13 15:51:00 +00:00

140 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../domain/search_controller.dart';
import 'search_result_slivers.dart';
import 'search_layout.dart';
/// 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,
required this.controller,
required this.query,
required this.onOpen,
required this.header,
required this.selectedIndex,
required this.rowKeys,
});
final OmniSearchController controller;
final String query;
final ValueChanged<JsonMap> onOpen;
final Widget header;
final int selectedIndex;
final Map<int, GlobalKey> rowKeys;
@override
Widget build(BuildContext context) {
return SearchScrollView(
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 searchResultSlivers(
controller: controller,
query: query,
onOpen: onOpen,
message: (text) => _SearchMessage(message: text),
selectedIndex: selectedIndex,
rowKeys: rowKeys,
);
case SearchBodyKind.empty:
return [
SliverToBoxAdapter(
child: _SearchMessage(message: controller.emptyMessage!),
),
];
case SearchBodyKind.idle:
return const [
SliverFillRemaining(
hasScrollBody: false,
child: _SearchMessage(
message: 'Search pipelines, runs, artifacts and chats.',
),
),
];
}
}
}
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'),
),
],
),
),
);
}