wip(app): runs-day-groups (retained from the cancelled overrun lane)
This commit is contained in:
@@ -15,6 +15,55 @@ const runStates = [
|
||||
/// `0x7fffffffffffffff` literals failed dart2js compilation.
|
||||
const int _maxMillis = 8640000000000000;
|
||||
|
||||
String localDayKey(DateTime date) {
|
||||
final local = date.toLocal();
|
||||
String two(int value) => value.toString().padLeft(2, '0');
|
||||
return '${local.year}-${two(local.month)}-${two(local.day)}';
|
||||
}
|
||||
|
||||
String runDayLabel(String createdAt, DateTime today) {
|
||||
final created = DateTime.tryParse(createdAt)?.toLocal();
|
||||
if (created == null) return 'Unknown date';
|
||||
final day = localDayKey(created);
|
||||
if (day == localDayKey(today)) return 'Today';
|
||||
final yesterday = DateTime(
|
||||
today.year,
|
||||
today.month,
|
||||
today.day,
|
||||
).subtract(const Duration(days: 1));
|
||||
if (day == localDayKey(yesterday)) return 'Yesterday';
|
||||
const months = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec',
|
||||
];
|
||||
return '${created.day} ${months[created.month - 1]} ${created.year}';
|
||||
}
|
||||
|
||||
List<({String label, List<JsonMap> runs})> groupRunsByDay(
|
||||
List<JsonMap> sortedRuns,
|
||||
DateTime today,
|
||||
) {
|
||||
final groups = <({String label, List<JsonMap> runs})>[];
|
||||
for (final run in sortedRuns) {
|
||||
final label = runDayLabel('${run['created_at'] ?? ''}', today);
|
||||
if (groups.isEmpty || groups.last.label != label) {
|
||||
groups.add((label: label, runs: <JsonMap>[]));
|
||||
}
|
||||
groups.last.runs.add(run);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
({String label, String? pipeline}) runIdentity(dynamic title, dynamic name) {
|
||||
final stored = '${title ?? ''}'.trim();
|
||||
return (
|
||||
|
||||
@@ -74,13 +74,7 @@ class RunsList extends StatelessWidget {
|
||||
Expanded(
|
||||
child: controller.visibleRuns.isEmpty
|
||||
? const Center(child: Text('No runs found.'))
|
||||
: ListView.separated(
|
||||
itemCount: controller.visibleRuns.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const Divider(height: 1),
|
||||
itemBuilder: (context, index) =>
|
||||
_runTile(context, controller.visibleRuns[index]),
|
||||
),
|
||||
: _groupedRuns(context),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -113,6 +107,31 @@ class RunsList extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
|
||||
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,
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/features/runs/domain/run_models.dart';
|
||||
|
||||
void main() {
|
||||
group('run day grouping', () {
|
||||
final today = DateTime(2026, 10, 22, 12);
|
||||
|
||||
test('labels local days and invalid dates', () {
|
||||
expect(runDayLabel('2026-10-22T08:00:00', today), 'Today');
|
||||
expect(runDayLabel('2026-10-21T08:00:00', today), 'Yesterday');
|
||||
expect(runDayLabel('2026-10-17T08:00:00', today), '17 Oct 2026');
|
||||
expect(runDayLabel('', today), 'Unknown date');
|
||||
expect(localDayKey(DateTime(2026, 1, 2)), '2026-01-02');
|
||||
});
|
||||
|
||||
test('retains encounter order and groups adjacent equal labels', () {
|
||||
final runs = [
|
||||
{'id': 3, 'created_at': '2026-10-22T09:00:00'},
|
||||
{'id': 2, 'created_at': '2026-10-21T09:00:00'},
|
||||
{'id': 1, 'created_at': '2026-10-21T08:00:00'},
|
||||
{'id': 0, 'created_at': ''},
|
||||
];
|
||||
final groups = groupRunsByDay(runs, today);
|
||||
expect(groups.map((group) => group.label), [
|
||||
'Today',
|
||||
'Yesterday',
|
||||
'Unknown date',
|
||||
]);
|
||||
expect(groups.expand((group) => group.runs).map((run) => run['id']), [
|
||||
3,
|
||||
2,
|
||||
1,
|
||||
0,
|
||||
]);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user