Open Search artifact hits in the viewer over the run's Artifacts tab
On a phone-width window the open run is its own page pushed on the app navigator, so RunDetailTabs was not a descendant of the shell's RunSearchSelectionScope (which wraps only the Runs tab body). The field or artifact selection was never seen and the run opened at its plain Summary. The previous widget tests injected the scope directly above RunDetailView at 900 px, where the detail is an inline pane, so they could not catch it. - RunsScreen relays the shell's search scope into the detail it builds, so the pushed page sees the selection too (also fixes field hits on phones). - An artifact hit now opens the run's Artifacts tab and the gallery opens that artifact exactly as a tap there does: selected, scrolled into view (ArtifactVisitReveal) and in the viewer. Back returns to the tab with the artifact highlighted. An unknown URL leaves the tab open with the existing "That artifact is no longer available." notice. - New test/application/search_artifact_open_test.dart drives the real Search tab -> typed query -> result tap -> run read -> viewer on a 390x844 phone, Material and Cupertino; it fails without the scope relay.
This commit is contained in:
@@ -56,6 +56,8 @@ class ArtifactGalleryPage extends StatefulWidget {
|
||||
this.fileBridge = const ArtifactFileBridge(),
|
||||
this.embedded = false,
|
||||
this.initiallyCollapsed = false,
|
||||
this.openArtifactUrl,
|
||||
this.onOpenArtifactHandled,
|
||||
});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
@@ -78,6 +80,12 @@ class ArtifactGalleryPage extends StatefulWidget {
|
||||
/// preserve their established open layout.
|
||||
final bool initiallyCollapsed;
|
||||
|
||||
/// A recorded artifact URL to open as if tapped here (a search hit): it is
|
||||
/// selected, scrolled into view and opened in the viewer. The page reports
|
||||
/// [onOpenArtifactHandled] with whether its groups record that URL.
|
||||
final String? openArtifactUrl;
|
||||
final ValueChanged<bool>? onOpenArtifactHandled;
|
||||
|
||||
@override
|
||||
State<ArtifactGalleryPage> createState() => _ArtifactGalleryPageState();
|
||||
}
|
||||
@@ -91,6 +99,56 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
String? _status;
|
||||
bool _showTurnDocuments = false;
|
||||
|
||||
/// The requested artifact the list is scrolling to before it opens.
|
||||
({ArtifactGroup group, ArtifactRecord artifact})? _opening;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_requestOpen(widget.openArtifactUrl);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ArtifactGalleryPage oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.openArtifactUrl != oldWidget.openArtifactUrl) {
|
||||
_requestOpen(widget.openArtifactUrl);
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds [url] among every recorded group, turn documents included, and
|
||||
/// lets the list reveal it; [_revealed] then opens it.
|
||||
void _requestOpen(String? url) {
|
||||
if (url == null) return;
|
||||
for (final group in _groups) {
|
||||
for (final document in group.documents) {
|
||||
final record = document.record;
|
||||
if (record == null || record.url != url) continue;
|
||||
// A turn document is listed only while the debug toggle shows them.
|
||||
_showTurnDocuments = true;
|
||||
_opening = (group: group, artifact: record);
|
||||
}
|
||||
for (final artifact in group.artifacts) {
|
||||
if (artifact.url == url) _opening = (group: group, artifact: artifact);
|
||||
}
|
||||
final opening = _opening;
|
||||
if (opening != null) {
|
||||
_selectedIdentity = artifactVisitIdentity(group, opening.artifact);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final handled = widget.onOpenArtifactHandled;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => handled?.call(false));
|
||||
}
|
||||
|
||||
void _revealed() {
|
||||
final opening = _opening;
|
||||
if (!mounted || opening == null) return;
|
||||
setState(() => _opening = null);
|
||||
widget.onOpenArtifactHandled?.call(true);
|
||||
_select(opening.group, opening.artifact);
|
||||
}
|
||||
|
||||
List<ArtifactGroup> _groupsOf(int? focusIndex) {
|
||||
final allGroups = _withRepairDocuments(galleryGroups(widget.steps));
|
||||
if (focusIndex == null) return allGroups;
|
||||
@@ -555,6 +613,8 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
fetch: widget.fetch,
|
||||
initiallyCollapsed: widget.initiallyCollapsed,
|
||||
showTurnDocuments: _showTurnDocuments,
|
||||
revealIdentity: _opening == null ? null : _selectedIdentity,
|
||||
onRevealed: _revealed,
|
||||
);
|
||||
if (widget.embedded) return body;
|
||||
if (usesCupertinoHost(context)) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'artifact_record_row.dart';
|
||||
import 'artifact_tile.dart';
|
||||
import 'artifact_viewer_fetch.dart';
|
||||
import 'artifact_row_labels.dart';
|
||||
import 'artifact_visit_reveal.dart';
|
||||
import '../../../ui/adaptive/floating_bar_layout.dart';
|
||||
|
||||
export 'artifact_row_labels.dart'
|
||||
@@ -47,6 +48,8 @@ class ArtifactVisitList extends StatefulWidget {
|
||||
this.fetch = fetchArtifact,
|
||||
this.initiallyCollapsed = true,
|
||||
this.showTurnDocuments = false,
|
||||
this.revealIdentity,
|
||||
this.onRevealed,
|
||||
});
|
||||
|
||||
final Widget? header;
|
||||
@@ -67,6 +70,12 @@ class ArtifactVisitList extends StatefulWidget {
|
||||
/// Whether debugging documents are visible below their visit's artifacts.
|
||||
final bool showTurnDocuments;
|
||||
|
||||
/// An artifact to open its section for and scroll into view, by
|
||||
/// [artifactVisitIdentity]; [onRevealed] follows once it is (or once the
|
||||
/// list has no further to scroll).
|
||||
final String? revealIdentity;
|
||||
final VoidCallback? onRevealed;
|
||||
|
||||
/// The layout last chosen, kept for the app's lifetime.
|
||||
static ArtifactGalleryMode lastMode = ArtifactGalleryMode.grid;
|
||||
|
||||
@@ -81,6 +90,8 @@ class _ArtifactVisitListState extends State<ArtifactVisitList> {
|
||||
/// so a run with many visits does not open every file list at once.
|
||||
late final Set<String> _closed;
|
||||
|
||||
final ArtifactVisitReveal _reveal = ArtifactVisitReveal();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -90,11 +101,42 @@ class _ArtifactVisitListState extends State<ArtifactVisitList> {
|
||||
if (group.artifacts.isNotEmpty)
|
||||
'${group.stageKey}\u0000${group.visit}\u0000artifacts',
|
||||
};
|
||||
_startReveal();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_reveal.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Opens the requested artifact's section and scrolls the artifact into view.
|
||||
void _startReveal() {
|
||||
final identity = widget.revealIdentity;
|
||||
if (identity == null) return;
|
||||
for (final group in widget.groups) {
|
||||
final records = [
|
||||
...group.artifacts,
|
||||
for (final document in group.documents) ?document.record,
|
||||
];
|
||||
if (records.any((r) => artifactVisitIdentity(group, r) == identity)) {
|
||||
_closed.remove('${group.stageKey}\u0000${group.visit}\u0000artifacts');
|
||||
}
|
||||
}
|
||||
_reveal.reveal(() => widget.onRevealed?.call());
|
||||
}
|
||||
|
||||
/// [child] carries the reveal target when it shows the requested artifact.
|
||||
Widget _revealable(bool requested, Widget child) =>
|
||||
requested ? KeyedSubtree(key: _reveal.target, child: child) : child;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ArtifactVisitList oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.revealIdentity != oldWidget.revealIdentity) {
|
||||
_reveal.cancel();
|
||||
_startReveal();
|
||||
}
|
||||
// Embedded galleries begin with their visits collapsed. Debug must reveal
|
||||
// the documents immediately rather than require a second tap on the visit
|
||||
// heading.
|
||||
@@ -129,6 +171,7 @@ class _ArtifactVisitListState extends State<ArtifactVisitList> {
|
||||
// On the page colour (that of the pinned section headings), not a
|
||||
// grouped band.
|
||||
child: ColoredBox(
|
||||
key: _reveal.anchor,
|
||||
color: SectionHeadingStyle.of(context).background,
|
||||
child: _modeSwitch(context),
|
||||
),
|
||||
@@ -155,13 +198,21 @@ class _ArtifactVisitListState extends State<ArtifactVisitList> {
|
||||
: _list(group),
|
||||
if (widget.showTurnDocuments && group.documents.isNotEmpty)
|
||||
SliverToBoxAdapter(
|
||||
child: _inkSurface(
|
||||
context,
|
||||
ArtifactDocumentSection(
|
||||
group: group,
|
||||
selectedIdentity: widget.selectedIdentity,
|
||||
onSelected: widget.onSelected,
|
||||
showHeader: false,
|
||||
child: _revealable(
|
||||
group.documents.any(
|
||||
(document) =>
|
||||
document.record != null &&
|
||||
artifactVisitIdentity(group, document.record!) ==
|
||||
widget.revealIdentity,
|
||||
),
|
||||
_inkSurface(
|
||||
context,
|
||||
ArtifactDocumentSection(
|
||||
group: group,
|
||||
selectedIdentity: widget.selectedIdentity,
|
||||
onSelected: widget.onSelected,
|
||||
showHeader: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -262,22 +313,25 @@ class _ArtifactVisitListState extends State<ArtifactVisitList> {
|
||||
itemBuilder: (context, index) {
|
||||
final artifact = group.artifacts[index];
|
||||
final identity = artifactVisitIdentity(group, artifact);
|
||||
return _inkSurface(
|
||||
context,
|
||||
ArtifactRecordRow(
|
||||
key: ValueKey<String>('$identity\u0000$index'),
|
||||
group: group,
|
||||
artifact: artifact,
|
||||
selected: widget.selectedIdentity == identity,
|
||||
onSelected: widget.onSelected,
|
||||
leading: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: SizedBox.square(
|
||||
dimension: 44,
|
||||
child: ArtifactThumbnail(
|
||||
artifact: artifact,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
fetch: widget.fetch,
|
||||
return _revealable(
|
||||
widget.revealIdentity == identity,
|
||||
_inkSurface(
|
||||
context,
|
||||
ArtifactRecordRow(
|
||||
key: ValueKey<String>('$identity\u0000$index'),
|
||||
group: group,
|
||||
artifact: artifact,
|
||||
selected: widget.selectedIdentity == identity,
|
||||
onSelected: widget.onSelected,
|
||||
leading: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: SizedBox.square(
|
||||
dimension: 44,
|
||||
child: ArtifactThumbnail(
|
||||
artifact: artifact,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
fetch: widget.fetch,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -312,19 +366,23 @@ class _ArtifactVisitListState extends State<ArtifactVisitList> {
|
||||
if (index > first) const SizedBox(width: gap),
|
||||
SizedBox(
|
||||
width: tile,
|
||||
child: ArtifactTile(
|
||||
key: ValueKey<String>(
|
||||
'${artifactVisitIdentity(group, artifacts[index])}'
|
||||
'\u0000$index',
|
||||
),
|
||||
group: group,
|
||||
artifact: artifacts[index],
|
||||
selected:
|
||||
widget.selectedIdentity ==
|
||||
child: _revealable(
|
||||
widget.revealIdentity ==
|
||||
artifactVisitIdentity(group, artifacts[index]),
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
fetch: widget.fetch,
|
||||
onSelected: widget.onSelected,
|
||||
ArtifactTile(
|
||||
key: ValueKey<String>(
|
||||
'${artifactVisitIdentity(group, artifacts[index])}'
|
||||
'\u0000$index',
|
||||
),
|
||||
group: group,
|
||||
artifact: artifacts[index],
|
||||
selected:
|
||||
widget.selectedIdentity ==
|
||||
artifactVisitIdentity(group, artifacts[index]),
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
fetch: widget.fetch,
|
||||
onSelected: widget.onSelected,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Scrolls one artifact of a lazy gallery into view.
|
||||
///
|
||||
/// The gallery builds only the rows on screen, so a requested artifact far
|
||||
/// down a run may not exist yet. [reveal] scrolls by most of a viewport each
|
||||
/// frame until the row keyed by [target] is built, then centres it. It stops
|
||||
/// at the end of the list either way and always reports [onDone] exactly once.
|
||||
class ArtifactVisitReveal {
|
||||
/// Wraps the requested row so its position can be found once it is built.
|
||||
final GlobalKey target = GlobalKey(debugLabel: 'artifact-reveal-target');
|
||||
|
||||
/// Any widget that is always built inside the gallery's scroll view.
|
||||
final GlobalKey anchor = GlobalKey(debugLabel: 'artifact-reveal-anchor');
|
||||
|
||||
int _generation = 0;
|
||||
|
||||
/// Abandons a reveal in progress (a new request, or the list going away).
|
||||
void cancel() => _generation++;
|
||||
|
||||
void reveal(VoidCallback onDone) {
|
||||
final generation = ++_generation;
|
||||
// Generous for any recorded run, yet bounded so a row that never builds
|
||||
// cannot keep scheduling frames.
|
||||
var remaining = 200;
|
||||
void step() {
|
||||
if (generation != _generation) return;
|
||||
final row = target.currentContext;
|
||||
if (row != null && row.mounted) {
|
||||
Scrollable.ensureVisible(row, alignment: 0.5);
|
||||
onDone();
|
||||
return;
|
||||
}
|
||||
final anchorContext = anchor.currentContext;
|
||||
final position = anchorContext == null
|
||||
? null
|
||||
: Scrollable.maybeOf(anchorContext)?.position;
|
||||
if (position == null ||
|
||||
!position.hasContentDimensions ||
|
||||
position.pixels >= position.maxScrollExtent ||
|
||||
--remaining <= 0) {
|
||||
onDone();
|
||||
return;
|
||||
}
|
||||
position.jumpTo(
|
||||
(position.pixels + position.viewportDimension * 0.8).clamp(
|
||||
position.minScrollExtent,
|
||||
position.maxScrollExtent,
|
||||
),
|
||||
);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => step());
|
||||
WidgetsBinding.instance.scheduleFrame();
|
||||
}
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => step());
|
||||
WidgetsBinding.instance.scheduleFrame();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import 'data/runs_sort_store.dart';
|
||||
import 'domain/run_decisions.dart';
|
||||
import 'ui/run_pipeline_link.dart';
|
||||
import 'ui/run_detail_view.dart';
|
||||
import 'ui/run_search_selection.dart';
|
||||
import 'ui/runs_controller.dart';
|
||||
import 'ui/runs_list.dart';
|
||||
|
||||
@@ -248,18 +249,37 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _detail(VoidCallback onBack) => RunDetailView(
|
||||
controller: controller,
|
||||
gateway: widget.gateway,
|
||||
onBack: onBack,
|
||||
onRunOpened: _select,
|
||||
onOpenPipeline: widget.onOpenPipeline,
|
||||
initialStageKey: widget.initialStageKey,
|
||||
initialVisit: widget.initialVisit,
|
||||
);
|
||||
/// The shell's pending search selection, read in [build] so this screen
|
||||
/// rebuilds (and refreshes an open detail page) whenever it changes.
|
||||
RunSearchSelectionScope? _searchScope;
|
||||
|
||||
/// The run detail, under the shell's search selection.
|
||||
///
|
||||
/// On a narrow window the detail is its own page on the app's navigator, so
|
||||
/// it is not a descendant of the shell's [RunSearchSelectionScope]; relaying
|
||||
/// the scope keeps a field or artifact hit's selection reachable there too.
|
||||
Widget _detail(VoidCallback onBack) {
|
||||
final view = RunDetailView(
|
||||
controller: controller,
|
||||
gateway: widget.gateway,
|
||||
onBack: onBack,
|
||||
onRunOpened: _select,
|
||||
onOpenPipeline: widget.onOpenPipeline,
|
||||
initialStageKey: widget.initialStageKey,
|
||||
initialVisit: widget.initialVisit,
|
||||
);
|
||||
final scope = _searchScope;
|
||||
if (scope == null) return view;
|
||||
return RunSearchSelectionScope(
|
||||
selection: scope.selection,
|
||||
onConsumed: scope.onConsumed,
|
||||
child: view,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_searchScope = RunSearchSelectionScope.maybeOf(context);
|
||||
final selected = controller.selectedRunId != null;
|
||||
// The same adaptive list/detail layout as Pipelines and Chat.
|
||||
final narrow = !showsListBesideDetail(context);
|
||||
|
||||
@@ -13,10 +13,6 @@ import '../../../core/api_gateway.dart';
|
||||
import '../../graph/widgets/run_graph_view.dart';
|
||||
import '../../artifacts/ui/artifact_gallery_action.dart';
|
||||
import '../../artifacts/ui/artifact_gallery_page.dart';
|
||||
import '../../artifacts/domain/artifact_groups.dart';
|
||||
import '../../artifacts/domain/artifact_record.dart';
|
||||
import '../../artifacts/domain/gallery_navigation.dart';
|
||||
import '../../artifacts/ui/artifact_viewer_page.dart';
|
||||
import '../../changes/changes.dart';
|
||||
import 'run_changes_action.dart';
|
||||
import 'run_detail_content.dart';
|
||||
@@ -116,9 +112,8 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
/// request never reopens a pane the operator closed in the meantime.
|
||||
RunSearchSelection? _appliedSearchSelection;
|
||||
|
||||
/// Search artifacts open above their visit, so the normal visit-page sync
|
||||
/// must wait for the search callback to install both routes.
|
||||
bool _searchArtifactVisitPending = false;
|
||||
/// The artifact a search hit asked the Artifacts tab to open, until it has.
|
||||
String? _searchArtifactUrl;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -249,62 +244,30 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
_selectedStage = stageKey;
|
||||
_selectedVisit = timelineIndex;
|
||||
_tab = RunDetailTab.timeline;
|
||||
case RunArtifactTarget(:final visit, :final url):
|
||||
if (detailVisitStepAt(widget.run, visit.timelineIndex) == null) return;
|
||||
// The viewer is opened above the visit. Prevent build() from opening
|
||||
// that visit first in its own callback; the search callback installs
|
||||
// the visit route and then the viewer route in that order.
|
||||
_selectedStage = visit.stageKey;
|
||||
_selectedVisit = visit.timelineIndex;
|
||||
_tab = RunDetailTab.timeline;
|
||||
_searchArtifactVisitPending = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => mounted ? _openSearchArtifact(url, visit.timelineIndex) : null,
|
||||
);
|
||||
case RunArtifactTarget(:final url):
|
||||
_selectedStage = null;
|
||||
_selectedVisit = null;
|
||||
if (!_tabsFor(widget.run).contains(RunDetailTab.artifacts)) {
|
||||
// A run with no recorded steps has no gallery to open it in.
|
||||
_tab = RunDetailTab.summary;
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => mounted ? _showSearchArtifactMissingNotice() : null,
|
||||
);
|
||||
return;
|
||||
}
|
||||
// The gallery opens it as if tapped there: highlighted, scrolled into
|
||||
// view and in the viewer, so Back returns to the Artifacts tab.
|
||||
_tab = RunDetailTab.artifacts;
|
||||
_searchArtifactUrl = url;
|
||||
}
|
||||
}
|
||||
|
||||
void _openSearchArtifact(String url, int visitIndex) {
|
||||
// _pushVisit reaches Navigator.push before its first await. Install the
|
||||
// visit first so it remains the run-detail destination on Back, including
|
||||
// when the recorded artifact has disappeared.
|
||||
unawaited(_pushVisit(visitIndex));
|
||||
// The visit page is now the shown one (_pushVisit records it before its
|
||||
// first await), so later visit selections sync normally again.
|
||||
_searchArtifactVisitPending = false;
|
||||
final steps = detailRunSteps(widget.run);
|
||||
final groups = galleryGroups(steps);
|
||||
ArtifactGroup? selectedGroup;
|
||||
ArtifactRecord? selectedArtifact;
|
||||
for (final group in groups) {
|
||||
for (final artifact in [
|
||||
...group.artifacts,
|
||||
...group.documents.map((document) => document.record),
|
||||
]) {
|
||||
if (artifact == null || artifact.url != url) continue;
|
||||
selectedGroup = group;
|
||||
selectedArtifact = artifact;
|
||||
break;
|
||||
}
|
||||
if (selectedArtifact != null) break;
|
||||
}
|
||||
if (selectedGroup == null || selectedArtifact == null) {
|
||||
_showSearchArtifactMissingNotice();
|
||||
return;
|
||||
}
|
||||
final group = selectedGroup;
|
||||
final artifact = selectedArtifact;
|
||||
final page = ArtifactViewerPage(
|
||||
groups: groups,
|
||||
selectedIdentity: artifactVisitIdentityOf(group, artifact),
|
||||
includeExternalDocuments: true,
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
);
|
||||
Navigator.of(context).push<void>(
|
||||
widget.cupertino
|
||||
? CupertinoPageRoute<void>(builder: (_) => page)
|
||||
: MaterialPageRoute<void>(builder: (_) => page),
|
||||
);
|
||||
/// The Artifacts tab handled the search request: it opened the artifact, or
|
||||
/// found no recorded file with that URL.
|
||||
void _searchArtifactHandled(bool found) {
|
||||
if (!mounted) return;
|
||||
setState(() => _searchArtifactUrl = null);
|
||||
if (!found) _showSearchArtifactMissingNotice();
|
||||
}
|
||||
|
||||
void _showSearchArtifactMissingNotice() {
|
||||
@@ -439,7 +402,7 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// A selected visit opens on its own page; the tab keeps the list.
|
||||
if (_selectedVisit != _shownVisit && !_searchArtifactVisitPending) {
|
||||
if (_selectedVisit != _shownVisit) {
|
||||
_syncVisitPage();
|
||||
}
|
||||
final tabs = _tabsFor(widget.run);
|
||||
@@ -558,6 +521,8 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
executing: runDetailExecuting(widget.run),
|
||||
configuredEndpoint: widget.configuredEndpoint,
|
||||
embedded: true,
|
||||
openArtifactUrl: _searchArtifactUrl,
|
||||
onOpenArtifactHandled: _searchArtifactHandled,
|
||||
);
|
||||
case RunDetailTab.changes:
|
||||
final viewer = ChangesViewer(
|
||||
|
||||
@@ -66,12 +66,12 @@ final class RunVisitTarget extends RunSearchTarget {
|
||||
final int timelineIndex;
|
||||
}
|
||||
|
||||
/// A recorded artifact hit selects its visit first, then opens the artifact
|
||||
/// viewer on the exact recorded file.
|
||||
/// A recorded artifact hit opens the run's Artifacts tab and that tab opens
|
||||
/// the exact recorded file, exactly as tapping it in the gallery does.
|
||||
final class RunArtifactTarget extends RunSearchTarget {
|
||||
const RunArtifactTarget({required this.visit, required this.url});
|
||||
const RunArtifactTarget({required this.url});
|
||||
|
||||
final RunVisitTarget visit;
|
||||
/// The recorded artifact URL, matched against the gallery's own records.
|
||||
final String url;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,8 @@ final class RunArtifactTarget extends RunSearchTarget {
|
||||
/// unknown field leaves the plain Summary instead of guessing a section. A
|
||||
/// visit hit selects the step with the recorded sequence; a sequence the run did
|
||||
/// not record falls back to the plain Summary, as the browser does, so a stale
|
||||
/// hit never leaves an unrelated visit pane open.
|
||||
/// hit never leaves an unrelated visit pane open. An artifact hit names the
|
||||
/// Artifacts tab and its recorded URL.
|
||||
RunSearchTarget resolveRunSearchSelection(
|
||||
RunSearchSelection selection,
|
||||
JsonMap run,
|
||||
@@ -97,13 +98,11 @@ RunSearchTarget resolveRunSearchSelection(
|
||||
},
|
||||
);
|
||||
}
|
||||
// The URL is the artifact's identity; the gallery matches it among every
|
||||
// recorded visit, so a sequence the detail numbers differently still opens
|
||||
// the file, and a file the run no longer lists reports itself as gone.
|
||||
final artifactUrl = selection.artifactUrl?.trim() ?? '';
|
||||
if (artifactUrl.isNotEmpty) {
|
||||
final visit = _visitTarget(selection, run);
|
||||
return visit == null
|
||||
? const RunSummaryTarget()
|
||||
: RunArtifactTarget(visit: visit, url: artifactUrl);
|
||||
}
|
||||
if (artifactUrl.isNotEmpty) return RunArtifactTarget(url: artifactUrl);
|
||||
final visit = _visitTarget(selection, run);
|
||||
if (visit != null) return visit;
|
||||
return const RunSummaryTarget();
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import 'package:pipelines_app/features/search/search_screen.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import 'search_wiring_test.dart'
|
||||
show
|
||||
closeViewer,
|
||||
expectArtifactsTabSelecting,
|
||||
openArtifactHit,
|
||||
pumpApp,
|
||||
replyRunDetailFor,
|
||||
replyRunList,
|
||||
searchSelectionDetail;
|
||||
|
||||
/// The real Search screen, tapped on a phone-sized window.
|
||||
///
|
||||
/// On a narrow window the open run is its own page on the app's navigator
|
||||
/// rather than a pane under the shell, which is where the search selection
|
||||
/// once went missing: the run opened at its plain Summary. These tests drive
|
||||
/// the whole path (Search tab, typed query, server results, row tap, run
|
||||
/// read) rather than injecting a selection into the detail.
|
||||
void main() {
|
||||
Future<PlatformRouteInformationProvider> openPhoneApp(
|
||||
WidgetTester tester,
|
||||
FakeChannel channel, {
|
||||
required bool cupertino,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
await pumpApp(
|
||||
tester,
|
||||
channel: channel,
|
||||
client: PipelinesClient(channelFactory: (_) => channel),
|
||||
provider: provider,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
await replyRunList(tester, channel);
|
||||
return provider;
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final platform = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$platform phone: an artifact hit opens that artifact in the '
|
||||
'viewer, and Back shows it on the run Artifacts tab', (tester) async {
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final provider = await openPhoneApp(
|
||||
tester,
|
||||
channel,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
|
||||
await openArtifactHit(tester, channel);
|
||||
expect(provider.value.uri.path, '/runs/7');
|
||||
await replyRunDetailFor(tester, channel, searchSelectionDetail());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SearchScreen), findsNothing);
|
||||
final viewer = tester.widget<ArtifactViewerPage>(
|
||||
find.byType(ArtifactViewerPage),
|
||||
);
|
||||
expect(viewer.selectedIdentity, contains('report.txt'));
|
||||
expect(find.text('report.txt'), findsWidgets);
|
||||
|
||||
await closeViewer(tester);
|
||||
expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt');
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
testWidgets('$platform phone: an artifact the run no longer lists opens '
|
||||
'its Artifacts tab with a notice', (tester) async {
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
await openPhoneApp(tester, channel, cupertino: cupertino);
|
||||
|
||||
await openArtifactHit(tester, channel);
|
||||
final detail = searchSelectionDetail();
|
||||
final steps = [
|
||||
for (final step in detail['steps'] as List)
|
||||
Map<String, dynamic>.from(step as Map),
|
||||
];
|
||||
steps[1]['artifacts'] = <JsonMap>[
|
||||
{
|
||||
'name': 'other.txt',
|
||||
'content_type': 'text/plain',
|
||||
'size_bytes': 3,
|
||||
'url': '/artifacts/7/2/other.txt',
|
||||
},
|
||||
];
|
||||
await replyRunDetailFor(tester, channel, {...detail, 'steps': steps});
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
expect(
|
||||
find.byKey(const ValueKey('run-detail-artifacts-7')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text('That artifact is no longer available.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../features/runs/ui/run_detail_finders.dart';
|
||||
import '../native_back.dart';
|
||||
import 'package:pipelines_app/application/app_route.dart';
|
||||
import 'package:pipelines_app/application/app_router.dart';
|
||||
@@ -11,6 +10,8 @@ import 'package:pipelines_app/application/search_destination.dart';
|
||||
import 'package:pipelines_app/application/server_endpoint.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_tile.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import 'package:pipelines_app/features/search/search_screen.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
@@ -190,10 +191,35 @@ JsonMap searchSelectionDetail() => {
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'artifacts': [
|
||||
{
|
||||
'name': 'report.txt',
|
||||
'content_type': 'text/plain',
|
||||
'size_bytes': 12,
|
||||
'url': '/artifacts/7/2/report.txt',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/// Closes the open artifact viewer the way its own Back does.
|
||||
Future<void> closeViewer(WidgetTester tester) async {
|
||||
Navigator.of(tester.element(find.byType(ArtifactViewerPage))).pop();
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
/// Run 7's Artifacts tab is shown with the hit's artifact selected.
|
||||
void expectArtifactsTabSelecting(WidgetTester tester, String url) {
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
expect(find.byKey(const ValueKey('run-detail-artifacts-7')), findsOneWidget);
|
||||
final tile = find.byWidgetPredicate(
|
||||
(widget) => widget is ArtifactTile && widget.artifact.url == url,
|
||||
);
|
||||
expect(tile, findsOneWidget);
|
||||
expect(tester.widget<ArtifactTile>(tile).selected, isTrue);
|
||||
}
|
||||
|
||||
JsonMap artifactHit() => {
|
||||
'kind': 'artifact',
|
||||
'target': '/artifacts/7/2/report.txt',
|
||||
@@ -480,24 +506,21 @@ void main() {
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
// An artifact hit opens the run and selects the visit that recorded it.
|
||||
// An artifact hit opens the run's Artifacts tab and that artifact's viewer.
|
||||
await sendSearch(query: 'report', index: 0, hit: artifactHit());
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('search.result./artifacts/7/2/report.txt')),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(provider.value.uri.path, '/runs/7');
|
||||
expect(find.byType(SearchScreen), findsNothing);
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expectVisitHeading(tester, 'build', 1);
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
|
||||
// Leave the visit page (it covers the shell), then a retired field hit
|
||||
// opens the plain Summary with no visit.
|
||||
await tester.tap(find.byKey(const Key('run-visit-back')));
|
||||
await tester.pumpAndSettle();
|
||||
// Leave the viewer for the Artifacts tab, then a retired field hit opens
|
||||
// the plain Summary with no visit.
|
||||
await closeViewer(tester);
|
||||
expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt');
|
||||
await sendSearch(query: 'retired', index: 1, hit: retiredFieldHit());
|
||||
await tester.tap(
|
||||
find.byKey(const ValueKey('search.result.run:7:5:evidence')),
|
||||
@@ -536,7 +559,7 @@ void main() {
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
testWidgets('an artifact hit selects its visit after the run detail loads', (
|
||||
testWidgets('an artifact hit opens its viewer after the run detail loads', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(900, 1000);
|
||||
@@ -602,8 +625,9 @@ void main() {
|
||||
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 0);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expectVisitHeading(tester, 'build', 1);
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
await closeViewer(tester);
|
||||
expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt');
|
||||
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
await tester.pump();
|
||||
@@ -693,10 +717,9 @@ void main() {
|
||||
await openArtifactHit(tester, channel);
|
||||
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 0);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('run-visit-back')));
|
||||
await tester.pumpAndSettle();
|
||||
await closeViewer(tester);
|
||||
await provider.didPushRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('/runs')),
|
||||
);
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'run_detail_finders.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_tile.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||
@@ -103,6 +104,8 @@ void _expectSummarySection(RunSearchTarget target, RunSummarySection? section) {
|
||||
expect((target as RunSummaryTarget).section, section);
|
||||
}
|
||||
|
||||
const _origin = 'http://127.0.0.1:8096';
|
||||
|
||||
void main() {
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets('${platform.name} artifact hit opens its recorded visit', (
|
||||
@@ -120,6 +123,11 @@ void main() {
|
||||
}
|
||||
|
||||
/// The search fixture with one recorded artifact on build (sequence 2).
|
||||
///
|
||||
/// The fake gateway configures no server, so the recorded URLs are absolute:
|
||||
/// a relative one would not resolve and the gallery would show its facts
|
||||
/// dialog instead of the viewer. The app-level search wiring test covers the
|
||||
/// server-relative URLs a real server records.
|
||||
JsonMap runWithArtifact() {
|
||||
final run = searchSelectionRun();
|
||||
final steps = [
|
||||
@@ -131,33 +139,40 @@ void main() {
|
||||
'name': 'release-report.txt',
|
||||
'content_type': 'text/plain',
|
||||
'size_bytes': 12,
|
||||
'url': '/artifacts/77/2/release-report.txt',
|
||||
'url': '$_origin/artifacts/77/2/release-report.txt',
|
||||
},
|
||||
];
|
||||
return {...run, 'steps': steps};
|
||||
}
|
||||
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets('${platform.name} artifact hit opens that artifact, and the '
|
||||
'timeline keeps working afterwards', (tester) async {
|
||||
testWidgets('${platform.name} artifact hit opens that artifact over the '
|
||||
'Artifacts tab, and the timeline keeps working afterwards', (
|
||||
tester,
|
||||
) async {
|
||||
final pending = await pumpLiveSelection(
|
||||
tester,
|
||||
platform,
|
||||
const RunSearchSelection(
|
||||
runId: 77,
|
||||
sequence: 2,
|
||||
artifactUrl: '/artifacts/77/2/release-report.txt',
|
||||
artifactUrl: '$_origin/artifacts/77/2/release-report.txt',
|
||||
),
|
||||
run: runWithArtifact(),
|
||||
);
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
expect(find.text('release-report.txt'), findsWidgets);
|
||||
|
||||
// Back from the viewer lands on the artifact's visit.
|
||||
// Back from the viewer lands on the run's Artifacts tab, the artifact
|
||||
// shown there selected, exactly as after tapping it in the gallery.
|
||||
Navigator.of(tester.element(find.byType(ArtifactViewerPage))).pop();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
expectVisitHeading(tester, 'build', 1);
|
||||
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
|
||||
expect(find.byKey(const ValueKey('run-detail-artifacts-77')), findsOne);
|
||||
final tile = tester.widget<ArtifactTile>(find.byType(ArtifactTile));
|
||||
expect(tile.artifact.url, '$_origin/artifacts/77/2/release-report.txt');
|
||||
expect(tile.selected, isTrue);
|
||||
|
||||
// Selecting another visit afterwards still opens it.
|
||||
pending.value = const RunSearchSelection(runId: 77, sequence: 5);
|
||||
@@ -166,20 +181,78 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('a missing artifact opens the run with a notice', (tester) async {
|
||||
await pumpSelection(
|
||||
testWidgets('a missing artifact opens the Artifacts tab with a notice', (
|
||||
tester,
|
||||
) async {
|
||||
await pumpLiveSelection(
|
||||
tester,
|
||||
RunDetailTestPlatform.material,
|
||||
const RunSearchSelection(
|
||||
runId: 77,
|
||||
sequence: 2,
|
||||
artifactUrl: '/artifacts/77/2/gone.txt',
|
||||
artifactUrl: '$_origin/artifacts/77/2/gone.txt',
|
||||
),
|
||||
run: runWithArtifact(),
|
||||
);
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
expect(find.byKey(const ValueKey('run-detail-artifacts-77')), findsOne);
|
||||
expect(find.text('That artifact is no longer available.'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('an artifact far down the gallery is scrolled into view', (
|
||||
tester,
|
||||
) async {
|
||||
final run = runWithArtifact();
|
||||
final steps = [
|
||||
for (final step in run['steps'] as List)
|
||||
Map<String, dynamic>.from(step as Map),
|
||||
];
|
||||
// Both plan visits list many files ahead of the build visit's, which
|
||||
// pushes the requested build artifact well below the fold.
|
||||
for (final index in [0, 2]) {
|
||||
final sequence = steps[index]['sequence'];
|
||||
steps[index]['artifacts'] = <dynamic>[
|
||||
for (var i = 0; i < 30; i++)
|
||||
<String, dynamic>{
|
||||
'name': 'filler-$i.bin',
|
||||
'content_type': 'application/octet-stream',
|
||||
'size_bytes': 1,
|
||||
'url': '$_origin/artifacts/77/$sequence/filler-$i.bin',
|
||||
},
|
||||
];
|
||||
}
|
||||
(steps[1]['artifacts'] as List).add(<String, dynamic>{
|
||||
'name': 'late-notes.txt',
|
||||
'content_type': 'text/plain',
|
||||
'size_bytes': 3,
|
||||
'url': '$_origin/artifacts/77/2/late-notes.txt',
|
||||
});
|
||||
await pumpLiveSelection(
|
||||
tester,
|
||||
RunDetailTestPlatform.material,
|
||||
const RunSearchSelection(
|
||||
runId: 77,
|
||||
sequence: 2,
|
||||
artifactUrl: '$_origin/artifacts/77/2/late-notes.txt',
|
||||
),
|
||||
run: {...run, 'steps': steps},
|
||||
);
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
Navigator.of(tester.element(find.byType(ArtifactViewerPage))).pop();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final late = find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is ArtifactTile &&
|
||||
widget.artifact.url == '$_origin/artifacts/77/2/late-notes.txt',
|
||||
);
|
||||
expect(late, findsOneWidget);
|
||||
expect(tester.widget<ArtifactTile>(late).selected, isTrue);
|
||||
final rect = tester.getRect(late);
|
||||
expect(rect.top, greaterThanOrEqualTo(0));
|
||||
expect(rect.bottom, lessThanOrEqualTo(1000));
|
||||
});
|
||||
|
||||
testWidgets('an unknown artifact sequence opens the plain run', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -333,21 +406,19 @@ void main() {
|
||||
expect(target.timelineIndex, 1);
|
||||
});
|
||||
|
||||
test('an artifact selection keeps its URL while naming the visit', () {
|
||||
test('an artifact selection names its recorded URL', () {
|
||||
final target = resolveRunSearchSelection(
|
||||
const RunSearchSelection(
|
||||
runId: 77,
|
||||
sequence: 2,
|
||||
artifactUrl: '/artifacts/77/2/release-report.txt',
|
||||
artifactUrl: '$_origin/artifacts/77/2/release-report.txt',
|
||||
),
|
||||
searchSelectionRun(),
|
||||
);
|
||||
|
||||
expect(target, isA<RunArtifactTarget>());
|
||||
final artifact = target as RunArtifactTarget;
|
||||
expect(artifact.url, '/artifacts/77/2/release-report.txt');
|
||||
expect(artifact.visit.stageKey, 'build');
|
||||
expect(artifact.visit.timelineIndex, 1);
|
||||
expect(artifact.url, '$_origin/artifacts/77/2/release-report.txt');
|
||||
});
|
||||
|
||||
test('an unrecorded sequence falls back to the plain Summary', () {
|
||||
|
||||
Reference in New Issue
Block a user