266916f92a
- 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.
320 lines
10 KiB
Dart
320 lines
10 KiB
Dart
import '../../../ui/motion/motion.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../ui/adaptive/floating_bar_layout.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../attention/notify/notification_controller.dart';
|
|
import '../../attention/runtime/attention_controller.dart';
|
|
import '../../attention/runtime/attention_store.dart';
|
|
import '../../attention/ui/needs_you_runs_heading.dart';
|
|
import '../domain/run_models.dart';
|
|
import '../../../shell/shell_bar.dart';
|
|
import 'run_list_row.dart';
|
|
import 'runs_controller.dart';
|
|
import 'runs_filter_options.dart';
|
|
import 'runs_selection_bar.dart';
|
|
import 'runs_stats_page.dart';
|
|
import 'runs_filters.dart';
|
|
|
|
export 'run_list_row.dart';
|
|
|
|
class RunsList extends StatelessWidget {
|
|
const RunsList({
|
|
super.key,
|
|
required this.controller,
|
|
required this.onSelected,
|
|
this.syncToken = 0,
|
|
this.attentionStore = const SharedPreferencesAttentionStore(),
|
|
this.attentionNow,
|
|
this.notifications,
|
|
this.attention,
|
|
this.active = true,
|
|
});
|
|
|
|
/// False while a run detail covers the list; the bar is then the run's.
|
|
final bool active;
|
|
|
|
final RunsController controller;
|
|
final ValueChanged<num> onSelected;
|
|
|
|
/// Advances when the shared socket is replaced, so the attention detector
|
|
/// rebaselines instead of replaying a transition from before the gap.
|
|
final int syncToken;
|
|
|
|
/// Test and fixture seam for the persisted attention dismissals.
|
|
final AttentionStore attentionStore;
|
|
|
|
/// Deterministic local-day clock for the attention window.
|
|
final DateTime Function()? attentionNow;
|
|
|
|
/// App-level notification delivery; absent in list-only fixtures.
|
|
final NotificationController? notifications;
|
|
|
|
/// The app's shared attention controller; absent in list-only fixtures.
|
|
final AttentionController? attention;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Select mode replaces the bar: `N selected` and its size, Delete, Done.
|
|
if (controller.selection.active) {
|
|
final bar = runsSelectionBar(context, controller);
|
|
if (!ShellBar.available(context)) {
|
|
return _ownBar(context, [
|
|
Expanded(
|
|
child: Text(
|
|
[bar.title, ?bar.subtitle].join(' · '),
|
|
key: runsSelectionCountKey,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
...bar.actions,
|
|
]);
|
|
}
|
|
return ShellBar(
|
|
active: active,
|
|
title: bar.title,
|
|
subtitle: bar.subtitle,
|
|
actions: bar.actions,
|
|
child: _list(context),
|
|
);
|
|
}
|
|
final actions = [
|
|
// The Needs-you bell sits with the other actions, freeing the row.
|
|
NeedsYouRunsHeading(
|
|
rows: controller.runs,
|
|
frames: controller.repository.gateway.frames,
|
|
onOpen: (entry) => onSelected(entry.runId),
|
|
syncToken: syncToken,
|
|
store: attentionStore,
|
|
now: attentionNow,
|
|
notifications: notifications,
|
|
attention: attention,
|
|
),
|
|
...RunsBarActions(
|
|
controller,
|
|
).build(context, onStats: () => openRunsStats(context, controller)),
|
|
if (controller.runs.isNotEmpty) runsSelectAction(context, controller),
|
|
];
|
|
// Outside the app shell (the list on its own) the actions head the list.
|
|
if (!ShellBar.available(context)) {
|
|
return _ownBar(context, [const Spacer(), ...actions]);
|
|
}
|
|
return ShellBar(
|
|
active: active,
|
|
actions: actions,
|
|
// The Runs tab counts runs still executing.
|
|
child: ShellBadge(
|
|
kind: ShellBadgeKind.running,
|
|
count: controller.runs.where((run) => run['executing'] == true).length,
|
|
child: _list(context),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _ownBar(BuildContext context, List<Widget> bar) => Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 8, 0),
|
|
child: Row(children: bar),
|
|
),
|
|
Expanded(child: _list(context)),
|
|
],
|
|
);
|
|
|
|
Widget _list(BuildContext context) {
|
|
if (controller.loading && controller.runs.isEmpty) {
|
|
return _state(
|
|
context,
|
|
icon: usesCupertinoHost(context)
|
|
? const CupertinoActivityIndicator()
|
|
: const CircularProgressIndicator(),
|
|
title: 'Loading runs…',
|
|
);
|
|
}
|
|
if (controller.error != null && controller.runs.isEmpty) {
|
|
return _emptyError(context);
|
|
}
|
|
// The notice and the applied filters lead the list, so they scroll
|
|
// behind the top bar with the runs and start below it at rest.
|
|
final header = [
|
|
if (controller.error != null) _inlineError(context),
|
|
if (controller.selection.report != null)
|
|
RunsDeleteReport(controller: controller),
|
|
RunsFilters(controller: controller),
|
|
];
|
|
if (controller.visibleRuns.isNotEmpty) return _groupedRuns(context, header);
|
|
return BelowTopBar(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
...header,
|
|
Expanded(
|
|
child: _state(
|
|
context,
|
|
icon: Icon(
|
|
usesCupertinoHost(context)
|
|
? CupertinoIcons.tray
|
|
: Icons.inbox_outlined,
|
|
),
|
|
title: 'No runs found.',
|
|
subtitle: 'Try changing or clearing the filters.',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _groupedRuns(BuildContext context, List<Widget> header) {
|
|
final entries = <_Entry>[];
|
|
if (flatRunSorts.contains(controller.sort)) {
|
|
// An order by size is one flat list: day headings would split it.
|
|
entries.addAll(
|
|
controller.visibleRuns.map((run) => (day: null, run: run)),
|
|
);
|
|
} else {
|
|
final groups = groupRunsByDay(controller.visibleRuns, DateTime.now());
|
|
for (final group in groups) {
|
|
entries.add((day: group, run: null));
|
|
entries.addAll(group.runs.map((run) => (day: null, run: run)));
|
|
}
|
|
}
|
|
// Runs that start while the list is open enter with a short fade.
|
|
return ArrivalScope(
|
|
ids: [for (final run in controller.visibleRuns) '${run['id']}'],
|
|
child: _entriesList(entries, header),
|
|
);
|
|
}
|
|
|
|
Widget _entriesList(List<_Entry> entries, List<Widget> header) {
|
|
// The default padding is the media padding: the first row starts below
|
|
// the top bar and the last clears the floating tab bar.
|
|
return ListView.builder(
|
|
itemCount: header.length + entries.length,
|
|
itemBuilder: (context, index) {
|
|
if (index < header.length) return header[index];
|
|
final entry = entries[index - header.length];
|
|
if (entry.day case final day?) {
|
|
// A day heading reads as a divider between groups of runs.
|
|
return RunsDayHeading(
|
|
label: day.label,
|
|
runs: day.runs,
|
|
controller: controller,
|
|
);
|
|
}
|
|
// The last run of a day (before the next heading) has no divider.
|
|
final next = index - header.length + 1;
|
|
final last = next >= entries.length || entries[next].run == null;
|
|
return Arrival(
|
|
id: '${entry.run!['id']}',
|
|
child: _runTile(context, entry.run!, divider: !last),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _emptyError(BuildContext context) => Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(
|
|
usesCupertinoHost(context)
|
|
? CupertinoIcons.exclamationmark_triangle
|
|
: Icons.error_outline,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(controller.error!),
|
|
const SizedBox(height: 8),
|
|
usesCupertinoHost(context)
|
|
? CupertinoButton(
|
|
onPressed: controller.load,
|
|
child: const Text('Retry'),
|
|
)
|
|
: FilledButton(
|
|
onPressed: controller.load,
|
|
child: const Text('Retry'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
Widget _state(
|
|
BuildContext context, {
|
|
required Widget icon,
|
|
required String title,
|
|
String? subtitle,
|
|
}) => Center(
|
|
// A short pane (a list beside a detail, or the keyboard up) scrolls the
|
|
// state instead of overflowing it.
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
icon,
|
|
const SizedBox(height: 12),
|
|
Text(title, textAlign: TextAlign.center),
|
|
if (subtitle != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
subtitle,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
color: usesCupertinoHost(context)
|
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
Widget _inlineError(BuildContext context) => Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Row(
|
|
children: [
|
|
Expanded(child: Text(controller.error!)),
|
|
if (usesCupertinoHost(context))
|
|
CupertinoButton(
|
|
onPressed: controller.load,
|
|
child: const Text('Retry'),
|
|
)
|
|
else
|
|
TextButton(onPressed: controller.load, child: const Text('Retry')),
|
|
],
|
|
),
|
|
);
|
|
|
|
Widget _runTile(BuildContext context, JsonMap run, {bool divider = true}) {
|
|
final id = run['id'];
|
|
final selection = controller.selection;
|
|
return RunListRow(
|
|
selecting: selection.active,
|
|
checked: selection.contains(id),
|
|
onToggle: () => selection.toggle(run),
|
|
// A long-press enters select mode with this run selected.
|
|
onLongPress: () => selection.enter(run),
|
|
onDeleted: controller.applyDeletion,
|
|
run: run,
|
|
divider: divider,
|
|
selected: id == controller.selectedRunId,
|
|
now: DateTime.now(),
|
|
onTap: id is num ? () => onSelected(id) : null,
|
|
gateway: controller.repository.gateway,
|
|
onRunChanged: controller.acceptRunDetail,
|
|
onRunOpened: onSelected,
|
|
);
|
|
}
|
|
}
|
|
|
|
typedef _Entry = ({({String label, List<JsonMap> runs})? day, JsonMap? run});
|