Merge branch 'main' into flutter/chat-cmd-stop
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
@@ -9,7 +10,10 @@ import '../core/transport/pipelines_client.dart';
|
||||
import '../shell/adaptive_shell.dart';
|
||||
import '../shell/destination.dart';
|
||||
import '../features/attention/notify/notification_controller.dart';
|
||||
import '../features/attention/notify/chat_question_notices.dart';
|
||||
import '../features/attention/notify/notification_store.dart';
|
||||
import '../features/attention/runtime/attention_controller.dart';
|
||||
import '../features/attention/runtime/attention_store.dart';
|
||||
import '../features/runs/ui/run_search_selection.dart';
|
||||
import '../features/search/domain/search_target.dart';
|
||||
import '../features/settings/settings_screen.dart';
|
||||
@@ -88,6 +92,21 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
late final NotificationController _notifications = NotificationController(
|
||||
store: const SharedPreferencesNotificationStore(),
|
||||
);
|
||||
ChatQuestionNotices? _chatQuestionNotices;
|
||||
|
||||
/// One attention surface for the app: the Runs heading's bell draws from it
|
||||
/// and the shell mirrors its count on the Runs tab, so the badge is visible
|
||||
/// from every destination. The Runs list seeds the rows when it loads; pushed
|
||||
/// `run_event` frames are folded here so the count moves while another
|
||||
/// destination is shown, and a replaced socket drops the status baseline.
|
||||
late final AttentionController _attention = AttentionController(
|
||||
store: const SharedPreferencesAttentionStore(),
|
||||
);
|
||||
StreamSubscription<JsonMap>? _attentionFrames;
|
||||
int _attentionEpoch = 0;
|
||||
|
||||
/// The count the shell's Runs tab shows; only a changed count rebuilds it.
|
||||
final ValueNotifier<int> _attentionCount = ValueNotifier<int>(0);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -115,6 +134,12 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
_cupertino = widget.cupertino ?? _platformIsCupertino;
|
||||
_notifications.onOpenRun = (id) => _delegate.goTo(AppRoute.run(id));
|
||||
unawaited(_notifications.load());
|
||||
unawaited(_attention.load());
|
||||
_attentionFrames = _session.gateway.frames
|
||||
.where((frame) => frame['type'] == 'run_event')
|
||||
.listen(_attention.observeFrame);
|
||||
_session.addListener(_attentionSessionChanged);
|
||||
_attention.addListener(_attentionChanged);
|
||||
_delegate = AppRouterDelegate(
|
||||
initial: initial,
|
||||
cupertino: _cupertino,
|
||||
@@ -126,6 +151,17 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
builder: _buildShell,
|
||||
);
|
||||
_delegate.addListener(_routeChanged);
|
||||
_chatQuestionNotices = ChatQuestionNotices(
|
||||
gateway: _session.gateway,
|
||||
canNotify: () => _notifications.canNotify,
|
||||
activeChatSessionId: () {
|
||||
final route = _delegate.shellRoute;
|
||||
return route.kind == AppRouteKind.chat ? route.chatSessionId : null;
|
||||
},
|
||||
sessionTitle: _chatSessionTitle,
|
||||
openChat: (id) => _delegate.goTo(AppRoute.chatSession(id)),
|
||||
bridge: _notifications.bridge,
|
||||
);
|
||||
_config = RouterConfig<AppRoute>(
|
||||
routeInformationParser: const AppRouteParser(),
|
||||
routerDelegate: _delegate,
|
||||
@@ -137,7 +173,13 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_session.removeListener(_attentionSessionChanged);
|
||||
unawaited(_attentionFrames?.cancel());
|
||||
_attention.removeListener(_attentionChanged);
|
||||
_attention.dispose();
|
||||
_attentionCount.dispose();
|
||||
_notifications.dispose();
|
||||
_chatQuestionNotices?.dispose();
|
||||
_delegate.removeListener(_routeChanged);
|
||||
_delegate.dispose();
|
||||
if (_ownsProvider) {
|
||||
@@ -161,6 +203,33 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
unawaited(_session.retry());
|
||||
}
|
||||
|
||||
/// A replaced socket drops the attention status baseline so the gap cannot
|
||||
/// replay a transition; the Runs list's next read reseeds the rows.
|
||||
void _attentionSessionChanged() {
|
||||
final epoch = _session.connectionEpoch;
|
||||
if (epoch == _attentionEpoch) return;
|
||||
_attentionEpoch = epoch;
|
||||
_attention.resetForReconnect();
|
||||
}
|
||||
|
||||
/// Mirrors the controller's entry count for the shell. The Runs list seeds
|
||||
/// the rows from inside its own build, and the shell sits above that layout
|
||||
/// scope, so a count that changes mid-build lands after the frame; a pushed
|
||||
/// frame arrives outside any build and applies at once.
|
||||
void _attentionChanged() {
|
||||
if (!mounted) return;
|
||||
final count = _attention.entries.length;
|
||||
if (count == _attentionCount.value) return;
|
||||
if (SchedulerBinding.instance.schedulerPhase ==
|
||||
SchedulerPhase.persistentCallbacks) {
|
||||
SchedulerBinding.instance.addPostFrameCallback(
|
||||
(_) => _attentionChanged(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
_attentionCount.value = count;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
MyApp.router(cupertino: _cupertino, routerConfig: _config);
|
||||
@@ -199,9 +268,12 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
case SearchRunTarget(:final runId):
|
||||
route = AppRoute.run(runId);
|
||||
case SearchStepTarget(:final runId, :final stage, :final visit):
|
||||
// The server records a 1-based visit number; the route's `visit` is the
|
||||
// zero-based index into the recorded timeline.
|
||||
final index = visit == null || visit < 1 ? null : visit - 1;
|
||||
route = stage == null
|
||||
? AppRoute.run(runId)
|
||||
: AppRoute.run.stage(runId, stage, visit: visit);
|
||||
: AppRoute.run.stage(runId, stage, visit: index);
|
||||
case SearchFieldTarget(:final runId, :final sequence, :final field):
|
||||
selection = RunSearchSelection(
|
||||
runId: runId,
|
||||
@@ -242,6 +314,16 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
setState(() => _pendingRunSearch = null);
|
||||
}
|
||||
|
||||
Future<String?> _chatSessionTitle(String id) async {
|
||||
final reply = await _session.gateway.call('chat_sessions');
|
||||
final sessions = reply['chat_sessions'];
|
||||
if (sessions is! List) return null;
|
||||
for (final value in sessions) {
|
||||
if (value is Map && value['id'] == id) return '${value['title'] ?? ''}';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// The Templates page above Settings. Closing it restores the same Settings
|
||||
/// screen instance, so an edited field or an open connection state survives.
|
||||
Widget _buildSchedules(BuildContext context) => SchedulesDestination(
|
||||
@@ -277,7 +359,16 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
_delegate.goTo(AppRoute.run(id));
|
||||
}
|
||||
|
||||
Widget _buildShell(BuildContext context, AppRoute route) => AdaptiveShell(
|
||||
/// The shell rebuilds its Runs tab badge from the attention count alone; the
|
||||
/// destination bodies keep their state through it.
|
||||
Widget _buildShell(BuildContext context, AppRoute route) =>
|
||||
ValueListenableBuilder<int>(
|
||||
valueListenable: _attentionCount,
|
||||
builder: (context, count, _) => _shellFor(route, count),
|
||||
);
|
||||
|
||||
Widget _shellFor(AppRoute route, int attentionCount) => AdaptiveShell(
|
||||
attentionCount: attentionCount,
|
||||
cupertino: _cupertino,
|
||||
destination: _destinationOf(route.kind),
|
||||
onDestinationSelected: (destination) =>
|
||||
@@ -289,6 +380,8 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
server: widget.server,
|
||||
refreshToken: _pipelinesRefresh,
|
||||
onRunStarted: _runStarted,
|
||||
onViewPipelineRuns: (id) =>
|
||||
_delegate.goTo(AppRoute.runsForPipeline(id)),
|
||||
initialPipelineId: route.pipelineId,
|
||||
initialVersion: route.version,
|
||||
initialStageKey: route.stageKey,
|
||||
@@ -302,13 +395,20 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
session: _session,
|
||||
server: widget.server,
|
||||
initialRunId: route.runId,
|
||||
initialPipelineId: route.pipelineId,
|
||||
initialStageKey: route.stageKey,
|
||||
initialVisit: route.visit,
|
||||
initialDecide: route.decide,
|
||||
listRefreshToken: _runsRefresh,
|
||||
notifications: _notifications,
|
||||
attention: _attention,
|
||||
onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)),
|
||||
onBack: () => _delegate.goTo(AppRoute.runs),
|
||||
onBack: (id) => _delegate.goTo(
|
||||
id == null ? AppRoute.runs : AppRoute.runsForPipeline(id),
|
||||
),
|
||||
onPipelineFilterChanged: (id) => _delegate.goTo(
|
||||
id == null ? AppRoute.runs : AppRoute.runsForPipeline(id),
|
||||
),
|
||||
),
|
||||
),
|
||||
AppDestination.chat: (_) => ChatDestination(
|
||||
|
||||
@@ -19,6 +19,7 @@ class PipelinesDestination extends StatelessWidget {
|
||||
required this.server,
|
||||
this.refreshToken = 0,
|
||||
this.onRunStarted,
|
||||
this.onViewPipelineRuns,
|
||||
this.initialPipelineId,
|
||||
this.initialVersion = 0,
|
||||
this.initialStageKey,
|
||||
@@ -34,6 +35,7 @@ class PipelinesDestination extends StatelessWidget {
|
||||
|
||||
/// Receives the run id an accepted launch named; the shell opens that route.
|
||||
final ValueChanged<int>? onRunStarted;
|
||||
final ValueChanged<int>? onViewPipelineRuns;
|
||||
|
||||
/// The pipeline and pinned version a deep link names.
|
||||
final int? initialPipelineId;
|
||||
@@ -77,6 +79,7 @@ class PipelinesDestination extends StatelessWidget {
|
||||
gateway: session.gateway,
|
||||
embedded: true,
|
||||
onRunStarted: onRunStarted,
|
||||
onViewPipelineRuns: onViewPipelineRuns,
|
||||
initialPipelineId: initialPipelineId,
|
||||
initialVersion: initialVersion,
|
||||
initialStageKey: initialStageKey,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../features/attention/notify/notification_controller.dart';
|
||||
import '../features/attention/runtime/attention_controller.dart';
|
||||
import '../features/runs/screen.dart';
|
||||
import '../ui/adaptive/host.dart';
|
||||
import 'app_session.dart';
|
||||
@@ -19,18 +20,22 @@ class RunsDestination extends StatelessWidget {
|
||||
required this.session,
|
||||
required this.server,
|
||||
this.initialRunId,
|
||||
this.initialPipelineId,
|
||||
this.initialStageKey,
|
||||
this.initialVisit,
|
||||
this.initialDecide = false,
|
||||
this.onRunSelected,
|
||||
this.onBack,
|
||||
this.onPipelineFilterChanged,
|
||||
this.listRefreshToken = 0,
|
||||
this.notifications,
|
||||
this.attention,
|
||||
});
|
||||
|
||||
final AppSession session;
|
||||
final ServerEndpoint server;
|
||||
final int? initialRunId;
|
||||
final int? initialPipelineId;
|
||||
|
||||
/// The stage key and optional visit a `/runs/:id/stage/:key[?visit=N]` route
|
||||
/// names. They reach the detail only through [RunsScreen]; the destination
|
||||
@@ -43,7 +48,8 @@ class RunsDestination extends StatelessWidget {
|
||||
final bool initialDecide;
|
||||
|
||||
final ValueChanged<int>? onRunSelected;
|
||||
final VoidCallback? onBack;
|
||||
final ValueChanged<int?>? onBack;
|
||||
final ValueChanged<int?>? onPipelineFilterChanged;
|
||||
|
||||
/// Advances when a launch was accepted elsewhere. The mounted Runs screen
|
||||
/// re-reads its list once; no row is inserted locally.
|
||||
@@ -52,6 +58,9 @@ class RunsDestination extends StatelessWidget {
|
||||
/// The app-level notification capability shared with Settings.
|
||||
final NotificationController? notifications;
|
||||
|
||||
/// The app-level attention controller the shell's Runs tab badge reads.
|
||||
final AttentionController? attention;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
animation: session,
|
||||
@@ -87,13 +96,16 @@ class RunsDestination extends StatelessWidget {
|
||||
Widget _runsScreen() => RunsScreen(
|
||||
gateway: session.gateway,
|
||||
initialRunId: initialRunId,
|
||||
initialPipelineId: initialPipelineId,
|
||||
initialStageKey: initialStageKey,
|
||||
initialVisit: initialVisit,
|
||||
initialDecide: initialDecide,
|
||||
syncToken: session.connectionEpoch,
|
||||
listRefreshToken: listRefreshToken,
|
||||
notifications: notifications,
|
||||
attention: attention,
|
||||
onRunSelected: onRunSelected,
|
||||
onBack: onBack,
|
||||
onPipelineFilterChanged: onPipelineFilterChanged,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'notification_bridge.dart';
|
||||
import 'notification_models.dart';
|
||||
|
||||
/// Delivers live unanswered chat questions through the shared notification
|
||||
/// capability, without coupling chat event folding to platform notifications.
|
||||
class ChatQuestionNotices {
|
||||
ChatQuestionNotices({
|
||||
required ApiGateway gateway,
|
||||
required this.canNotify,
|
||||
required this.activeChatSessionId,
|
||||
required this.sessionTitle,
|
||||
required this.openChat,
|
||||
required this.bridge,
|
||||
}) {
|
||||
_frames = gateway.frames.listen(_onEnvelope);
|
||||
}
|
||||
|
||||
final bool Function() canNotify;
|
||||
final String? Function() activeChatSessionId;
|
||||
final Future<String?> Function(String sessionId) sessionTitle;
|
||||
final void Function(String sessionId) openChat;
|
||||
final NotificationBridge bridge;
|
||||
late final StreamSubscription<JsonMap> _frames;
|
||||
bool _disposed = false;
|
||||
|
||||
void _onEnvelope(JsonMap envelope) {
|
||||
if (envelope['type'] != 'chat_event') return;
|
||||
final event = envelope['chat_event'];
|
||||
if (event is! Map || event['kind'] != 'form') return;
|
||||
final sessionId = event['session_id'];
|
||||
final form = event['form'];
|
||||
if (sessionId is! String || sessionId.isEmpty ||
|
||||
form is! Map || form['kind'] != 'question' ||
|
||||
form['resolved'] == true || form['cancelled'] == true ||
|
||||
form['id'] == null || !canNotify() ||
|
||||
activeChatSessionId() == sessionId) {
|
||||
return;
|
||||
}
|
||||
unawaited(_show(sessionId, Map<String, dynamic>.from(form)));
|
||||
}
|
||||
|
||||
Future<void> _show(String sessionId, JsonMap form) async {
|
||||
String? session;
|
||||
try {
|
||||
session = await sessionTitle(sessionId);
|
||||
} catch (_) {
|
||||
// An unavailable session list is equivalent to an unknown session title.
|
||||
}
|
||||
if (_disposed || !canNotify() || activeChatSessionId() == sessionId) return;
|
||||
final title = (session ?? '').trim();
|
||||
try {
|
||||
bridge.show(
|
||||
NotificationMessage(
|
||||
chatSessionId: sessionId,
|
||||
title: '${title.isEmpty ? 'Chat' : title} needs your answer',
|
||||
body: '${form['title'] ?? 'The agent asked a question.'}',
|
||||
tag: 'chat-question:${form['id']}',
|
||||
),
|
||||
onTap: () => openChat(sessionId),
|
||||
);
|
||||
} catch (_) {
|
||||
// Notification delivery must not interfere with the in-page question.
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
unawaited(_frames.cancel());
|
||||
}
|
||||
}
|
||||
@@ -156,13 +156,15 @@ String notificationAlertBody(AttentionEntry entry) {
|
||||
/// the stable identity used as the browser's coalescing tag.
|
||||
class NotificationMessage {
|
||||
const NotificationMessage({
|
||||
required this.runId,
|
||||
this.runId,
|
||||
this.chatSessionId,
|
||||
required this.title,
|
||||
required this.body,
|
||||
required this.tag,
|
||||
});
|
||||
|
||||
final int runId;
|
||||
final int? runId;
|
||||
final String? chatSessionId;
|
||||
final String title;
|
||||
final String body;
|
||||
final String tag;
|
||||
|
||||
@@ -28,6 +28,7 @@ class NeedsYouRunsHeading extends StatefulWidget {
|
||||
this.now,
|
||||
this.cupertino,
|
||||
this.notifications,
|
||||
this.attention,
|
||||
});
|
||||
|
||||
/// The run summaries the Runs destination already holds.
|
||||
@@ -55,23 +56,36 @@ class NeedsYouRunsHeading extends StatefulWidget {
|
||||
/// the bell, so no store or platform bridge is touched there.
|
||||
final NotificationController? notifications;
|
||||
|
||||
/// The app's shared attention controller, so the shell can mirror the same
|
||||
/// count on the Runs tab. The heading seeds it with [rows]; its owner folds
|
||||
/// [frames] and resets it on reconnect. Absent, the heading owns a private
|
||||
/// controller fed from [frames], which fixtures and the list tests rely on.
|
||||
final AttentionController? attention;
|
||||
|
||||
@override
|
||||
State<NeedsYouRunsHeading> createState() => _NeedsYouRunsHeadingState();
|
||||
}
|
||||
|
||||
class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
||||
late final AttentionController _attention = AttentionController(
|
||||
store: widget.store,
|
||||
now: widget.now,
|
||||
);
|
||||
late final AttentionController _attention =
|
||||
widget.attention ??
|
||||
AttentionController(store: widget.store, now: widget.now);
|
||||
StreamSubscription<JsonMap>? _frames;
|
||||
|
||||
bool get _ownsController => widget.attention == null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_attention.seedRows(widget.rows);
|
||||
unawaited(_attention.load());
|
||||
_listen();
|
||||
if (_ownsController) {
|
||||
unawaited(_attention.load());
|
||||
_listen();
|
||||
} else {
|
||||
// The owner folds frames; publishing after every change it makes is the
|
||||
// same idempotent call the private path makes after each frame.
|
||||
_attention.addListener(_publish);
|
||||
}
|
||||
final notifications = widget.notifications;
|
||||
if (notifications != null) {
|
||||
notifications.onOpenRun = _openRunById;
|
||||
@@ -115,7 +129,7 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
||||
@override
|
||||
void didUpdateWidget(covariant NeedsYouRunsHeading oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!identical(oldWidget.frames, widget.frames)) {
|
||||
if (_ownsController && !identical(oldWidget.frames, widget.frames)) {
|
||||
unawaited(_frames?.cancel());
|
||||
_frames = null;
|
||||
_listen();
|
||||
@@ -135,7 +149,11 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
||||
@override
|
||||
void dispose() {
|
||||
unawaited(_frames?.cancel());
|
||||
_attention.dispose();
|
||||
if (_ownsController) {
|
||||
_attention.dispose();
|
||||
} else {
|
||||
_attention.removeListener(_publish);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../../../core/api_gateway.dart';
|
||||
import '../domain/chat_attachment_draft.dart';
|
||||
import '../domain/chat_attachment_picker.dart';
|
||||
import '../domain/chat_attachment_wire.dart';
|
||||
import '../domain/chat_clipboard_paste.dart';
|
||||
import '../domain/chat_commands.dart';
|
||||
import '../ui/sessions/chat_adaptive.dart';
|
||||
import 'chat_command_palette.dart';
|
||||
@@ -50,13 +51,16 @@ const String chatQueuedNotice =
|
||||
/// their names are shown with the host's own remove action and the bounded
|
||||
/// draft owns every refusal. Send carries the chips as the landed wire parts,
|
||||
/// keeps them until the prompt is accepted and leaves them in place on a
|
||||
/// refusal; paste is not wired.
|
||||
/// refusal. Pasting files takes the same draft path as the picker; pasting text
|
||||
/// stays with the host field, so its caret, selection and draft behave exactly
|
||||
/// as typing does.
|
||||
class ChatComposerBar extends StatefulWidget {
|
||||
const ChatComposerBar({
|
||||
super.key,
|
||||
required this.composer,
|
||||
required this.running,
|
||||
this.picker,
|
||||
this.paste,
|
||||
});
|
||||
|
||||
final ChatComposerController composer;
|
||||
@@ -67,6 +71,9 @@ class ChatComposerBar extends StatefulWidget {
|
||||
/// The host picker seam; production uses [hostChatAttachmentPicker].
|
||||
final ChatAttachmentPicker? picker;
|
||||
|
||||
/// The host clipboard-file seam; production uses [hostChatClipboardPaste].
|
||||
final ChatClipboardPaste? paste;
|
||||
|
||||
@override
|
||||
State<ChatComposerBar> createState() => _ChatComposerBarState();
|
||||
}
|
||||
@@ -99,11 +106,15 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
bool _commandFailed = false;
|
||||
|
||||
ChatAttachmentPicker get _picker => widget.picker ?? hostChatAttachmentPicker;
|
||||
ChatClipboardPaste get _paste => widget.paste ?? hostChatClipboardPaste;
|
||||
|
||||
ChatPasteUnsubscribe? _stopPaste;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.composer.addListener(_syncDraft);
|
||||
_listenForPaste();
|
||||
unawaited(widget.composer.loadDraft());
|
||||
}
|
||||
|
||||
@@ -115,6 +126,42 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
widget.composer.addListener(_syncDraft);
|
||||
_syncDraft();
|
||||
}
|
||||
if (oldWidget.paste != widget.paste) {
|
||||
_stopListeningForPaste();
|
||||
_listenForPaste();
|
||||
}
|
||||
}
|
||||
|
||||
void _listenForPaste() {
|
||||
if (!_paste.isSupported) return;
|
||||
_stopPaste = _paste.listen(
|
||||
onFiles: _onPastedFiles,
|
||||
canAccept: _canAcceptPaste,
|
||||
onError: _onPasteError,
|
||||
);
|
||||
}
|
||||
|
||||
void _stopListeningForPaste() {
|
||||
final stop = _stopPaste;
|
||||
_stopPaste = null;
|
||||
stop?.call();
|
||||
}
|
||||
|
||||
/// A pasted file is taken only while this composer owns the field and no
|
||||
/// prompt is in flight, which is the same window as the attach control. The
|
||||
/// host checks this before it suppresses the paste's default behaviour, so a
|
||||
/// paste elsewhere is never swallowed.
|
||||
bool _canAcceptPaste() =>
|
||||
mounted && _focus.hasFocus && !widget.composer.sending;
|
||||
|
||||
void _onPastedFiles(List<ChatPickedFile> files) {
|
||||
if (!mounted) return;
|
||||
_addFiles(files);
|
||||
}
|
||||
|
||||
void _onPasteError(Object error) {
|
||||
if (!mounted) return;
|
||||
setState(() => _attachmentError = '$error');
|
||||
}
|
||||
|
||||
/// External draft changes (saved-draft load, send clear, refusal restore)
|
||||
@@ -355,12 +402,19 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
return;
|
||||
}
|
||||
if (!mounted || files == null) return;
|
||||
final picked = files;
|
||||
_addFiles(files);
|
||||
}
|
||||
|
||||
/// Adds each file through the landed attachment draft. A refusal keeps every
|
||||
/// attachment already in the draft and shows the draft's own words; the
|
||||
/// refused file's bytes are never retained. Picking and pasting share this
|
||||
/// path so both apply the same name and 1 MiB decisions.
|
||||
void _addFiles(List<ChatPickedFile> files) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_attachmentError = null;
|
||||
for (final file in picked) {
|
||||
final attachment = file.attachment;
|
||||
final refusal = _attachments.add(attachment);
|
||||
for (final file in files) {
|
||||
final refusal = _attachments.add(file.attachment);
|
||||
if (refusal != null) {
|
||||
_attachmentError = refusal.message;
|
||||
} else {
|
||||
@@ -410,6 +464,7 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_stopListeningForPaste();
|
||||
widget.composer.removeListener(_syncDraft);
|
||||
_text.dispose();
|
||||
_focus.dispose();
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'chat_attachment_picker.dart';
|
||||
import 'chat_clipboard_paste_stub.dart'
|
||||
if (dart.library.js_interop) 'chat_clipboard_paste_web.dart'
|
||||
as impl;
|
||||
|
||||
/// Receives the files one paste carried, in clipboard order.
|
||||
typedef ChatPasteFiles = void Function(List<ChatPickedFile> files);
|
||||
|
||||
/// Whether the composer would take a pasted file right now. The host asks this
|
||||
/// before it suppresses the paste's default behaviour.
|
||||
typedef ChatPasteCanAccept = bool Function();
|
||||
|
||||
/// Reports a clipboard file whose bytes could not be read.
|
||||
typedef ChatPasteFailed = void Function(Object error);
|
||||
|
||||
/// Stops observing paste events for one composer.
|
||||
typedef ChatPasteUnsubscribe = void Function();
|
||||
|
||||
/// Registers [onFiles] for file pastes the composer may take and returns the
|
||||
/// cancellation for that registration.
|
||||
///
|
||||
/// A text-only paste is never reported: it stays with the host field, so caret,
|
||||
/// selection and the draft update exactly as typing does.
|
||||
typedef ChatPasteSubscribe =
|
||||
ChatPasteUnsubscribe Function(
|
||||
ChatPasteFiles onFiles,
|
||||
ChatPasteCanAccept canAccept,
|
||||
ChatPasteFailed onError,
|
||||
);
|
||||
|
||||
/// The clipboard seam for one host.
|
||||
///
|
||||
/// The web host observes the browser's own `paste` event. A paste carrying at
|
||||
/// least one file is consumed ([ChatPasteCanAccept] permitting) and handed to
|
||||
/// the composer as [ChatPickedFile] rows, so the landed attachment draft owns
|
||||
/// every size decision and refusal. A clipboard file the browser recorded
|
||||
/// without a name takes the web client's pasted name. A host without
|
||||
/// clipboard-file paste constructs [ChatClipboardPaste.unsupported] and the
|
||||
/// composer simply keeps its native text behaviour. Tests inject a fake
|
||||
/// [subscribe].
|
||||
class ChatClipboardPaste {
|
||||
const ChatClipboardPaste({required ChatPasteSubscribe this.subscribe})
|
||||
: unsupportedMessage = null;
|
||||
|
||||
const ChatClipboardPaste.unsupported(String message)
|
||||
: subscribe = null,
|
||||
unsupportedMessage = message;
|
||||
|
||||
/// The host's paste listener, or null when this host cannot observe files.
|
||||
final ChatPasteSubscribe? subscribe;
|
||||
|
||||
/// Why this host cannot observe pasted files, when [subscribe] is null.
|
||||
final String? unsupportedMessage;
|
||||
|
||||
bool get isSupported => subscribe != null;
|
||||
|
||||
/// Starts observing the host's paste event. A host without the capability
|
||||
/// throws [UnsupportedError] with [unsupportedMessage].
|
||||
ChatPasteUnsubscribe listen({
|
||||
required ChatPasteFiles onFiles,
|
||||
required ChatPasteCanAccept canAccept,
|
||||
required ChatPasteFailed onError,
|
||||
}) {
|
||||
final subscribe = this.subscribe;
|
||||
if (subscribe == null) throw UnsupportedError(unsupportedMessage!);
|
||||
return subscribe(onFiles, canAccept, onError);
|
||||
}
|
||||
}
|
||||
|
||||
/// The web composer's recorded name for a clipboard file that arrived without
|
||||
/// one: the MIME subtype becomes the extension, with the web client's `jpeg`
|
||||
/// to `jpg` mapping and `bin` fallback.
|
||||
String chatPastedAttachmentName(String mime, int sequence) {
|
||||
final subtype = mime.split('/').last.toLowerCase();
|
||||
final extension = subtype == 'jpeg'
|
||||
? 'jpg'
|
||||
: subtype.replaceAll(RegExp('[^a-z0-9]'), '');
|
||||
return 'pasted-$sequence.${extension.isEmpty ? 'bin' : extension}';
|
||||
}
|
||||
|
||||
/// The clipboard seam for the running host.
|
||||
ChatClipboardPaste get hostChatClipboardPaste => impl.hostChatClipboardPaste;
|
||||
@@ -0,0 +1,12 @@
|
||||
import 'chat_clipboard_paste.dart';
|
||||
|
||||
/// Native fallback for clipboard-file paste.
|
||||
///
|
||||
/// The composer keeps the host field's own text paste on every platform; this
|
||||
/// slice observes clipboard files on web only. A non-web host reports that
|
||||
/// missing capability rather than pretending no paste happened.
|
||||
const String chatClipboardPasteUnsupportedMessage =
|
||||
'Pasting files is not supported on this platform yet.';
|
||||
|
||||
ChatClipboardPaste get hostChatClipboardPaste =>
|
||||
const ChatClipboardPaste.unsupported(chatClipboardPasteUnsupportedMessage);
|
||||
@@ -0,0 +1,126 @@
|
||||
import 'dart:async';
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
import 'chat_attachment_picker.dart';
|
||||
import 'chat_clipboard_paste.dart';
|
||||
|
||||
/// The browser's clipboard-file paste, observed at the document once per
|
||||
/// composer.
|
||||
///
|
||||
/// Declared with `dart:js_interop` rather than `package:web`, so the same source
|
||||
/// compiles for the JavaScript and WebAssembly web targets. A paste carrying no
|
||||
/// file is left completely alone: the field's own text paste keeps its caret,
|
||||
/// selection and draft behaviour. Only a paste with files the composer will
|
||||
/// accept is consumed, and its bytes are read before the files join the
|
||||
/// composer's attachment draft.
|
||||
@JS('document')
|
||||
external _Document get _document;
|
||||
|
||||
extension type _Document._(JSObject _) implements JSObject {
|
||||
external void addEventListener(JSString type, JSFunction listener);
|
||||
|
||||
external void removeEventListener(JSString type, JSFunction listener);
|
||||
}
|
||||
|
||||
extension type _ClipboardEvent._(JSObject _) implements JSObject {
|
||||
external bool get defaultPrevented;
|
||||
|
||||
external _ClipboardData? get clipboardData;
|
||||
|
||||
external void preventDefault();
|
||||
}
|
||||
|
||||
extension type _ClipboardData._(JSObject _) implements JSObject {
|
||||
external _DataTransferItemList get items;
|
||||
}
|
||||
|
||||
extension type _DataTransferItemList._(JSObject _) implements JSObject {
|
||||
external int get length;
|
||||
}
|
||||
|
||||
extension type _DataTransferItem._(JSObject _) implements JSObject {
|
||||
external JSString get kind;
|
||||
|
||||
external _ClipboardFile? getAsFile();
|
||||
}
|
||||
|
||||
extension type _ClipboardFile._(JSObject _) implements JSObject {
|
||||
external JSString get name;
|
||||
|
||||
external JSString get type;
|
||||
|
||||
external JSPromise<JSArrayBuffer> arrayBuffer();
|
||||
}
|
||||
|
||||
ChatClipboardPaste get hostChatClipboardPaste =>
|
||||
const ChatClipboardPaste(subscribe: _subscribeToPaste);
|
||||
|
||||
ChatPasteUnsubscribe _subscribeToPaste(
|
||||
ChatPasteFiles onFiles,
|
||||
ChatPasteCanAccept canAccept,
|
||||
ChatPasteFailed onError,
|
||||
) {
|
||||
var sequence = 0;
|
||||
|
||||
void handlePaste(JSObject raw) {
|
||||
final event = _ClipboardEvent._(raw);
|
||||
if (event.defaultPrevented) return;
|
||||
final data = event.clipboardData;
|
||||
if (data == null) return;
|
||||
final items = data.items;
|
||||
final files = <_ClipboardFile>[];
|
||||
for (var index = 0; index < items.length; index += 1) {
|
||||
// DataTransferItemList is indexed, not a method list like FileList.
|
||||
final raw = items.getProperty<JSObject?>('$index'.toJS);
|
||||
if (raw == null) continue;
|
||||
final item = _DataTransferItem._(raw);
|
||||
if (item.kind.toDart != 'file') continue;
|
||||
final file = item.getAsFile();
|
||||
if (file != null) files.add(file);
|
||||
}
|
||||
// A text-only clipboard keeps the field's native paste untouched.
|
||||
if (files.isEmpty || !canAccept()) return;
|
||||
event.preventDefault();
|
||||
unawaited(_readFiles(files, onFiles, onError, () => ++sequence));
|
||||
}
|
||||
|
||||
final listener = handlePaste.toJS;
|
||||
_document.addEventListener('paste'.toJS, listener);
|
||||
return () => _document.removeEventListener('paste'.toJS, listener);
|
||||
}
|
||||
|
||||
Future<void> _readFiles(
|
||||
List<_ClipboardFile> files,
|
||||
ChatPasteFiles onFiles,
|
||||
ChatPasteFailed onError,
|
||||
int Function() nextSequence,
|
||||
) async {
|
||||
final pasted = <ChatPickedFile>[];
|
||||
final failures = <Object>[];
|
||||
for (final file in files) {
|
||||
try {
|
||||
final buffer = await file.arrayBuffer().toDart;
|
||||
final mime = file.type.toDart;
|
||||
final recorded = file.name.toDart.trim();
|
||||
pasted.add(
|
||||
ChatPickedFile(
|
||||
name: recorded.isEmpty
|
||||
? chatPastedAttachmentName(mime, nextSequence())
|
||||
: recorded,
|
||||
mime: mime,
|
||||
bytes: buffer.toDart.asUint8List(),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
// One unreadable clipboard file must not hide the others.
|
||||
failures.add(error);
|
||||
}
|
||||
}
|
||||
// Deliver the readable files first: the composer's add clears an older
|
||||
// error, so a partial failure is reported after its kept files.
|
||||
if (pasted.isNotEmpty) onFiles(pasted);
|
||||
for (final failure in failures) {
|
||||
onError(failure);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,18 @@ enum RunNotifyMode {
|
||||
};
|
||||
}
|
||||
|
||||
/// Optional report requirement requested for a manually started run.
|
||||
enum RunOutputFormat {
|
||||
none('No report requirement', ''),
|
||||
html('HTML report', 'html'),
|
||||
markdown('Markdown report', 'markdown');
|
||||
|
||||
const RunOutputFormat(this.label, this.wireValue);
|
||||
|
||||
final String label;
|
||||
final String wireValue;
|
||||
}
|
||||
|
||||
/// One confirmed launch intent: the pinned pipeline identity, the operator's
|
||||
/// fields and the idempotency key that belongs to them.
|
||||
///
|
||||
@@ -34,6 +46,7 @@ class RunPipelineIntent {
|
||||
required this.prompt,
|
||||
required this.workspace,
|
||||
required this.notifyMode,
|
||||
this.outputFormat = RunOutputFormat.none,
|
||||
required this.requestKey,
|
||||
});
|
||||
|
||||
@@ -42,6 +55,7 @@ class RunPipelineIntent {
|
||||
final String prompt;
|
||||
final String workspace;
|
||||
final RunNotifyMode notifyMode;
|
||||
final RunOutputFormat outputFormat;
|
||||
final String requestKey;
|
||||
|
||||
/// The same key is only ever reused for the same pinned definition.
|
||||
|
||||
@@ -28,6 +28,7 @@ class PipelinesScreen extends StatefulWidget {
|
||||
this.embedded = false,
|
||||
this.syncToken = 0,
|
||||
this.onRunStarted,
|
||||
this.onViewPipelineRuns,
|
||||
this.initialPipelineId,
|
||||
this.initialVersion = 0,
|
||||
this.initialStageKey,
|
||||
@@ -45,6 +46,7 @@ class PipelinesScreen extends StatefulWidget {
|
||||
/// 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;
|
||||
final ValueChanged<int>? onViewPipelineRuns;
|
||||
|
||||
/// The pipeline a deep link names, opened after the list read starts.
|
||||
final int? initialPipelineId;
|
||||
@@ -170,6 +172,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
gateway: widget.gateway,
|
||||
showBack: true,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
onViewPipelineRuns: widget.onViewPipelineRuns,
|
||||
stageKey: stageKey,
|
||||
stagePipelineId: widget.initialPipelineId,
|
||||
stageVersion: widget.initialVersion,
|
||||
@@ -192,6 +195,7 @@ class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
gateway: widget.gateway,
|
||||
showBack: false,
|
||||
onRunStarted: widget.onRunStarted,
|
||||
onViewPipelineRuns: widget.onViewPipelineRuns,
|
||||
stageKey: stageKey,
|
||||
stagePipelineId: widget.initialPipelineId,
|
||||
stageVersion: widget.initialVersion,
|
||||
|
||||
@@ -51,6 +51,7 @@ class _RunPipelineActionState extends State<RunPipelineAction> {
|
||||
await showRunPipelineDialog(
|
||||
context: context,
|
||||
detail: widget.detail,
|
||||
gateway: widget.gateway,
|
||||
pending: widget.controller.pendingRunFor(_pipelineId, _version),
|
||||
onSubmit: _submit,
|
||||
onPendingChanged: (intent) {
|
||||
@@ -102,6 +103,7 @@ class _RunPipelineActionState extends State<RunPipelineAction> {
|
||||
workspace: intent.workspace,
|
||||
requestKey: intent.requestKey,
|
||||
notifyMode: intent.notifyMode.wireValue,
|
||||
outputFormat: intent.outputFormat.wireValue,
|
||||
);
|
||||
final accepted = _accept(run);
|
||||
if (accepted is RunPipelineAccepted) return accepted;
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../settings/settings_store.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../run_pipeline_intent.dart';
|
||||
@@ -16,6 +17,7 @@ import 'run_pipeline_wording.dart';
|
||||
Future<void> showRunPipelineDialog({
|
||||
required BuildContext context,
|
||||
required PipelineDetail detail,
|
||||
required ApiGateway gateway,
|
||||
required RunPipelineIntent? pending,
|
||||
required Future<RunPipelineOutcome> Function(RunPipelineIntent intent)
|
||||
onSubmit,
|
||||
@@ -24,6 +26,7 @@ Future<void> showRunPipelineDialog({
|
||||
}) {
|
||||
final dialog = _RunPipelineDialog(
|
||||
detail: detail,
|
||||
gateway: gateway,
|
||||
pending: pending,
|
||||
cupertino: usesCupertinoHost(context),
|
||||
onSubmit: onSubmit,
|
||||
@@ -46,6 +49,7 @@ Future<void> showRunPipelineDialog({
|
||||
class _RunPipelineDialog extends StatefulWidget {
|
||||
const _RunPipelineDialog({
|
||||
required this.detail,
|
||||
required this.gateway,
|
||||
required this.pending,
|
||||
required this.cupertino,
|
||||
required this.onSubmit,
|
||||
@@ -54,6 +58,7 @@ class _RunPipelineDialog extends StatefulWidget {
|
||||
});
|
||||
|
||||
final PipelineDetail detail;
|
||||
final ApiGateway gateway;
|
||||
final RunPipelineIntent? pending;
|
||||
final bool cupertino;
|
||||
final Future<RunPipelineOutcome> Function(RunPipelineIntent intent) onSubmit;
|
||||
@@ -68,8 +73,11 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
late final TextEditingController _prompt;
|
||||
late final TextEditingController _workspace;
|
||||
late RunNotifyMode _notify;
|
||||
late RunOutputFormat _outputFormat;
|
||||
late RunPipelineIntent? _intent;
|
||||
bool _sending = false;
|
||||
bool _directoriesLoading = true;
|
||||
List<String> _directories = const [];
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
@@ -83,11 +91,49 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
: null;
|
||||
_intent = restored;
|
||||
_notify = restored?.notifyMode ?? RunNotifyMode.pipelineDefault;
|
||||
_outputFormat = restored?.outputFormat ?? RunOutputFormat.none;
|
||||
_prompt = TextEditingController(text: restored?.prompt ?? '');
|
||||
_workspace = TextEditingController(text: restored?.workspace ?? '');
|
||||
_error = restored == null ? null : runPipelineUnknownAdmission;
|
||||
_loadDirectories(restored);
|
||||
}
|
||||
|
||||
Future<void> _loadDirectories(RunPipelineIntent? restored) async {
|
||||
final savedWorkspace = const SharedPreferencesSettingsStore().load().then(
|
||||
(settings) => settings.workspace,
|
||||
);
|
||||
try {
|
||||
final reply = await _gateway.call('chat_directories');
|
||||
final value = reply['chat_directories'];
|
||||
final directories = value is List
|
||||
? value.whereType<String>().toList()
|
||||
: <String>[];
|
||||
final saved = await savedWorkspace;
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_directories = directories
|
||||
.where((path) => path.startsWith('/'))
|
||||
.toList();
|
||||
if (_workspace.text.isEmpty) {
|
||||
_workspace.text = saved.startsWith('/')
|
||||
? saved
|
||||
: _directories.isEmpty
|
||||
? ''
|
||||
: _directories.first;
|
||||
}
|
||||
_directoriesLoading = false;
|
||||
});
|
||||
} catch (error) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_directoriesLoading = false;
|
||||
_error = '$error';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ApiGateway get _gateway => widget.gateway;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_prompt.dispose();
|
||||
@@ -122,6 +168,7 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
prompt: prompt,
|
||||
workspace: workspace.trim(),
|
||||
notifyMode: _notify,
|
||||
outputFormat: _outputFormat,
|
||||
requestKey: newRunPipelineRequestKey(
|
||||
widget.detail.id,
|
||||
widget.detail.resolvedVersion,
|
||||
@@ -213,10 +260,21 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
RunPipelineFields(
|
||||
prompt: _prompt,
|
||||
workspace: _workspace,
|
||||
directories: _directories,
|
||||
cupertino: widget.cupertino,
|
||||
onChooseDirectory: _chooseDirectory,
|
||||
notifyMode: _notify,
|
||||
outputFormat: _outputFormat,
|
||||
locked: _locked,
|
||||
onNotifyChanged: (mode) => setState(() => _notify = mode),
|
||||
onOutputFormatChanged: (format) =>
|
||||
setState(() => _outputFormat = format),
|
||||
),
|
||||
if (_directoriesLoading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(runPipelineDirectoriesLoading),
|
||||
),
|
||||
if (_error case final error?)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
@@ -228,4 +286,8 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _chooseDirectory(String directory) {
|
||||
_workspace.text = directory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,26 @@ class RunPipelineFields extends StatelessWidget {
|
||||
super.key,
|
||||
required this.prompt,
|
||||
required this.workspace,
|
||||
required this.directories,
|
||||
required this.cupertino,
|
||||
required this.onChooseDirectory,
|
||||
required this.notifyMode,
|
||||
required this.outputFormat,
|
||||
required this.locked,
|
||||
required this.onNotifyChanged,
|
||||
required this.onOutputFormatChanged,
|
||||
});
|
||||
|
||||
final TextEditingController prompt;
|
||||
final TextEditingController workspace;
|
||||
final List<String> directories;
|
||||
final bool cupertino;
|
||||
final ValueChanged<String> onChooseDirectory;
|
||||
final RunNotifyMode notifyMode;
|
||||
final RunOutputFormat outputFormat;
|
||||
final bool locked;
|
||||
final ValueChanged<RunNotifyMode> onNotifyChanged;
|
||||
final ValueChanged<RunOutputFormat> onOutputFormatChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -41,6 +51,10 @@ class RunPipelineFields extends StatelessWidget {
|
||||
const SizedBox(height: 12),
|
||||
_FieldLabel(runPipelineNotifyLabel, cupertino: cupertino),
|
||||
_notifyField(context, cupertino),
|
||||
const SizedBox(height: 12),
|
||||
_FieldLabel(runPipelineOutputFormatLabel, cupertino: cupertino),
|
||||
_outputFormatField(context, cupertino),
|
||||
_helper(context, runPipelineOutputFormatHelper, cupertino),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -77,18 +91,51 @@ class RunPipelineFields extends StatelessWidget {
|
||||
}
|
||||
|
||||
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),
|
||||
);
|
||||
}
|
||||
final field = cupertino
|
||||
? _cupertinoWorkspace(context)
|
||||
: _materialWorkspace();
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: field),
|
||||
if (directories.isNotEmpty)
|
||||
cupertino
|
||||
? CupertinoButton(
|
||||
key: runPipelineWorkspaceSuggestionsKey,
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: locked
|
||||
? null
|
||||
: () => _chooseCupertinoDirectory(context),
|
||||
child: const Icon(CupertinoIcons.folder),
|
||||
)
|
||||
: PopupMenuButton<String>(
|
||||
key: runPipelineWorkspaceSuggestionsKey,
|
||||
tooltip: runPipelineWorkspaceLabel,
|
||||
enabled: !locked,
|
||||
onSelected: onChooseDirectory,
|
||||
itemBuilder: (_) => [
|
||||
for (final path in directories)
|
||||
PopupMenuItem(value: path, child: Text(path)),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoWorkspace(BuildContext context) {
|
||||
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),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _materialWorkspace() {
|
||||
return TextField(
|
||||
key: runPipelineWorkspaceKey,
|
||||
controller: workspace,
|
||||
@@ -101,6 +148,27 @@ class RunPipelineFields extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _chooseCupertinoDirectory(BuildContext context) async {
|
||||
final chosen = await showCupertinoModalPopup<String>(
|
||||
context: context,
|
||||
builder: (sheetContext) => CupertinoActionSheet(
|
||||
title: const Text(runPipelineWorkspaceLabel),
|
||||
actions: [
|
||||
for (final path in directories)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.of(sheetContext).pop(path),
|
||||
child: Text(path),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.of(sheetContext).pop(),
|
||||
child: const Text(runPipelineCancelLabel),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (chosen != null) onChooseDirectory(chosen);
|
||||
}
|
||||
|
||||
Widget _notifyField(BuildContext context, bool cupertino) {
|
||||
if (cupertino) {
|
||||
return CupertinoButton(
|
||||
@@ -156,10 +224,67 @@ class RunPipelineFields extends StatelessWidget {
|
||||
if (chosen != null) onNotifyChanged(chosen);
|
||||
}
|
||||
|
||||
Widget _outputFormatField(BuildContext context, bool cupertino) {
|
||||
if (cupertino) {
|
||||
return CupertinoButton(
|
||||
key: runPipelineOutputFormatKey,
|
||||
padding: EdgeInsets.zero,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
onPressed: locked ? null : () => _chooseOutputFormat(context),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Flexible(child: Text(outputFormat.label)),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(CupertinoIcons.chevron_down, size: 14),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return DropdownButtonFormField<RunOutputFormat>(
|
||||
key: runPipelineOutputFormatKey,
|
||||
initialValue: outputFormat,
|
||||
decoration: const InputDecoration(border: OutlineInputBorder()),
|
||||
items: [
|
||||
for (final format in RunOutputFormat.values)
|
||||
DropdownMenuItem(value: format, child: Text(format.label)),
|
||||
],
|
||||
onChanged: locked
|
||||
? null
|
||||
: (format) {
|
||||
if (format != null) onOutputFormatChanged(format);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _chooseOutputFormat(BuildContext context) async {
|
||||
final chosen = await showCupertinoModalPopup<RunOutputFormat>(
|
||||
context: context,
|
||||
builder: (sheetContext) => CupertinoActionSheet(
|
||||
title: const Text(runPipelineOutputFormatLabel),
|
||||
actions: [
|
||||
for (final format in RunOutputFormat.values)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.of(sheetContext).pop(format),
|
||||
child: Text(format.label),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(sheetContext).pop(),
|
||||
child: const Text(runPipelineCancelLabel),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (chosen != null) onOutputFormatChanged(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));
|
||||
return TextStyle(
|
||||
color: CupertinoColors.placeholderText.resolveFrom(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _helper(BuildContext context, String text, bool cupertino) {
|
||||
|
||||
@@ -12,7 +12,14 @@ 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 runPipelineDirectoriesLoading = 'Loading directories…';
|
||||
const runPipelineWorkspaceSuggestionsKey = ValueKey<String>(
|
||||
'run-pipeline-workspace-suggestions',
|
||||
);
|
||||
const runPipelineNotifyLabel = 'Notifications for this run';
|
||||
const runPipelineOutputFormatLabel = 'Report format';
|
||||
const runPipelineOutputFormatHelper =
|
||||
'Requires a nonempty server-written report before success. Structure only; facts are not verified.';
|
||||
const runPipelineCancelLabel = 'Cancel';
|
||||
const runPipelineConfirmLabel = 'Run';
|
||||
const runPipelineSendingLabel = 'Starting…';
|
||||
@@ -37,13 +44,12 @@ 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 runPipelineOutputFormatKey = ValueKey<String>('run-pipeline-output-format');
|
||||
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.',
|
||||
);
|
||||
String describeRunPipelineError(Object error) =>
|
||||
describeErrorReason(error, fallback: 'The server did not start the run.');
|
||||
|
||||
@@ -30,6 +30,7 @@ class PipelineDetailPanel extends StatefulWidget {
|
||||
required this.gateway,
|
||||
required this.showBack,
|
||||
this.onRunStarted,
|
||||
this.onViewPipelineRuns,
|
||||
this.stageKey,
|
||||
this.stagePipelineId,
|
||||
this.stageVersion = 0,
|
||||
@@ -45,6 +46,7 @@ class PipelineDetailPanel extends StatefulWidget {
|
||||
|
||||
/// A run started from this detail's Run action; receives the server's id.
|
||||
final ValueChanged<int>? onRunStarted;
|
||||
final ValueChanged<int>? onViewPipelineRuns;
|
||||
|
||||
/// The stage the route names for this detail, or null when it names none.
|
||||
final String? stageKey;
|
||||
@@ -337,6 +339,25 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
|
||||
onRunStarted: widget.onRunStarted,
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Semantics(
|
||||
button: true,
|
||||
label: detail.name.trim().isEmpty
|
||||
? 'View runs of this pipeline'
|
||||
: 'View runs of ${detail.name}',
|
||||
child: ExcludeSemantics(
|
||||
child: TextButton.icon(
|
||||
onPressed: widget.onViewPipelineRuns == null
|
||||
? null
|
||||
: () => widget.onViewPipelineRuns!(detail.id),
|
||||
icon: const Icon(Icons.list_alt),
|
||||
label: const Text('Runs'),
|
||||
key: const Key('pipeline-view-runs'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -15,6 +15,55 @@ const runStates = [
|
||||
/// `0x7fffffffffffffff` literals failed dart2js compilation.
|
||||
const int _maxMillis = 8640000000000000;
|
||||
|
||||
String localDayKey(DateTime date) {
|
||||
final local = date.toLocal();
|
||||
String two(int value) => value.toString().padLeft(2, '0');
|
||||
return '${local.year}-${two(local.month)}-${two(local.day)}';
|
||||
}
|
||||
|
||||
String runDayLabel(String createdAt, DateTime today) {
|
||||
final created = DateTime.tryParse(createdAt)?.toLocal();
|
||||
if (created == null) return 'Unknown date';
|
||||
final day = localDayKey(created);
|
||||
if (day == localDayKey(today)) return 'Today';
|
||||
final yesterday = DateTime(
|
||||
today.year,
|
||||
today.month,
|
||||
today.day,
|
||||
).subtract(const Duration(days: 1));
|
||||
if (day == localDayKey(yesterday)) return 'Yesterday';
|
||||
const months = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec',
|
||||
];
|
||||
return '${created.day} ${months[created.month - 1]} ${created.year}';
|
||||
}
|
||||
|
||||
List<({String label, List<JsonMap> runs})> groupRunsByDay(
|
||||
List<JsonMap> sortedRuns,
|
||||
DateTime today,
|
||||
) {
|
||||
final groups = <({String label, List<JsonMap> runs})>[];
|
||||
for (final run in sortedRuns) {
|
||||
final label = runDayLabel('${run['created_at'] ?? ''}', today);
|
||||
if (groups.isEmpty || groups.last.label != label) {
|
||||
groups.add((label: label, runs: <JsonMap>[]));
|
||||
}
|
||||
groups.last.runs.add(run);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
({String label, String? pipeline}) runIdentity(dynamic title, dynamic name) {
|
||||
final stored = '${title ?? ''}'.trim();
|
||||
return (
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart';
|
||||
import '../../core/api_gateway.dart';
|
||||
import '../../ui/adaptive/host.dart';
|
||||
import '../attention/notify/notification_controller.dart';
|
||||
import '../attention/runtime/attention_controller.dart';
|
||||
import '../attention/runtime/attention_store.dart';
|
||||
import 'actions/decision_action.dart';
|
||||
import 'data/runs_repository.dart';
|
||||
@@ -24,6 +25,7 @@ class RunsScreen extends StatefulWidget {
|
||||
super.key,
|
||||
required this.gateway,
|
||||
this.initialRunId,
|
||||
this.initialPipelineId,
|
||||
this.initialStageKey,
|
||||
this.initialVisit,
|
||||
this.initialDecide = false,
|
||||
@@ -31,15 +33,18 @@ class RunsScreen extends StatefulWidget {
|
||||
this.listRefreshToken = 0,
|
||||
this.onRunSelected,
|
||||
this.onBack,
|
||||
this.onPipelineFilterChanged,
|
||||
this.attentionStore = const SharedPreferencesAttentionStore(),
|
||||
this.attentionNow,
|
||||
this.notifications,
|
||||
this.attention,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
|
||||
/// The run the current route names, or null for the list.
|
||||
final int? initialRunId;
|
||||
final int? initialPipelineId;
|
||||
|
||||
/// The recorded stage visit the route names inside [initialRunId]. The detail
|
||||
/// applies it once per route target; the feature never invents a visit.
|
||||
@@ -60,7 +65,8 @@ class RunsScreen extends StatefulWidget {
|
||||
final int listRefreshToken;
|
||||
|
||||
final ValueChanged<int>? onRunSelected;
|
||||
final VoidCallback? onBack;
|
||||
final ValueChanged<int?>? onBack;
|
||||
final ValueChanged<int?>? onPipelineFilterChanged;
|
||||
|
||||
/// Persisted attention dismissals and the clock for its local-day window.
|
||||
/// The app uses SharedPreferences; tests and fixtures inject a memory store.
|
||||
@@ -70,6 +76,9 @@ class RunsScreen extends StatefulWidget {
|
||||
/// App-level notification delivery for live attention transitions.
|
||||
final NotificationController? notifications;
|
||||
|
||||
/// The app's shared attention controller, mirrored on the shell's Runs tab.
|
||||
final AttentionController? attention;
|
||||
|
||||
@override
|
||||
State<RunsScreen> createState() => _RunsScreenState();
|
||||
}
|
||||
@@ -77,6 +86,8 @@ class RunsScreen extends StatefulWidget {
|
||||
class _RunsScreenState extends State<RunsScreen> {
|
||||
late final RunsController controller;
|
||||
num? _shownRunId;
|
||||
int? _reportedPipelineId;
|
||||
bool _applyingRoutePipeline = false;
|
||||
|
||||
/// The route's decision request is one-shot: the first loaded detail for the
|
||||
/// named run consumes it, whether or not that run is waiting.
|
||||
@@ -86,8 +97,14 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = RunsController(RunsRepository(widget.gateway));
|
||||
_reportedPipelineId = widget.initialPipelineId;
|
||||
if (widget.initialPipelineId != null) {
|
||||
controller.clearFilters();
|
||||
controller.setPipeline(widget.initialPipelineId);
|
||||
}
|
||||
controller.listen(widget.gateway.frames);
|
||||
controller.addListener(_selectionChanged);
|
||||
controller.addListener(_pipelineFilterChanged);
|
||||
controller.addListener(_detailChanged);
|
||||
controller.load(widget.initialRunId);
|
||||
}
|
||||
@@ -99,6 +116,21 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
widget.initialDecide != oldWidget.initialDecide) {
|
||||
_decideConsumed = false;
|
||||
}
|
||||
if (widget.initialPipelineId != oldWidget.initialPipelineId) {
|
||||
final id = widget.initialPipelineId;
|
||||
// A run detail replaces the list URL but retains its active list filter.
|
||||
// Only a route back to the list can explicitly clear that facet.
|
||||
if (id != null || widget.initialRunId == null) {
|
||||
_applyingRoutePipeline = true;
|
||||
try {
|
||||
if (id != null) controller.clearFilters();
|
||||
controller.setPipeline(id);
|
||||
_reportedPipelineId = id;
|
||||
} finally {
|
||||
_applyingRoutePipeline = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (widget.syncToken != oldWidget.syncToken) {
|
||||
controller.resync();
|
||||
}
|
||||
@@ -132,6 +164,19 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
void _pipelineFilterChanged() {
|
||||
final id = controller.pipelineId;
|
||||
if (_applyingRoutePipeline) {
|
||||
_reportedPipelineId = id;
|
||||
return;
|
||||
}
|
||||
if (id == _reportedPipelineId) return;
|
||||
_reportedPipelineId = id;
|
||||
if (controller.selectedRunId == null) {
|
||||
widget.onPipelineFilterChanged?.call(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the route's decision prompt after the named detail has arrived.
|
||||
/// A non-waiting run consumes the request without a prompt, and the prompt
|
||||
/// itself only closes; the detail underneath is left as it is.
|
||||
@@ -166,12 +211,13 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
|
||||
void _back() {
|
||||
controller.back();
|
||||
widget.onBack?.call();
|
||||
widget.onBack?.call(controller.pipelineId);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.removeListener(_selectionChanged);
|
||||
controller.removeListener(_pipelineFilterChanged);
|
||||
controller.removeListener(_detailChanged);
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
@@ -193,6 +239,7 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
attentionStore: widget.attentionStore,
|
||||
attentionNow: widget.attentionNow,
|
||||
notifications: widget.notifications,
|
||||
attention: widget.attention,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -209,7 +209,10 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
|
||||
case RunSummarySection.output:
|
||||
_outputSection.expand();
|
||||
case null:
|
||||
break;
|
||||
// A hit that names no section must not leave a previously expanded
|
||||
// one open; the Summary panel starts collapsed.
|
||||
_inputSection.collapse();
|
||||
_outputSection.collapse();
|
||||
}
|
||||
case RunVisitTarget(:final stageKey, :final timelineIndex):
|
||||
if (detailVisitStepAt(widget.run, timelineIndex) == null) return;
|
||||
|
||||
@@ -177,6 +177,11 @@ class RunsController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setTimeRange(String value) {
|
||||
timeRange = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setSort(String value) {
|
||||
sort = value;
|
||||
notifyListeners();
|
||||
|
||||
@@ -7,8 +7,8 @@ import 'runs_controller.dart';
|
||||
|
||||
/// The runs list's compact native filter/sort toolbar and applied-filter chips.
|
||||
///
|
||||
/// Mirrors the browser's run toolbar: one `Filter` menu carrying the status and
|
||||
/// trigger facets, one `Sort:` menu, and a removable chip per applied facet.
|
||||
/// Mirrors the browser's run toolbar: one `Filter` menu carrying its facets,
|
||||
/// one `Sort:` menu, and a removable chip per applied facet.
|
||||
/// The buttons sit in a single horizontally scrollable row so a phone at a
|
||||
/// doubled text scale can still reach them without crushing the list.
|
||||
class RunsFilters extends StatelessWidget {
|
||||
@@ -58,6 +58,8 @@ class RunsFilters extends StatelessWidget {
|
||||
checked: controller.sort == sort.$1,
|
||||
child: Text(sort.$2),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
const PopupMenuItem(value: 'newest_first', child: Text('Reset')),
|
||||
],
|
||||
child: _materialButton(
|
||||
Icons.sort,
|
||||
@@ -79,6 +81,7 @@ class RunsFilters extends StatelessWidget {
|
||||
);
|
||||
|
||||
List<PopupMenuEntry<_FilterChoice>> _materialMenuItems() => [
|
||||
const PopupMenuItem(enabled: false, child: Text('Status')),
|
||||
for (final status in runStates)
|
||||
CheckedPopupMenuItem(
|
||||
value: (kind: 'status', value: status),
|
||||
@@ -86,6 +89,28 @@ class RunsFilters extends StatelessWidget {
|
||||
child: Text(status),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
const PopupMenuItem(enabled: false, child: Text('Pipeline')),
|
||||
CheckedPopupMenuItem(
|
||||
value: (kind: 'pipeline', value: ''),
|
||||
checked: controller.pipelineId == null,
|
||||
child: const Text('Any pipeline'),
|
||||
),
|
||||
for (final pipeline in _pipelines(controller))
|
||||
CheckedPopupMenuItem(
|
||||
value: (kind: 'pipeline', value: '${pipeline.id}'),
|
||||
checked: controller.pipelineId == pipeline.id,
|
||||
child: Text(pipeline.name),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
const PopupMenuItem(enabled: false, child: Text('Time range')),
|
||||
for (final range in _timeRanges)
|
||||
CheckedPopupMenuItem(
|
||||
value: (kind: 'time', value: range.$1),
|
||||
checked: controller.timeRange == range.$1,
|
||||
child: Text(range.$2),
|
||||
),
|
||||
const PopupMenuDivider(),
|
||||
const PopupMenuItem(enabled: false, child: Text('Trigger')),
|
||||
for (final schedule in _schedules)
|
||||
CheckedPopupMenuItem(
|
||||
value: (kind: 'schedule', value: schedule.$1),
|
||||
@@ -99,6 +124,15 @@ class RunsFilters extends StatelessWidget {
|
||||
child: Text('Clear filters'),
|
||||
),
|
||||
],
|
||||
if (_hasUnclassifiedRuns(controller)) ...[
|
||||
const PopupMenuDivider(),
|
||||
const PopupMenuItem(
|
||||
enabled: false,
|
||||
child: Text(
|
||||
'Some records have no scheduling provenance; they stay unclassified.',
|
||||
),
|
||||
),
|
||||
],
|
||||
];
|
||||
|
||||
void _apply(_FilterChoice choice) {
|
||||
@@ -106,6 +140,12 @@ class RunsFilters extends StatelessWidget {
|
||||
controller.setStatus(choice.value);
|
||||
} else if (choice.kind == 'schedule') {
|
||||
controller.setScheduled(choice.value);
|
||||
} else if (choice.kind == 'pipeline') {
|
||||
controller.setPipeline(
|
||||
choice.value.isEmpty ? null : int.tryParse(choice.value),
|
||||
);
|
||||
} else if (choice.kind == 'time') {
|
||||
controller.setTimeRange(choice.value);
|
||||
} else {
|
||||
controller.clearFilters();
|
||||
}
|
||||
@@ -127,7 +167,7 @@ class RunsFilters extends StatelessWidget {
|
||||
onPressed: () => _choose(
|
||||
context,
|
||||
'Sort runs',
|
||||
_sorts,
|
||||
_sortChoices,
|
||||
controller.sort,
|
||||
controller.setSort,
|
||||
),
|
||||
@@ -148,6 +188,7 @@ class RunsFilters extends StatelessWidget {
|
||||
builder: (context, _) => CupertinoActionSheet(
|
||||
title: const Text('Filter runs'),
|
||||
actions: [
|
||||
_cupertinoSection('Status'),
|
||||
for (final status in runStates)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => controller.setStatus(status),
|
||||
@@ -155,6 +196,29 @@ class RunsFilters extends StatelessWidget {
|
||||
'${controller.statuses.contains(status) ? '✓ ' : ''}$status',
|
||||
),
|
||||
),
|
||||
_cupertinoSection('Pipeline'),
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => controller.setPipeline(null),
|
||||
child: Text(
|
||||
'${controller.pipelineId == null ? '✓ ' : ''}Any pipeline',
|
||||
),
|
||||
),
|
||||
for (final pipeline in _pipelines(controller))
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => controller.setPipeline(pipeline.id),
|
||||
child: Text(
|
||||
'${controller.pipelineId == pipeline.id ? '✓ ' : ''}${pipeline.name}',
|
||||
),
|
||||
),
|
||||
_cupertinoSection('Time range'),
|
||||
for (final range in _timeRanges)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => controller.setTimeRange(range.$1),
|
||||
child: Text(
|
||||
'${controller.timeRange == range.$1 ? '✓ ' : ''}${range.$2}',
|
||||
),
|
||||
),
|
||||
_cupertinoSection('Trigger'),
|
||||
for (final schedule in _schedules)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => controller.setScheduled(schedule.$1),
|
||||
@@ -163,6 +227,13 @@ class RunsFilters extends StatelessWidget {
|
||||
'${schedule.$2}',
|
||||
),
|
||||
),
|
||||
if (_hasUnclassifiedRuns(controller))
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () {},
|
||||
child: const Text(
|
||||
'Some records have no scheduling provenance; they stay unclassified.',
|
||||
),
|
||||
),
|
||||
if (controller.activeFilterCount > 0)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: controller.clearFilters,
|
||||
@@ -206,12 +277,16 @@ class RunsFilters extends StatelessWidget {
|
||||
|
||||
Widget _appliedFilters(BuildContext context) {
|
||||
final applied = _applied();
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [for (final entry in applied) _appliedChip(context, entry)],
|
||||
return Semantics(
|
||||
container: true,
|
||||
label: 'Applied run filters',
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: [for (final entry in applied) _appliedChip(context, entry)],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -225,6 +300,12 @@ class RunsFilters extends StatelessWidget {
|
||||
for (final status in controller.statuses) {
|
||||
applied.add((label: status, clear: () => controller.setStatus(status)));
|
||||
}
|
||||
if (controller.timeRange != 'any_time') {
|
||||
applied.add((
|
||||
label: _timeRangeLabel(controller.timeRange),
|
||||
clear: () => controller.setTimeRange('any_time'),
|
||||
));
|
||||
}
|
||||
if (controller.scheduled != 'any') {
|
||||
applied.add((
|
||||
label: _scheduleLabel(controller.scheduled),
|
||||
@@ -288,14 +369,58 @@ typedef _FilterChoice = ({String kind, String value});
|
||||
const _sorts = [
|
||||
('newest_first', 'Newest first'),
|
||||
('oldest_first', 'Oldest first'),
|
||||
('longest_duration', 'Longest duration'),
|
||||
('shortest_duration', 'Shortest duration'),
|
||||
('pipeline_name', 'Pipeline name'),
|
||||
('status', 'Status'),
|
||||
];
|
||||
const _sortChoices = [..._sorts, ('newest_first', 'Reset')];
|
||||
const _schedules = [
|
||||
('any', 'Any trigger'),
|
||||
('scheduled', 'Scheduled runs'),
|
||||
('unscheduled', 'Not scheduled'),
|
||||
];
|
||||
const _timeRanges = [
|
||||
('any_time', 'Any time'),
|
||||
('today', 'Today'),
|
||||
('last_7_days', 'Last 7 days'),
|
||||
('last_30_days', 'Last 30 days'),
|
||||
];
|
||||
|
||||
List<({int id, String name})> _pipelines(RunsController controller) {
|
||||
final names = <int, String>{};
|
||||
final ids = <int>{};
|
||||
for (final run in controller.runs) {
|
||||
final id = run['pipeline_id'];
|
||||
if (id is! int) continue;
|
||||
ids.add(id);
|
||||
final name = '${run['name'] ?? ''}'.trim();
|
||||
if (name.isNotEmpty && !names.containsKey(id)) names[id] = name;
|
||||
}
|
||||
final options = ids
|
||||
.map((id) => (id: id, name: names[id] ?? 'Pipeline $id'))
|
||||
.toList();
|
||||
options.sort((a, b) {
|
||||
final nameOrder = a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
return nameOrder != 0 ? nameOrder : a.id.compareTo(b.id);
|
||||
});
|
||||
return options;
|
||||
}
|
||||
|
||||
bool _hasUnclassifiedRuns(RunsController controller) =>
|
||||
controller.runs.any((run) {
|
||||
final id = run['schedule_id'];
|
||||
return run['scheduled'] is! bool && !(id is num && id > 0);
|
||||
});
|
||||
|
||||
Widget _cupertinoSection(String title) => Padding(
|
||||
padding: const EdgeInsetsDirectional.only(top: 8),
|
||||
child: Text(title, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
);
|
||||
|
||||
String _timeRangeLabel(String value) => _timeRanges
|
||||
.firstWhere((entry) => entry.$1 == value, orElse: () => _timeRanges.first)
|
||||
.$2;
|
||||
String _sortLabel(String value) =>
|
||||
_sorts.firstWhere((e) => e.$1 == value, orElse: () => _sorts.first).$2;
|
||||
String _scheduleLabel(String value) => _schedules
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../attention/notify/notification_controller.dart';
|
||||
import '../../attention/runtime/attention_controller.dart';
|
||||
import '../../attention/runtime/attention_store.dart';
|
||||
import '../../attention/ui/needs_you_runs_heading.dart';
|
||||
import '../domain/run_models.dart';
|
||||
@@ -19,6 +20,7 @@ class RunsList extends StatelessWidget {
|
||||
this.attentionStore = const SharedPreferencesAttentionStore(),
|
||||
this.attentionNow,
|
||||
this.notifications,
|
||||
this.attention,
|
||||
});
|
||||
|
||||
final RunsController controller;
|
||||
@@ -37,6 +39,9 @@ class RunsList extends StatelessWidget {
|
||||
/// App-level notification delivery; absent in list-only fixtures.
|
||||
final NotificationController? notifications;
|
||||
|
||||
/// The app's shared attention controller; absent in list-only fixtures.
|
||||
final AttentionController? attention;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (controller.loading && controller.runs.isEmpty) {
|
||||
@@ -74,13 +79,7 @@ class RunsList extends StatelessWidget {
|
||||
Expanded(
|
||||
child: controller.visibleRuns.isEmpty
|
||||
? const Center(child: Text('No runs found.'))
|
||||
: ListView.separated(
|
||||
itemCount: controller.visibleRuns.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const Divider(height: 1),
|
||||
itemBuilder: (context, index) =>
|
||||
_runTile(context, controller.visibleRuns[index]),
|
||||
),
|
||||
: _groupedRuns(context),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -108,11 +107,37 @@ class RunsList extends StatelessWidget {
|
||||
store: attentionStore,
|
||||
now: attentionNow,
|
||||
notifications: notifications,
|
||||
attention: attention,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _groupedRuns(BuildContext context) {
|
||||
final groups = groupRunsByDay(controller.visibleRuns, DateTime.now());
|
||||
final entries = <({String? label, JsonMap? run})>[];
|
||||
for (final group in groups) {
|
||||
entries.add((label: group.label, run: null));
|
||||
entries.addAll(group.runs.map((run) => (label: null, run: run)));
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: entries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final entry = entries[index];
|
||||
if (entry.label case final label?) {
|
||||
final style = usesCupertinoHost(context)
|
||||
? CupertinoTheme.of(context).textTheme.textStyle
|
||||
: Theme.of(context).textTheme.labelLarge;
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
|
||||
child: Semantics(header: true, child: Text(label, style: style)),
|
||||
);
|
||||
}
|
||||
return _runTile(context, entry.run!);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyError(BuildContext context) => Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'attention_badge.dart';
|
||||
import 'destination.dart';
|
||||
|
||||
class AdaptiveShell extends StatefulWidget {
|
||||
@@ -11,6 +12,7 @@ class AdaptiveShell extends StatefulWidget {
|
||||
this.destination,
|
||||
this.onDestinationSelected,
|
||||
this.onSearch,
|
||||
this.attentionCount = 0,
|
||||
});
|
||||
|
||||
final Map<AppDestination, WidgetBuilder> destinationBodies;
|
||||
@@ -25,6 +27,10 @@ class AdaptiveShell extends StatefulWidget {
|
||||
/// shell tests and compositions without routing keep their tab set only.
|
||||
final VoidCallback? onSearch;
|
||||
|
||||
/// Runs needing the operator today, mirrored on the Runs tab in every mount
|
||||
/// so it stays visible from any destination. Zero shows no badge.
|
||||
final int attentionCount;
|
||||
|
||||
@override
|
||||
State<AdaptiveShell> createState() => _AdaptiveShellState();
|
||||
}
|
||||
@@ -65,6 +71,17 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
List<T> _items<T>(T Function(AppDestination) build) =>
|
||||
AppDestination.values.map(build).toList();
|
||||
|
||||
/// The destination's icon; only Runs carries the attention count.
|
||||
Widget _icon(AppDestination destination, IconData data) {
|
||||
final icon = Icon(data);
|
||||
if (destination != AppDestination.runs) return icon;
|
||||
return AttentionDestinationIcon(
|
||||
count: widget.attentionCount,
|
||||
cupertino: widget.cupertino,
|
||||
child: icon,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final index = AppDestination.values.indexOf(_selected);
|
||||
@@ -108,6 +125,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
_CupertinoSidebar(
|
||||
selected: _selected,
|
||||
onSelected: _select,
|
||||
attentionCount: widget.attentionCount,
|
||||
),
|
||||
Expanded(child: _destinationStack(contents, index)),
|
||||
],
|
||||
@@ -117,11 +135,12 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
Expanded(child: _destinationStack(contents, index)),
|
||||
CupertinoTabBar(
|
||||
currentIndex: index,
|
||||
onTap: (value) => _select(AppDestination.values[value]),
|
||||
onTap: (value) =>
|
||||
_select(AppDestination.values[value]),
|
||||
items: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return BottomNavigationBarItem(
|
||||
icon: Icon(item.cupertinoIcon),
|
||||
icon: _icon(destination, item.cupertinoIcon),
|
||||
label: item.label,
|
||||
);
|
||||
}),
|
||||
@@ -155,7 +174,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
destinations: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return NavigationRailDestination(
|
||||
icon: Icon(item.icon),
|
||||
icon: _icon(destination, item.icon),
|
||||
label: Text(item.label),
|
||||
);
|
||||
}),
|
||||
@@ -172,7 +191,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
destinations: _items((destination) {
|
||||
final item = destinationDetails(destination);
|
||||
return NavigationDestination(
|
||||
icon: Icon(item.icon),
|
||||
icon: _icon(destination, item.icon),
|
||||
label: item.label,
|
||||
);
|
||||
}),
|
||||
@@ -189,10 +208,15 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
/// The wide-window Cupertino destination list: the web's 200px rail with the
|
||||
/// host's own grouped list controls.
|
||||
class _CupertinoSidebar extends StatelessWidget {
|
||||
const _CupertinoSidebar({required this.selected, required this.onSelected});
|
||||
const _CupertinoSidebar({
|
||||
required this.selected,
|
||||
required this.onSelected,
|
||||
this.attentionCount = 0,
|
||||
});
|
||||
|
||||
final AppDestination selected;
|
||||
final ValueChanged<AppDestination> onSelected;
|
||||
final int attentionCount;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -215,7 +239,15 @@ class _CupertinoSidebar extends StatelessWidget {
|
||||
for (final destination in AppDestination.values)
|
||||
CupertinoListTile(
|
||||
key: ValueKey('shell.destination.${destination.name}'),
|
||||
leading: Icon(destinationDetails(destination).cupertinoIcon),
|
||||
leading: destination == AppDestination.runs
|
||||
? AttentionDestinationIcon(
|
||||
count: attentionCount,
|
||||
cupertino: true,
|
||||
child: Icon(
|
||||
destinationDetails(destination).cupertinoIcon,
|
||||
),
|
||||
)
|
||||
: Icon(destinationDetails(destination).cupertinoIcon),
|
||||
title: Text(destinationDetails(destination).label),
|
||||
trailing: destination == selected
|
||||
? Icon(
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../features/attention/domain/attention_models.dart';
|
||||
|
||||
/// Mirrors the Runs-heading bell count onto the Runs destination icon.
|
||||
///
|
||||
/// The bell itself lives in the Runs heading, so without this the count would
|
||||
/// be visible only on that destination; the web mirrors it on the rail and
|
||||
/// dock tab. Material hosts use the framework [Badge]; Cupertino has no badge
|
||||
/// control, so its tab bar and sidebar get the host's red count overlay. Zero
|
||||
/// draws the bare icon, and a count labels the item exactly like the bell:
|
||||
/// `Notifications, {n} needing attention`.
|
||||
class AttentionDestinationIcon extends StatelessWidget {
|
||||
const AttentionDestinationIcon({
|
||||
super.key,
|
||||
required this.count,
|
||||
required this.cupertino,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final int count;
|
||||
final bool cupertino;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final visible = count > 0;
|
||||
final Widget icon = cupertino
|
||||
? _CupertinoCountOverlay(count: count, visible: visible, child: child)
|
||||
: Badge(label: Text('$count'), isLabelVisible: visible, child: child);
|
||||
if (!visible) return icon;
|
||||
// The number alone would read as a stray "3"; the item carries the bell's
|
||||
// full label instead.
|
||||
return Semantics(
|
||||
label: attentionBadgeLabel(count),
|
||||
child: ExcludeSemantics(child: icon),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The iOS tab-badge idiom: a red stadium with the count over the icon's
|
||||
/// trailing corner. Content-driven size; only the overlap offset is fixed.
|
||||
class _CupertinoCountOverlay extends StatelessWidget {
|
||||
const _CupertinoCountOverlay({
|
||||
required this.count,
|
||||
required this.visible,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final int count;
|
||||
final bool visible;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!visible) return child;
|
||||
final style = CupertinoTheme.of(
|
||||
context,
|
||||
).textTheme.tabLabelTextStyle.copyWith(color: CupertinoColors.white);
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
child,
|
||||
PositionedDirectional(
|
||||
top: -6,
|
||||
end: -10,
|
||||
child: DecoratedBox(
|
||||
decoration: ShapeDecoration(
|
||||
color: CupertinoColors.systemRed.resolveFrom(context),
|
||||
shape: const StadiumBorder(),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
|
||||
child: Text('$count', style: style),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user