merge(app): land schedule from the run dialog
This commit is contained in:
@@ -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/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@@ -24,6 +27,19 @@ Future<void> showRunPipelineDialog({
|
|||||||
required ValueChanged<RunPipelineIntent?> onPendingChanged,
|
required ValueChanged<RunPipelineIntent?> onPendingChanged,
|
||||||
required ValueChanged<JsonMap> onAccepted,
|
required ValueChanged<JsonMap> onAccepted,
|
||||||
}) {
|
}) {
|
||||||
|
// Schedule instead: the editor opens as the next page from the screen that
|
||||||
|
// opened this dialog, seeded with what was typed here.
|
||||||
|
Future<void> 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(
|
final dialog = _RunPipelineDialog(
|
||||||
detail: detail,
|
detail: detail,
|
||||||
gateway: gateway,
|
gateway: gateway,
|
||||||
@@ -32,6 +48,7 @@ Future<void> showRunPipelineDialog({
|
|||||||
onSubmit: onSubmit,
|
onSubmit: onSubmit,
|
||||||
onPendingChanged: onPendingChanged,
|
onPendingChanged: onPendingChanged,
|
||||||
onAccepted: onAccepted,
|
onAccepted: onAccepted,
|
||||||
|
onSchedule: schedule,
|
||||||
);
|
);
|
||||||
return dialog.cupertino
|
return dialog.cupertino
|
||||||
? showCupertinoDialog<void>(
|
? showCupertinoDialog<void>(
|
||||||
@@ -55,8 +72,11 @@ class _RunPipelineDialog extends StatefulWidget {
|
|||||||
required this.onSubmit,
|
required this.onSubmit,
|
||||||
required this.onPendingChanged,
|
required this.onPendingChanged,
|
||||||
required this.onAccepted,
|
required this.onAccepted,
|
||||||
|
required this.onSchedule,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final Future<void> Function(ScheduleDraft draft) onSchedule;
|
||||||
|
|
||||||
final PipelineDetail detail;
|
final PipelineDetail detail;
|
||||||
final ApiGateway gateway;
|
final ApiGateway gateway;
|
||||||
final RunPipelineIntent? pending;
|
final RunPipelineIntent? pending;
|
||||||
@@ -213,6 +233,11 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
|||||||
onPressed: _sending ? null : _cancel,
|
onPressed: _sending ? null : _cancel,
|
||||||
child: const Text(runPipelineCancelLabel),
|
child: const Text(runPipelineCancelLabel),
|
||||||
),
|
),
|
||||||
|
TextButton(
|
||||||
|
key: const Key('run-pipeline-schedule'),
|
||||||
|
onPressed: _sending ? null : _schedule,
|
||||||
|
child: const Text('Schedule…'),
|
||||||
|
),
|
||||||
FilledButton(
|
FilledButton(
|
||||||
key: runPipelineConfirmKey,
|
key: runPipelineConfirmKey,
|
||||||
onPressed: _sending ? null : _confirm,
|
onPressed: _sending ? null : _confirm,
|
||||||
@@ -232,6 +257,11 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
|||||||
onPressed: _sending ? null : _cancel,
|
onPressed: _sending ? null : _cancel,
|
||||||
child: const Text(runPipelineCancelLabel),
|
child: const Text(runPipelineCancelLabel),
|
||||||
),
|
),
|
||||||
|
CupertinoDialogAction(
|
||||||
|
key: const Key('run-pipeline-schedule'),
|
||||||
|
onPressed: _sending ? null : _schedule,
|
||||||
|
child: const Text('Schedule…'),
|
||||||
|
),
|
||||||
CupertinoDialogAction(
|
CupertinoDialogAction(
|
||||||
key: runPipelineConfirmKey,
|
key: runPipelineConfirmKey,
|
||||||
isDefaultAction: true,
|
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 {
|
String get _confirmLabel {
|
||||||
if (_sending) return runPipelineSendingLabel;
|
if (_sending) return runPipelineSendingLabel;
|
||||||
return _intent == null
|
return _intent == null
|
||||||
|
|||||||
@@ -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/run_pipeline_intent.dart';
|
||||||
import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.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';
|
import '../fixtures.dart';
|
||||||
|
|
||||||
typedef LaunchHandler = FutureOr<JsonMap> Function(JsonMap fields);
|
typedef LaunchHandler = FutureOr<JsonMap> Function(JsonMap fields);
|
||||||
@@ -96,8 +97,9 @@ void main() {
|
|||||||
requestKey: 'endpoint-intent',
|
requestKey: 'endpoint-intent',
|
||||||
);
|
);
|
||||||
SharedPreferences.setMockInitialValues({
|
SharedPreferences.setMockInitialValues({
|
||||||
pendingRunStorageKey('ws://server-a/connect', 1, 2):
|
pendingRunStorageKey('ws://server-a/connect', 1, 2): jsonEncode(
|
||||||
jsonEncode(intent.toJson()),
|
intent.toJson(),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
final fixture = PipelineFixture();
|
final fixture = PipelineFixture();
|
||||||
final gateway = launchGateway(fixture, onLaunch: (_) => noRun());
|
final gateway = launchGateway(fixture, onLaunch: (_) => noRun());
|
||||||
@@ -416,9 +418,11 @@ void main() {
|
|||||||
final prompt = tester.widget<TextField>(find.byKey(runPipelinePromptKey));
|
final prompt = tester.widget<TextField>(find.byKey(runPipelinePromptKey));
|
||||||
expect(prompt.enabled, isFalse);
|
expect(prompt.enabled, isFalse);
|
||||||
expect(
|
expect(
|
||||||
tester.widget<DropdownButtonFormField<dynamic>>(
|
tester
|
||||||
find.byKey(runPipelineOutputFormatKey),
|
.widget<DropdownButtonFormField<dynamic>>(
|
||||||
).onChanged,
|
find.byKey(runPipelineOutputFormatKey),
|
||||||
|
)
|
||||||
|
.onChanged,
|
||||||
isNull,
|
isNull,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -645,4 +649,31 @@ void main() {
|
|||||||
expect(helper?.color, CupertinoColors.secondaryLabel.resolveFrom(context));
|
expect(helper?.color, CupertinoColors.secondaryLabel.resolveFrom(context));
|
||||||
expect(helper?.fontSize, theme.textTheme.tabLabelTextStyle.fontSize);
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user