feat(app): suggest server workspaces in run dialog
This commit is contained in:
@@ -51,6 +51,7 @@ class _RunPipelineActionState extends State<RunPipelineAction> {
|
|||||||
await showRunPipelineDialog(
|
await showRunPipelineDialog(
|
||||||
context: context,
|
context: context,
|
||||||
detail: widget.detail,
|
detail: widget.detail,
|
||||||
|
gateway: widget.gateway,
|
||||||
pending: widget.controller.pendingRunFor(_pipelineId, _version),
|
pending: widget.controller.pendingRunFor(_pipelineId, _version),
|
||||||
onSubmit: _submit,
|
onSubmit: _submit,
|
||||||
onPendingChanged: (intent) {
|
onPendingChanged: (intent) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../../core/api_gateway.dart';
|
import '../../../core/api_gateway.dart';
|
||||||
|
import '../../settings/settings_store.dart';
|
||||||
import '../../../ui/adaptive/host.dart';
|
import '../../../ui/adaptive/host.dart';
|
||||||
import '../pipeline_models.dart';
|
import '../pipeline_models.dart';
|
||||||
import '../run_pipeline_intent.dart';
|
import '../run_pipeline_intent.dart';
|
||||||
@@ -16,6 +17,7 @@ import 'run_pipeline_wording.dart';
|
|||||||
Future<void> showRunPipelineDialog({
|
Future<void> showRunPipelineDialog({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required PipelineDetail detail,
|
required PipelineDetail detail,
|
||||||
|
required ApiGateway gateway,
|
||||||
required RunPipelineIntent? pending,
|
required RunPipelineIntent? pending,
|
||||||
required Future<RunPipelineOutcome> Function(RunPipelineIntent intent)
|
required Future<RunPipelineOutcome> Function(RunPipelineIntent intent)
|
||||||
onSubmit,
|
onSubmit,
|
||||||
@@ -24,6 +26,7 @@ Future<void> showRunPipelineDialog({
|
|||||||
}) {
|
}) {
|
||||||
final dialog = _RunPipelineDialog(
|
final dialog = _RunPipelineDialog(
|
||||||
detail: detail,
|
detail: detail,
|
||||||
|
gateway: gateway,
|
||||||
pending: pending,
|
pending: pending,
|
||||||
cupertino: usesCupertinoHost(context),
|
cupertino: usesCupertinoHost(context),
|
||||||
onSubmit: onSubmit,
|
onSubmit: onSubmit,
|
||||||
@@ -46,6 +49,7 @@ Future<void> showRunPipelineDialog({
|
|||||||
class _RunPipelineDialog extends StatefulWidget {
|
class _RunPipelineDialog extends StatefulWidget {
|
||||||
const _RunPipelineDialog({
|
const _RunPipelineDialog({
|
||||||
required this.detail,
|
required this.detail,
|
||||||
|
required this.gateway,
|
||||||
required this.pending,
|
required this.pending,
|
||||||
required this.cupertino,
|
required this.cupertino,
|
||||||
required this.onSubmit,
|
required this.onSubmit,
|
||||||
@@ -54,6 +58,7 @@ class _RunPipelineDialog extends StatefulWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
final PipelineDetail detail;
|
final PipelineDetail detail;
|
||||||
|
final ApiGateway gateway;
|
||||||
final RunPipelineIntent? pending;
|
final RunPipelineIntent? pending;
|
||||||
final bool cupertino;
|
final bool cupertino;
|
||||||
final Future<RunPipelineOutcome> Function(RunPipelineIntent intent) onSubmit;
|
final Future<RunPipelineOutcome> Function(RunPipelineIntent intent) onSubmit;
|
||||||
@@ -70,6 +75,8 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
|||||||
late RunNotifyMode _notify;
|
late RunNotifyMode _notify;
|
||||||
late RunPipelineIntent? _intent;
|
late RunPipelineIntent? _intent;
|
||||||
bool _sending = false;
|
bool _sending = false;
|
||||||
|
bool _directoriesLoading = true;
|
||||||
|
List<String> _directories = const [];
|
||||||
String? _error;
|
String? _error;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -86,8 +93,45 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
|||||||
_prompt = TextEditingController(text: restored?.prompt ?? '');
|
_prompt = TextEditingController(text: restored?.prompt ?? '');
|
||||||
_workspace = TextEditingController(text: restored?.workspace ?? '');
|
_workspace = TextEditingController(text: restored?.workspace ?? '');
|
||||||
_error = restored == null ? null : runPipelineUnknownAdmission;
|
_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
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_prompt.dispose();
|
_prompt.dispose();
|
||||||
@@ -213,10 +257,18 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
|||||||
RunPipelineFields(
|
RunPipelineFields(
|
||||||
prompt: _prompt,
|
prompt: _prompt,
|
||||||
workspace: _workspace,
|
workspace: _workspace,
|
||||||
|
directories: _directories,
|
||||||
|
cupertino: widget.cupertino,
|
||||||
|
onChooseDirectory: _chooseDirectory,
|
||||||
notifyMode: _notify,
|
notifyMode: _notify,
|
||||||
locked: _locked,
|
locked: _locked,
|
||||||
onNotifyChanged: (mode) => setState(() => _notify = mode),
|
onNotifyChanged: (mode) => setState(() => _notify = mode),
|
||||||
),
|
),
|
||||||
|
if (_directoriesLoading)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 4),
|
||||||
|
child: Text(runPipelineDirectoriesLoading),
|
||||||
|
),
|
||||||
if (_error case final error?)
|
if (_error case final error?)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 12),
|
padding: const EdgeInsets.only(top: 12),
|
||||||
@@ -228,4 +280,8 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _chooseDirectory(String directory) {
|
||||||
|
_workspace.text = directory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ class RunPipelineFields extends StatelessWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.prompt,
|
required this.prompt,
|
||||||
required this.workspace,
|
required this.workspace,
|
||||||
|
required this.directories,
|
||||||
|
required this.cupertino,
|
||||||
|
required this.onChooseDirectory,
|
||||||
required this.notifyMode,
|
required this.notifyMode,
|
||||||
required this.locked,
|
required this.locked,
|
||||||
required this.onNotifyChanged,
|
required this.onNotifyChanged,
|
||||||
@@ -21,6 +24,9 @@ class RunPipelineFields extends StatelessWidget {
|
|||||||
|
|
||||||
final TextEditingController prompt;
|
final TextEditingController prompt;
|
||||||
final TextEditingController workspace;
|
final TextEditingController workspace;
|
||||||
|
final List<String> directories;
|
||||||
|
final bool cupertino;
|
||||||
|
final ValueChanged<String> onChooseDirectory;
|
||||||
final RunNotifyMode notifyMode;
|
final RunNotifyMode notifyMode;
|
||||||
final bool locked;
|
final bool locked;
|
||||||
final ValueChanged<RunNotifyMode> onNotifyChanged;
|
final ValueChanged<RunNotifyMode> onNotifyChanged;
|
||||||
@@ -77,18 +83,51 @@ class RunPipelineFields extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _workspaceField(BuildContext context, bool cupertino) {
|
Widget _workspaceField(BuildContext context, bool cupertino) {
|
||||||
if (cupertino) {
|
final field = cupertino
|
||||||
return CupertinoTextField(
|
? _cupertinoWorkspace(context)
|
||||||
key: runPipelineWorkspaceKey,
|
: _materialWorkspace();
|
||||||
controller: workspace,
|
return Row(
|
||||||
placeholder: runPipelineWorkspacePlaceholder,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
placeholderStyle: _cupertinoPlaceholder(context),
|
children: [
|
||||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
Expanded(child: field),
|
||||||
enabled: !locked,
|
if (directories.isNotEmpty)
|
||||||
autocorrect: false,
|
cupertino
|
||||||
padding: const EdgeInsets.all(8),
|
? 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(
|
return TextField(
|
||||||
key: runPipelineWorkspaceKey,
|
key: runPipelineWorkspaceKey,
|
||||||
controller: workspace,
|
controller: workspace,
|
||||||
@@ -101,6 +140,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) {
|
Widget _notifyField(BuildContext context, bool cupertino) {
|
||||||
if (cupertino) {
|
if (cupertino) {
|
||||||
return CupertinoButton(
|
return CupertinoButton(
|
||||||
@@ -159,7 +219,9 @@ class RunPipelineFields extends StatelessWidget {
|
|||||||
TextStyle _cupertinoPlaceholder(BuildContext context) {
|
TextStyle _cupertinoPlaceholder(BuildContext context) {
|
||||||
// The host's own dynamic placeholder colour (light and dark), resolved for
|
// The host's own dynamic placeholder colour (light and dark), resolved for
|
||||||
// the dialog's inherited Cupertino brightness.
|
// 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) {
|
Widget _helper(BuildContext context, String text, bool cupertino) {
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ const runPipelineWorkspaceLabel = 'Working directory (on the server)';
|
|||||||
const runPipelineWorkspaceHelper =
|
const runPipelineWorkspaceHelper =
|
||||||
'Choose a recent directory or type an absolute path.';
|
'Choose a recent directory or type an absolute path.';
|
||||||
const runPipelineWorkspacePlaceholder = '/absolute/path/on/the/server';
|
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 runPipelineNotifyLabel = 'Notifications for this run';
|
||||||
const runPipelineCancelLabel = 'Cancel';
|
const runPipelineCancelLabel = 'Cancel';
|
||||||
const runPipelineConfirmLabel = 'Run';
|
const runPipelineConfirmLabel = 'Run';
|
||||||
@@ -43,7 +47,5 @@ const runPipelineErrorKey = ValueKey<String>('run-pipeline-error');
|
|||||||
|
|
||||||
/// The server's refusal, verbatim. Only a blank error gets a sentence so the
|
/// The server's refusal, verbatim. Only a blank error gets a sentence so the
|
||||||
/// prompt never claims a run that was not admitted.
|
/// prompt never claims a run that was not admitted.
|
||||||
String describeRunPipelineError(Object error) => describeErrorReason(
|
String describeRunPipelineError(Object error) =>
|
||||||
error,
|
describeErrorReason(error, fallback: 'The server did not start the run.');
|
||||||
fallback: 'The server did not start the run.',
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:pipelines_app/core/api_gateway.dart';
|
import 'package:pipelines_app/core/api_gateway.dart';
|
||||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||||
@@ -28,6 +29,10 @@ FakeGateway launchGateway(
|
|||||||
)!,
|
)!,
|
||||||
),
|
),
|
||||||
'list_schedules' => {'type': 'schedules', 'schedules': <dynamic>[]},
|
'list_schedules' => {'type': 'schedules', 'schedules': <dynamic>[]},
|
||||||
|
'chat_directories' => {
|
||||||
|
'type': 'chat_directories',
|
||||||
|
'chat_directories': ['/work/recent', 'relative', '/work/other'],
|
||||||
|
},
|
||||||
'run_pipeline' => onLaunch(fields),
|
'run_pipeline' => onLaunch(fields),
|
||||||
'get_run' when onLookup != null => onLookup(fields),
|
'get_run' when onLookup != null => onLookup(fields),
|
||||||
_ => errorReply('unexpected $type'),
|
_ => errorReply('unexpected $type'),
|
||||||
@@ -74,6 +79,45 @@ Future<void> fillFields(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
testWidgets(
|
||||||
|
'workspace directory suggestions load on open and selection is local',
|
||||||
|
(tester) async {
|
||||||
|
final fixture = PipelineFixture();
|
||||||
|
final gateway = launchGateway(fixture, onLaunch: (_) => acceptedRun(76));
|
||||||
|
await pumpScreen(tester, gateway, <int>[]);
|
||||||
|
await openDetail(tester);
|
||||||
|
await tester.tap(find.byKey(runPipelineActionKey));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(gateway.callsOf('chat_directories'), hasLength(1));
|
||||||
|
expect(find.text(runPipelineDirectoriesLoading), findsNothing);
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<TextField>(find.byKey(runPipelineWorkspaceKey))
|
||||||
|
.controller
|
||||||
|
?.text,
|
||||||
|
'/work/recent',
|
||||||
|
);
|
||||||
|
await tester.tap(find.byKey(runPipelineWorkspaceSuggestionsKey));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('/work/other'), findsOneWidget);
|
||||||
|
expect(find.text('relative'), findsNothing);
|
||||||
|
await tester.tap(find.text('/work/other'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
tester
|
||||||
|
.widget<TextField>(find.byKey(runPipelineWorkspaceKey))
|
||||||
|
.controller
|
||||||
|
?.text,
|
||||||
|
'/work/other',
|
||||||
|
);
|
||||||
|
expect(gateway.callsOf('run_pipeline'), isEmpty);
|
||||||
|
expect(gateway.callsOf('chat_directories'), hasLength(1));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
testWidgets('the detail Run action sends the web request for the pinned '
|
testWidgets('the detail Run action sends the web request for the pinned '
|
||||||
'version and opens only the reply run', (tester) async {
|
'version and opens only the reply run', (tester) async {
|
||||||
final fixture = PipelineFixture();
|
final fixture = PipelineFixture();
|
||||||
@@ -104,10 +148,7 @@ void main() {
|
|||||||
expect(gateway.callsOf('run_pipeline'), isEmpty);
|
expect(gateway.callsOf('run_pipeline'), isEmpty);
|
||||||
|
|
||||||
await fillFields(tester, prompt: ' Review the change. ');
|
await fillFields(tester, prompt: ' Review the change. ');
|
||||||
await tester.enterText(
|
await tester.enterText(find.byKey(runPipelineWorkspaceKey), '/work/alpha ');
|
||||||
find.byKey(runPipelineWorkspaceKey),
|
|
||||||
'/work/alpha ',
|
|
||||||
);
|
|
||||||
await tester.tap(find.byKey(runPipelineNotifyKey));
|
await tester.tap(find.byKey(runPipelineNotifyKey));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
await tester.tap(find.text('Silent').last);
|
await tester.tap(find.text('Silent').last);
|
||||||
@@ -495,13 +536,7 @@ void main() {
|
|||||||
final helper = tester
|
final helper = tester
|
||||||
.widget<Text>(find.text(runPipelineWorkspaceHelper))
|
.widget<Text>(find.text(runPipelineWorkspaceHelper))
|
||||||
.style;
|
.style;
|
||||||
expect(
|
expect(helper?.color, CupertinoColors.secondaryLabel.resolveFrom(context));
|
||||||
helper?.color,
|
expect(helper?.fontSize, theme.textTheme.tabLabelTextStyle.fontSize);
|
||||||
CupertinoColors.secondaryLabel.resolveFrom(context),
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
helper?.fontSize,
|
|
||||||
theme.textTheme.tabLabelTextStyle.fontSize,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user