feat(app): add native pipelines list and detail screen
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.
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
import 'pipeline_format.dart';
|
||||
import 'pipeline_models.dart';
|
||||
|
||||
/// The has/no-runs narrowing offered by the filter's Runs section.
|
||||
enum RunPresence {
|
||||
any('Any'),
|
||||
hasRuns('Has runs'),
|
||||
noRuns('No runs');
|
||||
|
||||
const RunPresence(this.label);
|
||||
|
||||
final String label;
|
||||
}
|
||||
|
||||
/// Configured schedule narrowing; paused schedules still count as configured.
|
||||
enum ScheduleFilter {
|
||||
any('Any schedule'),
|
||||
scheduled('Has schedules'),
|
||||
unscheduled('No schedules');
|
||||
|
||||
const ScheduleFilter(this.label);
|
||||
|
||||
final String label;
|
||||
}
|
||||
|
||||
/// The server's own run vocabulary offered by the last-run status filter. The
|
||||
/// app-only `active` bucket and stage outcome words are deliberately excluded.
|
||||
const runStatusFilters = <String>[
|
||||
'queued',
|
||||
'running',
|
||||
'waiting',
|
||||
'succeeded',
|
||||
'failed',
|
||||
'canceled',
|
||||
'interrupted',
|
||||
];
|
||||
|
||||
/// The default, no-narrowing filter.
|
||||
const emptyPipelineFilters = PipelineFilters();
|
||||
|
||||
/// One immutable capture of the list's filter controls.
|
||||
class PipelineFilters {
|
||||
const PipelineFilters({
|
||||
this.name = '',
|
||||
this.presence = RunPresence.any,
|
||||
this.lastRunStatuses = const <String>{},
|
||||
this.schedule = ScheduleFilter.any,
|
||||
});
|
||||
|
||||
final String name;
|
||||
final RunPresence presence;
|
||||
final Set<String> lastRunStatuses;
|
||||
final ScheduleFilter schedule;
|
||||
|
||||
bool get hasRunFacets =>
|
||||
presence != RunPresence.any || lastRunStatuses.isNotEmpty;
|
||||
|
||||
bool get active =>
|
||||
hasRunFacets || name.trim().isNotEmpty || schedule != ScheduleFilter.any;
|
||||
|
||||
int get count =>
|
||||
(presence != RunPresence.any ? 1 : 0) +
|
||||
(lastRunStatuses.isNotEmpty ? 1 : 0) +
|
||||
(name.trim().isNotEmpty ? 1 : 0) +
|
||||
(schedule != ScheduleFilter.any ? 1 : 0);
|
||||
|
||||
PipelineFilters copyWith({
|
||||
String? name,
|
||||
RunPresence? presence,
|
||||
Set<String>? lastRunStatuses,
|
||||
ScheduleFilter? schedule,
|
||||
}) => PipelineFilters(
|
||||
name: name ?? this.name,
|
||||
presence: presence ?? this.presence,
|
||||
lastRunStatuses: lastRunStatuses ?? this.lastRunStatuses,
|
||||
schedule: schedule ?? this.schedule,
|
||||
);
|
||||
}
|
||||
|
||||
/// The empty-state sentence for the list plus its optional reset action.
|
||||
class PipelineEmptyState {
|
||||
const PipelineEmptyState(this.message, {this.clearAction});
|
||||
|
||||
final String message;
|
||||
final String? clearAction;
|
||||
}
|
||||
|
||||
bool _matchesName(String needle, String pipelineName) {
|
||||
final query = needle.trim().toLowerCase();
|
||||
return query.isEmpty || pipelineName.toLowerCase().contains(query);
|
||||
}
|
||||
|
||||
bool _matchesSchedule(PipelineScheduleState state, ScheduleFilter filter) {
|
||||
switch (filter) {
|
||||
case ScheduleFilter.any:
|
||||
return true;
|
||||
case ScheduleFilter.scheduled:
|
||||
return state == PipelineScheduleState.scheduled;
|
||||
case ScheduleFilter.unscheduled:
|
||||
return state == PipelineScheduleState.unscheduled;
|
||||
}
|
||||
}
|
||||
|
||||
bool _matchesPresence(RunPresence presence, bool hasRun) {
|
||||
switch (presence) {
|
||||
case RunPresence.any:
|
||||
return true;
|
||||
case RunPresence.hasRuns:
|
||||
return hasRun;
|
||||
case RunPresence.noRuns:
|
||||
return !hasRun;
|
||||
}
|
||||
}
|
||||
|
||||
/// Narrows [pipelines] by [filters] with AND. Run facets are skipped until the
|
||||
/// run history is known, so a slow runs read never briefly hides everything.
|
||||
List<PipelineSummary> filterPipelines(
|
||||
List<PipelineSummary> pipelines,
|
||||
PipelineFilters filters,
|
||||
Map<int, PipelineRun> latestRuns,
|
||||
bool runsKnown,
|
||||
) {
|
||||
if (!filters.active) return pipelines;
|
||||
return pipelines
|
||||
.where((pipeline) {
|
||||
if (!_matchesName(filters.name, pipeline.name)) return false;
|
||||
if (!_matchesSchedule(pipeline.scheduleState, filters.schedule)) {
|
||||
return false;
|
||||
}
|
||||
if (filters.hasRunFacets && runsKnown) {
|
||||
final latestRun = latestRuns[pipeline.id];
|
||||
if (!_matchesPresence(filters.presence, latestRun != null)) {
|
||||
return false;
|
||||
}
|
||||
if (filters.lastRunStatuses.isNotEmpty) {
|
||||
if (latestRun == null) return false;
|
||||
if (!filters.lastRunStatuses.contains(
|
||||
runStateOf(latestRun.status),
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.toList(growable: false);
|
||||
}
|
||||
|
||||
PipelineEmptyState? pipelineListEmptyState(
|
||||
List<PipelineSummary> all,
|
||||
List<PipelineSummary> items,
|
||||
PipelineFilters filters,
|
||||
) {
|
||||
if (items.isNotEmpty) return null;
|
||||
if (all.isEmpty) {
|
||||
return const PipelineEmptyState('No pipelines are defined on this server.');
|
||||
}
|
||||
final name = filters.name;
|
||||
final onlyName =
|
||||
name.trim().isNotEmpty &&
|
||||
!filters.hasRunFacets &&
|
||||
filters.schedule == ScheduleFilter.any;
|
||||
final message = onlyName
|
||||
? 'No pipelines match "$name".'
|
||||
: 'No pipelines match the current filters.';
|
||||
return PipelineEmptyState(message, clearAction: 'Clear filters');
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/// Formatting shared by the pipeline list and detail.
|
||||
///
|
||||
/// The wording mirrors the web client (`src/pipelines.js`), which in turn
|
||||
/// mirrors the Android app: one date shape, one duration shape, one status
|
||||
/// vocabulary and one singular/plural rule.
|
||||
library;
|
||||
|
||||
const _monthNames = <String>[
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'May',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Aug',
|
||||
'Sep',
|
||||
'Oct',
|
||||
'Nov',
|
||||
'Dec',
|
||||
];
|
||||
|
||||
/// Parses an RFC3339 timestamp, or null when blank or unparseable.
|
||||
DateTime? parseInstant(String? text) {
|
||||
final trimmed = text?.trim() ?? '';
|
||||
if (trimmed.isEmpty) return null;
|
||||
return DateTime.tryParse(trimmed);
|
||||
}
|
||||
|
||||
/// `d MMM HH:mm` in local time, e.g. `17 Oct 21:26`, or null when the
|
||||
/// timestamp is unusable so callers omit the value instead of printing blank.
|
||||
String? formatLocalTimestamp(String? text) {
|
||||
final instant = parseInstant(text);
|
||||
if (instant == null) return null;
|
||||
final local = instant.toLocal();
|
||||
final hour = local.hour.toString().padLeft(2, '0');
|
||||
final minute = local.minute.toString().padLeft(2, '0');
|
||||
return '${local.day} ${_monthNames[local.month - 1]} $hour:$minute';
|
||||
}
|
||||
|
||||
/// `45s`, `2m 5s`, `1h 2m`. Negative values clamp to `0s`.
|
||||
String formatDuration(int totalSeconds) {
|
||||
final seconds = totalSeconds < 0 ? 0 : totalSeconds;
|
||||
if (seconds < 60) return '${seconds}s';
|
||||
if (seconds < 3600) return '${seconds ~/ 60}m ${seconds % 60}s';
|
||||
return '${seconds ~/ 3600}h ${(seconds % 3600) ~/ 60}m';
|
||||
}
|
||||
|
||||
/// Whole non-negative seconds between two timestamps, or null when either is
|
||||
/// unusable or the end precedes the start.
|
||||
int? durationSeconds(String? start, String? end) {
|
||||
final from = parseInstant(start);
|
||||
final to = parseInstant(end);
|
||||
if (from == null || to == null) return null;
|
||||
final seconds = to.difference(from).inSeconds;
|
||||
return seconds >= 0 ? seconds : null;
|
||||
}
|
||||
|
||||
/// `just now`, `Nm ago`, `Nh ago`, `Nd ago`; a future timestamp reads as
|
||||
/// `just now`, never a negative age.
|
||||
String? formatRanAgo(String? createdAt, DateTime now) {
|
||||
final start = parseInstant(createdAt);
|
||||
if (start == null) return null;
|
||||
final seconds = now.difference(start).inSeconds;
|
||||
if (seconds < 60) return 'just now';
|
||||
if (seconds < 3600) return '${seconds ~/ 60}m ago';
|
||||
if (seconds < 86400) return '${seconds ~/ 3600}h ago';
|
||||
return '${seconds ~/ 86400}d ago';
|
||||
}
|
||||
|
||||
/// `1 stage` / `n stages`.
|
||||
String stageCountText(int count) => '$count ${count == 1 ? 'stage' : 'stages'}';
|
||||
|
||||
const _runStateAliases = <String, String>{
|
||||
'running': 'running',
|
||||
'queued': 'queued',
|
||||
'waiting': 'waiting',
|
||||
'active': 'active',
|
||||
'succeeded': 'succeeded',
|
||||
'success': 'succeeded',
|
||||
'completed': 'succeeded',
|
||||
'done': 'succeeded',
|
||||
'failed': 'failed',
|
||||
'error': 'failed',
|
||||
'canceled': 'canceled',
|
||||
'cancelled': 'canceled',
|
||||
'interrupted': 'interrupted',
|
||||
'blocked': 'blocked',
|
||||
'skipped': 'skipped',
|
||||
};
|
||||
|
||||
/// Maps a server status word to the shared run-state vocabulary. Unknown or
|
||||
/// blank values become `unknown` rather than crashing a row.
|
||||
String runStateOf(String? status) {
|
||||
final key = (status ?? '').trim().toLowerCase();
|
||||
return _runStateAliases[key] ?? 'unknown';
|
||||
}
|
||||
|
||||
/// `Running`-style title for a run state.
|
||||
String runStateLabel(String? status) {
|
||||
final state = runStateOf(status);
|
||||
return state.isEmpty
|
||||
? state
|
||||
: '${state[0].toUpperCase()}${state.substring(1)}';
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'pipeline_models.dart';
|
||||
|
||||
/// Optional graph integration supplied by the later graph item (P2).
|
||||
///
|
||||
/// [onStageSelected] reports the graph's stage key with the pipeline identity
|
||||
/// this detail was loaded for, so a host can route to a stage view without the
|
||||
/// pipelines feature owning the graph.
|
||||
typedef PipelineGraphBuilder =
|
||||
Widget Function(
|
||||
BuildContext context,
|
||||
PipelineDetail detail,
|
||||
ValueChanged<String> onStageSelected,
|
||||
);
|
||||
|
||||
/// One stage selected in a hosted graph.
|
||||
class PipelineStageRef {
|
||||
const PipelineStageRef({
|
||||
required this.pipelineId,
|
||||
required this.version,
|
||||
required this.stageKey,
|
||||
});
|
||||
|
||||
final int pipelineId;
|
||||
final int version;
|
||||
final String stageKey;
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// The shared decoded-envelope type from the transport contract.
|
||||
typedef PipelineJson = Map<String, dynamic>;
|
||||
|
||||
/// Whether a pipeline currently has configured schedules.
|
||||
///
|
||||
/// Configuration is not run provenance: an unknown older record stays
|
||||
/// [unclassified] rather than being reported as unscheduled.
|
||||
enum PipelineScheduleState { scheduled, unscheduled, unclassified }
|
||||
|
||||
/// One row of `list_pipelines`.
|
||||
@immutable
|
||||
class PipelineSummary {
|
||||
const PipelineSummary({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.version,
|
||||
required this.stages,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.scheduled,
|
||||
required this.scheduleCount,
|
||||
required this.enabledScheduleCount,
|
||||
});
|
||||
|
||||
factory PipelineSummary.fromJson(PipelineJson json) {
|
||||
final scheduleCount = _optionalInt(json['schedule_count']);
|
||||
final scheduled = json['scheduled'];
|
||||
return PipelineSummary(
|
||||
id: _int(json['id']),
|
||||
name: _string(json['name']),
|
||||
version: _int(json['version']),
|
||||
stages: _int(json['stages']),
|
||||
createdAt: _string(json['created_at']),
|
||||
updatedAt: _string(json['updated_at']),
|
||||
scheduled: scheduled is bool ? scheduled : null,
|
||||
scheduleCount: scheduleCount,
|
||||
enabledScheduleCount: _optionalInt(json['enabled_schedule_count']),
|
||||
);
|
||||
}
|
||||
|
||||
final int id;
|
||||
final String name;
|
||||
final int version;
|
||||
final int stages;
|
||||
final String createdAt;
|
||||
final String updatedAt;
|
||||
final bool? scheduled;
|
||||
final int? scheduleCount;
|
||||
final int? enabledScheduleCount;
|
||||
|
||||
String get displayName => name.isEmpty ? 'pipeline $id' : name;
|
||||
|
||||
/// Mirrors the web's schedule configuration rule, including its fallbacks
|
||||
/// for peers that predate the schedule fields.
|
||||
PipelineScheduleState get scheduleState {
|
||||
if (scheduleCount != null && scheduleCount! > 0) {
|
||||
return PipelineScheduleState.scheduled;
|
||||
}
|
||||
if (scheduled != null) {
|
||||
return scheduled!
|
||||
? PipelineScheduleState.scheduled
|
||||
: PipelineScheduleState.unscheduled;
|
||||
}
|
||||
if (scheduleCount == 0) return PipelineScheduleState.unscheduled;
|
||||
return PipelineScheduleState.unclassified;
|
||||
}
|
||||
|
||||
/// The configured-schedule label, or an empty string when unscheduled.
|
||||
String get scheduleLabel {
|
||||
if (scheduleState != PipelineScheduleState.scheduled) return '';
|
||||
final count = scheduleCount;
|
||||
if (count != null && count > 0) {
|
||||
return '$count ${count == 1 ? 'schedule' : 'schedules'}';
|
||||
}
|
||||
return 'Has schedules';
|
||||
}
|
||||
}
|
||||
|
||||
/// One entry of a pipeline detail's version history.
|
||||
@immutable
|
||||
class PipelineVersion {
|
||||
const PipelineVersion({
|
||||
required this.version,
|
||||
required this.stages,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
factory PipelineVersion.fromJson(PipelineJson json) => PipelineVersion(
|
||||
version: _int(json['version']),
|
||||
stages: _int(json['stages']),
|
||||
createdAt: _string(json['created_at']),
|
||||
);
|
||||
|
||||
final int version;
|
||||
final int stages;
|
||||
final String createdAt;
|
||||
}
|
||||
|
||||
/// The `detail` payload of a `get_pipeline` reply.
|
||||
@immutable
|
||||
class PipelineDetail extends PipelineSummary {
|
||||
const PipelineDetail({
|
||||
required super.id,
|
||||
required super.name,
|
||||
required super.version,
|
||||
required super.stages,
|
||||
required super.createdAt,
|
||||
required super.updatedAt,
|
||||
required super.scheduled,
|
||||
required super.scheduleCount,
|
||||
required super.enabledScheduleCount,
|
||||
required this.latestVersion,
|
||||
required this.versionCreatedAt,
|
||||
required this.contentHash,
|
||||
required this.source,
|
||||
required this.versions,
|
||||
});
|
||||
|
||||
factory PipelineDetail.fromJson(PipelineJson json) {
|
||||
final summary = PipelineSummary.fromJson(json);
|
||||
final versions = json['versions'];
|
||||
return PipelineDetail(
|
||||
id: summary.id,
|
||||
name: summary.name,
|
||||
version: summary.version,
|
||||
stages: summary.stages,
|
||||
createdAt: summary.createdAt,
|
||||
updatedAt: summary.updatedAt,
|
||||
scheduled: summary.scheduled,
|
||||
scheduleCount: summary.scheduleCount,
|
||||
enabledScheduleCount: summary.enabledScheduleCount,
|
||||
latestVersion: _int(json['latest_version']),
|
||||
versionCreatedAt: _string(json['version_created_at']),
|
||||
contentHash: _string(json['content_hash']),
|
||||
source: _string(json['source']),
|
||||
versions: versions is List
|
||||
? List.unmodifiable(
|
||||
versions.whereType<Map>().map(
|
||||
(version) => PipelineVersion.fromJson(
|
||||
Map<String, dynamic>.from(version),
|
||||
),
|
||||
),
|
||||
)
|
||||
: const <PipelineVersion>[],
|
||||
);
|
||||
}
|
||||
|
||||
final int latestVersion;
|
||||
final String versionCreatedAt;
|
||||
final String contentHash;
|
||||
final String source;
|
||||
final List<PipelineVersion> versions;
|
||||
|
||||
/// The concrete version this detail describes. A request for version 0 asks
|
||||
/// for latest, so the reply's own `version` is authoritative for display.
|
||||
int get resolvedVersion => version > 0 ? version : latestVersion;
|
||||
}
|
||||
|
||||
/// The subset of a run summary the pipeline list needs for its last-run join.
|
||||
@immutable
|
||||
class PipelineRun {
|
||||
const PipelineRun({
|
||||
required this.id,
|
||||
required this.pipelineId,
|
||||
required this.status,
|
||||
required this.createdAt,
|
||||
required this.finishedAt,
|
||||
required this.executing,
|
||||
});
|
||||
|
||||
factory PipelineRun.fromJson(PipelineJson json) => PipelineRun(
|
||||
id: _int(json['id']),
|
||||
pipelineId: _int(json['pipeline_id']),
|
||||
status: _string(json['status']),
|
||||
createdAt: _string(json['created_at']),
|
||||
finishedAt: _string(json['finished_at']),
|
||||
executing: json['executing'] == true,
|
||||
);
|
||||
|
||||
final int id;
|
||||
final int pipelineId;
|
||||
final String status;
|
||||
final String createdAt;
|
||||
final String finishedAt;
|
||||
final bool executing;
|
||||
}
|
||||
|
||||
/// Timestamps decide recency; a higher run id breaks an exact tie or two bad
|
||||
/// timestamps. This is the one recency rule shared by the list's join and the
|
||||
/// "Most recent run" ordering.
|
||||
bool isMoreRecent(PipelineRun candidate, PipelineRun current) {
|
||||
final a = DateTime.tryParse(candidate.createdAt);
|
||||
final b = DateTime.tryParse(current.createdAt);
|
||||
if (a != null && b != null && a != b) return a.isAfter(b);
|
||||
return candidate.id > current.id;
|
||||
}
|
||||
|
||||
/// The latest run per pipeline id.
|
||||
Map<int, PipelineRun> latestRunByPipeline(Iterable<PipelineRun> runs) {
|
||||
final latest = <int, PipelineRun>{};
|
||||
for (final run in runs) {
|
||||
final current = latest[run.pipelineId];
|
||||
if (current == null || isMoreRecent(run, current)) {
|
||||
latest[run.pipelineId] = run;
|
||||
}
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
|
||||
int _int(Object? value) {
|
||||
if (value is int) return value;
|
||||
if (value is num) return value.toInt();
|
||||
return int.tryParse('${value ?? ''}') ?? 0;
|
||||
}
|
||||
|
||||
int? _optionalInt(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is int) return value;
|
||||
if (value is num) return value.toInt();
|
||||
return int.tryParse('$value');
|
||||
}
|
||||
|
||||
String _string(Object? value) => value is String ? value : '';
|
||||
@@ -0,0 +1,92 @@
|
||||
import 'pipeline_format.dart';
|
||||
import 'pipeline_models.dart';
|
||||
|
||||
export 'pipeline_filter.dart';
|
||||
export 'pipeline_sort.dart';
|
||||
|
||||
/// One Summary key/value row.
|
||||
class PipelineField {
|
||||
const PipelineField(this.key, this.value, {this.monospace = false});
|
||||
|
||||
final String key;
|
||||
final String value;
|
||||
final bool monospace;
|
||||
}
|
||||
|
||||
/// The last-run values a row displays.
|
||||
class RunBadge {
|
||||
const RunBadge({
|
||||
required this.runId,
|
||||
required this.state,
|
||||
required this.ranAgo,
|
||||
required this.duration,
|
||||
});
|
||||
|
||||
final int runId;
|
||||
final String state;
|
||||
final String? ranAgo;
|
||||
final String? duration;
|
||||
|
||||
/// `2h ago · 1m 5s · run 42`; missing fragments are omitted.
|
||||
String get metaLine => [
|
||||
ranAgo,
|
||||
duration,
|
||||
'run $runId',
|
||||
].whereType<String>().where((fragment) => fragment.isNotEmpty).join(' · ');
|
||||
}
|
||||
|
||||
RunBadge runBadge(PipelineRun run, DateTime now) {
|
||||
final duration = run.executing
|
||||
? _liveDuration(run, now)
|
||||
: _finishedDuration(run);
|
||||
return RunBadge(
|
||||
runId: run.id,
|
||||
state: runStateOf(run.status),
|
||||
ranAgo: formatRanAgo(run.createdAt, now),
|
||||
duration: duration,
|
||||
);
|
||||
}
|
||||
|
||||
String? _liveDuration(PipelineRun run, DateTime now) {
|
||||
final start = parseInstant(run.createdAt);
|
||||
if (start == null) return null;
|
||||
final seconds = now.difference(start).inSeconds;
|
||||
return formatDuration(seconds < 0 ? 0 : seconds);
|
||||
}
|
||||
|
||||
String? _finishedDuration(PipelineRun run) {
|
||||
final seconds = durationSeconds(run.createdAt, run.finishedAt);
|
||||
return seconds == null ? null : formatDuration(seconds);
|
||||
}
|
||||
|
||||
/// `id {id} · v{version} · {N stages}`.
|
||||
String pipelineSubtitle(PipelineSummary pipeline) =>
|
||||
'id ${pipeline.id} · v${pipeline.version} · '
|
||||
'${stageCountText(pipeline.stages)}';
|
||||
|
||||
/// `updated d MMM HH:mm`, or null when the timestamp is unusable.
|
||||
String? pipelineUpdatedLine(PipelineSummary pipeline) {
|
||||
final formatted = formatLocalTimestamp(pipeline.updatedAt);
|
||||
return formatted == null ? null : 'updated $formatted';
|
||||
}
|
||||
|
||||
/// The Summary tab's rows in the app's order.
|
||||
List<PipelineField> pipelineSummaryFields(PipelineDetail detail) => [
|
||||
PipelineField('Content hash', detail.contentHash, monospace: true),
|
||||
PipelineField(
|
||||
'Latest version',
|
||||
detail.latestVersion > 0 ? 'v${detail.latestVersion}' : '',
|
||||
),
|
||||
PipelineField(
|
||||
'Version created',
|
||||
formatLocalTimestamp(detail.versionCreatedAt) ?? '',
|
||||
),
|
||||
PipelineField(
|
||||
'Pipeline created',
|
||||
formatLocalTimestamp(detail.createdAt) ?? '',
|
||||
),
|
||||
PipelineField(
|
||||
'Pipeline updated',
|
||||
formatLocalTimestamp(detail.updatedAt) ?? '',
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,98 @@
|
||||
import '../../core/api_gateway.dart';
|
||||
import 'pipeline_models.dart';
|
||||
|
||||
/// A refusal or malformed reply with a message that is safe to show verbatim.
|
||||
class PipelineRequestException implements Exception {
|
||||
const PipelineRequestException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
|
||||
/// Read-only pipeline requests. Request shapes mirror `web/src/repository.js`
|
||||
/// exactly; no mutation of server state is offered here.
|
||||
class PipelinesRepository {
|
||||
PipelinesRepository(this._gateway);
|
||||
|
||||
final ApiGateway _gateway;
|
||||
|
||||
/// `list_pipelines` -> the whole `pipelines` array.
|
||||
Future<List<PipelineSummary>> listPipelines() async {
|
||||
final envelope = await _gateway.call('list_pipelines');
|
||||
_throwIfError(envelope, 'The server returned no pipeline list.');
|
||||
final type = envelope['type'];
|
||||
if (type != null && type != 'pipelines') {
|
||||
throw const PipelineRequestException(
|
||||
'The server returned no pipeline list.',
|
||||
);
|
||||
}
|
||||
final raw = envelope['pipelines'];
|
||||
if (raw == null) {
|
||||
if (type == 'pipelines') return const <PipelineSummary>[];
|
||||
throw const PipelineRequestException(
|
||||
'The server returned no pipeline list.',
|
||||
);
|
||||
}
|
||||
if (raw is! List) {
|
||||
throw const PipelineRequestException(
|
||||
'The server returned no pipeline list.',
|
||||
);
|
||||
}
|
||||
return List.unmodifiable(
|
||||
raw.whereType<Map>().map(
|
||||
(item) => PipelineSummary.fromJson(Map<String, dynamic>.from(item)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// `get_pipeline` with the web's exact `pipeline_id`/`version` fields.
|
||||
/// Version 0 asks the server for the latest version.
|
||||
Future<PipelineDetail> getPipeline(int id, int version) async {
|
||||
final envelope = await _gateway.call('get_pipeline', {
|
||||
'pipeline_id': id,
|
||||
'version': version,
|
||||
});
|
||||
_throwIfError(envelope, 'The server returned no pipeline detail.');
|
||||
if (envelope['type'] != null && envelope['type'] != 'pipeline') {
|
||||
throw const PipelineRequestException(
|
||||
'The server returned no pipeline detail.',
|
||||
);
|
||||
}
|
||||
final detail = envelope['detail'];
|
||||
if (detail is! Map) {
|
||||
throw const PipelineRequestException(
|
||||
'The server returned no pipeline detail.',
|
||||
);
|
||||
}
|
||||
return PipelineDetail.fromJson(Map<String, dynamic>.from(detail));
|
||||
}
|
||||
|
||||
/// `list_runs` is read only here for the pipeline list's last-run join.
|
||||
Future<List<PipelineRun>> listRuns() async {
|
||||
final envelope = await _gateway.call('list_runs');
|
||||
_throwIfError(envelope, 'The server returned no run list.');
|
||||
if (envelope['type'] != null && envelope['type'] != 'runs') {
|
||||
throw const PipelineRequestException('The server returned no run list.');
|
||||
}
|
||||
final raw = envelope['runs'];
|
||||
if (raw == null) return const <PipelineRun>[];
|
||||
if (raw is! List) {
|
||||
throw const PipelineRequestException('The server returned no run list.');
|
||||
}
|
||||
return List.unmodifiable(
|
||||
raw.whereType<Map>().map(
|
||||
(item) => PipelineRun.fromJson(Map<String, dynamic>.from(item)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _throwIfError(JsonMap envelope, String fallback) {
|
||||
final error = envelope['error'];
|
||||
if (envelope['type'] == 'error' || (error is String && error.isNotEmpty)) {
|
||||
final message = error is String ? error.trim() : '';
|
||||
throw PipelineRequestException(message.isEmpty ? fallback : message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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];
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'pipeline_models.dart';
|
||||
import 'pipeline_query.dart';
|
||||
import 'pipeline_repository.dart';
|
||||
|
||||
/// The user-facing message for a request failure, keeping server refusals
|
||||
/// verbatim and removing only the generic `Exception:` prefix.
|
||||
String pipelineErrorMessage(Object error) {
|
||||
if (error is PipelineRequestException) return error.message;
|
||||
final text = error.toString();
|
||||
return text.startsWith('Exception: ') ? text.substring(11) : text;
|
||||
}
|
||||
|
||||
/// Owns the pipeline list/detail state. The screen only renders this object;
|
||||
/// every request is sequenced here so a late reply can never replace a newer
|
||||
/// selection.
|
||||
class PipelinesController extends ChangeNotifier {
|
||||
PipelinesController(this._repository);
|
||||
|
||||
final PipelinesRepository _repository;
|
||||
|
||||
List<PipelineSummary> _pipelines = const <PipelineSummary>[];
|
||||
List<PipelineRun> _runs = const <PipelineRun>[];
|
||||
PipelineFilters _filters = emptyPipelineFilters;
|
||||
PipelineSort _sort = PipelineSort.serverOrder;
|
||||
|
||||
int? _selectedId;
|
||||
int _selectedVersion = 0;
|
||||
PipelineDetail? _detail;
|
||||
|
||||
bool _listLoading = false;
|
||||
bool _pipelinesLoaded = false;
|
||||
bool _runsLoaded = false;
|
||||
String? _listError;
|
||||
String? _runsError;
|
||||
bool _detailLoading = false;
|
||||
String? _detailError;
|
||||
|
||||
int _listSequence = 0;
|
||||
int _runsSequence = 0;
|
||||
int _detailSequence = 0;
|
||||
bool _disposed = false;
|
||||
|
||||
List<PipelineRun>? _latestSource;
|
||||
Map<int, PipelineRun>? _latestCache;
|
||||
|
||||
List<PipelineSummary> get pipelines => _pipelines;
|
||||
PipelineFilters get filters => _filters;
|
||||
PipelineSort get sort => _sort;
|
||||
bool get listLoading => _listLoading;
|
||||
bool get pipelinesLoaded => _pipelinesLoaded;
|
||||
bool get runsLoaded => _runsLoaded;
|
||||
String? get listError => _listError;
|
||||
String? get runsError => _runsError;
|
||||
bool get detailLoading => _detailLoading;
|
||||
String? get detailError => _detailError;
|
||||
PipelineDetail? get detail => _detail;
|
||||
int? get selectedId => _selectedId;
|
||||
int get selectedVersion => _selectedVersion;
|
||||
bool get hasSelection => _selectedId != null;
|
||||
bool get initialListLoading => _listLoading && !_pipelinesLoaded;
|
||||
|
||||
Map<int, PipelineRun> get latestRuns {
|
||||
final cache = _latestCache;
|
||||
if (cache != null && identical(_latestSource, _runs)) return cache;
|
||||
_latestSource = _runs;
|
||||
return _latestCache = latestRunByPipeline(_runs);
|
||||
}
|
||||
|
||||
/// The rows after sorting and filtering, using the same pure rules as web.
|
||||
List<PipelineSummary> get visiblePipelines {
|
||||
final runs = latestRuns;
|
||||
final sorted = sortPipelines(_pipelines, _sort, runs);
|
||||
return filterPipelines(sorted, _filters, runs, _runsLoaded);
|
||||
}
|
||||
|
||||
PipelineEmptyState? get emptyState =>
|
||||
pipelineListEmptyState(_pipelines, visiblePipelines, _filters);
|
||||
|
||||
/// Reloads the list and runs and re-reads the current detail. The selection
|
||||
/// (pipeline id and requested version) is deliberately preserved.
|
||||
Future<void> load() async {
|
||||
final listToken = ++_listSequence;
|
||||
final runsToken = ++_runsSequence;
|
||||
_listLoading = true;
|
||||
_listError = null;
|
||||
_runsError = null;
|
||||
_notify();
|
||||
await Future.wait([_readList(listToken), _readRuns(runsToken)]);
|
||||
if (_selectedId != null) await _reloadDetail();
|
||||
}
|
||||
|
||||
Future<void> _readList(int token) async {
|
||||
try {
|
||||
final rows = await _repository.listPipelines();
|
||||
if (!_current(_listSequence, token)) return;
|
||||
_pipelines = rows;
|
||||
_pipelinesLoaded = true;
|
||||
_listError = null;
|
||||
} catch (error) {
|
||||
if (!_current(_listSequence, token)) return;
|
||||
_listError = pipelineErrorMessage(error);
|
||||
} finally {
|
||||
if (_current(_listSequence, token)) {
|
||||
_listLoading = false;
|
||||
_notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _readRuns(int token) async {
|
||||
try {
|
||||
final runs = await _repository.listRuns();
|
||||
if (!_current(_runsSequence, token)) return;
|
||||
_runs = runs;
|
||||
_runsLoaded = true;
|
||||
_runsError = null;
|
||||
} catch (error) {
|
||||
if (!_current(_runsSequence, token)) return;
|
||||
// Retain any previously successful run history: a failed refresh must
|
||||
// not silently change the meaning of an active last-run filter.
|
||||
_runsError = pipelineErrorMessage(error);
|
||||
}
|
||||
if (_current(_runsSequence, token)) _notify();
|
||||
}
|
||||
|
||||
/// Opens [id] at [version] (0 asks for latest), discarding the previous
|
||||
/// detail immediately so no unrelated entity sits under the new selection.
|
||||
Future<void> openPipeline(int id, {int version = 0}) async {
|
||||
final requestedVersion = version > 0 ? version : 0;
|
||||
_selectedId = id;
|
||||
_selectedVersion = requestedVersion;
|
||||
_detail = null;
|
||||
_detailError = null;
|
||||
await _requestDetail(id, requestedVersion);
|
||||
}
|
||||
|
||||
/// Selects a recorded version by its version number; 0 returns to latest.
|
||||
Future<void> selectVersion(int version) async {
|
||||
final id = _selectedId;
|
||||
if (id == null) return;
|
||||
await openPipeline(id, version: version);
|
||||
}
|
||||
|
||||
Future<void> retryDetail() async {
|
||||
final id = _selectedId;
|
||||
if (id == null) return;
|
||||
await _requestDetail(id, _selectedVersion);
|
||||
}
|
||||
|
||||
Future<void> _reloadDetail() async {
|
||||
final id = _selectedId;
|
||||
if (id == null) return;
|
||||
await _requestDetail(id, _selectedVersion);
|
||||
}
|
||||
|
||||
Future<void> _requestDetail(int id, int version) async {
|
||||
final token = ++_detailSequence;
|
||||
_detailLoading = true;
|
||||
_detailError = null;
|
||||
_notify();
|
||||
try {
|
||||
final detail = await _repository.getPipeline(id, version);
|
||||
if (!_currentDetail(token, id, version)) return;
|
||||
_detail = detail;
|
||||
_detailError = null;
|
||||
} catch (error) {
|
||||
if (!_currentDetail(token, id, version)) return;
|
||||
_detail = null;
|
||||
_detailError = pipelineErrorMessage(error);
|
||||
} finally {
|
||||
if (_currentDetail(token, id, version)) {
|
||||
_detailLoading = false;
|
||||
_notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears the selection for narrow-layout Back and for an explicit close.
|
||||
void clearSelection() {
|
||||
_detailSequence++;
|
||||
_selectedId = null;
|
||||
_selectedVersion = 0;
|
||||
_detail = null;
|
||||
_detailError = null;
|
||||
_detailLoading = false;
|
||||
_notify();
|
||||
}
|
||||
|
||||
void setFilters(PipelineFilters filters) {
|
||||
_filters = filters;
|
||||
_notify();
|
||||
}
|
||||
|
||||
void clearFilters() {
|
||||
_filters = emptyPipelineFilters;
|
||||
_notify();
|
||||
}
|
||||
|
||||
void setSort(PipelineSort sort) {
|
||||
_sort = sort;
|
||||
_notify();
|
||||
}
|
||||
|
||||
bool _current(int sequence, int token) => !_disposed && sequence == token;
|
||||
|
||||
bool _currentDetail(int token, int id, int version) =>
|
||||
!_disposed &&
|
||||
token == _detailSequence &&
|
||||
id == _selectedId &&
|
||||
version == _selectedVersion;
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
import 'pipeline_graph_hook.dart';
|
||||
import 'pipeline_repository.dart';
|
||||
import 'pipelines_controller.dart';
|
||||
import 'widgets/pipeline_controls.dart';
|
||||
import 'widgets/pipeline_detail_panel.dart';
|
||||
import 'widgets/pipeline_list_panel.dart';
|
||||
|
||||
export 'pipeline_graph_hook.dart';
|
||||
export 'pipeline_models.dart' show PipelineDetail, PipelineVersion;
|
||||
|
||||
/// Below this width the list and detail are separate pages; above it they sit
|
||||
/// side by side. One local breakpoint, not a styling system.
|
||||
const double kPipelinesWideBreakpoint = 720;
|
||||
|
||||
/// The read-only Pipelines destination: list, filters/sort, detail, source and
|
||||
/// version history.
|
||||
///
|
||||
/// [graphBuilder] is the optional integration hook for the later graph item.
|
||||
/// Without it the Graph tab states that graph rendering is pending.
|
||||
class PipelinesScreen extends StatefulWidget {
|
||||
const PipelinesScreen({
|
||||
super.key,
|
||||
required this.gateway,
|
||||
this.graphBuilder,
|
||||
this.onStageSelected,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
final PipelineGraphBuilder? graphBuilder;
|
||||
final ValueChanged<PipelineStageRef>? onStageSelected;
|
||||
|
||||
@override
|
||||
State<PipelinesScreen> createState() => _PipelinesScreenState();
|
||||
}
|
||||
|
||||
class _PipelinesScreenState extends State<PipelinesScreen> {
|
||||
late PipelinesController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = PipelinesController(PipelinesRepository(widget.gateway))
|
||||
..load();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(PipelinesScreen oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.gateway != widget.gateway) {
|
||||
_controller.dispose();
|
||||
_controller = PipelinesController(PipelinesRepository(widget.gateway))
|
||||
..load();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _controller,
|
||||
builder: (context, _) {
|
||||
final body = LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= kPipelinesWideBreakpoint;
|
||||
if (!wide) {
|
||||
return _controller.hasSelection
|
||||
? PipelineDetailPanel(
|
||||
controller: _controller,
|
||||
showBack: true,
|
||||
graphBuilder: widget.graphBuilder,
|
||||
onStageSelected: widget.onStageSelected,
|
||||
)
|
||||
: PipelineListPanel(controller: _controller);
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: PipelineListPanel(controller: _controller),
|
||||
),
|
||||
_divider(context),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: PipelineDetailPanel(
|
||||
controller: _controller,
|
||||
showBack: false,
|
||||
graphBuilder: widget.graphBuilder,
|
||||
onStageSelected: widget.onStageSelected,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
return useCupertinoControls(context)
|
||||
? _cupertinoShell(context, body)
|
||||
: _materialShell(context, body);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _divider(BuildContext context) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return Container(
|
||||
width: 1,
|
||||
color: CupertinoColors.separator.resolveFrom(context),
|
||||
);
|
||||
}
|
||||
return const VerticalDivider(width: 1);
|
||||
}
|
||||
|
||||
Widget _materialShell(BuildContext context, Widget body) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Pipelines'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: 'Refresh',
|
||||
onPressed: _controller.load,
|
||||
icon: const Icon(Icons.refresh),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(child: body),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoShell(BuildContext context, Widget body) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: const Text('Pipelines'),
|
||||
trailing: Semantics(
|
||||
button: true,
|
||||
label: 'Refresh',
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _controller.load,
|
||||
child: const Icon(CupertinoIcons.refresh),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: SafeArea(top: false, child: body),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../pipeline_query.dart';
|
||||
|
||||
/// The one platform decision for this feature. The screen itself receives no
|
||||
/// platform flag, so tests and integration obey Flutter's target platform.
|
||||
bool useCupertinoControls(BuildContext context) =>
|
||||
defaultTargetPlatform == TargetPlatform.iOS;
|
||||
|
||||
/// Standard platform activity indicator with an accessible status label.
|
||||
class PipelineProgress extends StatelessWidget {
|
||||
const PipelineProgress({super.key, this.label = 'Loading'});
|
||||
|
||||
final String label;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Semantics(
|
||||
label: label,
|
||||
liveRegion: true,
|
||||
child: useCupertinoControls(context)
|
||||
? const CupertinoActivityIndicator()
|
||||
: const CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A standard text action in the current platform's style.
|
||||
class PipelineTextButton extends StatelessWidget {
|
||||
const PipelineTextButton({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onPressed,
|
||||
child: Text(label),
|
||||
);
|
||||
}
|
||||
return TextButton(onPressed: onPressed, child: Text(label));
|
||||
}
|
||||
}
|
||||
|
||||
/// Native back affordance used by the narrow list/detail layout.
|
||||
class PipelineBackButton extends StatelessWidget {
|
||||
const PipelineBackButton({super.key, required this.onPressed});
|
||||
|
||||
final VoidCallback onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: 'Back to pipelines',
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onPressed,
|
||||
child: const Icon(CupertinoIcons.back),
|
||||
),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
tooltip: 'Back to pipelines',
|
||||
onPressed: onPressed,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The list's sort control: a Material menu on Android/desktop, an action
|
||||
/// sheet on iOS. The label is the current choice, exactly as on web.
|
||||
class PipelineSortButton extends StatelessWidget {
|
||||
const PipelineSortButton({
|
||||
super.key,
|
||||
required this.sort,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final PipelineSort sort;
|
||||
final ValueChanged<PipelineSort> onSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final label = 'Sort: ${sort.label}';
|
||||
if (useCupertinoControls(context)) {
|
||||
return CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () => _showCupertinoSheet(context),
|
||||
child: Text(label),
|
||||
);
|
||||
}
|
||||
return MenuAnchor(
|
||||
menuChildren: [
|
||||
for (final option in PipelineSort.values)
|
||||
MenuItemButton(
|
||||
onPressed: () => onSelected(option),
|
||||
child: Text(option.label),
|
||||
),
|
||||
],
|
||||
builder: (context, menu, child) => TextButton(
|
||||
onPressed: () => menu.isOpen ? menu.close() : menu.open(),
|
||||
child: Text(label),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showCupertinoSheet(BuildContext context) {
|
||||
return showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (sheetContext) => CupertinoActionSheet(
|
||||
title: const Text('Sort pipelines'),
|
||||
actions: [
|
||||
for (final option in PipelineSort.values)
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () {
|
||||
Navigator.of(sheetContext).pop();
|
||||
onSelected(option);
|
||||
},
|
||||
child: Text(option.label),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(sheetContext).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A truthful, non-blocking error line with an optional retry action.
|
||||
class PipelineErrorBanner extends StatelessWidget {
|
||||
const PipelineErrorBanner({
|
||||
super.key,
|
||||
required this.message,
|
||||
this.retryLabel = 'Retry',
|
||||
this.onRetry,
|
||||
});
|
||||
|
||||
final String message;
|
||||
final String retryLabel;
|
||||
final VoidCallback? onRetry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = useCupertinoControls(context);
|
||||
final color = cupertino
|
||||
? CupertinoColors.systemRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error;
|
||||
return Semantics(
|
||||
liveRegion: true,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(message, style: TextStyle(color: color)),
|
||||
if (onRetry != null)
|
||||
PipelineTextButton(label: retryLabel, onPressed: onRetry),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../pipeline_graph_hook.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipeline_query.dart';
|
||||
import '../pipelines_controller.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
import 'pipeline_detail_styles.dart';
|
||||
import 'pipeline_summary_view.dart';
|
||||
import 'pipeline_tabs.dart';
|
||||
|
||||
/// The right/bottom pane: Summary, Source and the optional graph hook.
|
||||
class PipelineDetailPanel extends StatefulWidget {
|
||||
const PipelineDetailPanel({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.showBack,
|
||||
this.graphBuilder,
|
||||
this.onStageSelected,
|
||||
});
|
||||
|
||||
final PipelinesController controller;
|
||||
final bool showBack;
|
||||
final PipelineGraphBuilder? graphBuilder;
|
||||
final ValueChanged<PipelineStageRef>? onStageSelected;
|
||||
|
||||
@override
|
||||
State<PipelineDetailPanel> createState() => _PipelineDetailPanelState();
|
||||
}
|
||||
|
||||
class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
|
||||
PipelineDetailTab _tab = PipelineDetailTab.summary;
|
||||
|
||||
PipelinesController get _controller => widget.controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final detail = _controller.detail;
|
||||
if (detail == null) return _withoutDetail(context);
|
||||
return ListView(
|
||||
key: const Key('pipeline-detail'),
|
||||
children: [
|
||||
_header(context, detail),
|
||||
if (_controller.detailLoading)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: PipelineProgress(label: 'Refreshing pipeline detail'),
|
||||
),
|
||||
if (_controller.detailError != null)
|
||||
PipelineErrorBanner(
|
||||
message: _controller.detailError!,
|
||||
onRetry: _controller.retryDetail,
|
||||
),
|
||||
PipelineDetailTabs(
|
||||
selected: _tab,
|
||||
onSelected: (tab) => setState(() => _tab = tab),
|
||||
),
|
||||
switch (_tab) {
|
||||
PipelineDetailTab.summary => PipelineSummaryView(
|
||||
controller: _controller,
|
||||
detail: detail,
|
||||
),
|
||||
PipelineDetailTab.graph => _graph(context, detail),
|
||||
PipelineDetailTab.source => _source(context, detail),
|
||||
},
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _withoutDetail(BuildContext context) {
|
||||
if (!_controller.hasSelection) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text('Select a pipeline.', style: pipelineMutedStyle(context)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListView(
|
||||
children: [
|
||||
if (widget.showBack) _backRow(context),
|
||||
if (_controller.detailLoading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
children: [
|
||||
const PipelineProgress(label: 'Loading pipeline'),
|
||||
const SizedBox(height: 12),
|
||||
Text('Loading pipeline…', style: pipelineMutedStyle(context)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_controller.detailError != null)
|
||||
PipelineErrorBanner(
|
||||
message: _controller.detailError!,
|
||||
onRetry: _controller.retryDetail,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _backRow(BuildContext context) => Padding(
|
||||
padding: const EdgeInsets.fromLTRB(4, 4, 16, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
PipelineBackButton(onPressed: _controller.clearSelection),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(child: Text('Pipeline', style: pipelineTitleStyle(context))),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _header(BuildContext context, PipelineDetail detail) {
|
||||
final title = Text(detail.displayName, style: pipelineTitleStyle(context));
|
||||
final subtitle = Text(
|
||||
pipelineSubtitle(detail),
|
||||
style: pipelineMutedStyle(context),
|
||||
);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||
child: widget.showBack
|
||||
? Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
PipelineBackButton(onPressed: _controller.clearSelection),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [title, subtitle],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [title, subtitle],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _graph(BuildContext context, PipelineDetail detail) {
|
||||
final builder = widget.graphBuilder;
|
||||
if (builder == null) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
'Graph rendering is pending (P2).',
|
||||
style: pipelineMutedStyle(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
return builder(
|
||||
context,
|
||||
detail,
|
||||
(stageKey) => widget.onStageSelected?.call(
|
||||
PipelineStageRef(
|
||||
pipelineId: detail.id,
|
||||
version: detail.resolvedVersion,
|
||||
stageKey: stageKey,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _source(BuildContext context, PipelineDetail detail) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: detail.source.isEmpty
|
||||
? Text('No source recorded.', style: pipelineMutedStyle(context))
|
||||
: SelectableText(detail.source, style: pipelineValueStyle(context)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'pipeline_controls.dart';
|
||||
|
||||
TextStyle? pipelineTitleStyle(BuildContext context) =>
|
||||
useCupertinoControls(context)
|
||||
? CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle
|
||||
: Theme.of(context).textTheme.headlineSmall;
|
||||
|
||||
TextStyle? pipelineSectionStyle(BuildContext context) =>
|
||||
useCupertinoControls(context)
|
||||
? CupertinoTheme.of(context).textTheme.navTitleTextStyle
|
||||
: Theme.of(context).textTheme.titleMedium;
|
||||
|
||||
TextStyle? pipelineValueStyle(BuildContext context, {bool monospace = false}) {
|
||||
final base = useCupertinoControls(context)
|
||||
// SelectableText requires an explicit baseline when it inherits no style;
|
||||
// merge the Cupertino system style with the ambient text style.
|
||||
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(inherit: true)
|
||||
: Theme.of(context).textTheme.bodyMedium;
|
||||
return monospace ? base?.copyWith(fontFamily: 'monospace') : base;
|
||||
}
|
||||
|
||||
TextStyle? pipelineMutedStyle(BuildContext context) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
|
||||
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
);
|
||||
}
|
||||
final theme = Theme.of(context);
|
||||
return theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/// The detail sections. Graph rendering is owned by the later graph item; the
|
||||
/// tab row provides the tab and an optional integration hook.
|
||||
enum PipelineDetailTab {
|
||||
summary('Summary'),
|
||||
graph('Graph'),
|
||||
source('Source');
|
||||
|
||||
const PipelineDetailTab(this.label);
|
||||
|
||||
final String label;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../pipeline_filter.dart';
|
||||
|
||||
/// Cupertino filter form using native grouped lists and checkboxes.
|
||||
class PipelineFilterCupertinoBody extends StatelessWidget {
|
||||
const PipelineFilterCupertinoBody({
|
||||
super.key,
|
||||
required this.filters,
|
||||
required this.name,
|
||||
required this.hasUnclassified,
|
||||
required this.onChanged,
|
||||
required this.onClear,
|
||||
});
|
||||
|
||||
final PipelineFilters filters;
|
||||
final TextEditingController name;
|
||||
final bool hasUnclassified;
|
||||
final ValueChanged<PipelineFilters> onChanged;
|
||||
final VoidCallback onClear;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: CupertinoTextField(
|
||||
controller: name,
|
||||
placeholder: 'Pipeline name contains',
|
||||
),
|
||||
),
|
||||
CupertinoListSection.insetGrouped(
|
||||
header: const Text('RUNS'),
|
||||
children: [
|
||||
for (final presence in RunPresence.values)
|
||||
_choice(
|
||||
label: presence.label,
|
||||
selected: filters.presence == presence,
|
||||
onTap: () => onChanged(filters.copyWith(presence: presence)),
|
||||
),
|
||||
],
|
||||
),
|
||||
CupertinoListSection.insetGrouped(
|
||||
header: const Text('LAST RUN STATUS'),
|
||||
children: [
|
||||
for (final status in runStatusFilters)
|
||||
_check(
|
||||
label: status,
|
||||
checked: filters.lastRunStatuses.contains(status),
|
||||
onChanged: (checked) {
|
||||
final next = {...filters.lastRunStatuses};
|
||||
if (checked) {
|
||||
next.add(status);
|
||||
} else {
|
||||
next.remove(status);
|
||||
}
|
||||
onChanged(filters.copyWith(lastRunStatuses: next));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
CupertinoListSection.insetGrouped(
|
||||
header: const Text('SCHEDULING'),
|
||||
footer: const Text('Configured schedules, including paused.'),
|
||||
children: [
|
||||
for (final schedule in ScheduleFilter.values)
|
||||
_choice(
|
||||
label: schedule.label,
|
||||
selected: filters.schedule == schedule,
|
||||
onTap: () => onChanged(filters.copyWith(schedule: schedule)),
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (hasUnclassified)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
child: Text(
|
||||
'Some records have no scheduling metadata; they stay unclassified.',
|
||||
),
|
||||
),
|
||||
CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onClear,
|
||||
child: const Text('Clear filters'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _choice({
|
||||
required String label,
|
||||
required bool selected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return CupertinoListTile(
|
||||
title: Text(label),
|
||||
trailing: CupertinoCheckbox(value: selected, onChanged: (_) => onTap()),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _check({
|
||||
required String label,
|
||||
required bool checked,
|
||||
required ValueChanged<bool> onChanged,
|
||||
}) {
|
||||
return CupertinoListTile(
|
||||
title: Text(label),
|
||||
trailing: CupertinoCheckbox(
|
||||
value: checked,
|
||||
onChanged: (value) => onChanged(value ?? false),
|
||||
),
|
||||
onTap: () => onChanged(!checked),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../pipeline_filter.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
|
||||
/// Material filter form. Every change is reported to the page's draft; Done
|
||||
/// applies the draft and leaving discards it.
|
||||
class PipelineFilterMaterialBody extends StatelessWidget {
|
||||
const PipelineFilterMaterialBody({
|
||||
super.key,
|
||||
required this.filters,
|
||||
required this.name,
|
||||
required this.hasUnclassified,
|
||||
required this.onChanged,
|
||||
required this.onClear,
|
||||
});
|
||||
|
||||
final PipelineFilters filters;
|
||||
final TextEditingController name;
|
||||
final bool hasUnclassified;
|
||||
final ValueChanged<PipelineFilters> onChanged;
|
||||
final VoidCallback onClear;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
TextField(
|
||||
controller: name,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Pipeline name contains',
|
||||
),
|
||||
),
|
||||
_section(context, 'Runs'),
|
||||
RadioGroup<RunPresence>(
|
||||
groupValue: filters.presence,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
onChanged(filters.copyWith(presence: value));
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
for (final presence in RunPresence.values)
|
||||
RadioListTile<RunPresence>(
|
||||
value: presence,
|
||||
title: Text(presence.label),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_section(context, 'Last run status'),
|
||||
for (final status in runStatusFilters)
|
||||
CheckboxListTile(
|
||||
value: filters.lastRunStatuses.contains(status),
|
||||
onChanged: (checked) {
|
||||
final next = {...filters.lastRunStatuses};
|
||||
if (checked == true) {
|
||||
next.add(status);
|
||||
} else {
|
||||
next.remove(status);
|
||||
}
|
||||
onChanged(filters.copyWith(lastRunStatuses: next));
|
||||
},
|
||||
title: Text(status),
|
||||
),
|
||||
_section(context, 'Scheduling'),
|
||||
Text(
|
||||
'Configured schedules, including paused.',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
RadioGroup<ScheduleFilter>(
|
||||
groupValue: filters.schedule,
|
||||
onChanged: (value) {
|
||||
if (value != null) onChanged(filters.copyWith(schedule: value));
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
for (final schedule in ScheduleFilter.values)
|
||||
RadioListTile<ScheduleFilter>(
|
||||
value: schedule,
|
||||
title: Text(schedule.label),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (hasUnclassified)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
'Some records have no scheduling metadata; they stay unclassified.',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: PipelineTextButton(label: 'Clear filters', onPressed: onClear),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _section(BuildContext context, String title) => Padding(
|
||||
padding: const EdgeInsets.only(top: 20, bottom: 4),
|
||||
child: Text(title, style: Theme.of(context).textTheme.titleSmall),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../pipeline_filter.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
import 'pipeline_filter_cupertino_body.dart';
|
||||
import 'pipeline_filter_material_body.dart';
|
||||
|
||||
/// Opens the platform's native full-screen filter editor.
|
||||
Future<void> openPipelineFilters(
|
||||
BuildContext context, {
|
||||
required PipelineFilters initial,
|
||||
required bool hasUnclassified,
|
||||
required ValueChanged<PipelineFilters> onApply,
|
||||
}) {
|
||||
final cupertino = useCupertinoControls(context);
|
||||
final route = cupertino
|
||||
? CupertinoPageRoute<void>(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => PipelineFilterPage(
|
||||
initial: initial,
|
||||
hasUnclassified: hasUnclassified,
|
||||
onApply: onApply,
|
||||
cupertino: true,
|
||||
),
|
||||
)
|
||||
: MaterialPageRoute<void>(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => PipelineFilterPage(
|
||||
initial: initial,
|
||||
hasUnclassified: hasUnclassified,
|
||||
onApply: onApply,
|
||||
cupertino: false,
|
||||
),
|
||||
);
|
||||
return Navigator.of(context).push(route);
|
||||
}
|
||||
|
||||
/// A draft copy of the filters. Changes take effect on Done; leaving the page
|
||||
/// discards them, so a half-edited filter never silently narrows the list.
|
||||
class PipelineFilterPage extends StatefulWidget {
|
||||
const PipelineFilterPage({
|
||||
super.key,
|
||||
required this.initial,
|
||||
required this.hasUnclassified,
|
||||
required this.onApply,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final PipelineFilters initial;
|
||||
final bool hasUnclassified;
|
||||
final ValueChanged<PipelineFilters> onApply;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
State<PipelineFilterPage> createState() => _PipelineFilterPageState();
|
||||
}
|
||||
|
||||
class _PipelineFilterPageState extends State<PipelineFilterPage> {
|
||||
late PipelineFilters _draft = widget.initial;
|
||||
late final TextEditingController _name = TextEditingController(
|
||||
text: widget.initial.name,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_name.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _apply() {
|
||||
widget.onApply(_draft.copyWith(name: _name.text));
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
void _clear() {
|
||||
setState(() {
|
||||
_draft = emptyPipelineFilters;
|
||||
_name.text = '';
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final body = widget.cupertino
|
||||
? PipelineFilterCupertinoBody(
|
||||
filters: _draft,
|
||||
name: _name,
|
||||
hasUnclassified: widget.hasUnclassified,
|
||||
onChanged: (filters) => setState(() => _draft = filters),
|
||||
onClear: _clear,
|
||||
)
|
||||
: PipelineFilterMaterialBody(
|
||||
filters: _draft,
|
||||
name: _name,
|
||||
hasUnclassified: widget.hasUnclassified,
|
||||
onChanged: (filters) => setState(() => _draft = filters),
|
||||
onClear: _clear,
|
||||
);
|
||||
if (widget.cupertino) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: const Text('Filter pipelines'),
|
||||
trailing: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: _apply,
|
||||
child: const Text('Done'),
|
||||
),
|
||||
),
|
||||
child: SafeArea(child: body),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Filter pipelines'),
|
||||
actions: [TextButton(onPressed: _apply, child: const Text('Done'))],
|
||||
),
|
||||
body: SafeArea(child: body),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../pipeline_format.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipeline_query.dart';
|
||||
import '../pipelines_controller.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
import 'pipeline_filter_page.dart';
|
||||
|
||||
/// The left/top pane: filter and sort controls, then the truthful list states.
|
||||
class PipelineListPanel extends StatelessWidget {
|
||||
const PipelineListPanel({super.key, required this.controller});
|
||||
|
||||
final PipelinesController controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final filters = controller.filters;
|
||||
final hasUnclassified = controller.pipelines.any(
|
||||
(pipeline) =>
|
||||
pipeline.scheduleState == PipelineScheduleState.unclassified,
|
||||
);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
PipelineTextButton(
|
||||
key: const Key('pipeline-filter'),
|
||||
label: filters.count == 0
|
||||
? 'Filter'
|
||||
: 'Filter (${filters.count})',
|
||||
onPressed: () => openPipelineFilters(
|
||||
context,
|
||||
initial: filters,
|
||||
hasUnclassified: hasUnclassified,
|
||||
onApply: controller.setFilters,
|
||||
),
|
||||
),
|
||||
PipelineSortButton(
|
||||
key: const Key('pipeline-sort'),
|
||||
sort: controller.sort,
|
||||
onSelected: controller.setSort,
|
||||
),
|
||||
if (filters.active)
|
||||
PipelineTextButton(
|
||||
key: const Key('pipeline-clear-filters'),
|
||||
label: 'Clear filters',
|
||||
onPressed: controller.clearFilters,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (controller.listError != null)
|
||||
PipelineErrorBanner(
|
||||
message: controller.listError!,
|
||||
onRetry: controller.load,
|
||||
),
|
||||
if (controller.runsError != null)
|
||||
PipelineErrorBanner(
|
||||
message:
|
||||
'${controller.runsLoaded ? 'Last runs could not be refreshed' : 'Last runs unavailable'}: '
|
||||
'${controller.runsError}',
|
||||
onRetry: controller.load,
|
||||
),
|
||||
if (controller.listLoading && controller.pipelinesLoaded)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: PipelineProgress(label: 'Refreshing pipelines'),
|
||||
),
|
||||
Expanded(child: _content(context)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _content(BuildContext context) {
|
||||
if (controller.initialListLoading) {
|
||||
return _centered(context, const ['Loading pipelines…']);
|
||||
}
|
||||
if (!controller.pipelinesLoaded) {
|
||||
if (controller.listError != null) return const SizedBox.shrink();
|
||||
return _centered(context, const ['Loading pipelines…']);
|
||||
}
|
||||
final items = controller.visiblePipelines;
|
||||
if (items.isEmpty) {
|
||||
final empty = controller.emptyState;
|
||||
if (empty == null) return const SizedBox.shrink();
|
||||
return _empty(context, empty);
|
||||
}
|
||||
return useCupertinoControls(context)
|
||||
? _cupertinoList(context, items)
|
||||
: _materialList(context, items);
|
||||
}
|
||||
|
||||
Widget _centered(BuildContext context, List<String> messages) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const PipelineProgress(label: 'Loading pipelines'),
|
||||
for (final message in messages)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Text(message),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _empty(BuildContext context, PipelineEmptyState empty) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
empty.message,
|
||||
textAlign: TextAlign.center,
|
||||
style: _mutedStyle(context),
|
||||
),
|
||||
if (empty.clearAction != null)
|
||||
PipelineTextButton(
|
||||
label: empty.clearAction!,
|
||||
onPressed: controller.clearFilters,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _materialList(BuildContext context, List<PipelineSummary> items) {
|
||||
final now = DateTime.now();
|
||||
return ListView.builder(
|
||||
key: const Key('pipeline-list'),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, index) {
|
||||
final pipeline = items[index];
|
||||
return ListTile(
|
||||
key: Key('pipeline-row-${pipeline.id}'),
|
||||
selected: controller.selectedId == pipeline.id,
|
||||
onTap: () =>
|
||||
controller.openPipeline(pipeline.id, version: pipeline.version),
|
||||
title: Text(pipeline.displayName),
|
||||
subtitle: _subtitle(context, pipeline, now),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoList(BuildContext context, List<PipelineSummary> items) {
|
||||
final now = DateTime.now();
|
||||
return ListView(
|
||||
key: const Key('pipeline-list'),
|
||||
children: [
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
for (final pipeline in items)
|
||||
CupertinoListTile(
|
||||
key: Key('pipeline-row-${pipeline.id}'),
|
||||
title: Text(pipeline.displayName),
|
||||
subtitle: _subtitle(context, pipeline, now),
|
||||
trailing: const CupertinoListTileChevron(),
|
||||
onTap: () => controller.openPipeline(
|
||||
pipeline.id,
|
||||
version: pipeline.version,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _subtitle(
|
||||
BuildContext context,
|
||||
PipelineSummary pipeline,
|
||||
DateTime now,
|
||||
) {
|
||||
final rows = <Widget>[Text(pipelineSubtitle(pipeline))];
|
||||
final updated = pipelineUpdatedLine(pipeline);
|
||||
if (updated != null) rows.add(Text(updated));
|
||||
if (pipeline.scheduleLabel.isNotEmpty) {
|
||||
rows.add(Text(pipeline.scheduleLabel));
|
||||
}
|
||||
if (controller.runsLoaded) {
|
||||
final run = controller.latestRuns[pipeline.id];
|
||||
if (run == null) {
|
||||
rows.add(Text('no runs recorded', style: _mutedStyle(context)));
|
||||
} else {
|
||||
final badge = runBadge(run, now);
|
||||
rows.add(Text('${runStateLabel(badge.state)} · ${badge.metaLine}'));
|
||||
}
|
||||
}
|
||||
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: rows);
|
||||
}
|
||||
|
||||
TextStyle? _mutedStyle(BuildContext context) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(
|
||||
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||
);
|
||||
}
|
||||
final theme = Theme.of(context);
|
||||
return theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../pipeline_format.dart';
|
||||
import '../pipeline_models.dart';
|
||||
import '../pipeline_query.dart';
|
||||
import '../pipelines_controller.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
import 'pipeline_detail_styles.dart';
|
||||
|
||||
/// Summary tab: key/value facts plus the version history. Version rows are
|
||||
/// selectable; the latest version's row is marked and a historical selection
|
||||
/// offers an explicit return to latest.
|
||||
class PipelineSummaryView extends StatelessWidget {
|
||||
const PipelineSummaryView({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.detail,
|
||||
});
|
||||
|
||||
final PipelinesController controller;
|
||||
final PipelineDetail detail;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final historical = detail.resolvedVersion != detail.latestVersion;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (historical)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: Text(
|
||||
'Viewing v${detail.resolvedVersion} '
|
||||
'(latest v${detail.latestVersion}).',
|
||||
style: pipelineMutedStyle(context),
|
||||
),
|
||||
),
|
||||
_fields(context),
|
||||
_versions(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _fields(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final field in pipelineSummaryFields(detail))
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(field.key, style: pipelineMutedStyle(context)),
|
||||
SelectableText(
|
||||
field.value,
|
||||
style: pipelineValueStyle(
|
||||
context,
|
||||
monospace: field.monospace,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _versions(BuildContext context) {
|
||||
final effective = detail.resolvedVersion;
|
||||
final showingLatest = effective == detail.latestVersion;
|
||||
final rows = <Widget>[
|
||||
if (!showingLatest)
|
||||
_versionTile(
|
||||
context,
|
||||
key: const Key('pipeline-latest-version'),
|
||||
subtitle: 'Return to the latest version',
|
||||
selected: false,
|
||||
label: 'View latest v${detail.latestVersion}',
|
||||
onTap: () => controller.selectVersion(0),
|
||||
),
|
||||
for (final version in detail.versions)
|
||||
_versionTile(
|
||||
context,
|
||||
key: Key('pipeline-version-${version.version}'),
|
||||
subtitle: [
|
||||
stageCountText(version.stages),
|
||||
?formatLocalTimestamp(version.createdAt),
|
||||
].join(' · '),
|
||||
selected: version.version == effective,
|
||||
label: 'v${version.version}',
|
||||
onTap: () => controller.selectVersion(version.version),
|
||||
),
|
||||
if (detail.versions.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
'No versions recorded.',
|
||||
style: pipelineMutedStyle(context),
|
||||
),
|
||||
),
|
||||
];
|
||||
if (useCupertinoControls(context)) {
|
||||
return CupertinoListSection.insetGrouped(
|
||||
header: const Text('VERSIONS'),
|
||||
children: rows,
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
|
||||
child: Text('Versions', style: pipelineSectionStyle(context)),
|
||||
),
|
||||
...rows,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _versionTile(
|
||||
BuildContext context, {
|
||||
required Key key,
|
||||
required String subtitle,
|
||||
required bool selected,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
if (useCupertinoControls(context)) {
|
||||
return CupertinoListTile(
|
||||
key: key,
|
||||
title: Text(label),
|
||||
subtitle: Text(subtitle),
|
||||
trailing: selected ? const Icon(CupertinoIcons.check_mark) : null,
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
return ListTile(
|
||||
key: key,
|
||||
selected: selected,
|
||||
title: Text(label),
|
||||
subtitle: Text(subtitle),
|
||||
trailing: selected ? const Icon(Icons.check) : null,
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'pipeline_detail_tab.dart';
|
||||
|
||||
/// Horizontal inset a label needs on each side in the per-label row.
|
||||
const double pipelineTabSegmentPadding = 8;
|
||||
|
||||
/// The style the platform segmented control renders its labels in, so a
|
||||
/// measured width is the width the label really paints.
|
||||
TextStyle pipelineTabLabelStyle(
|
||||
BuildContext context, {
|
||||
required bool cupertino,
|
||||
}) {
|
||||
if (cupertino) return CupertinoTheme.of(context).textTheme.textStyle;
|
||||
return Theme.of(context).textTheme.labelLarge ?? const TextStyle();
|
||||
}
|
||||
|
||||
/// Measures every label for the current text style and text scaler.
|
||||
List<Size> measurePipelineTabLabels(BuildContext context, TextStyle style) {
|
||||
return [
|
||||
for (final tab in PipelineDetailTab.values)
|
||||
_measureLabel(context, tab.label, style),
|
||||
];
|
||||
}
|
||||
|
||||
Size _measureLabel(BuildContext context, String label, TextStyle style) {
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(text: label, style: style),
|
||||
textDirection: Directionality.of(context),
|
||||
textScaler: MediaQuery.textScalerOf(context),
|
||||
maxLines: 1,
|
||||
)..layout();
|
||||
final size = painter.size;
|
||||
painter.dispose();
|
||||
return size;
|
||||
}
|
||||
|
||||
/// A segmented row whose segments are as wide as their own labels. It keeps
|
||||
/// the platform segmented control's shape and theme colors, but not its
|
||||
/// equal-share sizing.
|
||||
///
|
||||
/// [PipelineDetailTabs] uses it only when an equal share of the pane is too
|
||||
/// narrow for the widest label or wider than the labels need together.
|
||||
class PipelineTabRow extends StatelessWidget {
|
||||
const PipelineTabRow({
|
||||
super.key,
|
||||
required this.selected,
|
||||
required this.onSelected,
|
||||
required this.labelSizes,
|
||||
required this.labelStyle,
|
||||
required this.rowHeight,
|
||||
required this.available,
|
||||
required this.cupertino,
|
||||
});
|
||||
|
||||
final PipelineDetailTab selected;
|
||||
final ValueChanged<PipelineDetailTab> onSelected;
|
||||
final List<Size> labelSizes;
|
||||
final TextStyle labelStyle;
|
||||
final double rowHeight;
|
||||
final double available;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context);
|
||||
final Color borderColor = cupertino
|
||||
? cupertinoTheme.primaryColor
|
||||
: scheme.outline;
|
||||
final Color selectedFill = cupertino
|
||||
? cupertinoTheme.primaryColor
|
||||
: scheme.secondaryContainer;
|
||||
final Color selectedText = cupertino
|
||||
? cupertinoTheme.primaryContrastingColor
|
||||
: scheme.onSecondaryContainer;
|
||||
final Color textColor = cupertino
|
||||
? CupertinoColors.label.resolveFrom(context)
|
||||
: scheme.onSurface;
|
||||
|
||||
final widths = [
|
||||
for (final size in labelSizes) size.width + 2 * pipelineTabSegmentPadding,
|
||||
];
|
||||
final content = widths.fold<double>(0, (total, width) => total + width);
|
||||
// The outer border takes one pixel on each side; spread any remaining
|
||||
// width evenly so a row whose labels fit still fills the pane.
|
||||
final inner = available.isFinite
|
||||
? math.max(0, available - 2)
|
||||
: double.infinity;
|
||||
final extra = content < inner ? (inner - content) / widths.length : 0;
|
||||
|
||||
final tabs = PipelineDetailTab.values;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: cupertino
|
||||
? cupertinoTheme.primaryContrastingColor
|
||||
: scheme.surface,
|
||||
border: Border.all(color: borderColor),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (var index = 0; index < tabs.length; index++)
|
||||
_PerLabelSegment(
|
||||
tab: tabs[index],
|
||||
width: widths[index] + extra,
|
||||
height: rowHeight,
|
||||
selected: tabs[index] == selected,
|
||||
labelStyle: labelStyle.copyWith(
|
||||
color: tabs[index] == selected ? selectedText : textColor,
|
||||
),
|
||||
fillColor: tabs[index] == selected ? selectedFill : null,
|
||||
dividerColor: index == tabs.length - 1 ? null : borderColor,
|
||||
cupertino: cupertino,
|
||||
onTap: () => onSelected(tabs[index]),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PerLabelSegment extends StatelessWidget {
|
||||
const _PerLabelSegment({
|
||||
required this.tab,
|
||||
required this.width,
|
||||
required this.height,
|
||||
required this.selected,
|
||||
required this.labelStyle,
|
||||
required this.fillColor,
|
||||
required this.dividerColor,
|
||||
required this.cupertino,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final PipelineDetailTab tab;
|
||||
final double width;
|
||||
final double height;
|
||||
final bool selected;
|
||||
final TextStyle labelStyle;
|
||||
final Color? fillColor;
|
||||
final Color? dividerColor;
|
||||
final bool cupertino;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final label = Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: pipelineTabSegmentPadding,
|
||||
),
|
||||
child: Text(tab.label, maxLines: 1, softWrap: false, style: labelStyle),
|
||||
);
|
||||
final Widget button = cupertino
|
||||
? CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: Size.zero,
|
||||
onPressed: onTap,
|
||||
child: label,
|
||||
)
|
||||
: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Center(child: label),
|
||||
),
|
||||
);
|
||||
return SizedBox(
|
||||
key: ValueKey('pipeline-tab-${tab.name}'),
|
||||
width: width,
|
||||
height: height,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: fillColor,
|
||||
border: dividerColor == null
|
||||
? null
|
||||
: Border(right: BorderSide(color: dividerColor!)),
|
||||
),
|
||||
child: Semantics(
|
||||
button: true,
|
||||
inMutuallyExclusiveGroup: true,
|
||||
selected: selected,
|
||||
child: button,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'pipeline_controls.dart';
|
||||
import 'pipeline_detail_tab.dart';
|
||||
import 'pipeline_tab_row.dart';
|
||||
|
||||
export 'pipeline_detail_tab.dart';
|
||||
|
||||
/// Platform tabs: a Material segmented button or a Cupertino segmented control.
|
||||
///
|
||||
/// Both platform controls give every segment the width of the widest label. At
|
||||
/// narrow widths and scaled text that share is narrower than a label, so the
|
||||
/// labels would wrap or be cut at the pane edge. When the equal share still
|
||||
/// fits, the platform control is used unchanged. Otherwise a per-label row
|
||||
/// gives every segment exactly its label's width and fills the pane when the
|
||||
/// three labels fit; only a row that genuinely needs more room scrolls.
|
||||
class PipelineDetailTabs extends StatelessWidget {
|
||||
const PipelineDetailTabs({
|
||||
super.key,
|
||||
required this.selected,
|
||||
required this.onSelected,
|
||||
});
|
||||
|
||||
final PipelineDetailTab selected;
|
||||
final ValueChanged<PipelineDetailTab> onSelected;
|
||||
|
||||
/// A safe upper bound for the padding the platform segmented controls add
|
||||
/// inside each segment; the equal-share layout is only used when every label
|
||||
/// still fits with this much room.
|
||||
static const double _controlSegmentPadding = 32;
|
||||
|
||||
/// Smallest visual height, matching the platform controls at normal text.
|
||||
static const double _minHeight = 32;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = useCupertinoControls(context);
|
||||
final labelStyle = pipelineTabLabelStyle(context, cupertino: cupertino);
|
||||
final labelSizes = measurePipelineTabLabels(context, labelStyle);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final available = constraints.hasBoundedWidth
|
||||
? constraints.maxWidth
|
||||
: double.infinity;
|
||||
final widest = labelSizes.map((size) => size.width).reduce(math.max);
|
||||
final equalShareFits =
|
||||
!available.isFinite ||
|
||||
available >= 3 * (widest + _controlSegmentPadding);
|
||||
final control = equalShareFits
|
||||
? (cupertino ? _cupertinoControl() : _materialControl())
|
||||
: PipelineTabRow(
|
||||
selected: selected,
|
||||
onSelected: onSelected,
|
||||
labelSizes: labelSizes,
|
||||
labelStyle: labelStyle,
|
||||
rowHeight: math.max(_minHeight, labelSizes.first.height),
|
||||
available: available,
|
||||
cupertino: cupertino,
|
||||
);
|
||||
return _ScrollWhenOverflowing(
|
||||
child: KeyedSubtree(
|
||||
key: const Key('pipeline-detail-tabs'),
|
||||
child: control,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _materialControl() {
|
||||
return SegmentedButton<PipelineDetailTab>(
|
||||
segments: [
|
||||
for (final tab in PipelineDetailTab.values)
|
||||
ButtonSegment(value: tab, label: _label(tab)),
|
||||
],
|
||||
selected: {selected},
|
||||
showSelectedIcon: false,
|
||||
onSelectionChanged: (selection) => onSelected(selection.single),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cupertinoControl() {
|
||||
return CupertinoSegmentedControl<PipelineDetailTab>(
|
||||
groupValue: selected,
|
||||
onValueChanged: onSelected,
|
||||
children: {
|
||||
for (final tab in PipelineDetailTab.values)
|
||||
tab: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: _label(tab),
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _label(PipelineDetailTab tab) {
|
||||
// One line, and let the control size the segment to the whole word rather
|
||||
// than wrapping inside it when scaled text is wider than the pane.
|
||||
return Text(tab.label, maxLines: 1, softWrap: false);
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives [child] the full available width as a minimum, then scrolls instead of
|
||||
/// squeezing it below its content width.
|
||||
class _ScrollWhenOverflowing extends StatelessWidget {
|
||||
const _ScrollWhenOverflowing({required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (!constraints.hasBoundedWidth) return child;
|
||||
return ScrollConfiguration(
|
||||
// Desktop pointer scrolling is vertical only, so allow dragging the
|
||||
// tab row with a mouse as well as touch and trackpad.
|
||||
behavior: ScrollConfiguration.of(context).copyWith(
|
||||
dragDevices: const {
|
||||
PointerDeviceKind.touch,
|
||||
PointerDeviceKind.mouse,
|
||||
PointerDeviceKind.stylus,
|
||||
PointerDeviceKind.invertedStylus,
|
||||
PointerDeviceKind.trackpad,
|
||||
},
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user