Files
pipelines/app/lib/features/pipelines/pipeline_repository.dart
T
alan a44f31b989 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.
2026-10-21 19:09:29 +01:00

99 lines
3.3 KiB
Dart

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);
}
}
}