214 lines
6.6 KiB
Dart
214 lines
6.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../core/api_gateway.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_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.
|
|
///
|
|
/// Standalone use keeps the screen's own native scaffolding. The application
|
|
/// shell sets [embedded] because it already owns the one navigation bar, and
|
|
/// supplies [syncToken] so a reconnect refreshes in place.
|
|
class PipelinesScreen extends StatefulWidget {
|
|
const PipelinesScreen({
|
|
super.key,
|
|
required this.gateway,
|
|
this.embedded = false,
|
|
this.syncToken = 0,
|
|
this.onRunStarted,
|
|
this.initialPipelineId,
|
|
this.initialVersion = 0,
|
|
});
|
|
|
|
final ApiGateway gateway;
|
|
|
|
/// True under the application shell, which owns the single navigation bar.
|
|
final bool embedded;
|
|
|
|
/// Advances when the shared socket is replaced. The mounted controller
|
|
/// reloads the list and the selected detail without losing the selection.
|
|
final int syncToken;
|
|
|
|
/// Receives the run id an accepted launch names, so the composition can open
|
|
/// the existing run route. The feature never navigates on its own.
|
|
final ValueChanged<int>? onRunStarted;
|
|
|
|
/// The pipeline a deep link names, opened after the list read starts.
|
|
final int? initialPipelineId;
|
|
|
|
/// The pinned version for [initialPipelineId]; 0 means latest.
|
|
final int initialVersion;
|
|
|
|
@override
|
|
State<PipelinesScreen> createState() => _PipelinesScreenState();
|
|
}
|
|
|
|
class _PipelinesScreenState extends State<PipelinesScreen> {
|
|
late PipelinesController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = PipelinesController(PipelinesRepository(widget.gateway))
|
|
..load();
|
|
final id = widget.initialPipelineId;
|
|
if (id != null) {
|
|
// The detail read owns its own failure state; the list read continues.
|
|
_controller.openPipeline(id, version: widget.initialVersion);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(PipelinesScreen oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.gateway != widget.gateway) {
|
|
_controller.dispose();
|
|
_controller = PipelinesController(PipelinesRepository(widget.gateway))
|
|
..load();
|
|
} else if (oldWidget.syncToken != widget.syncToken) {
|
|
// The socket was replaced; re-read through the existing controller so the
|
|
// selected pipeline and requested version survive the reconnect.
|
|
_controller.load();
|
|
} else if (oldWidget.initialPipelineId != widget.initialPipelineId ||
|
|
oldWidget.initialVersion != widget.initialVersion) {
|
|
final id = widget.initialPipelineId;
|
|
if (id != null) {
|
|
_controller.openPipeline(id, version: widget.initialVersion);
|
|
} else {
|
|
_controller.clearSelection();
|
|
}
|
|
}
|
|
}
|
|
|
|
@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,
|
|
gateway: widget.gateway,
|
|
showBack: true,
|
|
onRunStarted: widget.onRunStarted,
|
|
)
|
|
: 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,
|
|
gateway: widget.gateway,
|
|
showBack: false,
|
|
onRunStarted: widget.onRunStarted,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
if (widget.embedded) return _embeddedBody(context, body);
|
|
return useCupertinoControls(context)
|
|
? _cupertinoShell(context, body)
|
|
: _materialShell(context, body);
|
|
},
|
|
);
|
|
}
|
|
|
|
/// The shell owns the navigation bar here, so the content keeps a native
|
|
/// Refresh action without adding a second bar.
|
|
Widget _embeddedBody(BuildContext context, Widget body) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Align(
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: _refreshButton(context),
|
|
),
|
|
),
|
|
Expanded(child: body),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _refreshButton(BuildContext context) {
|
|
if (useCupertinoControls(context)) {
|
|
return Semantics(
|
|
button: true,
|
|
label: 'Refresh',
|
|
child: CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: _controller.load,
|
|
child: const Icon(CupertinoIcons.refresh),
|
|
),
|
|
);
|
|
}
|
|
return IconButton(
|
|
tooltip: 'Refresh',
|
|
onPressed: _controller.load,
|
|
icon: const Icon(Icons.refresh),
|
|
);
|
|
}
|
|
|
|
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: [_refreshButton(context)],
|
|
),
|
|
body: SafeArea(child: body),
|
|
);
|
|
}
|
|
|
|
Widget _cupertinoShell(BuildContext context, Widget body) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
middle: const Text('Pipelines'),
|
|
trailing: _refreshButton(context),
|
|
),
|
|
child: SafeArea(top: false, child: body),
|
|
);
|
|
}
|
|
}
|