Files
pipelines/app/lib/features/search/ui/search_result_slivers.dart
T
alan 1b7da4106c Remove Cupertino search branches
Keep the Material-only search implementation while preserving public signatures and required icon fallback parameters.
2026-11-11 03:47:13 +00:00

72 lines
2.3 KiB
Dart

import 'package:flutter/widgets.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/layout/section_heading.dart';
import '../domain/search_controller.dart';
import '../domain/search_models.dart';
import 'search_bounds_note.dart';
import 'search_result_row.dart';
const searchChatsSectionKey = ValueKey<String>('search.section.chats');
const searchOthersSectionKey = ValueKey<String>('search.section.others');
const searchChatsNoteKey = ValueKey<String>('search.chats.note');
/// The results body shared by both hosts. With every kind searched, chat hits
/// lead as their own "Chats" group above the pipeline/run/artifact hits; with
/// Chats selected alone they are the list. A run search with no hits still
/// says so under the Chats group.
List<Widget> searchResultSlivers({
required OmniSearchController controller,
required String query,
required ValueChanged<JsonMap> onOpen,
required bool cupertino,
required Widget Function(String message) message,
}) {
final chats = controller.shownChats;
final others = controller.shownResults;
final grouped = controller.showsChatSection;
final note = controller.chatsNote;
Widget rows(List<JsonMap> hits) => SliverList.builder(
itemCount: hits.length,
itemBuilder: (context, index) => SearchResultRow(
hit: hits[index],
query: query,
onOpen: onOpen,
cupertino: false,
divider: index < hits.length - 1,
),
);
final empty = controller.emptyMessage;
return [
if (grouped)
SliverToBoxAdapter(
child: SectionHeading(
key: searchChatsSectionKey,
title: chats.isEmpty ? 'Chats' : 'Chats (${chats.length})',
header: true,
),
),
if (chats.isNotEmpty) rows(chats),
if (note != null)
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: SearchBoundsNote(key: searchChatsNoteKey, text: note),
),
),
if (grouped && others.isNotEmpty)
const SliverToBoxAdapter(
child: SectionHeading(
key: searchOthersSectionKey,
title: 'Pipelines and runs',
header: true,
),
),
if (others.isNotEmpty) rows(others),
if (others.isEmpty &&
controller.parsed.kind != SearchKind.chat &&
empty != null)
SliverToBoxAdapter(child: message(empty)),
];
}