Files
pipelines/app/lib/features/runs/actions/delete_runs_dialog.dart
T
alan 266916f92a Runs: multi-select delete, run sizes and Largest-first sort
- Select mode (bar Select or long-press): per-row checkboxes, per-day
  Select all/Deselect all over finished runs only, "N selected" with the
  selection size, Delete and Done. Active runs get a disabled checkbox
  whose semantics give the reason.
- Native destructive confirmation, then delete_runs {run_ids} (batched by
  1000); the nested runs_deleted reply removes deleted rows and reports
  "Deleted N runs, freed X" plus refusals verbatim. runs_removed pushes
  remove rows and close an open detail; a deleted open run closes too.
  Delete run in the row and detail menus.
- size_bytes shown compactly in rows (0/absent = unknown, nothing shown),
  updated from run_event frames that carry it; Largest first sort (flat,
  unknowns last); the sort choice persists.
- Shared AppListRow gains selectionControl and onLongPress.
- Browser probe tool/runs_delete_probe.mjs; fixture server implements
  delete_runs/runs_removed.
2026-10-31 22:19:36 +00:00

155 lines
4.2 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../domain/run_deletion.dart';
const deleteRunsConfirmKey = ValueKey<String>('runs.delete.confirm');
const deleteRunsKeepKey = ValueKey<String>('runs.delete.keep');
const deleteRunsErrorKey = ValueKey<String>('runs.delete.error');
/// Sends the confirmed deletion. Returns null once the server replied, or the
/// failure to show in the still-open prompt.
typedef DeleteRunsSubmit = Future<String?> Function();
/// Opens the native destructive confirmation for deleting [count] runs.
///
/// Nothing is sent until Delete is pressed; Cancel only closes the prompt.
/// Resolves true when the server answered the deletion.
Future<bool> showDeleteRunsPrompt({
required BuildContext context,
required int count,
required String? size,
required bool cupertino,
required DeleteRunsSubmit onSubmit,
}) async {
final prompt = _DeleteRunsPrompt(
count: count,
size: size,
cupertino: cupertino,
onSubmit: onSubmit,
);
final result = cupertino
? await showCupertinoDialog<bool>(
context: context,
barrierDismissible: false,
builder: (_) => prompt,
)
: await showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (_) => prompt,
);
return result ?? false;
}
class _DeleteRunsPrompt extends StatefulWidget {
const _DeleteRunsPrompt({
required this.count,
required this.size,
required this.cupertino,
required this.onSubmit,
});
final int count;
final String? size;
final bool cupertino;
final DeleteRunsSubmit onSubmit;
@override
State<_DeleteRunsPrompt> createState() => _DeleteRunsPromptState();
}
class _DeleteRunsPromptState extends State<_DeleteRunsPrompt> {
bool _sending = false;
String? _error;
Future<void> _confirm() async {
if (_sending) return;
setState(() {
_sending = true;
_error = null;
});
final error = await widget.onSubmit();
if (!mounted) return;
if (error == null) {
Navigator.of(context).pop(true);
return;
}
setState(() {
_sending = false;
_error = error;
});
}
void _keep() {
if (!_sending) Navigator.of(context).pop(false);
}
@override
Widget build(BuildContext context) => PopScope(
canPop: !_sending,
child: widget.cupertino ? _cupertinoDialog(context) : _material(context),
);
Widget _material(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return AlertDialog(
scrollable: true,
title: Text(deleteRunsTitle(widget.count)),
content: _body(TextStyle(color: scheme.error)),
actions: [
TextButton(
key: deleteRunsKeepKey,
onPressed: _sending ? null : _keep,
child: const Text('Cancel'),
),
FilledButton(
key: deleteRunsConfirmKey,
style: FilledButton.styleFrom(
backgroundColor: scheme.error,
foregroundColor: scheme.onError,
),
onPressed: _sending ? null : _confirm,
child: Text(_sending ? 'Deleting…' : 'Delete'),
),
],
);
}
Widget _cupertinoDialog(BuildContext context) => CupertinoAlertDialog(
title: Text(deleteRunsTitle(widget.count)),
content: _body(
TextStyle(color: CupertinoColors.systemRed.resolveFrom(context)),
),
actions: [
CupertinoDialogAction(
key: deleteRunsKeepKey,
onPressed: _sending ? null : _keep,
child: const Text('Cancel'),
),
CupertinoDialogAction(
key: deleteRunsConfirmKey,
isDestructiveAction: true,
onPressed: _sending ? null : _confirm,
child: Text(_sending ? 'Deleting…' : 'Delete'),
),
],
);
Widget _body(TextStyle errorStyle) => Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(deleteRunsMessage(widget.count, size: widget.size)),
if (_error case final error?)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Semantics(
liveRegion: true,
child: Text(error, key: deleteRunsErrorKey, style: errorStyle),
),
),
],
);
}