51140cd3b7
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.
88 lines
2.5 KiB
Dart
88 lines
2.5 KiB
Dart
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;
|
|
}
|