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,28 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../domain/search_models.dart';
|
||||
|
||||
/// Search protocol requests over the application's shared gateway.
|
||||
///
|
||||
/// The request body is exactly `SearchRequest{query, kind, limit}` with
|
||||
/// `limit: 0`, so the server applies its own default cap (`SearchDefaultLimit`,
|
||||
/// 50) instead of the client choosing a larger one.
|
||||
class SearchRepository {
|
||||
SearchRepository(this._gateway);
|
||||
|
||||
final ApiGateway _gateway;
|
||||
|
||||
/// Returns the bounded `search_results` body, or null when an older server
|
||||
/// answered without it (its default `pong`) so the caller can report the
|
||||
/// "cannot search" sentence rather than showing a false empty success.
|
||||
Future<SearchResponse?> search({
|
||||
required String query,
|
||||
required SearchKind kind,
|
||||
}) async {
|
||||
final reply = await _gateway.call('search', {
|
||||
'search': {'query': query, 'kind': kind.wire, 'limit': 0},
|
||||
});
|
||||
final results = reply['search_results'];
|
||||
if (results is! Map) return null;
|
||||
return SearchResponse.fromJson(Map<String, dynamic>.from(results));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../data/search_repository.dart';
|
||||
import 'search_models.dart';
|
||||
import 'search_query.dart';
|
||||
import 'search_row.dart';
|
||||
|
||||
/// The body the results area shows, in the browser's precedence order: an error
|
||||
/// takes precedence over retained results, a refresh keeps results on screen,
|
||||
/// and a first load shows the searching row.
|
||||
enum SearchBodyKind { idle, searching, results, empty, error }
|
||||
|
||||
/// Debounced, stale-safe omni-search state. It owns no widgets and no socket:
|
||||
/// the screen listens to it and the repository talks to the shared gateway.
|
||||
class OmniSearchController extends ChangeNotifier {
|
||||
OmniSearchController({
|
||||
required this.repository,
|
||||
this.debounce = const Duration(milliseconds: 250),
|
||||
});
|
||||
|
||||
final SearchRepository repository;
|
||||
final Duration debounce;
|
||||
final SearchSequencer _sequencer = SearchSequencer();
|
||||
|
||||
Timer? _timer;
|
||||
bool _disposed = false;
|
||||
|
||||
String _query = '';
|
||||
SearchKind _selectedKind = SearchKind.all;
|
||||
List<JsonMap> _results = const [];
|
||||
bool _loading = false;
|
||||
bool _loaded = false;
|
||||
bool _truncated = false;
|
||||
int _scannedSteps = 0;
|
||||
int _scannedBytes = 0;
|
||||
int _cap = 0;
|
||||
int _scanBoundBytes = 0;
|
||||
String? _error;
|
||||
|
||||
String get query => _query;
|
||||
SearchKind get selectedKind => _selectedKind;
|
||||
ParsedSearchQuery get parsed => parseSearchQuery(_query, _selectedKind);
|
||||
List<JsonMap> get results => _results;
|
||||
bool get loading => _loading;
|
||||
bool get loaded => _loaded;
|
||||
bool get truncated => _truncated;
|
||||
int get scannedSteps => _scannedSteps;
|
||||
int get scannedBytes => _scannedBytes;
|
||||
int get cap => _cap;
|
||||
int get scanBoundBytes => _scanBoundBytes;
|
||||
String? get error => _error;
|
||||
|
||||
/// The results already in hand, re-narrowed to the effective kind so the list
|
||||
/// always matches the control while a narrowed request loads.
|
||||
List<JsonMap> get shownResults {
|
||||
final kind = parsed.kind;
|
||||
if (kind == SearchKind.all) return _results;
|
||||
return _results
|
||||
.where((hit) => hit['kind'] == kind.wire)
|
||||
.toList(growable: false);
|
||||
}
|
||||
|
||||
SearchBodyKind get bodyKind {
|
||||
if (_error != null) return SearchBodyKind.error;
|
||||
if (shownResults.isNotEmpty) return SearchBodyKind.results;
|
||||
if (_loading && _results.isEmpty) return SearchBodyKind.searching;
|
||||
if (emptyMessage != null) return SearchBodyKind.empty;
|
||||
return SearchBodyKind.idle;
|
||||
}
|
||||
|
||||
/// A thin progress report above retained results while a newer query loads.
|
||||
bool get showProgress => _loading && _results.isNotEmpty;
|
||||
|
||||
String? get emptyMessage {
|
||||
if (_error != null || _loading || shownResults.isNotEmpty) return null;
|
||||
final effective = parsed;
|
||||
if (effective.query.trim().isEmpty) {
|
||||
if (!_loaded || effective.kind == SearchKind.all) return null;
|
||||
final label = effective.kind.label.toLowerCase();
|
||||
return _truncated
|
||||
? "No $label found within the server's scan limit."
|
||||
: 'No $label yet.';
|
||||
}
|
||||
final bounded = _truncated ? " within the server's scan limit" : '';
|
||||
if (effective.kind == SearchKind.all) {
|
||||
return 'No matches for "${effective.query}"$bounded.';
|
||||
}
|
||||
return 'No ${effective.kind.label.toLowerCase()} match '
|
||||
'"${effective.query}"$bounded.';
|
||||
}
|
||||
|
||||
/// The server's own result/scan bounds, so a capped answer is not presented as
|
||||
/// a complete one. A truncated reply keeps its warning even with no rows;
|
||||
/// before any loaded reply there is nothing to report.
|
||||
String? get boundsText {
|
||||
if (!_loaded) return null;
|
||||
// A new first load has no current result set yet, so do not carry the
|
||||
// previous reply's warning while the searching state is on screen.
|
||||
if (_loading && _results.isEmpty) return null;
|
||||
if (_results.isEmpty && !_truncated) return null;
|
||||
final count = _results.length;
|
||||
final parts = <String>[];
|
||||
if (_truncated) {
|
||||
parts.add("Results truncated by the server's result or scan limit.");
|
||||
}
|
||||
parts.add('$count ${count == 1 ? 'result' : 'results'}');
|
||||
if (_cap > 0) parts.add('cap $_cap');
|
||||
parts.add('scanned $_scannedSteps steps');
|
||||
parts.add('${humanBytes(_scannedBytes)} scanned');
|
||||
if (_scanBoundBytes > 0) {
|
||||
parts.add('scan limit ${humanBytes(_scanBoundBytes)}');
|
||||
}
|
||||
return parts.join(' · ');
|
||||
}
|
||||
|
||||
/// Record a keystroke. Blank text with no kind clears locally and sends
|
||||
/// nothing; valid kind-only browsing is sendable like the browser's search.
|
||||
void updateQuery(String value) {
|
||||
_query = value;
|
||||
_error = null;
|
||||
_cancelTimer();
|
||||
final effective = parsed;
|
||||
if (!searchQuerySendable(effective.query, effective.kind)) {
|
||||
_sequencer.edit('');
|
||||
_clearResults();
|
||||
_notify();
|
||||
return;
|
||||
}
|
||||
_loading = true;
|
||||
final edit = _sequencer.edit(value);
|
||||
_notify();
|
||||
_timer = Timer(debounce, () {
|
||||
_timer = null;
|
||||
final sent = _sequencer.begin(edit);
|
||||
if (sent != null) unawaited(_send(sent));
|
||||
});
|
||||
}
|
||||
|
||||
/// A kind change removes recognised type tokens from the visible text and
|
||||
/// sends at once, matching the browser's selector behaviour.
|
||||
void selectKind(SearchKind kind) {
|
||||
_query = parseSearchQuery(_query, _selectedKind).query;
|
||||
_selectedKind = kind;
|
||||
_error = null;
|
||||
_notify();
|
||||
unawaited(sendNow());
|
||||
}
|
||||
|
||||
/// Enter: send the current query immediately, skipping the debounce.
|
||||
Future<void> submit() => sendNow();
|
||||
|
||||
/// Retry the current query after a failure.
|
||||
Future<void> retry() => sendNow();
|
||||
|
||||
Future<void> sendNow() async {
|
||||
_cancelTimer();
|
||||
final effective = parseSearchQuery(_query, _selectedKind);
|
||||
if (!searchQuerySendable(effective.query, effective.kind)) {
|
||||
_sequencer.edit('');
|
||||
_clearResults();
|
||||
_notify();
|
||||
return;
|
||||
}
|
||||
final sent = _sequencer.begin(_sequencer.edit(_query));
|
||||
if (sent == null) return;
|
||||
await _send(sent);
|
||||
}
|
||||
|
||||
Future<void> _send(SearchEdit sent) async {
|
||||
final effective = parseSearchQuery(sent.query, _selectedKind);
|
||||
_loading = true;
|
||||
_error = null;
|
||||
_notify();
|
||||
try {
|
||||
final response = await repository.search(
|
||||
query: effective.query.trim(),
|
||||
kind: effective.kind,
|
||||
);
|
||||
if (!_sequencer.accepts(sent.token) || _disposed) return;
|
||||
if (response == null) {
|
||||
_loading = false;
|
||||
_loaded = true;
|
||||
_error = unsupportedSearchCopy;
|
||||
_notify();
|
||||
return;
|
||||
}
|
||||
_results = response.results;
|
||||
_truncated = response.truncated;
|
||||
_scannedSteps = response.scannedSteps;
|
||||
_scannedBytes = response.scannedBytes;
|
||||
_cap = response.cap;
|
||||
_scanBoundBytes = response.scanBoundBytes;
|
||||
_loading = false;
|
||||
_loaded = true;
|
||||
_error = null;
|
||||
_notify();
|
||||
} catch (error) {
|
||||
if (!_sequencer.accepts(sent.token) || _disposed) return;
|
||||
_loading = false;
|
||||
_loaded = true;
|
||||
_error = searchFailureText(error);
|
||||
_notify();
|
||||
}
|
||||
}
|
||||
|
||||
void _clearResults() {
|
||||
_results = const [];
|
||||
_truncated = false;
|
||||
_scannedSteps = 0;
|
||||
_scannedBytes = 0;
|
||||
_cap = 0;
|
||||
_scanBoundBytes = 0;
|
||||
_loading = false;
|
||||
_loaded = false;
|
||||
_error = null;
|
||||
}
|
||||
|
||||
void _cancelTimer() {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
}
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_cancelTimer();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/// Human bytes with the shared binary units (`2.0 KiB`), matching the browser.
|
||||
String humanBytes(int size) {
|
||||
const unit = 1024;
|
||||
if (size < unit) return '$size B';
|
||||
var divisor = unit;
|
||||
var exponent = 0;
|
||||
var scaled = size ~/ unit;
|
||||
while (scaled >= unit && exponent < 5) {
|
||||
divisor *= unit;
|
||||
exponent++;
|
||||
scaled ~/= unit;
|
||||
}
|
||||
return '${(size / divisor).toStringAsFixed(1)} ${'KMGTPE'[exponent]}iB';
|
||||
}
|
||||
|
||||
const _months = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec',
|
||||
];
|
||||
|
||||
/// An RFC3339 timestamp as the app's one human local rendering (`20 Oct 12:00`),
|
||||
/// or null when blank/unparseable so the caller omits the value rather than
|
||||
/// printing a blank.
|
||||
String? formatSearchTimestamp(String value) {
|
||||
final text = value.trim();
|
||||
if (text.isEmpty) return null;
|
||||
final instant = DateTime.tryParse(text);
|
||||
if (instant == null) return null;
|
||||
final local = instant.toLocal();
|
||||
final hour = local.hour.toString().padLeft(2, '0');
|
||||
final minute = local.minute.toString().padLeft(2, '0');
|
||||
return '${local.day} ${_months[local.month - 1]} $hour:$minute';
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
|
||||
/// The server's search narrowing vocabulary (`internal/protocol/search.go`),
|
||||
/// in the control's display order. The empty [wire] value means every kind.
|
||||
enum SearchKind {
|
||||
all('', 'All kinds'),
|
||||
pipeline('pipeline', 'Pipelines'),
|
||||
run('run', 'Runs'),
|
||||
step('step', 'Steps'),
|
||||
field('field', 'Fields'),
|
||||
artifact('artifact', 'Artifacts'),
|
||||
version('version', 'Versions');
|
||||
|
||||
const SearchKind(this.wire, this.label);
|
||||
|
||||
final String wire;
|
||||
final String label;
|
||||
|
||||
/// A stale or unknown value falls back to [SearchKind.all] rather than
|
||||
/// inventing an option the server does not accept.
|
||||
static SearchKind fromWire(String? wire) {
|
||||
for (final kind in values) {
|
||||
if (kind.wire == wire) return kind;
|
||||
}
|
||||
return SearchKind.all;
|
||||
}
|
||||
}
|
||||
|
||||
/// A query after `t:`/`type:` tokens have been recognised. [query] is the text
|
||||
/// the server should match; [kind] is the effective narrowing.
|
||||
class ParsedSearchQuery {
|
||||
const ParsedSearchQuery(this.query, this.kind, this.hasType);
|
||||
|
||||
final String query;
|
||||
final SearchKind kind;
|
||||
final bool hasType;
|
||||
}
|
||||
|
||||
/// The bounded `search_results` body from the server. Every bound the server
|
||||
/// reports is kept, so the screen can show a truncation/scan indicator instead
|
||||
/// of pretending a capped reply was complete.
|
||||
class SearchResponse {
|
||||
const SearchResponse({
|
||||
this.query = '',
|
||||
this.kind = SearchKind.all,
|
||||
this.results = const [],
|
||||
this.truncated = false,
|
||||
this.scannedSteps = 0,
|
||||
this.scannedBytes = 0,
|
||||
this.cap = 0,
|
||||
this.scanBoundBytes = 0,
|
||||
});
|
||||
|
||||
factory SearchResponse.fromJson(JsonMap json) {
|
||||
final rows = json['results'];
|
||||
return SearchResponse(
|
||||
query: '${json['query'] ?? ''}',
|
||||
kind: SearchKind.fromWire('${json['kind'] ?? ''}'),
|
||||
results: rows is List
|
||||
? rows
|
||||
.whereType<Map>()
|
||||
.map((row) => Map<String, dynamic>.from(row))
|
||||
.toList(growable: false)
|
||||
: const [],
|
||||
truncated: json['truncated'] == true,
|
||||
scannedSteps: _integer(json['scanned_steps']),
|
||||
scannedBytes: _integer(json['scanned_bytes']),
|
||||
cap: _integer(json['cap']),
|
||||
scanBoundBytes: _integer(json['scan_bound_bytes']),
|
||||
);
|
||||
}
|
||||
|
||||
final String query;
|
||||
final SearchKind kind;
|
||||
final List<JsonMap> results;
|
||||
final bool truncated;
|
||||
final int scannedSteps;
|
||||
final int scannedBytes;
|
||||
final int cap;
|
||||
final int scanBoundBytes;
|
||||
}
|
||||
|
||||
int _integer(Object? value) {
|
||||
if (value is int) return value;
|
||||
if (value is num) return value.toInt();
|
||||
return int.tryParse('$value') ?? 0;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'search_models.dart';
|
||||
|
||||
/// Wording for a server that cannot answer `search`: an explicit rejection
|
||||
/// naming an unknown/unsupported command, or a reply without
|
||||
/// `search_results`. Kept verbatim from the web client's AppViewModel copy.
|
||||
const unsupportedSearchCopy =
|
||||
'This server does not support search. Update the Pipelines server, then try again.';
|
||||
|
||||
/// Unquoted, whitespace-delimited `t:`/`type:` tokens; the last supported token
|
||||
/// wins. Unknown tokens and quoted text stay literal, including their whitespace.
|
||||
/// The selector is a fallback; explicitly changing it removes tokens in the view.
|
||||
///
|
||||
/// This is the same token grammar as `web/src/search.js`, so `"t:run"`,
|
||||
/// `t:unknown`, `prefix"t:run"` and `\t:run` all remain searchable text.
|
||||
ParsedSearchQuery parseSearchQuery(
|
||||
String value, [
|
||||
SearchKind selectedKind = SearchKind.all,
|
||||
]) {
|
||||
var kind = selectedKind;
|
||||
var hasType = false;
|
||||
final query = value.replaceAllMapped(_tokenPattern, (match) {
|
||||
final token = match[0] ?? '';
|
||||
final type = _typePattern.firstMatch(token);
|
||||
if (type == null) return token;
|
||||
final candidate = SearchKind.fromWire(type.group(1)!.toLowerCase());
|
||||
if (candidate == SearchKind.all) return token;
|
||||
kind = candidate;
|
||||
hasType = true;
|
||||
return '';
|
||||
});
|
||||
return ParsedSearchQuery(query, kind, hasType);
|
||||
}
|
||||
|
||||
final _tokenPattern = RegExp(
|
||||
r'''(?:[^\s"'\\]|\\[\s\S]|"(?:[^"\\]|\\[\s\S])*(?:"|$)|'(?:[^'\\]|\\[\s\S])*(?:'|$))+''',
|
||||
);
|
||||
final _typePattern = RegExp(r'^(?:t|type):([a-z]+)$', caseSensitive: false);
|
||||
|
||||
/// Text searches and valid kind-only browsing are sendable. Empty text with no
|
||||
/// supported kind clears locally, without an all-kind scan.
|
||||
bool searchQuerySendable(String query, SearchKind kind) =>
|
||||
query.trim().isNotEmpty || kind != SearchKind.all;
|
||||
|
||||
/// The message for a failed search: the unsupported sentence for a missing
|
||||
/// payload or an unknown-command rejection, otherwise the server's own text.
|
||||
String searchFailureText(Object? error) {
|
||||
if (error == null) return unsupportedSearchCopy;
|
||||
final message = error.toString().trim();
|
||||
if (message.isEmpty) return unsupportedSearchCopy;
|
||||
if (_unsupportedCommand.hasMatch(message)) return unsupportedSearchCopy;
|
||||
return message;
|
||||
}
|
||||
|
||||
final _unsupportedCommand = RegExp(
|
||||
r'\b(unknown|unsupported|unrecognised|unrecognized)\b[\s\S]*\bcommand\b',
|
||||
caseSensitive: false,
|
||||
);
|
||||
|
||||
/// One recorded edit being debounced.
|
||||
class SearchEdit {
|
||||
const SearchEdit(this.token, this.query);
|
||||
|
||||
final int token;
|
||||
final String query;
|
||||
}
|
||||
|
||||
/// Query sequencing: a burst of keystrokes collapses into one request, and a
|
||||
/// reply is accepted only for the newest recorded edit, so a stale reply can
|
||||
/// never overwrite a newer one. Recording an edit (a keystroke, or an empty
|
||||
/// edit when the field clears) is enough to invalidate an in-flight reply.
|
||||
class SearchSequencer {
|
||||
int _newest = 0;
|
||||
|
||||
SearchEdit edit(String query) => SearchEdit(++_newest, query);
|
||||
|
||||
SearchEdit? begin(SearchEdit? edit) {
|
||||
if (edit == null || edit.token != _newest) return null;
|
||||
return edit;
|
||||
}
|
||||
|
||||
bool accepts(int token) => token == _newest;
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'search_format.dart';
|
||||
|
||||
export 'search_format.dart' show humanBytes, formatSearchTimestamp;
|
||||
|
||||
/// One run of a field snippet, split so the first case-insensitive occurrence of
|
||||
/// the query can be emphasised without colour or markup.
|
||||
class SearchSnippetSpan {
|
||||
const SearchSnippetSpan(this.text, {required this.matched});
|
||||
|
||||
final String text;
|
||||
final bool matched;
|
||||
}
|
||||
|
||||
/// A render-ready search row. [target] is the server's own stable target token;
|
||||
/// it is null for an unknown/absent payload or a reply without a target, and
|
||||
/// such a row is read-only — the client never guesses a route.
|
||||
class SearchRowView {
|
||||
const SearchRowView({
|
||||
required this.title,
|
||||
required this.secondary,
|
||||
required this.kindLabel,
|
||||
required this.snippetSpans,
|
||||
required this.target,
|
||||
this.snippet,
|
||||
this.recency,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String secondary;
|
||||
final String kindLabel;
|
||||
final String? snippet;
|
||||
final List<SearchSnippetSpan> snippetSpans;
|
||||
final String? recency;
|
||||
final String? target;
|
||||
|
||||
bool get openable => target != null;
|
||||
}
|
||||
|
||||
/// One rendered search row, mirroring the browser's per-kind row text. Every
|
||||
/// server-provided string is only ever compared or rendered as text.
|
||||
SearchRowView searchRowView(JsonMap hit, String query) {
|
||||
final pipeline = _map(hit['pipeline']);
|
||||
final version = _map(hit['version']);
|
||||
final run = _map(hit['run']);
|
||||
final step = _map(hit['step']);
|
||||
final field = _map(hit['field']);
|
||||
final artifact = _map(hit['artifact']);
|
||||
|
||||
final recency = formatSearchTimestamp('${hit['recency'] ?? ''}');
|
||||
final target = _serverTarget(hit);
|
||||
|
||||
if (pipeline != null) {
|
||||
return SearchRowView(
|
||||
title: _nonBlank(pipeline['name']) ?? 'pipeline ${_num(pipeline['id'])}',
|
||||
secondary:
|
||||
'pipeline ${_num(pipeline['id'])} · v${_num(pipeline['version'])}'
|
||||
' · ${_stageCount(pipeline['stages'])}',
|
||||
kindLabel: 'Pipeline',
|
||||
snippetSpans: const [],
|
||||
recency: recency,
|
||||
target: target,
|
||||
);
|
||||
}
|
||||
if (version != null) {
|
||||
final hash = _nonBlank(version['content_hash']);
|
||||
return SearchRowView(
|
||||
title:
|
||||
'pipeline ${_num(version['pipeline_id'])}'
|
||||
' · v${_num(version['version'])}',
|
||||
secondary: _join([
|
||||
hash == null ? null : 'content $hash',
|
||||
formatSearchTimestamp('${version['created_at'] ?? ''}'),
|
||||
]),
|
||||
kindLabel: 'Pipeline version',
|
||||
snippetSpans: const [],
|
||||
recency: recency,
|
||||
target: target,
|
||||
);
|
||||
}
|
||||
if (run != null) {
|
||||
final name = _nonBlank(run['pipeline_name']);
|
||||
return SearchRowView(
|
||||
title: 'run #${_num(run['id'])}${name == null ? '' : ' · $name'}',
|
||||
secondary: _join([
|
||||
_nonBlank(run['status']),
|
||||
_nonBlank(run['workspace']),
|
||||
formatSearchTimestamp('${run['created_at'] ?? ''}'),
|
||||
]),
|
||||
kindLabel: 'Run',
|
||||
snippetSpans: const [],
|
||||
recency: recency,
|
||||
target: target,
|
||||
);
|
||||
}
|
||||
if (step != null) {
|
||||
final stage = _nonBlank(step['stage']) ?? 'step';
|
||||
return SearchRowView(
|
||||
title:
|
||||
'run #${_num(step['run_id'])} · $stage'
|
||||
' visit ${_num(step['visit'])}',
|
||||
secondary: _stepSecondary(step),
|
||||
kindLabel: 'Step',
|
||||
snippetSpans: const [],
|
||||
recency: recency,
|
||||
target: target,
|
||||
);
|
||||
}
|
||||
if (field != null) {
|
||||
final snippet = '${field['snippet'] ?? ''}';
|
||||
return SearchRowView(
|
||||
title:
|
||||
'run #${_num(field['run_id'])} · step ${_num(field['sequence'])}'
|
||||
' · ${_nonBlank(field['field']) ?? 'field'}',
|
||||
secondary: snippet,
|
||||
kindLabel: 'Field',
|
||||
snippet: snippet,
|
||||
snippetSpans: snippetSpans(snippet, query),
|
||||
recency: recency,
|
||||
target: target,
|
||||
);
|
||||
}
|
||||
if (artifact != null) {
|
||||
return SearchRowView(
|
||||
title: _nonBlank(artifact['name']) ?? 'artifact',
|
||||
secondary: _join([
|
||||
'run #${_num(artifact['run_id'])}',
|
||||
'step ${_num(artifact['sequence'])}',
|
||||
_nonBlank(artifact['content_type']),
|
||||
humanBytes(_num(artifact['size_bytes'])),
|
||||
]),
|
||||
kindLabel: 'Artifact',
|
||||
snippetSpans: const [],
|
||||
recency: recency,
|
||||
target: target,
|
||||
);
|
||||
}
|
||||
final kind = _nonBlank(hit['kind']);
|
||||
return SearchRowView(
|
||||
title: _nonBlank(hit['target']) ?? 'Unrecognised result',
|
||||
secondary: kind == null ? 'read-only' : 'kind "$kind" · read-only',
|
||||
kindLabel: 'Unrecognised result',
|
||||
snippetSpans: const [],
|
||||
recency: recency,
|
||||
target: target,
|
||||
);
|
||||
}
|
||||
|
||||
/// Splits [snippet] so the first case-insensitive occurrence of [query] is a
|
||||
/// distinct matched span. A blank query or absent match leaves the whole
|
||||
/// snippet unmatched, so no text is ever dropped.
|
||||
List<SearchSnippetSpan> snippetSpans(String snippet, String query) {
|
||||
if (snippet.isEmpty) return const [];
|
||||
final needle = query.trim();
|
||||
if (needle.isEmpty) {
|
||||
return [SearchSnippetSpan(snippet, matched: false)];
|
||||
}
|
||||
final index = snippet.toLowerCase().indexOf(needle.toLowerCase());
|
||||
if (index < 0) return [SearchSnippetSpan(snippet, matched: false)];
|
||||
final end = index + needle.length;
|
||||
return [
|
||||
if (index > 0)
|
||||
SearchSnippetSpan(snippet.substring(0, index), matched: false),
|
||||
SearchSnippetSpan(snippet.substring(index, end), matched: true),
|
||||
if (end < snippet.length)
|
||||
SearchSnippetSpan(snippet.substring(end), matched: false),
|
||||
];
|
||||
}
|
||||
|
||||
String _stepSecondary(JsonMap step) {
|
||||
final diagnostic = '${step['diagnostic'] ?? ''}';
|
||||
String? line;
|
||||
for (final candidate in diagnostic.split(RegExp(r'\r?\n'))) {
|
||||
if (candidate.trim().isNotEmpty) {
|
||||
line = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
final target = _nonBlank(step['target']);
|
||||
final joined = _join([
|
||||
_nonBlank(step['outcome']),
|
||||
target == null ? null : '→ $target',
|
||||
line?.trim(),
|
||||
]);
|
||||
return joined.isEmpty ? 'step ${_num(step['sequence'])}' : joined;
|
||||
}
|
||||
|
||||
/// The server's own target token, never a target the client invents. A known
|
||||
/// payload is not enough: an absent token makes the row read-only.
|
||||
String? _serverTarget(JsonMap hit) {
|
||||
final target = _nonBlank(hit['target']);
|
||||
if (target == null) return null;
|
||||
final known = [
|
||||
'pipeline',
|
||||
'version',
|
||||
'run',
|
||||
'step',
|
||||
'field',
|
||||
'artifact',
|
||||
].any((key) => _map(hit[key]) != null);
|
||||
return known ? target : null;
|
||||
}
|
||||
|
||||
String _stageCount(Object? count) {
|
||||
final n = _num(count);
|
||||
return '$n ${n == 1 ? 'stage' : 'stages'}';
|
||||
}
|
||||
|
||||
Map<String, dynamic>? _map(Object? value) {
|
||||
if (value is! Map) return null;
|
||||
return Map<String, dynamic>.from(value);
|
||||
}
|
||||
|
||||
String? _nonBlank(Object? value) {
|
||||
final text = '${value ?? ''}';
|
||||
return text.trim().isEmpty ? null : text;
|
||||
}
|
||||
|
||||
int _num(Object? value) {
|
||||
if (value is int) return value;
|
||||
if (value is num) return value.toInt();
|
||||
return int.tryParse('${value ?? ''}') ?? 0;
|
||||
}
|
||||
|
||||
String _join(List<String?> parts) =>
|
||||
parts.whereType<String>().where((part) => part.isNotEmpty).join(' · ');
|
||||
@@ -0,0 +1,228 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
import 'data/search_repository.dart';
|
||||
import 'domain/search_controller.dart';
|
||||
import 'domain/search_models.dart';
|
||||
import 'ui/cupertino_search_body.dart';
|
||||
import 'ui/material_search_body.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.
|
||||
class SearchScreen extends StatefulWidget {
|
||||
const SearchScreen({
|
||||
super.key,
|
||||
required this.gateway,
|
||||
required this.onOpen,
|
||||
this.cupertino,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
final ValueChanged<JsonMap> onOpen;
|
||||
|
||||
/// Lets the shell state the surface it composed. When omitted, iOS/macOS use
|
||||
/// Cupertino controls and every other platform uses Material.
|
||||
final bool? cupertino;
|
||||
|
||||
@override
|
||||
State<SearchScreen> createState() => _SearchScreenState();
|
||||
}
|
||||
|
||||
class _SearchScreenState extends State<SearchScreen> {
|
||||
late final OmniSearchController _controller;
|
||||
late final TextEditingController _text;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = OmniSearchController(
|
||||
repository: SearchRepository(widget.gateway),
|
||||
);
|
||||
_text = TextEditingController();
|
||||
_controller.addListener(_onState);
|
||||
}
|
||||
|
||||
void _onState() {
|
||||
final query = _controller.query;
|
||||
if (_text.text != query) {
|
||||
_text.value = TextEditingValue(
|
||||
text: query,
|
||||
selection: TextSelection.collapsed(offset: query.length),
|
||||
);
|
||||
}
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
void _clear() {
|
||||
_text.clear();
|
||||
_controller.updateQuery('');
|
||||
}
|
||||
|
||||
void _selectKind(SearchKind kind) => _controller.selectKind(kind);
|
||||
|
||||
bool get _showHint {
|
||||
final body = _controller.bodyKind;
|
||||
return body == SearchBodyKind.idle || body == SearchBodyKind.empty;
|
||||
}
|
||||
|
||||
Future<void> _pickKind(BuildContext context) async {
|
||||
final selected = await showCupertinoModalPopup<SearchKind>(
|
||||
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);
|
||||
_controller.dispose();
|
||||
_text.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
widget.cupertino ??
|
||||
switch (Theme.of(context).platform) {
|
||||
TargetPlatform.iOS || TargetPlatform.macOS => true,
|
||||
_ => false,
|
||||
};
|
||||
return cupertino ? _cupertinoScreen() : _materialScreen();
|
||||
}
|
||||
|
||||
Widget _materialScreen() => Scaffold(
|
||||
appBar: AppBar(title: const Text('Search')),
|
||||
body: SafeArea(
|
||||
child: MaterialSearchBody(
|
||||
controller: _controller,
|
||||
query: _controller.parsed.query,
|
||||
onOpen: widget.onOpen,
|
||||
header: _materialHeader(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
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<SearchKind>(
|
||||
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 _cupertinoScreen() => CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text('Search')),
|
||||
child: SafeArea(
|
||||
child: CupertinoSearchBody(
|
||||
controller: _controller,
|
||||
query: _controller.parsed.query,
|
||||
onOpen: widget.onOpen,
|
||||
header: _cupertinoHeader(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
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.';
|
||||
@@ -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