Files
pipelines/app/lib/features/runs/ui/runs_selection_bar.dart
T
alan a40a6e2e1c Narrow list panes: readable bar title, More overflow menu, rows keep status and actions
The floating bar keeps the title at its own width (up to half the bar) and
moves overflowable actions into one More menu instead of squeezing them
below their touch targets. List rows keep their leading status avatar and
More actions at any list-pane width; the time moves under the subtitle.
2026-11-03 18:04:10 +00:00

238 lines
7.2 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../../../ui/adaptive/segmented_bar_overflow.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();
final cupertino = usesCupertinoHost(context);
// A narrow bar moves it into its More menu.
return SegmentedOverflowAction(
overflowEntry: SegmentedOverflowEntry(
label: 'Select',
icon: cupertino ? CupertinoIcons.checkmark_circle : Icons.checklist,
onPressed: enter,
),
child: cupertino
? _selectButtonCupertino(enter)
: IconButton(
key: runsSelectKey,
tooltip: 'Select',
onPressed: enter,
icon: const Icon(Icons.checklist),
),
);
}
Widget _selectButtonCupertino(VoidCallback enter) => 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),
),
);
/// 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'),
),
],
),
);
}
}