App: archive and unarchive pipelines

The pipeline's bar gets a Pipeline actions menu with Archive (confirm
dialog: history is kept) or Unarchive; an archived detail says so and
offers no Run. The list hides archived pipelines and the scope control
gains an Archived view. Server refusals (enabled schedule, newer
version) are shown verbatim. The capture fixture answers archive
requests.
This commit is contained in:
2026-11-04 23:37:25 +00:00
parent 06bf580154
commit 5a9284ccf7
14 changed files with 576 additions and 64 deletions
@@ -25,6 +25,7 @@ class PipelineSummary {
this.recordedStages,
this.flowStages,
this.shape,
this.archivedAt,
});
factory PipelineSummary.fromJson(PipelineJson json) {
@@ -47,6 +48,7 @@ class PipelineSummary {
scheduleCount: scheduleCount,
enabledScheduleCount: _optionalInt(json['enabled_schedule_count']),
shape: _jsonObject(json['shape']),
archivedAt: _optionalString(json['archived_at']),
);
}
@@ -77,6 +79,12 @@ class PipelineSummary {
/// empty flow.
final PipelineJson? shape;
/// When the pipeline was archived, or null while it is active. An archived
/// pipeline keeps its versions, runs and name but cannot start runs.
final String? archivedAt;
bool get archived => archivedAt != null;
/// 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.
@@ -146,6 +154,7 @@ class PipelineDetail extends PipelineSummary {
super.recordedStages,
super.flowStages,
super.shape,
super.archivedAt,
required this.latestVersion,
required this.versionCreatedAt,
required this.contentHash,
@@ -170,6 +179,7 @@ class PipelineDetail extends PipelineSummary {
recordedStages: summary.recordedStages,
flowStages: summary.flowStages,
shape: summary.shape,
archivedAt: summary.archivedAt,
latestVersion: _int(json['latest_version']),
versionCreatedAt: _string(json['version_created_at']),
contentHash: _string(json['content_hash']),
@@ -270,6 +280,9 @@ int? _optionalInt(Object? value) {
String _string(Object? value) => value is String ? value : '';
String? _optionalString(Object? value) =>
value is String && value.isNotEmpty ? value : null;
/// 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) {
@@ -11,16 +11,19 @@ class PipelineRequestException implements Exception {
String toString() => message;
}
/// Read-only pipeline requests. Request shapes mirror `web/src/repository.js`
/// exactly; no mutation of server state is offered here.
/// Pipeline requests. Reads mirror `web/src/repository.js`; the one mutation
/// is archiving, which keeps every version and run.
class PipelinesRepository {
PipelinesRepository(this._gateway);
final ApiGateway _gateway;
/// `list_pipelines` -> the whole `pipelines` array.
/// `list_pipelines` -> the whole `pipelines` array, archived ones included
/// (each marked by `archived_at`) so the list can offer an Archived view.
Future<List<PipelineSummary>> listPipelines() async {
final envelope = await _gateway.call('list_pipelines');
final envelope = await _gateway.call('list_pipelines', {
'include_archived': true,
});
_throwIfError(envelope, 'The server returned no pipeline list.');
final type = envelope['type'];
if (type != null && type != 'pipelines') {
@@ -69,6 +72,28 @@ class PipelinesRepository {
return PipelineDetail.fromJson(Map<String, dynamic>.from(detail));
}
/// `archive_pipeline` / `unarchive_pipeline`, guarded by the latest
/// version the operator saw. Replies with the updated detail.
Future<PipelineDetail> setArchived(
int id, {
required bool archived,
required int expectedVersion,
}) async {
final type = archived ? 'archive_pipeline' : 'unarchive_pipeline';
final envelope = await _gateway.call(type, {
'pipeline_id': id,
if (expectedVersion > 0) 'expected_version': expectedVersion,
});
const fallback = 'The server did not confirm the change.';
_throwIfError(envelope, fallback);
final expected = archived ? 'pipeline_archived' : 'pipeline_unarchived';
final detail = envelope['detail'];
if (envelope['type'] != expected || detail is! Map) {
throw const PipelineRequestException(fallback);
}
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');
@@ -27,7 +27,9 @@ class PipelinesController extends ChangeNotifier {
final Set<String> _loadedPendingRuns = {};
final Map<String, int> _pendingRunGenerations = {};
List<PipelineSummary> _pipelines = const <PipelineSummary>[];
/// Every row the server listed, archived ones included.
List<PipelineSummary> _allPipelines = const <PipelineSummary>[];
bool _showArchived = false;
List<PipelineRun> _runs = const <PipelineRun>[];
PipelineFilters _filters = emptyPipelineFilters;
PipelineSort _sort = PipelineSort.serverOrder;
@@ -60,7 +62,13 @@ class PipelinesController extends ChangeNotifier {
final Map<String, RunPipelineIntent> _pendingRuns =
<String, RunPipelineIntent>{};
List<PipelineSummary> get pipelines => _pipelines;
/// The rows of the current view: active pipelines, or with [showArchived]
/// only the archived ones. Archived pipelines never mix into the main list.
List<PipelineSummary> get pipelines => List.unmodifiable(
_allPipelines.where((pipeline) => pipeline.archived == _showArchived),
);
bool get showArchived => _showArchived;
PipelineFilters get filters => _filters;
PipelineSort get sort => _sort;
bool get listLoading => _listLoading;
@@ -86,12 +94,13 @@ class PipelinesController extends ChangeNotifier {
/// 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);
final sorted = sortPipelines(pipelines, _sort, runs);
return filterPipelines(sorted, _filters, runs, _runsLoaded);
}
PipelineEmptyState? get emptyState =>
pipelineListEmptyState(_pipelines, visiblePipelines, _filters);
PipelineEmptyState? get emptyState => _showArchived && pipelines.isEmpty
? const PipelineEmptyState('No archived pipelines.')
: 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.
@@ -110,7 +119,7 @@ class PipelinesController extends ChangeNotifier {
try {
final rows = await _repository.listPipelines();
if (!_current(_listSequence, token)) return;
_pipelines = rows;
_allPipelines = rows;
_pipelinesLoaded = true;
_listError = null;
} catch (error) {
@@ -213,6 +222,35 @@ class PipelinesController extends ChangeNotifier {
_notify();
}
/// Switches between the active list and the Archived view.
void setShowArchived(bool value) {
if (_showArchived == value) return;
_showArchived = value;
_notify();
}
/// Archives or unarchives [detail] and refreshes the list. Returns the
/// server's refusal (an enabled schedule, a newer version) verbatim, or
/// null on success.
Future<String?> setArchived(PipelineDetail detail, bool archived) async {
try {
final updated = await _repository.setArchived(
detail.id,
archived: archived,
expectedVersion: detail.latestVersion,
);
if (_disposed) return null;
if (_selectedId == detail.id && _selectedVersion == 0) {
_detail = updated;
}
_notify();
} catch (error) {
return pipelineErrorMessage(error);
}
await load();
return null;
}
void setSort(PipelineSort sort) {
_sort = sort;
_notify();
@@ -0,0 +1,179 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import '../../../ui/layout/app_overflow_menu.dart';
import '../pipeline_models.dart';
import '../pipelines_controller.dart';
import 'pipeline_controls.dart';
import 'pipeline_detail_styles.dart';
/// The confirmation body: archiving hides, it never deletes.
String archiveConfirmation(String name) =>
'$name leaves the pipeline list and can no longer start runs. Its '
'versions, runs, artifacts and search history are kept, and you can '
'unarchive it from the Archived list at any time.';
/// The open pipeline's own actions menu in its bar: Archive or Unarchive.
/// A narrow bar moves it into the bar's More menu as one entry.
Widget pipelineActionsMenu(
BuildContext context,
PipelinesController controller,
PipelineDetail detail,
) {
final archived = detail.archived;
final label = archived ? 'Unarchive' : 'Archive…';
void run(BuildContext context) =>
archiveOrUnarchive(context, controller, detail);
return SegmentedOverflowAction(
overflowEntry: SegmentedOverflowEntry(
label: archived ? 'Unarchive pipeline' : 'Archive pipeline…',
icon: useCupertinoControls(context)
? CupertinoIcons.archivebox
: Icons.archive_outlined,
onPressed: () => run(context),
),
child: AppOverflowMenu<bool>(
key: const Key('pipeline-actions-menu'),
label: 'Pipeline actions',
sheetTitle: detail.displayName,
cupertino: useCupertinoControls(context),
actions: [
AppMenuAction(
key: Key(archived ? 'pipeline-unarchive' : 'pipeline-archive'),
value: true,
label: label,
),
],
onSelected: (context, _) => run(context),
),
);
}
/// Archives (after confirmation) or unarchives [detail], reporting a server
/// refusal such as an enabled schedule in a dialog.
Future<void> archiveOrUnarchive(
BuildContext context,
PipelinesController controller,
PipelineDetail detail,
) async {
final archiving = !detail.archived;
if (archiving && !await _confirmArchive(context, detail.displayName)) return;
final error = await controller.setArchived(detail, archiving);
if (error == null || !context.mounted) return;
await _showRefusal(
context,
archiving ? 'Could not archive' : 'Could not unarchive',
error,
);
}
/// The notice an archived pipeline's detail leads with.
class PipelineArchivedNotice extends StatelessWidget {
const PipelineArchivedNotice({
super.key,
required this.controller,
required this.detail,
});
final PipelinesController controller;
final PipelineDetail detail;
@override
Widget build(BuildContext context) {
return Padding(
key: const Key('pipeline-archived-notice'),
padding: const EdgeInsets.fromLTRB(16, 8, 16, 4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Archived. Its history is kept; unarchive it to run it again.',
style: pipelineMutedStyle(context),
),
PipelineTextButton(
key: const Key('pipeline-archived-unarchive'),
label: 'Unarchive',
onPressed: () => archiveOrUnarchive(context, controller, detail),
),
],
),
);
}
}
Future<bool> _confirmArchive(BuildContext context, String name) async {
final title = Text('Archive $name?');
final body = Text(archiveConfirmation(name));
final confirmed = useCupertinoControls(context)
? await showCupertinoDialog<bool>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: title,
content: body,
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
CupertinoDialogAction(
key: const Key('pipeline-archive-confirm'),
isDefaultAction: true,
onPressed: () => Navigator.pop(context, true),
child: const Text('Archive'),
),
],
),
)
: await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: title,
content: body,
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
FilledButton(
key: const Key('pipeline-archive-confirm'),
onPressed: () => Navigator.pop(context, true),
child: const Text('Archive'),
),
],
),
);
return confirmed == true;
}
Future<void> _showRefusal(BuildContext context, String title, String message) {
if (useCupertinoControls(context)) {
return showCupertinoDialog<void>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text(title),
content: Text(message),
actions: [
CupertinoDialogAction(
isDefaultAction: true,
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
return showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: Text(title),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
}
@@ -14,6 +14,7 @@ import '../pipeline_models.dart';
import '../pipeline_query.dart';
import '../pipelines_controller.dart';
import '../ui/run_pipeline_action.dart';
import 'pipeline_archive_action.dart';
import 'pipeline_controls.dart';
import 'pipeline_bar_buttons.dart';
import '../../../ui/text/markdown_source_view.dart';
@@ -114,6 +115,8 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
_applyStageRequest(context, detail);
final notices = [
if (!inBar) _header(context, detail),
if (detail.archived)
PipelineArchivedNotice(controller: _controller, detail: detail),
if (_controller.detailLoading)
const Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
@@ -394,8 +397,9 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
);
}
/// Runs and the primary Run: the top bar's actions, never floating over
/// the content (where they used to cover the version history).
/// Runs, the primary Run and the pipeline's actions menu: the top bar's
/// actions, never floating over the content (where they used to cover the
/// version history). An archived pipeline cannot run, so it offers no Run.
List<Widget> _actions(BuildContext context, PipelineDetail detail) => [
pipelineBarIconButton(
context,
@@ -409,13 +413,15 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
? null
: () => widget.onViewPipelineRuns!(detail.id),
),
RunPipelineAction(
controller: _controller,
detail: detail,
gateway: widget.gateway,
onRunStarted: widget.onRunStarted,
inBar: true,
),
if (!detail.archived)
RunPipelineAction(
controller: _controller,
detail: detail,
gateway: widget.gateway,
onRunStarted: widget.onRunStarted,
inBar: true,
),
pipelineActionsMenu(context, _controller, detail),
];
Widget _source(BuildContext context, PipelineDetail detail) {
@@ -82,18 +82,24 @@ class PipelineListPanel extends StatelessWidget {
/// The web's compact toolbar: filter (whose page carries the name search),
/// sort and clear, on the list's 12px inset with a separator underneath.
/// All pipelines, or only those with a schedule.
/// All pipelines, only those with a schedule, or the archived ones.
Widget _scope(BuildContext context, PipelineFilters filters) {
final scheduled = filters.schedule == ScheduleFilter.scheduled;
void pick(bool value) => controller.setFilters(
filters.copyWith(
schedule: value ? ScheduleFilter.scheduled : ScheduleFilter.any,
),
);
final control = PipelineScopeControl(
scheduled: scheduled,
onSelected: pick,
);
final scope = controller.showArchived
? PipelineScope.archived
: filters.schedule == ScheduleFilter.scheduled
? PipelineScope.scheduled
: PipelineScope.all;
void pick(PipelineScope value) {
controller.setShowArchived(value == PipelineScope.archived);
final schedule = value == PipelineScope.scheduled
? ScheduleFilter.scheduled
: ScheduleFilter.any;
if (filters.schedule != schedule) {
controller.setFilters(filters.copyWith(schedule: schedule));
}
}
final control = PipelineScopeControl(scope: scope, onSelected: pick);
return Padding(
padding: const EdgeInsets.fromLTRB(
kPipelineListInset,
@@ -3,18 +3,32 @@ import 'package:flutter/material.dart';
import 'pipeline_controls.dart';
/// The list's scope: every active pipeline, only scheduled ones, or the
/// archived pipelines (which the other two never show).
enum PipelineScope {
all('All'),
scheduled('Scheduled'),
archived('Archived');
const PipelineScope(this.label);
final String label;
}
/// Uses a native picker when the segmented labels cannot fit at the user's
/// text scale. The decision is content-measured, not a fixed pane width.
class PipelineScopeControl extends StatelessWidget {
const PipelineScopeControl({
super.key,
required this.scheduled,
required this.scope,
required this.onSelected,
});
final bool scheduled;
final ValueChanged<bool> onSelected;
final PipelineScope scope;
final ValueChanged<PipelineScope> onSelected;
static const labels = {false: 'All', true: 'Scheduled'};
static final labels = {
for (final scope in PipelineScope.values) scope: scope.label,
};
@override
Widget build(BuildContext context) {
@@ -36,30 +50,31 @@ class PipelineScopeControl extends StatelessWidget {
builder: (context, constraints) {
if (constraints.maxWidth >= requiredWidth) {
return cupertino
? CupertinoSlidingSegmentedControl<bool>(
? CupertinoSlidingSegmentedControl<PipelineScope>(
key: const Key('pipeline-scope'),
groupValue: scheduled,
onValueChanged: (value) => onSelected(value ?? false),
groupValue: scope,
onValueChanged: (value) =>
onSelected(value ?? PipelineScope.all),
children: {
for (final entry in labels.entries)
entry.key: Text(entry.value),
},
)
: SegmentedButton<bool>(
: SegmentedButton<PipelineScope>(
key: const Key('pipeline-scope'),
showSelectedIcon: false,
segments: [
for (final entry in labels.entries)
ButtonSegment(value: entry.key, label: Text(entry.value)),
],
selected: {scheduled},
selected: {scope},
onSelectionChanged: (value) => onSelected(value.single),
);
}
if (!cupertino) {
return DropdownButton<bool>(
return DropdownButton<PipelineScope>(
key: const Key('pipeline-scope'),
value: scheduled,
value: scope,
isExpanded: true,
items: [
for (final entry in labels.entries)
@@ -104,7 +119,7 @@ class PipelineScopeControl extends StatelessWidget {
children: [
Expanded(
child: Text(
labels[scheduled]!,
labels[scope]!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),