feat(app): open a pipeline stage from its URL
The route `/pipelines/:id[/:version]/stage/:key` now opens the pipeline detail's Graph tab with the named stage selected and its authored definition pane for the pinned version. A key the pinned definition does not declare opens the Graph tab with nothing selected and no pane; no key keeps the ordinary Summary tab. The request is scoped to the pipeline and version the URL names, consumed once the named pin's first reply is shown, and never replayed by a re-read, a later version switch or a different pipeline. A route change from a pin to latest re-reads latest, matching the web's requested-version rule.
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
import 'pipeline_models.dart';
|
||||
import 'pipeline_repository.dart';
|
||||
import 'pipelines_controller.dart';
|
||||
import 'widgets/pipeline_controls.dart';
|
||||
@@ -29,6 +30,7 @@ class PipelinesScreen extends StatefulWidget {
|
||||
this.onRunStarted,
|
||||
this.initialPipelineId,
|
||||
this.initialVersion = 0,
|
||||
this.initialStageKey,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -50,6 +52,13 @@ class PipelinesScreen extends StatefulWidget {
|
||||
/// The pinned version for [initialPipelineId]; 0 means latest.
|
||||
final int initialVersion;
|
||||
|
||||
/// The definition stage the route names for [initialPipelineId], or null.
|
||||
///
|
||||
/// The detail opens its Graph tab with this stage selected and its definition
|
||||
/// pane; a key the pinned version does not declare opens the Graph tab with
|
||||
/// nothing selected. Null keeps the ordinary default tab.
|
||||
final String? initialStageKey;
|
||||
|
||||
@override
|
||||
State<PipelinesScreen> createState() => _PipelinesScreenState();
|
||||
}
|
||||
@@ -57,6 +66,16 @@ class PipelinesScreen extends StatefulWidget {
|
||||
class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
late PipelinesController _controller;
|
||||
|
||||
/// Counts route stage requests so a re-read detail cannot replay an old one.
|
||||
int _stageRequest = 0;
|
||||
|
||||
/// Whether the route's stage request has been handed to its named pin.
|
||||
///
|
||||
/// The screen, not the detail panel, owns this because the narrow layout
|
||||
/// destroys the panel when it returns to the list: a deep link is a one-shot
|
||||
/// intent, so coming back to the same pipeline later keeps the ordinary tab.
|
||||
bool _stageRequestDone = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -81,12 +100,15 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
// selected pipeline and requested version survive the reconnect.
|
||||
_controller.load();
|
||||
} else if (oldWidget.initialPipelineId != widget.initialPipelineId ||
|
||||
oldWidget.initialVersion != widget.initialVersion) {
|
||||
oldWidget.initialVersion != widget.initialVersion ||
|
||||
oldWidget.initialStageKey != widget.initialStageKey) {
|
||||
_stageRequest++;
|
||||
_stageRequestDone = false;
|
||||
final id = widget.initialPipelineId;
|
||||
if (id != null) {
|
||||
_controller.openPipeline(id, version: widget.initialVersion);
|
||||
} else {
|
||||
if (id == null) {
|
||||
_controller.clearSelection();
|
||||
} else if (!_isRoutePin(_controller.detail)) {
|
||||
_controller.openPipeline(id, version: widget.initialVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,11 +119,47 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Whether [detail] is the pipeline and pin the route names.
|
||||
///
|
||||
/// The shown detail must have been *requested* for the route's version, not
|
||||
/// merely have resolved to it: a latest route (`initialVersion == 0`) never
|
||||
/// matches a detail still displayed from a pinned request, so a route change
|
||||
/// from a pin to latest re-reads latest. The web compares its requested
|
||||
/// version the same way. A pinned route additionally requires the reply's own
|
||||
/// concrete version.
|
||||
bool _isRoutePin(PipelineDetail? detail) {
|
||||
final id = widget.initialPipelineId;
|
||||
if (detail == null || id == null || detail.id != id) return false;
|
||||
final version = widget.initialVersion;
|
||||
if (_controller.selectedVersion != version) return false;
|
||||
return version <= 0 || detail.resolvedVersion == version;
|
||||
}
|
||||
|
||||
/// The route's stage request while it is still pending, or null once spent.
|
||||
///
|
||||
/// The request names one stage of one pinned pipeline. It is handed to the
|
||||
/// detail only until that pin's reply has been shown: the screen consumes the
|
||||
/// request as soon as the first reply for the current selection arrives, so a
|
||||
/// spent deep link cannot replay its pane when the operator later returns to
|
||||
/// the same pipeline. The panel still scopes the request to its named
|
||||
/// pipeline and version, which is what keeps it off an unrelated detail.
|
||||
String? _takeStageKey() {
|
||||
final key = widget.initialStageKey;
|
||||
final target = widget.initialPipelineId;
|
||||
if (key == null || key.isEmpty || target == null) return null;
|
||||
if (_stageRequestDone) return null;
|
||||
final detail = _controller.detail;
|
||||
if (detail == null) return key;
|
||||
_stageRequestDone = true;
|
||||
return _isRoutePin(detail) ? key : null;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, _) {
|
||||
final stageKey = _takeStageKey();
|
||||
final body = LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= kPipelinesWideBreakpoint;
|
||||
@@ -112,6 +170,10 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
gateway: widget.gateway,
|
||||
showBack: true,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
stageKey: stageKey,
|
||||
stagePipelineId: widget.initialPipelineId,
|
||||
stageVersion: widget.initialVersion,
|
||||
stageRequest: _stageRequest,
|
||||
)
|
||||
: PipelineListPanel(controller: _controller);
|
||||
}
|
||||
@@ -130,6 +192,10 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
gateway: widget.gateway,
|
||||
showBack: false,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
stageKey: stageKey,
|
||||
stagePipelineId: widget.initialPipelineId,
|
||||
stageVersion: widget.initialVersion,
|
||||
stageRequest: _stageRequest,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user