Merge branch 'main' into flutter/search-target
This commit is contained in:
@@ -57,6 +57,10 @@ class _PipelinesAppState extends State<PipelinesApp> {
|
||||
/// locally, so the next list reply is the only source of the new pipeline.
|
||||
int _pipelinesRefresh = 0;
|
||||
|
||||
/// Advances when a launch was accepted. The Runs destination re-reads its
|
||||
/// list once; the run itself is then opened from its route.
|
||||
int _runsRefresh = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -145,6 +149,17 @@ class _PipelinesAppState extends State<PipelinesApp> {
|
||||
setState(() => _pipelinesRefresh++);
|
||||
}
|
||||
|
||||
/// Opens the run id an accepted launch named and invalidates the Runs list.
|
||||
///
|
||||
/// The order is deliberate: the list token is already advanced when the Runs
|
||||
/// screen mounts for the first time, so it performs one fresh `list_runs`
|
||||
/// read and then opens the route's run. No row is inserted locally.
|
||||
void _runStarted(int id) {
|
||||
if (!mounted) return;
|
||||
setState(() => _runsRefresh++);
|
||||
_delegate.goTo(AppRoute.run(id));
|
||||
}
|
||||
|
||||
Widget _buildShell(BuildContext context, AppRoute route) => AdaptiveShell(
|
||||
cupertino: _cupertino,
|
||||
destination: _destinationOf(route.kind),
|
||||
@@ -156,11 +171,13 @@ class _PipelinesAppState extends State<PipelinesApp> {
|
||||
session: _session,
|
||||
server: widget.server,
|
||||
refreshToken: _pipelinesRefresh,
|
||||
onRunStarted: _runStarted,
|
||||
),
|
||||
AppDestination.runs: (_) => RunsDestination(
|
||||
session: _session,
|
||||
server: widget.server,
|
||||
initialRunId: route.runId,
|
||||
listRefreshToken: _runsRefresh,
|
||||
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
|
||||
onBack: () => _delegate.goTo(AppRoute.runs),
|
||||
),
|
||||
|
||||
@@ -18,6 +18,7 @@ class PipelinesDestination extends StatelessWidget {
|
||||
required this.session,
|
||||
required this.server,
|
||||
this.refreshToken = 0,
|
||||
this.onRunStarted,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
@@ -28,6 +29,9 @@ class PipelinesDestination extends StatelessWidget {
|
||||
/// accepted; the rows still come only from the server's next reply.
|
||||
final int refreshToken;
|
||||
|
||||
/// Receives the run id an accepted launch named; the shell opens that route.
|
||||
final ValueChanged<int>? onRunStarted;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
animation: session,
|
||||
@@ -62,6 +66,7 @@ class PipelinesDestination extends StatelessWidget {
|
||||
Widget _pipelinesScreen() => PipelinesScreen(
|
||||
gateway: session.gateway,
|
||||
embedded: true,
|
||||
onRunStarted: onRunStarted,
|
||||
// A reconnect or an accepted template create both advance this counter;
|
||||
// either change re-reads through the mounted controller.
|
||||
syncToken: session.connectionEpoch + refreshToken,
|
||||
|
||||
@@ -20,6 +20,7 @@ class RunsDestination extends StatelessWidget {
|
||||
this.initialRunId,
|
||||
this.onRunSelected,
|
||||
this.onBack,
|
||||
this.listRefreshToken = 0,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
@@ -28,6 +29,10 @@ class RunsDestination extends StatelessWidget {
|
||||
final ValueChanged<int>? onRunSelected;
|
||||
final VoidCallback? onBack;
|
||||
|
||||
/// Advances when a launch was accepted elsewhere. The mounted Runs screen
|
||||
/// re-reads its list once; no row is inserted locally.
|
||||
final int listRefreshToken;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
animation: session,
|
||||
@@ -64,6 +69,7 @@ class RunsDestination extends StatelessWidget {
|
||||
gateway: session.gateway,
|
||||
initialRunId: initialRunId,
|
||||
syncToken: session.connectionEpoch,
|
||||
listRefreshToken: listRefreshToken,
|
||||
onRunSelected: onRunSelected,
|
||||
onBack: onBack,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/// The reason text carried by a failed request, without runtime diagnostics.
|
||||
///
|
||||
/// The gateway fails pending requests with `StateError('Connection closed')`,
|
||||
/// whose `toString()` is `Bad state: Connection closed`. The browser shows the
|
||||
/// reason itself, never a Dart diagnostic, so those prefixes are stripped while
|
||||
/// deliberate protocol/refusal messages stay untouched. [fallback] is the
|
||||
/// honest sentence for a failure that carries no text at all.
|
||||
String describeErrorReason(
|
||||
Object error, {
|
||||
required String fallback,
|
||||
}) {
|
||||
final raw = switch (error) {
|
||||
StateError(:final message) => message.toString(),
|
||||
_ => '$error',
|
||||
};
|
||||
var message = raw.trim();
|
||||
for (final prefix in _runtimePrefixes) {
|
||||
if (message.startsWith(prefix)) {
|
||||
message = message.substring(prefix.length).trim();
|
||||
}
|
||||
}
|
||||
return message.isEmpty ? fallback : message;
|
||||
}
|
||||
|
||||
/// Dart runtime prefixes that never belong in operator-facing copy.
|
||||
const _runtimePrefixes = ['Bad state:', 'Exception:'];
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'pipeline_models.dart';
|
||||
import 'pipeline_query.dart';
|
||||
import 'pipeline_repository.dart';
|
||||
import 'run_pipeline_intent.dart';
|
||||
|
||||
/// The user-facing message for a request failure, keeping server refusals
|
||||
/// verbatim and removing only the generic `Exception:` prefix.
|
||||
@@ -45,6 +46,14 @@ class PipelinesController extends ChangeNotifier {
|
||||
List<PipelineRun>? _latestSource;
|
||||
Map<int, PipelineRun>? _latestCache;
|
||||
|
||||
/// Launch intents whose reply never arrived, keyed by pinned identity.
|
||||
///
|
||||
/// Kept per pipeline/version like the browser's sessionStorage intent, so a
|
||||
/// dialog reopened in this session still offers check/retry with the same
|
||||
/// request key instead of minting a possible duplicate.
|
||||
final Map<String, RunPipelineIntent> _pendingRuns =
|
||||
<String, RunPipelineIntent>{};
|
||||
|
||||
List<PipelineSummary> get pipelines => _pipelines;
|
||||
PipelineFilters get filters => _filters;
|
||||
PipelineSort get sort => _sort;
|
||||
@@ -203,6 +212,20 @@ class PipelinesController extends ChangeNotifier {
|
||||
_notify();
|
||||
}
|
||||
|
||||
/// The unresolved launch for one pinned definition, if any.
|
||||
RunPipelineIntent? pendingRunFor(int pipelineId, int version) =>
|
||||
_pendingRuns['$pipelineId@$version'];
|
||||
|
||||
/// Remembers an intent whose admission is unknown, or clears it once the
|
||||
/// server's truth is known.
|
||||
void rememberPendingRun(RunPipelineIntent intent) {
|
||||
_pendingRuns['${intent.pipelineId}@${intent.version}'] = intent;
|
||||
}
|
||||
|
||||
void clearPendingRun(int pipelineId, int version) {
|
||||
_pendingRuns.remove('$pipelineId@$version');
|
||||
}
|
||||
|
||||
bool _current(int sequence, int token) => !_disposed && sequence == token;
|
||||
|
||||
bool _currentDetail(int token, int id, int version) =>
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import 'dart:math';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
|
||||
/// The browser's three notification choices for a started run. `auto` omits
|
||||
/// the wire field so the pipeline definition applies.
|
||||
enum RunNotifyMode {
|
||||
pipelineDefault('Pipeline default'),
|
||||
notify('Notify me'),
|
||||
silent('Silent');
|
||||
|
||||
const RunNotifyMode(this.label);
|
||||
|
||||
final String label;
|
||||
|
||||
/// The `notify_mode` value, or null when the definition decides.
|
||||
String? get wireValue => switch (this) {
|
||||
RunNotifyMode.pipelineDefault => null,
|
||||
RunNotifyMode.notify => 'on',
|
||||
RunNotifyMode.silent => 'off',
|
||||
};
|
||||
}
|
||||
|
||||
/// One confirmed launch intent: the pinned pipeline identity, the operator's
|
||||
/// fields and the idempotency key that belongs to them.
|
||||
///
|
||||
/// A lost reply leaves this intent in place, so checking or retrying reuses
|
||||
/// [requestKey] and the server can dedupe it. A confirmed refusal clears it;
|
||||
/// the corrected attempt mints a fresh key.
|
||||
class RunPipelineIntent {
|
||||
const RunPipelineIntent({
|
||||
required this.pipelineId,
|
||||
required this.version,
|
||||
required this.prompt,
|
||||
required this.workspace,
|
||||
required this.notifyMode,
|
||||
required this.requestKey,
|
||||
});
|
||||
|
||||
final int pipelineId;
|
||||
final int version;
|
||||
final String prompt;
|
||||
final String workspace;
|
||||
final RunNotifyMode notifyMode;
|
||||
final String requestKey;
|
||||
|
||||
/// The same key is only ever reused for the same pinned definition.
|
||||
bool matches(int pipelineId, int version) =>
|
||||
this.pipelineId == pipelineId && this.version == version;
|
||||
}
|
||||
|
||||
/// The entropy bound for a fresh key, written as a literal because a web
|
||||
/// bitwise `1 << 32` wraps to 0 and makes `Random.nextInt` reject every call.
|
||||
const _entropyBound = 0x100000000;
|
||||
|
||||
/// A fresh `request_key` for one confirmed launch. The server caps keys at 128
|
||||
/// characters; this stays well inside that bound and is unique per call.
|
||||
String newRunPipelineRequestKey(
|
||||
int pipelineId,
|
||||
int version, {
|
||||
DateTime? now,
|
||||
int? random,
|
||||
}) {
|
||||
final stamp = (now ?? DateTime.now()).microsecondsSinceEpoch;
|
||||
final entropy = random ?? Random().nextInt(_entropyBound);
|
||||
return 'app-run-$pipelineId-$version-$stamp-${entropy.toRadixString(36)}';
|
||||
}
|
||||
|
||||
/// The id the server's run detail names, or null when it named no usable run.
|
||||
int? runPipelineRunId(JsonMap run) {
|
||||
final id = run['id'];
|
||||
if (id is int && id > 0) return id;
|
||||
if (id is num && id > 0) return id.toInt();
|
||||
return null;
|
||||
}
|
||||
|
||||
/// A launch attempt's outcome: either the server's run detail or a refusal
|
||||
/// with the truth about whether admission is still unknown.
|
||||
sealed class RunPipelineOutcome {
|
||||
const RunPipelineOutcome();
|
||||
}
|
||||
|
||||
class RunPipelineAccepted extends RunPipelineOutcome {
|
||||
const RunPipelineAccepted(this.run);
|
||||
|
||||
final JsonMap run;
|
||||
}
|
||||
|
||||
class RunPipelineRefused extends RunPipelineOutcome {
|
||||
const RunPipelineRefused(this.message, {required this.admissionUnknown});
|
||||
|
||||
final String message;
|
||||
final bool admissionUnknown;
|
||||
}
|
||||
@@ -26,6 +26,7 @@ class PipelinesScreen extends StatefulWidget {
|
||||
required this.gateway,
|
||||
this.embedded = false,
|
||||
this.syncToken = 0,
|
||||
this.onRunStarted,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -37,6 +38,10 @@ class PipelinesScreen extends StatefulWidget {
|
||||
/// reloads the list and the selected detail without losing the selection.
|
||||
final int syncToken;
|
||||
|
||||
/// Receives the run id an accepted launch names, so the composition can open
|
||||
/// the existing run route. The feature never navigates on its own.
|
||||
final ValueChanged<int>? onRunStarted;
|
||||
|
||||
@override
|
||||
State<PipelinesScreen> createState() => _PipelinesScreenState();
|
||||
}
|
||||
@@ -85,6 +90,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
controller: _controller,
|
||||
gateway: widget.gateway,
|
||||
showBack: true,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
)
|
||||
: PipelineListPanel(controller: _controller);
|
||||
}
|
||||
@@ -102,6 +108,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
controller: _controller,
|
||||
gateway: widget.gateway,
|
||||
showBack: false,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/transport/connection_state.dart';
|
||||
import '../../runs/data/runs_repository.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipelines_controller.dart';
|
||||
import '../run_pipeline_intent.dart';
|
||||
import '../widgets/pipeline_controls.dart';
|
||||
import 'run_pipeline_dialog.dart';
|
||||
import 'run_pipeline_wording.dart';
|
||||
|
||||
/// The pipeline detail's Run action.
|
||||
///
|
||||
/// Nothing is requested until the dialog's confirm. A confirmed attempt sends
|
||||
/// the web's exact `run_pipeline` body against the pinned resolved version; a
|
||||
/// lost reply keeps the intent so the next deliberate press checks by the same
|
||||
/// request key before resending. Only the id the server names is opened.
|
||||
class RunPipelineAction extends StatefulWidget {
|
||||
const RunPipelineAction({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.detail,
|
||||
required this.gateway,
|
||||
this.onRunStarted,
|
||||
});
|
||||
|
||||
final PipelinesController controller;
|
||||
final PipelineDetail detail;
|
||||
final ApiGateway gateway;
|
||||
|
||||
/// Receives the id from an accepted server reply. It is never called for a
|
||||
/// guessed or malformed response.
|
||||
final ValueChanged<int>? onRunStarted;
|
||||
|
||||
@override
|
||||
State<RunPipelineAction> createState() => _RunPipelineActionState();
|
||||
}
|
||||
|
||||
class _RunPipelineActionState extends State<RunPipelineAction> {
|
||||
bool _dialogOpen = false;
|
||||
|
||||
int get _pipelineId => widget.detail.id;
|
||||
int get _version => widget.detail.resolvedVersion;
|
||||
|
||||
Future<void> _open() async {
|
||||
if (_dialogOpen) return;
|
||||
_dialogOpen = true;
|
||||
try {
|
||||
await showRunPipelineDialog(
|
||||
context: context,
|
||||
detail: widget.detail,
|
||||
pending: widget.controller.pendingRunFor(_pipelineId, _version),
|
||||
onSubmit: _submit,
|
||||
onPendingChanged: (intent) {
|
||||
if (intent == null) {
|
||||
widget.controller.clearPendingRun(_pipelineId, _version);
|
||||
} else {
|
||||
widget.controller.rememberPendingRun(intent);
|
||||
}
|
||||
},
|
||||
onAccepted: _accepted,
|
||||
);
|
||||
} finally {
|
||||
_dialogOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
void _accepted(JsonMap run) {
|
||||
final id = runPipelineRunId(run);
|
||||
if (id == null) return;
|
||||
widget.controller.clearPendingRun(_pipelineId, _version);
|
||||
widget.onRunStarted?.call(id);
|
||||
}
|
||||
|
||||
Future<RunPipelineOutcome> _submit(RunPipelineIntent intent) async {
|
||||
final repository = RunsRepository(widget.gateway);
|
||||
final pending = widget.controller.pendingRunFor(
|
||||
intent.pipelineId,
|
||||
intent.version,
|
||||
);
|
||||
if (pending?.requestKey == intent.requestKey) {
|
||||
// A previous send may have been admitted even though its reply was lost.
|
||||
// Check before resending the same key; the server dedupes either way.
|
||||
try {
|
||||
final existing = await repository.runByRequestKey(intent.requestKey);
|
||||
if (existing != null) return _accept(existing);
|
||||
} catch (error) {
|
||||
widget.controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
try {
|
||||
final run = await repository.startRun(
|
||||
pipelineId: intent.pipelineId,
|
||||
version: intent.version,
|
||||
prompt: intent.prompt,
|
||||
workspace: intent.workspace,
|
||||
requestKey: intent.requestKey,
|
||||
notifyMode: intent.notifyMode.wireValue,
|
||||
);
|
||||
final accepted = _accept(run);
|
||||
if (accepted is RunPipelineAccepted) return accepted;
|
||||
// A reply without a usable run id is not navigable: read the admitted run
|
||||
// by key rather than inventing an id or starting another run.
|
||||
return _refuse(repository, intent, 'The server returned no run id.');
|
||||
} on ProtocolError catch (error) {
|
||||
return _refuse(repository, intent, describeRunPipelineError(error));
|
||||
} on RunsRepositoryException catch (error) {
|
||||
return _refuse(repository, intent, describeRunPipelineError(error));
|
||||
} catch (error) {
|
||||
widget.controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'${describeRunPipelineError(error)}$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A reply is only accepted when it names a usable run id.
|
||||
RunPipelineOutcome _accept(JsonMap run) {
|
||||
if (runPipelineRunId(run) == null) {
|
||||
return const RunPipelineRefused(
|
||||
'The server returned no run id.',
|
||||
admissionUnknown: false,
|
||||
);
|
||||
}
|
||||
widget.controller.clearPendingRun(widget.detail.id, _version);
|
||||
return RunPipelineAccepted(run);
|
||||
}
|
||||
|
||||
/// A confirmed refusal: prove by key that no run was admitted before letting
|
||||
/// the operator correct the fields and try with a fresh key.
|
||||
Future<RunPipelineOutcome> _refuse(
|
||||
RunsRepository repository,
|
||||
RunPipelineIntent intent,
|
||||
String message,
|
||||
) async {
|
||||
try {
|
||||
final existing = await repository.runByRequestKey(intent.requestKey);
|
||||
if (existing != null) return _accept(existing);
|
||||
widget.controller.clearPendingRun(intent.pipelineId, intent.version);
|
||||
return RunPipelineRefused(message, admissionUnknown: false);
|
||||
} catch (_) {
|
||||
// Admission cannot be proven either way: keep the intent immutable.
|
||||
widget.controller.rememberPendingRun(intent);
|
||||
return RunPipelineRefused(
|
||||
'$message$runPipelineUnknownSuffix',
|
||||
admissionUnknown: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final label = const Text(runPipelineActionLabel);
|
||||
if (useCupertinoControls(context)) {
|
||||
return CupertinoButton.filled(
|
||||
key: runPipelineActionKey,
|
||||
onPressed: _open,
|
||||
child: label,
|
||||
);
|
||||
}
|
||||
return FilledButton(
|
||||
key: runPipelineActionKey,
|
||||
onPressed: _open,
|
||||
child: label,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../run_pipeline_intent.dart';
|
||||
import 'run_pipeline_fields.dart';
|
||||
import 'run_pipeline_wording.dart';
|
||||
|
||||
/// Opens the native start-a-run prompt; resolves when it closes.
|
||||
///
|
||||
/// Opening, typing and Cancel send nothing. Only the confirm action validates
|
||||
/// and submits. [pending] restores an intent whose admission is still unknown,
|
||||
/// so its fields are locked and the same request key is offered for check/retry.
|
||||
Future<void> showRunPipelineDialog({
|
||||
required BuildContext context,
|
||||
required PipelineDetail detail,
|
||||
required RunPipelineIntent? pending,
|
||||
required Future<RunPipelineOutcome> Function(RunPipelineIntent intent)
|
||||
onSubmit,
|
||||
required ValueChanged<RunPipelineIntent?> onPendingChanged,
|
||||
required ValueChanged<JsonMap> onAccepted,
|
||||
}) {
|
||||
final dialog = _RunPipelineDialog(
|
||||
detail: detail,
|
||||
pending: pending,
|
||||
cupertino: usesCupertinoHost(context),
|
||||
onSubmit: onSubmit,
|
||||
onPendingChanged: onPendingChanged,
|
||||
onAccepted: onAccepted,
|
||||
);
|
||||
return dialog.cupertino
|
||||
? showCupertinoDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => dialog,
|
||||
)
|
||||
: showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => dialog,
|
||||
);
|
||||
}
|
||||
|
||||
class _RunPipelineDialog extends StatefulWidget {
|
||||
const _RunPipelineDialog({
|
||||
required this.detail,
|
||||
required this.pending,
|
||||
required this.cupertino,
|
||||
required this.onSubmit,
|
||||
required this.onPendingChanged,
|
||||
required this.onAccepted,
|
||||
});
|
||||
|
||||
final PipelineDetail detail;
|
||||
final RunPipelineIntent? pending;
|
||||
final bool cupertino;
|
||||
final Future<RunPipelineOutcome> Function(RunPipelineIntent intent) onSubmit;
|
||||
final ValueChanged<RunPipelineIntent?> onPendingChanged;
|
||||
final ValueChanged<JsonMap> onAccepted;
|
||||
|
||||
@override
|
||||
State<_RunPipelineDialog> createState() => _RunPipelineDialogState();
|
||||
}
|
||||
|
||||
class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
late final TextEditingController _prompt;
|
||||
late final TextEditingController _workspace;
|
||||
late RunNotifyMode _notify;
|
||||
late RunPipelineIntent? _intent;
|
||||
bool _sending = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final pending = widget.pending;
|
||||
final restored =
|
||||
pending != null &&
|
||||
pending.matches(widget.detail.id, widget.detail.resolvedVersion)
|
||||
? pending
|
||||
: null;
|
||||
_intent = restored;
|
||||
_notify = restored?.notifyMode ?? RunNotifyMode.pipelineDefault;
|
||||
_prompt = TextEditingController(text: restored?.prompt ?? '');
|
||||
_workspace = TextEditingController(text: restored?.workspace ?? '');
|
||||
_error = restored == null ? null : runPipelineUnknownAdmission;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_prompt.dispose();
|
||||
_workspace.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _locked => _intent != null || _sending;
|
||||
|
||||
void _cancel() {
|
||||
if (!_sending) Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
Future<void> _confirm() async {
|
||||
if (_sending) return;
|
||||
final prompt = _prompt.text.trim();
|
||||
if (prompt.isEmpty) {
|
||||
setState(() => _error = runPipelinePromptRequired);
|
||||
return;
|
||||
}
|
||||
// The browser checks the field as typed; only the sent value is trimmed.
|
||||
final workspace = _workspace.text;
|
||||
if (!workspace.startsWith('/')) {
|
||||
setState(() => _error = runPipelineWorkspaceAbsolute);
|
||||
return;
|
||||
}
|
||||
final intent =
|
||||
_intent ??
|
||||
RunPipelineIntent(
|
||||
pipelineId: widget.detail.id,
|
||||
version: widget.detail.resolvedVersion,
|
||||
prompt: prompt,
|
||||
workspace: workspace.trim(),
|
||||
notifyMode: _notify,
|
||||
requestKey: newRunPipelineRequestKey(
|
||||
widget.detail.id,
|
||||
widget.detail.resolvedVersion,
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
_sending = true;
|
||||
_error = null;
|
||||
});
|
||||
final outcome = await widget.onSubmit(intent);
|
||||
if (!mounted) return;
|
||||
switch (outcome) {
|
||||
case RunPipelineAccepted(:final run):
|
||||
widget.onPendingChanged(null);
|
||||
widget.onAccepted(run);
|
||||
Navigator.of(context).pop();
|
||||
case RunPipelineRefused(:final message, :final admissionUnknown):
|
||||
final keep = admissionUnknown ? intent : null;
|
||||
widget.onPendingChanged(keep);
|
||||
setState(() {
|
||||
_intent = keep;
|
||||
_sending = false;
|
||||
_error = message;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dialog = widget.cupertino ? _cupertino(context) : _material(context);
|
||||
return PopScope(canPop: !_sending, child: dialog);
|
||||
}
|
||||
|
||||
Widget _material(BuildContext context) {
|
||||
return AlertDialog(
|
||||
scrollable: true,
|
||||
title: Text(runPipelineDialogTitle(widget.detail.name)),
|
||||
content: _content(context),
|
||||
actions: [
|
||||
TextButton(
|
||||
key: runPipelineCancelKey,
|
||||
onPressed: _sending ? null : _cancel,
|
||||
child: const Text(runPipelineCancelLabel),
|
||||
),
|
||||
FilledButton(
|
||||
key: runPipelineConfirmKey,
|
||||
onPressed: _sending ? null : _confirm,
|
||||
child: Text(_confirmLabel),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertino(BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text(runPipelineDialogTitle(widget.detail.name)),
|
||||
content: _content(context),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
key: runPipelineCancelKey,
|
||||
onPressed: _sending ? null : _cancel,
|
||||
child: const Text(runPipelineCancelLabel),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
key: runPipelineConfirmKey,
|
||||
isDefaultAction: true,
|
||||
onPressed: _sending ? null : _confirm,
|
||||
child: Text(_confirmLabel),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String get _confirmLabel {
|
||||
if (_sending) return runPipelineSendingLabel;
|
||||
return _intent == null
|
||||
? runPipelineConfirmLabel
|
||||
: runPipelineCheckRetryLabel;
|
||||
}
|
||||
|
||||
Widget _content(BuildContext context) {
|
||||
final errorStyle = widget.cupertino
|
||||
? TextStyle(color: CupertinoColors.systemRed.resolveFrom(context))
|
||||
: TextStyle(color: Theme.of(context).colorScheme.error);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
RunPipelineFields(
|
||||
prompt: _prompt,
|
||||
workspace: _workspace,
|
||||
notifyMode: _notify,
|
||||
locked: _locked,
|
||||
onNotifyChanged: (mode) => setState(() => _notify = mode),
|
||||
),
|
||||
if (_error case final error?)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(error, key: runPipelineErrorKey, style: errorStyle),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../run_pipeline_intent.dart';
|
||||
import 'run_pipeline_wording.dart';
|
||||
|
||||
/// The dialog's three web fields, in the host's native controls.
|
||||
///
|
||||
/// A confirmed launch locks every field: the request is immutable until its
|
||||
/// admission is known, exactly like the browser's disabled inputs.
|
||||
class RunPipelineFields extends StatelessWidget {
|
||||
const RunPipelineFields({
|
||||
super.key,
|
||||
required this.prompt,
|
||||
required this.workspace,
|
||||
required this.notifyMode,
|
||||
required this.locked,
|
||||
required this.onNotifyChanged,
|
||||
});
|
||||
|
||||
final TextEditingController prompt;
|
||||
final TextEditingController workspace;
|
||||
final RunNotifyMode notifyMode;
|
||||
final bool locked;
|
||||
final ValueChanged<RunNotifyMode> onNotifyChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_FieldLabel(runPipelinePromptLabel, cupertino: cupertino),
|
||||
_promptField(context, cupertino),
|
||||
const SizedBox(height: 12),
|
||||
_FieldLabel(runPipelineWorkspaceLabel, cupertino: cupertino),
|
||||
_workspaceField(context, cupertino),
|
||||
_helper(context, runPipelineWorkspaceHelper, cupertino),
|
||||
const SizedBox(height: 12),
|
||||
_FieldLabel(runPipelineNotifyLabel, cupertino: cupertino),
|
||||
_notifyField(context, cupertino),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _promptField(BuildContext context, bool cupertino) {
|
||||
if (cupertino) {
|
||||
return CupertinoTextField(
|
||||
key: runPipelinePromptKey,
|
||||
controller: prompt,
|
||||
placeholder: runPipelinePromptPlaceholder,
|
||||
placeholderStyle: _cupertinoPlaceholder(context),
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
minLines: 3,
|
||||
maxLines: 5,
|
||||
enabled: !locked,
|
||||
autofocus: !locked,
|
||||
padding: const EdgeInsets.all(8),
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
);
|
||||
}
|
||||
return TextField(
|
||||
key: runPipelinePromptKey,
|
||||
controller: prompt,
|
||||
enabled: !locked,
|
||||
autofocus: !locked,
|
||||
minLines: 3,
|
||||
maxLines: 5,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
decoration: const InputDecoration(
|
||||
hintText: runPipelinePromptPlaceholder,
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _workspaceField(BuildContext context, bool cupertino) {
|
||||
if (cupertino) {
|
||||
return CupertinoTextField(
|
||||
key: runPipelineWorkspaceKey,
|
||||
controller: workspace,
|
||||
placeholder: runPipelineWorkspacePlaceholder,
|
||||
placeholderStyle: _cupertinoPlaceholder(context),
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
enabled: !locked,
|
||||
autocorrect: false,
|
||||
padding: const EdgeInsets.all(8),
|
||||
);
|
||||
}
|
||||
return TextField(
|
||||
key: runPipelineWorkspaceKey,
|
||||
controller: workspace,
|
||||
enabled: !locked,
|
||||
autocorrect: false,
|
||||
decoration: const InputDecoration(
|
||||
hintText: runPipelineWorkspacePlaceholder,
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _notifyField(BuildContext context, bool cupertino) {
|
||||
if (cupertino) {
|
||||
return CupertinoButton(
|
||||
key: runPipelineNotifyKey,
|
||||
padding: EdgeInsets.zero,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
onPressed: locked ? null : () => _chooseNotify(context),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(child: Text(notifyMode.label)),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(CupertinoIcons.chevron_down, size: 14),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return DropdownButtonFormField<RunNotifyMode>(
|
||||
key: runPipelineNotifyKey,
|
||||
initialValue: notifyMode,
|
||||
decoration: const InputDecoration(border: OutlineInputBorder()),
|
||||
items: [
|
||||
for (final mode in RunNotifyMode.values)
|
||||
DropdownMenuItem(value: mode, child: Text(mode.label)),
|
||||
],
|
||||
onChanged: locked
|
||||
? null
|
||||
: (mode) {
|
||||
if (mode != null) onNotifyChanged(mode);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _chooseNotify(BuildContext context) async {
|
||||
final chosen = await showCupertinoModalPopup<RunNotifyMode>(
|
||||
context: context,
|
||||
builder: (sheetContext) => CupertinoActionSheet(
|
||||
title: const Text(runPipelineNotifyLabel),
|
||||
actions: [
|
||||
for (final mode in RunNotifyMode.values)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.of(sheetContext).pop(mode),
|
||||
child: Text(mode.label),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(sheetContext).pop(),
|
||||
child: const Text(runPipelineCancelLabel),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (chosen != null) onNotifyChanged(chosen);
|
||||
}
|
||||
|
||||
TextStyle _cupertinoPlaceholder(BuildContext context) {
|
||||
// The host's own dynamic placeholder colour (light and dark), resolved for
|
||||
// the dialog's inherited Cupertino brightness.
|
||||
return TextStyle(color: CupertinoColors.placeholderText.resolveFrom(context));
|
||||
}
|
||||
|
||||
Widget _helper(BuildContext context, String text, bool cupertino) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(text, style: _secondaryStyle(context, cupertino)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Secondary copy under a field: the host's own secondary role, never a
|
||||
/// borrowed palette or invented point size.
|
||||
TextStyle _secondaryStyle(BuildContext context, bool cupertino) {
|
||||
if (cupertino) {
|
||||
return CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
|
||||
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
);
|
||||
}
|
||||
final theme = Theme.of(context);
|
||||
return (theme.textTheme.bodySmall ?? const TextStyle()).copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
}
|
||||
|
||||
/// The label above each native field, using the web's exact words.
|
||||
class _FieldLabel extends StatelessWidget {
|
||||
const _FieldLabel(this.text, {required this.cupertino});
|
||||
|
||||
final String text;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// A theme label role with the primary label colour, matching the app's
|
||||
// Cupertino form pattern; secondaryLabel is for helper copy only.
|
||||
final style = cupertino
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.labelLarge;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Text(text, style: style),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../core/error_reason.dart';
|
||||
|
||||
/// The browser client's start-a-run wording, kept verbatim.
|
||||
String runPipelineDialogTitle(String name) =>
|
||||
'Run ${name.isEmpty ? 'pipeline' : name}';
|
||||
const runPipelineActionLabel = 'Run';
|
||||
const runPipelinePromptLabel = 'Prompt';
|
||||
const runPipelinePromptPlaceholder = 'What should this run do?';
|
||||
const runPipelineWorkspaceLabel = 'Working directory (on the server)';
|
||||
const runPipelineWorkspaceHelper =
|
||||
'Choose a recent directory or type an absolute path.';
|
||||
const runPipelineWorkspacePlaceholder = '/absolute/path/on/the/server';
|
||||
const runPipelineNotifyLabel = 'Notifications for this run';
|
||||
const runPipelineCancelLabel = 'Cancel';
|
||||
const runPipelineConfirmLabel = 'Run';
|
||||
const runPipelineSendingLabel = 'Starting…';
|
||||
const runPipelineCheckRetryLabel = 'Check / retry';
|
||||
|
||||
/// Local validation, exactly the browser's two states.
|
||||
const runPipelinePromptRequired = 'Enter a prompt for this run.';
|
||||
const runPipelineWorkspaceAbsolute =
|
||||
'Choose an absolute working directory on the server.';
|
||||
|
||||
/// Shown when a stored launch already has an unknown result.
|
||||
const runPipelineUnknownAdmission =
|
||||
'A previous launch has an unknown result. Check/retry reconciles that '
|
||||
'same request; it will not start a duplicate.';
|
||||
|
||||
/// Appended to a transport failure whose admission cannot be proven either way.
|
||||
const runPipelineUnknownSuffix =
|
||||
'. Admission may be unknown. Check/retry uses the same request key.';
|
||||
|
||||
/// Stable test/semantics keys shared by the action and its prompt.
|
||||
const runPipelineActionKey = ValueKey<String>('run-pipeline-action');
|
||||
const runPipelinePromptKey = ValueKey<String>('run-pipeline-prompt');
|
||||
const runPipelineWorkspaceKey = ValueKey<String>('run-pipeline-workspace');
|
||||
const runPipelineNotifyKey = ValueKey<String>('run-pipeline-notify');
|
||||
const runPipelineCancelKey = ValueKey<String>('run-pipeline-cancel');
|
||||
const runPipelineConfirmKey = ValueKey<String>('run-pipeline-confirm');
|
||||
const runPipelineErrorKey = ValueKey<String>('run-pipeline-error');
|
||||
|
||||
/// The server's refusal, verbatim. Only a blank error gets a sentence so the
|
||||
/// prompt never claims a run that was not admitted.
|
||||
String describeRunPipelineError(Object error) => describeErrorReason(
|
||||
error,
|
||||
fallback: 'The server did not start the run.',
|
||||
);
|
||||
@@ -7,6 +7,7 @@ import '../../graph/widgets/stage_definition_view.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipeline_query.dart';
|
||||
import '../pipelines_controller.dart';
|
||||
import '../ui/run_pipeline_action.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
import 'pipeline_detail_styles.dart';
|
||||
import 'pipeline_graph_tab.dart';
|
||||
@@ -28,12 +29,16 @@ class PipelineDetailPanel extends StatefulWidget {
|
||||
required this.controller,
|
||||
required this.gateway,
|
||||
required this.showBack,
|
||||
this.onRunStarted,
|
||||
});
|
||||
|
||||
final PipelinesController controller;
|
||||
final ApiGateway gateway;
|
||||
final bool showBack;
|
||||
|
||||
/// A run started from this detail's Run action; receives the server's id.
|
||||
final ValueChanged<int>? onRunStarted;
|
||||
|
||||
@override
|
||||
State<PipelineDetailPanel> createState() => _PipelineDetailPanelState();
|
||||
}
|
||||
@@ -215,26 +220,39 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
|
||||
pipelineSubtitle(detail),
|
||||
style: pipelineMutedStyle(context),
|
||||
);
|
||||
final heading = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [title, subtitle],
|
||||
);
|
||||
final action = Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: RunPipelineAction(
|
||||
controller: _controller,
|
||||
detail: detail,
|
||||
gateway: widget.gateway,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
),
|
||||
);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||
child: widget.showBack
|
||||
? Row(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (widget.showBack)
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
PipelineBackButton(onPressed: _controller.clearSelection),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [title, subtitle],
|
||||
),
|
||||
),
|
||||
Expanded(child: heading),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [title, subtitle],
|
||||
),
|
||||
else
|
||||
heading,
|
||||
const SizedBox(height: 8),
|
||||
action,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../core/error_reason.dart';
|
||||
|
||||
/// The browser client's retry wording, kept verbatim.
|
||||
const retryActionLabel = 'Retry';
|
||||
const retryDialogMessage =
|
||||
@@ -27,7 +29,7 @@ String restartDialogTitle(num runId) => 'Restart run $runId?';
|
||||
|
||||
/// The server's refusal, verbatim. Only a blank error gets a generic sentence
|
||||
/// so the prompt never claims a retry that did not happen.
|
||||
String describeRetryError(Object error) {
|
||||
final message = '$error'.trim();
|
||||
return message.isEmpty ? 'The server did not retry the run.' : message;
|
||||
}
|
||||
String describeRetryError(Object error) => describeErrorReason(
|
||||
error,
|
||||
fallback: 'The server did not retry the run.',
|
||||
);
|
||||
|
||||
@@ -74,6 +74,20 @@ class RunsRepository {
|
||||
'run_detail',
|
||||
);
|
||||
|
||||
/// Reads a run by the idempotency key of a launch whose reply was lost.
|
||||
///
|
||||
/// This is a read, not a launch: a server that never admitted the key answers
|
||||
/// without a run detail, which is reported as null rather than invented.
|
||||
Future<JsonMap?> runByRequestKey(String requestKey) async {
|
||||
final key = requestKey.trim();
|
||||
if (key.isEmpty) {
|
||||
throw const RunsRepositoryException('A launch request key is required.');
|
||||
}
|
||||
final reply = await _gateway.call('get_run', {'request_key': key});
|
||||
final detail = reply['run_detail'];
|
||||
return detail is Map ? Map<String, dynamic>.from(detail) : null;
|
||||
}
|
||||
|
||||
Future<JsonMap> startRun({
|
||||
required num pipelineId,
|
||||
required num version,
|
||||
@@ -82,7 +96,7 @@ class RunsRepository {
|
||||
required String requestKey,
|
||||
String title = '',
|
||||
String outputFormat = '',
|
||||
String notifyMode = 'auto',
|
||||
String? notifyMode,
|
||||
}) async {
|
||||
final fields = <String, dynamic>{
|
||||
'pipeline_id': pipelineId,
|
||||
@@ -93,7 +107,7 @@ class RunsRepository {
|
||||
};
|
||||
if (title.trim().isNotEmpty) fields['title'] = title.trim();
|
||||
if (outputFormat.isNotEmpty) fields['output_format'] = outputFormat;
|
||||
final mode = notifyMode.trim().toLowerCase();
|
||||
final mode = (notifyMode ?? '').trim().toLowerCase();
|
||||
if (mode == 'on' || mode == 'off') fields['notify_mode'] = mode;
|
||||
return _required(await _gateway.call('run_pipeline', fields), 'run_detail');
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ class RunsScreen extends StatefulWidget {
|
||||
required this.gateway,
|
||||
this.initialRunId,
|
||||
this.syncToken = 0,
|
||||
this.listRefreshToken = 0,
|
||||
this.onRunSelected,
|
||||
this.onBack,
|
||||
this.attentionStore = const SharedPreferencesAttentionStore(),
|
||||
@@ -34,6 +35,10 @@ class RunsScreen extends StatefulWidget {
|
||||
/// in place instead of being remounted, so its selection survives.
|
||||
final int syncToken;
|
||||
|
||||
/// Advances when a launch accepted outside this screen must be reflected by a
|
||||
/// fresh `list_runs` read. It never inserts a row of its own.
|
||||
final int listRefreshToken;
|
||||
|
||||
final ValueChanged<int>? onRunSelected;
|
||||
final VoidCallback? onBack;
|
||||
|
||||
@@ -65,6 +70,12 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
if (widget.syncToken != oldWidget.syncToken) {
|
||||
controller.resync();
|
||||
}
|
||||
// A launch accepted on another destination invalidates the list only. The
|
||||
// route change below selects the returned run separately, so this is the
|
||||
// one fresh server read that makes the new row appear.
|
||||
if (widget.listRefreshToken != oldWidget.listRefreshToken) {
|
||||
controller.load();
|
||||
}
|
||||
if (widget.initialRunId != oldWidget.initialRunId) {
|
||||
final id = widget.initialRunId;
|
||||
if (id == null) {
|
||||
|
||||
Reference in New Issue
Block a user