feat(app): Rename and Schedule this run move into the run detail's more menu
This commit is contained in:
@@ -32,27 +32,19 @@ class RunTitleAction extends StatefulWidget {
|
||||
|
||||
class _RunTitleActionState extends State<RunTitleAction> {
|
||||
bool _dialogOpen = false;
|
||||
bool _saving = false;
|
||||
|
||||
bool _usesCupertino(BuildContext context) {
|
||||
final material = Localizations.of<MaterialLocalizations>(
|
||||
context,
|
||||
MaterialLocalizations,
|
||||
);
|
||||
return material == null;
|
||||
}
|
||||
bool _usesCupertino(BuildContext context) => _cupertinoLocale(context);
|
||||
|
||||
Future<void> _open() async {
|
||||
final id = runTitleId(widget.run);
|
||||
if (id == null || _dialogOpen) return;
|
||||
if (_dialogOpen) return;
|
||||
_dialogOpen = true;
|
||||
try {
|
||||
await showRunTitlePrompt(
|
||||
context: context,
|
||||
runId: id,
|
||||
initialTitle: storedRunTitle(widget.run),
|
||||
cupertino: _usesCupertino(context),
|
||||
onSubmit: (title) => _submit(id, title),
|
||||
await openRunTitleEditor(
|
||||
context,
|
||||
run: widget.run,
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: widget.onRunChanged,
|
||||
owns: (id) => mounted && runTitleId(widget.run) == id,
|
||||
);
|
||||
} finally {
|
||||
_dialogOpen = false;
|
||||
@@ -60,23 +52,6 @@ class _RunTitleActionState extends State<RunTitleAction> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<ActionRefusal?> _submit(num id, String title) async {
|
||||
if (_saving) return const ActionRefusal(actionAlreadySending);
|
||||
_saving = true;
|
||||
try {
|
||||
final run = await RunsRepository(widget.gateway).setRunTitle(id, title);
|
||||
if (!mounted) return null;
|
||||
if (_owns(id)) widget.onRunChanged(run);
|
||||
return null;
|
||||
} catch (error) {
|
||||
return ActionRefusal(describeTitleError(error));
|
||||
} finally {
|
||||
_saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool _owns(num id) => mounted && runTitleId(widget.run) == id;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (runTitleId(widget.run) == null) return const SizedBox.shrink();
|
||||
@@ -96,6 +71,44 @@ class _RunTitleActionState extends State<RunTitleAction> {
|
||||
}
|
||||
}
|
||||
|
||||
bool _cupertinoLocale(BuildContext context) =>
|
||||
Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) ==
|
||||
null;
|
||||
|
||||
/// Opens the rename prompt for [run]; only Save sends `set_run_title`, and the
|
||||
/// server's returned detail reaches [onRunChanged] while [owns] still holds
|
||||
/// for that run id. Shared by the button and the run detail's more menu.
|
||||
Future<void> openRunTitleEditor(
|
||||
BuildContext context, {
|
||||
required JsonMap run,
|
||||
required ApiGateway gateway,
|
||||
required ValueChanged<JsonMap> onRunChanged,
|
||||
required bool Function(num id) owns,
|
||||
}) async {
|
||||
final id = runTitleId(run);
|
||||
if (id == null) return;
|
||||
var saving = false;
|
||||
await showRunTitlePrompt(
|
||||
context: context,
|
||||
runId: id,
|
||||
initialTitle: storedRunTitle(run),
|
||||
cupertino: _cupertinoLocale(context),
|
||||
onSubmit: (title) async {
|
||||
if (saving) return const ActionRefusal(actionAlreadySending);
|
||||
saving = true;
|
||||
try {
|
||||
final updated = await RunsRepository(gateway).setRunTitle(id, title);
|
||||
if (owns(id)) onRunChanged(updated);
|
||||
return null;
|
||||
} catch (error) {
|
||||
return ActionRefusal(describeTitleError(error));
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// The run id used by the rename request, or null for a malformed run.
|
||||
num? runTitleId(JsonMap run) {
|
||||
final id = run['id'];
|
||||
|
||||
@@ -2,12 +2,10 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../artifacts/ui/artifact_gallery_action.dart';
|
||||
import '../../schedules/ui/run/schedule_run_action.dart';
|
||||
import '../actions/cancel_eligibility.dart';
|
||||
import '../actions/cancel_run_action.dart';
|
||||
import '../actions/retry_action.dart';
|
||||
import '../actions/retry_eligibility.dart';
|
||||
import '../actions/title_action.dart';
|
||||
import 'run_decision_notice.dart';
|
||||
|
||||
/// Native actions on the loaded run, all using the app's one gateway and
|
||||
@@ -47,14 +45,6 @@ class RunDetailActions extends StatelessWidget {
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
if (runTitleId(run) != null)
|
||||
RunTitleAction(
|
||||
run: run,
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
),
|
||||
if (canScheduleRun(run))
|
||||
ScheduleRunAction(run: run, gateway: gateway),
|
||||
if (retry && retryRunId(run) != null && canRetryRun(run))
|
||||
RetryRunAction(
|
||||
run: run,
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../domain/run_models.dart';
|
||||
import 'run_changes_action.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_tabs.dart';
|
||||
import 'run_more_menu.dart';
|
||||
|
||||
/// The runs detail with standard Cupertino controls. It has no Material
|
||||
/// ancestor: the host header keeps native navigation, actions and notices, and
|
||||
@@ -65,6 +66,12 @@ Widget buildCupertinoRunDetail({
|
||||
),
|
||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||
if (copying) const CupertinoActivityIndicator(),
|
||||
RunMoreMenu(
|
||||
run: run,
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
cupertino: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../domain/run_models.dart';
|
||||
import 'run_changes_action.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import 'run_detail_tabs.dart';
|
||||
import 'run_more_menu.dart';
|
||||
|
||||
/// The runs detail with standard Material controls.
|
||||
///
|
||||
@@ -45,17 +46,30 @@ Widget buildMaterialRunDetail({
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to list'),
|
||||
Expanded(
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to list'),
|
||||
),
|
||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||
],
|
||||
),
|
||||
),
|
||||
RunMoreMenu(
|
||||
run: run,
|
||||
gateway: gateway,
|
||||
onRunChanged: onRunChanged,
|
||||
cupertino: false,
|
||||
),
|
||||
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../schedules/ui/run/schedule_run_action.dart';
|
||||
import '../actions/title_action.dart';
|
||||
import '../actions/title_wording.dart';
|
||||
|
||||
const runMoreMenuKey = ValueKey<String>('run-more-menu');
|
||||
|
||||
/// Whether the run has anything for its more menu.
|
||||
bool showRunMoreMenu(JsonMap run) =>
|
||||
runTitleId(run) != null || canScheduleRun(run);
|
||||
|
||||
enum _RunMoreItem { rename, schedule }
|
||||
|
||||
/// The run detail's more menu: Rename and Schedule this run, which act on the
|
||||
/// run's pipeline record rather than its progress, kept out of the header.
|
||||
/// This widget stays mounted while a picked flow runs, so the flow's result
|
||||
/// still reaches the current run.
|
||||
class RunMoreMenu extends StatefulWidget {
|
||||
const RunMoreMenu({
|
||||
super.key,
|
||||
required this.run,
|
||||
required this.gateway,
|
||||
required this.onRunChanged,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
final ApiGateway gateway;
|
||||
final ValueChanged<JsonMap> onRunChanged;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<RunMoreMenu> createState() => _RunMoreMenuState();
|
||||
}
|
||||
|
||||
class _RunMoreMenuState extends State<RunMoreMenu> {
|
||||
JsonMap get run => widget.run;
|
||||
|
||||
List<(_RunMoreItem, String)> get _items => [
|
||||
if (runTitleId(run) != null) (_RunMoreItem.rename, runTitleActionLabel),
|
||||
if (canScheduleRun(run)) (_RunMoreItem.schedule, scheduleRunActionLabel),
|
||||
];
|
||||
|
||||
void _pick(BuildContext context, _RunMoreItem item) {
|
||||
switch (item) {
|
||||
case _RunMoreItem.rename:
|
||||
openRunTitleEditor(
|
||||
context,
|
||||
run: run,
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: widget.onRunChanged,
|
||||
// The latest run, so a result for a run no longer shown is dropped.
|
||||
owns: (owned) => mounted && runTitleId(widget.run) == owned,
|
||||
);
|
||||
case _RunMoreItem.schedule:
|
||||
openScheduleRunEditor(context, run: run, gateway: widget.gateway);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final items = _items;
|
||||
if (items.isEmpty) return const SizedBox.shrink();
|
||||
if (!widget.cupertino) {
|
||||
return PopupMenuButton<_RunMoreItem>(
|
||||
key: runMoreMenuKey,
|
||||
icon: const Icon(Icons.more_vert),
|
||||
tooltip: 'More actions',
|
||||
onSelected: (item) => _pick(context, item),
|
||||
itemBuilder: (_) => [
|
||||
for (final (item, label) in items)
|
||||
PopupMenuItem(value: item, child: Text(label)),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: 'More actions',
|
||||
excludeSemantics: true,
|
||||
child: CupertinoButton(
|
||||
key: runMoreMenuKey,
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
|
||||
onPressed: () async {
|
||||
final picked = await showCupertinoModalPopup<_RunMoreItem>(
|
||||
context: context,
|
||||
builder: (sheet) => CupertinoActionSheet(
|
||||
actions: [
|
||||
for (final (item, label) in items)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.of(sheet).pop(item),
|
||||
child: Text(label),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(sheet).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (picked != null && context.mounted) _pick(context, picked);
|
||||
},
|
||||
child: const Icon(CupertinoIcons.ellipsis_circle),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,25 @@ bool canScheduleRun(JsonMap run) =>
|
||||
|
||||
bool _positive(int? value) => value != null && value > 0;
|
||||
|
||||
/// Opens the create editor over [ScheduleDraft.fromRun]; nothing is sent until
|
||||
/// Save. One request key is minted per opening, so retrying a refused save
|
||||
/// cannot create a duplicate. Shared by the button and the run's more menu.
|
||||
Future<void> openScheduleRunEditor(
|
||||
BuildContext context, {
|
||||
required JsonMap run,
|
||||
required ApiGateway gateway,
|
||||
}) async {
|
||||
if (!canScheduleRun(run)) return;
|
||||
final requestKey = newScheduleCreateRequestKey();
|
||||
final repository = SchedulesRepository(gateway);
|
||||
await openSchedulePipelineEditor(
|
||||
context,
|
||||
draft: ScheduleDraft.fromRun(run),
|
||||
onSubmit: (record) =>
|
||||
repository.saveSchedule(record, requestKey: requestKey),
|
||||
);
|
||||
}
|
||||
|
||||
/// The run detail's "Schedule this run" action.
|
||||
///
|
||||
/// Pressing it only opens the landed create editor over [ScheduleDraft.fromRun]:
|
||||
@@ -49,17 +68,13 @@ class _ScheduleRunActionState extends State<ScheduleRunAction> {
|
||||
bool _opening = false;
|
||||
|
||||
Future<void> _open() async {
|
||||
if (_opening || !canScheduleRun(widget.run)) return;
|
||||
if (_opening) return;
|
||||
_opening = true;
|
||||
// Minted once for this editor; every retry inside it reuses the key.
|
||||
final requestKey = newScheduleCreateRequestKey();
|
||||
final repository = SchedulesRepository(widget.gateway);
|
||||
try {
|
||||
await openSchedulePipelineEditor(
|
||||
await openScheduleRunEditor(
|
||||
context,
|
||||
draft: ScheduleDraft.fromRun(widget.run),
|
||||
onSubmit: (record) =>
|
||||
repository.saveSchedule(record, requestKey: requestKey),
|
||||
run: widget.run,
|
||||
gateway: widget.gateway,
|
||||
);
|
||||
} finally {
|
||||
_opening = false;
|
||||
|
||||
Reference in New Issue
Block a user