208 lines
6.7 KiB
Dart
208 lines
6.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../../ui/status/run_status_icon.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 'runs_controller.dart';
|
|
import 'runs_filters.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,
|
|
});
|
|
|
|
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) {
|
|
if (controller.loading && controller.runs.isEmpty) {
|
|
return Center(
|
|
child: usesCupertinoHost(context)
|
|
? const CupertinoActivityIndicator()
|
|
: const CircularProgressIndicator(),
|
|
);
|
|
}
|
|
if (controller.error != null && controller.runs.isEmpty) {
|
|
return _emptyError(context);
|
|
}
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
_heading(context),
|
|
if (controller.error != null) _inlineError(context),
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
|
child: usesCupertinoHost(context)
|
|
? CupertinoSearchTextField(
|
|
placeholder: 'Filter runs',
|
|
onChanged: controller.setQuery,
|
|
)
|
|
: TextField(
|
|
decoration: const InputDecoration(
|
|
hintText: 'Filter runs',
|
|
isDense: true,
|
|
prefixIcon: Icon(Icons.search),
|
|
),
|
|
onChanged: controller.setQuery,
|
|
),
|
|
),
|
|
RunsFilters(
|
|
controller: controller,
|
|
action: NeedsYouRunsHeading(
|
|
rows: controller.runs,
|
|
frames: controller.repository.gateway.frames,
|
|
onOpen: (entry) => onSelected(entry.runId),
|
|
syncToken: syncToken,
|
|
store: attentionStore,
|
|
now: attentionNow,
|
|
notifications: notifications,
|
|
attention: attention,
|
|
),
|
|
),
|
|
Expanded(
|
|
child: controller.visibleRuns.isEmpty
|
|
? const Center(child: Text('No runs found.'))
|
|
: _groupedRuns(context),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _heading(BuildContext context) {
|
|
final usage = controller.usage;
|
|
if (usage == null) return const SizedBox.shrink();
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 0),
|
|
child: Text(
|
|
'Usage: $usage',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _groupedRuns(BuildContext context) {
|
|
final groups = groupRunsByDay(controller.visibleRuns, DateTime.now());
|
|
final entries = <({String? label, JsonMap? run})>[];
|
|
for (final group in groups) {
|
|
entries.add((label: group.label, run: null));
|
|
entries.addAll(group.runs.map((run) => (label: null, run: run)));
|
|
}
|
|
return ListView.builder(
|
|
itemCount: entries.length,
|
|
itemBuilder: (context, index) {
|
|
final entry = entries[index];
|
|
if (entry.label case final label?) {
|
|
final style = usesCupertinoHost(context)
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: Theme.of(context).textTheme.labelLarge;
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
|
|
child: Semantics(header: true, child: Text(label, style: style)),
|
|
);
|
|
}
|
|
return _runTile(context, entry.run!);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _emptyError(BuildContext context) => Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
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 _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) {
|
|
final identity = runIdentity(run['title'], run['name']);
|
|
final id = run['id'];
|
|
final title = identity.label.isEmpty ? 'Run $id' : identity.label;
|
|
// As the web's run row: the coloured status glyph leads (its tooltip and
|
|
// accessible name are the state word), then the run, then
|
|
// `pipeline · run N · local time · duration`.
|
|
final meta = [
|
|
'${run['name'] ?? 'Pipeline unavailable'}',
|
|
runRowMetaText(run, DateTime.now()),
|
|
if (run['scheduled'] == true) 'Scheduled',
|
|
].join(' · ');
|
|
final status = RunStatusIcon(
|
|
state: runStateOf(run['status']),
|
|
label: runStatusLabel(run),
|
|
);
|
|
if (usesCupertinoHost(context)) {
|
|
return CupertinoListTile(
|
|
leading: status,
|
|
title: Text(title),
|
|
subtitle: Text(meta),
|
|
trailing: const CupertinoListTileChevron(),
|
|
onTap: id is num ? () => onSelected(id) : null,
|
|
);
|
|
}
|
|
return ListTile(
|
|
leading: status,
|
|
title: Text(title),
|
|
subtitle: Text(meta),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: id is num ? () => onSelected(id) : null,
|
|
);
|
|
}
|
|
}
|