a44f31b989
Read-only Pipelines screen for the Flutter client: - list_pipelines and list_runs with a last-run join, plus get_pipeline with an explicit version (0 = latest); no mutation requests. - Name, run-presence, last-run-status and schedule filters; six sort orders; clear filters; truthful loading, empty and error states. - Detail Summary, selectable Source and version history with selection and return to latest. - Sequenced list/detail requests so stale replies cannot replace a newer selection or open a cleared one; refresh keeps the selected pipeline and version. - Material controls on Android/desktop and Cupertino on iOS; a per-label segmented tab row at narrow widths and scaled text, with the native control kept wherever an equal share fits. - Fixture probe entry and Chrome scripts for the rendered evidence; widget tests cover filters, sorting, formatting, sequencing, layout and the tab row. Graph rendering remains P2: the Graph tab states that it is pending and exposes a host hook. PipelinesScreen is not yet registered in the shell. Evidence and limits: app/notes/P1.md.
98 lines
3.2 KiB
Dart
98 lines
3.2 KiB
Dart
import 'pipeline_format.dart';
|
|
import 'pipeline_models.dart';
|
|
|
|
/// The pipeline-list orderings offered by the sort control.
|
|
enum PipelineSort {
|
|
serverOrder('Server order'),
|
|
nameAsc('Name A\u2013Z'),
|
|
nameDesc('Name Z\u2013A'),
|
|
recentRun('Most recent run'),
|
|
fewestStages('Fewest stages'),
|
|
mostStages('Most stages');
|
|
|
|
const PipelineSort(this.label);
|
|
|
|
final String label;
|
|
}
|
|
|
|
/// Case-insensitive primary comparison, then a case-sensitive tie-break.
|
|
int _compareInsensitive(String a, String b) {
|
|
final x = a.toUpperCase();
|
|
final y = b.toUpperCase();
|
|
final primary = x.compareTo(y);
|
|
return primary != 0 ? primary : a.compareTo(b);
|
|
}
|
|
|
|
/// The pure comparator for [sort], with an original-index final tie-break so
|
|
/// equal rows keep the server's order regardless of sort stability.
|
|
int _compare(
|
|
PipelineSummary a,
|
|
PipelineSummary b,
|
|
PipelineSort sort,
|
|
Map<int, PipelineRun> latestRuns,
|
|
int indexA,
|
|
int indexB,
|
|
) {
|
|
final stable = indexA - indexB;
|
|
switch (sort) {
|
|
case PipelineSort.serverOrder:
|
|
return stable;
|
|
case PipelineSort.nameAsc:
|
|
final name = _compareInsensitive(a.name, b.name);
|
|
if (name != 0) return name;
|
|
return a.id != b.id ? a.id - b.id : stable;
|
|
case PipelineSort.nameDesc:
|
|
final folded = -a.name.toUpperCase().compareTo(b.name.toUpperCase());
|
|
if (folded != 0) return folded;
|
|
final sensitive = a.name.compareTo(b.name);
|
|
if (sensitive != 0) return sensitive;
|
|
return a.id != b.id ? a.id - b.id : stable;
|
|
case PipelineSort.recentRun:
|
|
final ra = latestRuns[a.id];
|
|
final rb = latestRuns[b.id];
|
|
if ((ra == null) != (rb == null)) return ra == null ? 1 : -1;
|
|
final timeA = ra == null ? null : parseInstant(ra.createdAt);
|
|
final timeB = rb == null ? null : parseInstant(rb.createdAt);
|
|
if (timeA != timeB) {
|
|
if (timeA == null) return 1;
|
|
if (timeB == null) return -1;
|
|
return timeA.isAfter(timeB) ? -1 : 1;
|
|
}
|
|
final idA = ra?.id ?? -1;
|
|
final idB = rb?.id ?? -1;
|
|
if (idA != idB) return idA > idB ? -1 : 1;
|
|
return a.id != b.id ? a.id - b.id : stable;
|
|
case PipelineSort.fewestStages:
|
|
final stages = a.stages - b.stages;
|
|
if (stages != 0) return stages;
|
|
final name = _compareInsensitive(a.name, b.name);
|
|
if (name != 0) return name;
|
|
return a.id != b.id ? a.id - b.id : stable;
|
|
case PipelineSort.mostStages:
|
|
final stages = b.stages - a.stages;
|
|
if (stages != 0) return stages;
|
|
final name = _compareInsensitive(a.name, b.name);
|
|
if (name != 0) return name;
|
|
return a.id != b.id ? a.id - b.id : stable;
|
|
}
|
|
}
|
|
|
|
/// Orders [pipelines] without mutating the input; server order is preserved
|
|
/// exactly, including when the underlying sort is unstable.
|
|
List<PipelineSummary> sortPipelines(
|
|
List<PipelineSummary> pipelines,
|
|
PipelineSort sort,
|
|
Map<int, PipelineRun> latestRuns,
|
|
) {
|
|
if (sort == PipelineSort.serverOrder) return List.of(pipelines);
|
|
final indexed = List.generate(
|
|
pipelines.length,
|
|
(index) => (index: index, pipeline: pipelines[index]),
|
|
);
|
|
indexed.sort(
|
|
(a, b) =>
|
|
_compare(a.pipeline, b.pipeline, sort, latestRuns, a.index, b.index),
|
|
);
|
|
return [for (final entry in indexed) entry.pipeline];
|
|
}
|