feat(app): label pipeline rows from recorded version and stages
This commit is contained in:
@@ -22,16 +22,24 @@ class PipelineSummary {
|
||||
required this.scheduled,
|
||||
required this.scheduleCount,
|
||||
required this.enabledScheduleCount,
|
||||
this.recordedStages,
|
||||
this.flowStages,
|
||||
});
|
||||
|
||||
factory PipelineSummary.fromJson(PipelineJson json) {
|
||||
final scheduleCount = _optionalInt(json['schedule_count']);
|
||||
final scheduled = json['scheduled'];
|
||||
final recordedStages = _optionalInt(json['stages']);
|
||||
return PipelineSummary(
|
||||
id: _int(json['id']),
|
||||
name: _string(json['name']),
|
||||
version: _int(json['version']),
|
||||
stages: _int(json['stages']),
|
||||
stages: recordedStages ?? 0,
|
||||
recordedStages: recordedStages,
|
||||
// A summary may omit `stages` while still carrying the current
|
||||
// version's flow (`shape`); keep that recorded count for the list row
|
||||
// without changing the summary's own field or its sorting.
|
||||
flowStages: _flowStageCount(json['shape']),
|
||||
createdAt: _string(json['created_at']),
|
||||
updatedAt: _string(json['updated_at']),
|
||||
scheduled: scheduled is bool ? scheduled : null,
|
||||
@@ -50,6 +58,21 @@ class PipelineSummary {
|
||||
final int? scheduleCount;
|
||||
final int? enabledScheduleCount;
|
||||
|
||||
/// The stage count the summary itself recorded, or null when it omitted it.
|
||||
///
|
||||
/// Kept apart from [stages] so sorting keeps the web's rule (its own
|
||||
/// `stages` field, never the flow) while the list row can use the recorded
|
||||
/// flow below.
|
||||
final int? recordedStages;
|
||||
|
||||
/// The stage count recorded by the current version's optional `shape` flow.
|
||||
final int? flowStages;
|
||||
|
||||
/// The list row's stage count from recorded values only: the summary's own
|
||||
/// count, else the recorded flow's count, else its plain [stages] field.
|
||||
/// Zero only when none was recorded, which is the web row's own fallback.
|
||||
int get rowStageCount => recordedStages ?? flowStages ?? stages;
|
||||
|
||||
String get displayName => name.isEmpty ? 'pipeline $id' : name;
|
||||
|
||||
/// Mirrors the web's schedule configuration rule, including its fallbacks
|
||||
@@ -111,6 +134,8 @@ class PipelineDetail extends PipelineSummary {
|
||||
required super.scheduled,
|
||||
required super.scheduleCount,
|
||||
required super.enabledScheduleCount,
|
||||
super.recordedStages,
|
||||
super.flowStages,
|
||||
required this.latestVersion,
|
||||
required this.versionCreatedAt,
|
||||
required this.contentHash,
|
||||
@@ -133,6 +158,8 @@ class PipelineDetail extends PipelineSummary {
|
||||
scheduled: summary.scheduled,
|
||||
scheduleCount: summary.scheduleCount,
|
||||
enabledScheduleCount: summary.enabledScheduleCount,
|
||||
recordedStages: summary.recordedStages,
|
||||
flowStages: summary.flowStages,
|
||||
latestVersion: _int(json['latest_version']),
|
||||
versionCreatedAt: _string(json['version_created_at']),
|
||||
contentHash: _string(json['content_hash']),
|
||||
@@ -237,6 +264,14 @@ int? _optionalInt(Object? value) {
|
||||
|
||||
String _string(Object? value) => value is String ? value : '';
|
||||
|
||||
/// The stage count recorded by a list row's optional flow summary (`shape`),
|
||||
/// or null when that flow was not recorded with a stage list.
|
||||
int? _flowStageCount(Object? value) {
|
||||
if (value is! Map) return null;
|
||||
final stages = value['stages'];
|
||||
return stages is List ? stages.length : null;
|
||||
}
|
||||
|
||||
/// A raw JSON object exactly as a reply carried it, or null when absent.
|
||||
PipelineJson? _jsonObject(Object? value) =>
|
||||
value is Map ? Map<String, dynamic>.from(value) : null;
|
||||
|
||||
@@ -59,10 +59,19 @@ String? _finishedDuration(PipelineRun run) {
|
||||
return seconds == null ? null : formatDuration(seconds);
|
||||
}
|
||||
|
||||
/// The web's version label for a pipeline: `v{n}`.
|
||||
String pipelineVersionLabel(PipelineSummary pipeline) => 'v${pipeline.version}';
|
||||
|
||||
/// The row's flow summary: the web's `{N stages}` label for the recorded stage
|
||||
/// count. A summary without `stages` falls back to its recorded `shape` flow,
|
||||
/// so a count is never taken from an unrecorded flow.
|
||||
String pipelineStageSummary(PipelineSummary pipeline) =>
|
||||
stageCountText(pipeline.rowStageCount);
|
||||
|
||||
/// `id {id} · v{version} · {N stages}`.
|
||||
String pipelineSubtitle(PipelineSummary pipeline) =>
|
||||
'id ${pipeline.id} · v${pipeline.version} · '
|
||||
'${stageCountText(pipeline.stages)}';
|
||||
'id ${pipeline.id} · ${pipelineVersionLabel(pipeline)} · '
|
||||
'${pipelineStageSummary(pipeline)}';
|
||||
|
||||
/// `updated d MMM HH:mm`, or null when the timestamp is unusable.
|
||||
String? pipelineUpdatedLine(PipelineSummary pipeline) {
|
||||
|
||||
Reference in New Issue
Block a user