feat(app): suggest server workspaces in run dialog
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
@@ -70,6 +75,8 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
late RunNotifyMode _notify;
|
||||
late RunPipelineIntent? _intent;
|
||||
bool _sending = false;
|
||||
bool _directoriesLoading = true;
|
||||
List<String> _directories = const [];
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
@@ -86,8 +93,45 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
_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();
|
||||
@@ -213,10 +257,18 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
RunPipelineFields(
|
||||
prompt: _prompt,
|
||||
workspace: _workspace,
|
||||
directories: _directories,
|
||||
cupertino: widget.cupertino,
|
||||
onChooseDirectory: _chooseDirectory,
|
||||
notifyMode: _notify,
|
||||
locked: _locked,
|
||||
onNotifyChanged: (mode) => setState(() => _notify = mode),
|
||||
),
|
||||
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 +280,8 @@ class _RunPipelineDialogState extends State<_RunPipelineDialog> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _chooseDirectory(String directory) {
|
||||
_workspace.text = directory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ 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.locked,
|
||||
required this.onNotifyChanged,
|
||||
@@ -21,6 +24,9 @@ class RunPipelineFields extends StatelessWidget {
|
||||
|
||||
final TextEditingController prompt;
|
||||
final TextEditingController workspace;
|
||||
final List<String> directories;
|
||||
final bool cupertino;
|
||||
final ValueChanged<String> onChooseDirectory;
|
||||
final RunNotifyMode notifyMode;
|
||||
final bool locked;
|
||||
final ValueChanged<RunNotifyMode> onNotifyChanged;
|
||||
@@ -77,18 +83,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 +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) {
|
||||
if (cupertino) {
|
||||
return CupertinoButton(
|
||||
@@ -159,7 +219,9 @@ class RunPipelineFields extends StatelessWidget {
|
||||
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,6 +12,10 @@ 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 runPipelineCancelLabel = 'Cancel';
|
||||
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
|
||||
/// 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.');
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.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/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||
@@ -28,6 +29,10 @@ FakeGateway launchGateway(
|
||||
)!,
|
||||
),
|
||||
'list_schedules' => {'type': 'schedules', 'schedules': <dynamic>[]},
|
||||
'chat_directories' => {
|
||||
'type': 'chat_directories',
|
||||
'chat_directories': ['/work/recent', 'relative', '/work/other'],
|
||||
},
|
||||
'run_pipeline' => onLaunch(fields),
|
||||
'get_run' when onLookup != null => onLookup(fields),
|
||||
_ => errorReply('unexpected $type'),
|
||||
@@ -74,6 +79,45 @@ Future<void> fillFields(
|
||||
}
|
||||
|
||||
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 '
|
||||
'version and opens only the reply run', (tester) async {
|
||||
final fixture = PipelineFixture();
|
||||
@@ -104,10 +148,7 @@ void main() {
|
||||
expect(gateway.callsOf('run_pipeline'), isEmpty);
|
||||
|
||||
await fillFields(tester, prompt: ' Review the change. ');
|
||||
await tester.enterText(
|
||||
find.byKey(runPipelineWorkspaceKey),
|
||||
'/work/alpha ',
|
||||
);
|
||||
await tester.enterText(find.byKey(runPipelineWorkspaceKey), '/work/alpha ');
|
||||
await tester.tap(find.byKey(runPipelineNotifyKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Silent').last);
|
||||
@@ -495,13 +536,7 @@ void main() {
|
||||
final helper = tester
|
||||
.widget<Text>(find.text(runPipelineWorkspaceHelper))
|
||||
.style;
|
||||
expect(
|
||||
helper?.color,
|
||||
CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
);
|
||||
expect(
|
||||
helper?.fontSize,
|
||||
theme.textTheme.tabLabelTextStyle.fontSize,
|
||||
);
|
||||
expect(helper?.color, CupertinoColors.secondaryLabel.resolveFrom(context));
|
||||
expect(helper?.fontSize, theme.textTheme.tabLabelTextStyle.fontSize);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user