diff --git a/app/lib/features/pipelines/ui/run_pipeline_dialog.dart b/app/lib/features/pipelines/ui/run_pipeline_dialog.dart index 5bb650d0..e3883dc5 100644 --- a/app/lib/features/pipelines/ui/run_pipeline_dialog.dart +++ b/app/lib/features/pipelines/ui/run_pipeline_dialog.dart @@ -1,3 +1,6 @@ +import '../../schedules/data/schedules_repository.dart'; +import '../../schedules/domain/editor/schedule_draft.dart'; +import '../../schedules/ui/pipeline/schedule_pipeline_editor.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -24,6 +27,19 @@ Future showRunPipelineDialog({ required ValueChanged onPendingChanged, required ValueChanged onAccepted, }) { + // Schedule instead: the editor opens as the next page from the screen that + // opened this dialog, seeded with what was typed here. + Future schedule(ScheduleDraft draft) { + final requestKey = newScheduleCreateRequestKey(); + final repository = SchedulesRepository(gateway); + return openSchedulePipelineEditor( + context, + draft: draft, + onSubmit: (record) => + repository.saveSchedule(record, requestKey: requestKey), + ); + } + final dialog = _RunPipelineDialog( detail: detail, gateway: gateway, @@ -32,6 +48,7 @@ Future showRunPipelineDialog({ onSubmit: onSubmit, onPendingChanged: onPendingChanged, onAccepted: onAccepted, + onSchedule: schedule, ); return dialog.cupertino ? showCupertinoDialog( @@ -55,8 +72,11 @@ class _RunPipelineDialog extends StatefulWidget { required this.onSubmit, required this.onPendingChanged, required this.onAccepted, + required this.onSchedule, }); + final Future Function(ScheduleDraft draft) onSchedule; + final PipelineDetail detail; final ApiGateway gateway; final RunPipelineIntent? pending; @@ -213,6 +233,11 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> { onPressed: _sending ? null : _cancel, child: const Text(runPipelineCancelLabel), ), + TextButton( + key: const Key('run-pipeline-schedule'), + onPressed: _sending ? null : _schedule, + child: const Text('Schedule…'), + ), FilledButton( key: runPipelineConfirmKey, onPressed: _sending ? null : _confirm, @@ -232,6 +257,11 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> { onPressed: _sending ? null : _cancel, child: const Text(runPipelineCancelLabel), ), + CupertinoDialogAction( + key: const Key('run-pipeline-schedule'), + onPressed: _sending ? null : _schedule, + child: const Text('Schedule…'), + ), CupertinoDialogAction( key: runPipelineConfirmKey, isDefaultAction: true, @@ -242,6 +272,19 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> { ); } + /// Leaves the dialog for the schedule editor with the typed prompt, + /// workspace and the pinned version. + void _schedule() { + final draft = ScheduleDraft.create( + pipelineId: widget.detail.id, + version: '${widget.detail.resolvedVersion}', + workspace: _workspace.text.trim(), + )..prompt = _prompt.text; + final schedule = widget.onSchedule; + Navigator.of(context).pop(); + schedule(draft); + } + String get _confirmLabel { if (_sending) return runPipelineSendingLabel; return _intent == null diff --git a/app/test/features/pipelines/ui/run_pipeline_launch_test.dart b/app/test/features/pipelines/ui/run_pipeline_launch_test.dart index a7448236..afe8897f 100644 --- a/app/test/features/pipelines/ui/run_pipeline_launch_test.dart +++ b/app/test/features/pipelines/ui/run_pipeline_launch_test.dart @@ -12,6 +12,7 @@ import 'package:pipelines_app/features/pipelines/pending_run_store.dart'; import 'package:pipelines_app/features/pipelines/run_pipeline_intent.dart'; import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.dart'; +import 'package:pipelines_app/features/schedules/ui/editor/schedule_editor_wording.dart'; import '../fixtures.dart'; typedef LaunchHandler = FutureOr Function(JsonMap fields); @@ -96,8 +97,9 @@ void main() { requestKey: 'endpoint-intent', ); SharedPreferences.setMockInitialValues({ - pendingRunStorageKey('ws://server-a/connect', 1, 2): - jsonEncode(intent.toJson()), + pendingRunStorageKey('ws://server-a/connect', 1, 2): jsonEncode( + intent.toJson(), + ), }); final fixture = PipelineFixture(); final gateway = launchGateway(fixture, onLaunch: (_) => noRun()); @@ -416,9 +418,11 @@ void main() { final prompt = tester.widget(find.byKey(runPipelinePromptKey)); expect(prompt.enabled, isFalse); expect( - tester.widget>( - find.byKey(runPipelineOutputFormatKey), - ).onChanged, + tester + .widget>( + find.byKey(runPipelineOutputFormatKey), + ) + .onChanged, isNull, ); @@ -645,4 +649,31 @@ void main() { expect(helper?.color, CupertinoColors.secondaryLabel.resolveFrom(context)); expect(helper?.fontSize, theme.textTheme.tabLabelTextStyle.fontSize); }); + + testWidgets('Schedule… leaves the run dialog for the schedule editor', ( + tester, + ) async { + final fixture = PipelineFixture(); + var launches = 0; + final gateway = launchGateway( + fixture, + onLaunch: (_) { + launches++; + return acceptedRun(9); + }, + ); + await pumpScreen(tester, gateway, []); + await openDetail(tester); + await tester.tap(find.byKey(runPipelineActionKey)); + await tester.pumpAndSettle(); + await fillFields(tester, prompt: 'Nightly review'); + await tester.tap(find.byKey(const Key('run-pipeline-schedule'))); + await tester.pumpAndSettle(); + + // The editor is the next page, seeded with the typed prompt; no run left. + expect(find.byKey(runPipelineConfirmKey), findsNothing); + expect(find.byKey(scheduleEditorSubmitKey), findsOneWidget); + expect(find.text('Nightly review'), findsWidgets); + expect(launches, 0); + }); }