Files
pipelines/app/lib/features/runs/ui/runs_selection_bar.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

227 lines
6.8 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/layout/section_heading.dart';
import '../actions/delete_runs_action.dart';
import '../domain/run_deletion.dart';
import 'runs_controller.dart';
const runsSelectKey = ValueKey<String>('runs.select');
const runsSelectDoneKey = ValueKey<String>('runs.select.done');
const runsDeleteSelectedKey = ValueKey<String>('runs.select.delete');
const runsSelectionCountKey = ValueKey<String>('runs.select.count');
const runsDeleteReportKey = ValueKey<String>('runs.delete.report');
const runsDeleteReportDismissKey = ValueKey<String>(
'runs.delete.report.dismiss',
);
/// The day heading's Select all / Deselect all toggle key.
ValueKey<String> runsDaySelectKey(String day) =>
ValueKey('runs.select.day.$day');
/// The Runs bar's `Select` action, entering multi-select.
Widget runsSelectAction(BuildContext context, RunsController controller) {
void enter() => controller.selection.enter();
if (usesCupertinoHost(context)) {
return Semantics(
button: true,
label: 'Select',
excludeSemantics: true,
onTap: enter,
child: CupertinoButton(
key: runsSelectKey,
padding: EdgeInsets.zero,
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
onPressed: enter,
child: const Icon(CupertinoIcons.checkmark_circle),
),
);
}
return IconButton(
key: runsSelectKey,
tooltip: 'Select',
onPressed: enter,
icon: const Icon(Icons.checklist),
);
}
/// What the bar shows in select mode: `N selected` over the selection's size,
/// then Delete and Done.
({String title, String? subtitle, List<Widget> actions}) runsSelectionBar(
BuildContext context,
RunsController controller,
) {
final selection = controller.selection;
final selected = [
for (final run in controller.runs)
if (selection.contains(run['id'])) run,
];
final count = selected.length;
final size = count == 0 ? null : runsSizeLabel(selected);
final cupertino = usesCupertinoHost(context);
final delete = count == 0
? null
: () => confirmDeleteRuns(
context,
runs: selected,
gateway: controller.repository.gateway,
onDeleted: controller.applyDeletion,
cupertino: cupertino,
);
final deleteLabel = count == 0
? 'Delete selected runs'
: 'Delete $count selected ${count == 1 ? 'run' : 'runs'}';
final List<Widget> actions;
if (cupertino) {
actions = [
Semantics(
button: true,
enabled: delete != null,
label: deleteLabel,
excludeSemantics: true,
onTap: delete,
child: CupertinoButton(
key: runsDeleteSelectedKey,
onPressed: delete,
child: Text(
'Delete',
style: TextStyle(
color: delete == null
? null
: CupertinoColors.systemRed.resolveFrom(context),
),
),
),
),
CupertinoButton(
key: runsSelectDoneKey,
onPressed: selection.exit,
child: const Text('Done'),
),
];
} else {
final scheme = Theme.of(context).colorScheme;
actions = [
Semantics(
label: deleteLabel,
excludeSemantics: true,
onTap: delete,
button: true,
enabled: delete != null,
child: TextButton(
key: runsDeleteSelectedKey,
style: TextButton.styleFrom(foregroundColor: scheme.error),
onPressed: delete,
child: const Text('Delete'),
),
),
TextButton(
key: runsSelectDoneKey,
onPressed: selection.exit,
child: const Text('Done'),
),
];
}
return (title: '$count selected', subtitle: size, actions: actions);
}
/// A day's heading; in select mode it carries that day's Select all /
/// Deselect all toggle, covering only the day's finished runs.
class RunsDayHeading extends StatelessWidget {
const RunsDayHeading({
super.key,
required this.label,
required this.runs,
required this.controller,
});
final String label;
final List<JsonMap> runs;
final RunsController controller;
@override
Widget build(BuildContext context) {
final selection = controller.selection;
final trailing = <Widget>[];
if (selection.active) {
final any = deletableRunIds(runs).isNotEmpty;
final all = selection.allSelected(runs);
final text = all ? 'Deselect all' : 'Select all';
final toggle = any ? () => selection.toggleAll(runs) : null;
final key = runsDaySelectKey(label);
trailing.add(
Semantics(
button: true,
enabled: any,
label: any
? '$text $label'
: '$text $label. No finished runs to select.',
excludeSemantics: true,
onTap: toggle,
child: usesCupertinoHost(context)
? CupertinoButton(
key: key,
padding: const EdgeInsets.symmetric(horizontal: 8),
minimumSize: const Size(0, kMinInteractiveDimensionCupertino),
onPressed: toggle,
child: Text(text),
)
: TextButton(key: key, onPressed: toggle, child: Text(text)),
),
);
}
return Padding(
padding: const EdgeInsets.only(top: 8),
child: SectionHeading(
title: label,
minHeight: 32,
header: true,
trailing: trailing,
),
);
}
}
/// The last deletion's outcome above the list, until dismissed.
class RunsDeleteReport extends StatelessWidget {
const RunsDeleteReport({super.key, required this.controller});
final RunsController controller;
@override
Widget build(BuildContext context) {
final report = controller.selection.report;
if (report == null) return const SizedBox.shrink();
final cupertino = usesCupertinoHost(context);
final dismiss = controller.selection.dismissReport;
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 8, 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Semantics(
liveRegion: true,
child: Text(report, key: runsDeleteReportKey),
),
),
cupertino
? CupertinoButton(
key: runsDeleteReportDismissKey,
padding: const EdgeInsets.symmetric(horizontal: 8),
onPressed: dismiss,
child: const Text('Dismiss'),
)
: TextButton(
key: runsDeleteReportDismissKey,
onPressed: dismiss,
child: const Text('Dismiss'),
),
],
),
);
}
}