Files
pipelines/app/lib/features/search/ui/search_result_view.dart
T
alan 3704d98d4d Search field in the bar, refresh and Back as bar pieces, even Cupertino actions (F8/F28/F10/F11/F20/F1)
- Search: field, compact Kind menu and syntax help in the bar's actions pill;
  bounds shown only when truncated; rows with bold title, kind tag and one
  muted line; results run behind the bar in a start-aligned 840 column.
- AppSearchField: one search field per platform (Search, Schedules, Runs filter).
- BarIconButton: whole 44pt/48dp bar actions; Runs, bell and Pipelines icons
  use the same 44pt targets on Cupertino.
- Templates and Schedules pages put Refresh in the bar and use the shared
  round SegmentedBackButton; Templates shows one Back at a time.
- PipelineBackButton is the round segmented Back.
- notes/pages-fixes.md records the batch, tests and evidence.
2026-10-31 03:31:25 +00:00

258 lines
8.3 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../core/transport/pipelines_client.dart'
show configuredGatewayEndpoint;
import '../../../ui/adaptive/host.dart';
import '../../artifacts/domain/artifact_kind.dart';
import '../../artifacts/domain/artifact_record.dart';
import '../../artifacts/ui/artifact_tile.dart';
import '../../artifacts/ui/artifact_viewer_fetch.dart';
import '../domain/search_row.dart';
/// A row's title line: the bold title and, at its trailing edge, a small tag
/// naming the kind.
Widget searchRowTitle(BuildContext context, SearchRowView row) => Row(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 8,
children: [
Expanded(
child: Text(
row.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
SearchKindTag(label: row.kindLabel),
],
);
/// A row's one muted line: recency, then the snippet (its first query
/// occurrence emphasised by weight, never by parsing server text as markup)
/// or, without one, the kind's own facts.
Widget searchRowLine(BuildContext context, SearchRowView row) {
final snippet = row.snippet;
final lead = row.recency == null ? '' : '${row.recency} · ';
final spans = <InlineSpan>[
if (snippet == null)
TextSpan(text: '$lead${row.secondary}')
else ...[
if (lead.isNotEmpty) TextSpan(text: lead),
for (final span in row.snippetSpans)
TextSpan(
text: span.text,
style: span.matched
? const TextStyle(fontWeight: FontWeight.bold)
: null,
),
],
];
return Text.rich(
TextSpan(children: spans),
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: _muted(context)),
);
}
Color _muted(BuildContext context) => usesCupertinoHost(context)
? CupertinoColors.secondaryLabel.resolveFrom(context)
: Theme.of(context).colorScheme.onSurfaceVariant;
/// The result's kind as a small tinted capsule.
class SearchKindTag extends StatelessWidget {
const SearchKindTag({super.key, required this.label});
final String label;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final Color fill;
final TextStyle? style;
if (cupertino) {
fill = CupertinoColors.tertiarySystemFill.resolveFrom(context);
style = CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
);
} else {
final theme = Theme.of(context);
fill = theme.colorScheme.surfaceContainerHighest;
style = theme.textTheme.labelSmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
);
}
return DecoratedBox(
decoration: ShapeDecoration(color: fill, shape: const StadiumBorder()),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
child: Text(label, style: style),
),
);
}
}
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,
};
/// What artifact hits need from the screen: the app's gateway (to resolve a
/// thumbnail and look up a run's pipeline) and the screen's opener.
class SearchArtifactScope extends InheritedWidget {
const SearchArtifactScope({
super.key,
required this.gateway,
required this.onOpen,
required super.child,
});
final ApiGateway gateway;
final ValueChanged<JsonMap> onOpen;
static SearchArtifactScope? maybeOf(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<SearchArtifactScope>();
@override
bool updateShouldNotify(SearchArtifactScope oldWidget) =>
gateway != oldWidget.gateway || onOpen != oldWidget.onOpen;
}
JsonMap? _artifactOf(JsonMap hit) =>
hit['kind'] == 'artifact' && hit['artifact'] is Map
? Map<String, dynamic>.from(hit['artifact'] as Map)
: null;
/// An artifact hit's leading picture: the image itself when it is one,
/// otherwise null so the row keeps its kind icon.
Widget? searchArtifactThumbnail(BuildContext context, JsonMap hit) {
final artifact = _artifactOf(hit);
final scope = SearchArtifactScope.maybeOf(context);
if (artifact == null || scope == null) return null;
final record = ArtifactRecord.fromJson(artifact);
if (artifactPreviewFormat(record.contentType, record.name) !=
ArtifactPreviewFormat.image) {
return null;
}
return ClipRRect(
borderRadius: BorderRadius.circular(6),
child: SizedBox.square(
dimension: 44,
child: ArtifactThumbnail(
key: ValueKey('search.thumbnail.${hit['target']}'),
artifact: record,
configuredEndpoint: configuredGatewayEndpoint(scope.gateway),
fetch: fetchArtifact,
),
),
);
}
enum _ArtifactOpen { stage, run, pipeline }
/// An artifact hit's choices: open the stage that recorded it, its run, or
/// the run's pipeline.
Widget? searchArtifactActions(BuildContext context, JsonMap hit) {
final artifact = _artifactOf(hit);
final scope = SearchArtifactScope.maybeOf(context);
final runId = artifact?['run_id'];
if (artifact == null || scope == null || runId is! num) return null;
Future<void> pick(_ArtifactOpen choice) async {
switch (choice) {
case _ArtifactOpen.stage:
scope.onOpen(hit);
case _ArtifactOpen.run:
scope.onOpen({
'kind': 'run',
'target': 'run:${runId.toInt()}',
'run': {'id': runId.toInt()},
});
case _ArtifactOpen.pipeline:
// The hit names only the run; its pinned pipeline comes from the run.
final reply = await scope.gateway.call('get_run', {
'run_id': runId.toInt(),
});
final run = reply['run_detail'];
if (run is! Map) return;
final id = run['pipeline_id'];
final version = run['version'];
if (id is! num || id <= 0) return;
scope.onOpen(
version is num && version > 0
? {
'kind': 'version',
'target': 'pipeline:${id.toInt()}:v${version.toInt()}',
'version': {
'pipeline_id': id.toInt(),
'version': version.toInt(),
},
}
: {
'kind': 'pipeline',
'target': 'pipeline:${id.toInt()}',
'pipeline': {'id': id.toInt()},
},
);
}
}
const labels = {
_ArtifactOpen.stage: 'Open stage',
_ArtifactOpen.run: 'Open run',
_ArtifactOpen.pipeline: 'Open pipeline',
};
final key = ValueKey('search.actions.${hit['target']}');
if (usesCupertinoHost(context)) {
return CupertinoButton(
key: key,
padding: EdgeInsets.zero,
onPressed: () async {
final choice = await showCupertinoModalPopup<_ArtifactOpen>(
context: context,
builder: (sheet) => CupertinoActionSheet(
actions: [
for (final entry in labels.entries)
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(sheet, entry.key),
child: Text(entry.value),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(sheet),
child: const Text('Cancel'),
),
),
);
if (choice != null) await pick(choice);
},
child: const Icon(CupertinoIcons.ellipsis_circle),
);
}
return PopupMenuButton<_ArtifactOpen>(
key: key,
tooltip: 'Open…',
onSelected: pick,
itemBuilder: (_) => [
for (final entry in labels.entries)
PopupMenuItem(value: entry.key, child: Text(entry.value)),
],
);
}