Files
pipelines/app/lib/features/runs/ui/new_run_picker.dart
T
alan 26bb583f10 Refine Settings destination shell integration
Keep Settings navigation independent while preserving shell actions and destination-specific state. Add the reviewed chat, run-entry, layout, and regression-test updates needed by the destination behavior.
2026-11-12 11:21:26 +00:00

144 lines
4.7 KiB
Dart

import 'package:flutter/material.dart';
import '../../pipelines/pipeline_models.dart';
import '../../pipelines/pipeline_repository.dart';
import '../../pipelines/ui/run_pipeline_wording.dart';
/// Whether an active pipeline matches a picker search by name. An empty query
/// matches every pipeline.
bool pipelineMatchesQuery(PipelineSummary pipeline, String query) {
final needle = query.trim().toLowerCase();
if (needle.isEmpty) return true;
return pipeline.displayName.toLowerCase().contains(needle);
}
/// Opens the searchable list of active pipelines. Resolves to the chosen
/// pipeline's id, or null when the picker is dismissed.
Future<int?> pickPipelineForNewRun(
BuildContext context,
PipelinesRepository repository,
) => showDialog<int>(
context: context,
builder: (_) => _PipelinePicker(repository: repository),
);
class _PipelinePicker extends StatefulWidget {
const _PipelinePicker({required this.repository});
final PipelinesRepository repository;
@override
State<_PipelinePicker> createState() => _PipelinePickerState();
}
class _PipelinePickerState extends State<_PipelinePicker> {
late Future<List<PipelineSummary>> _pipelines = _loadActive();
String _query = '';
/// Archived pipelines cannot run, so the picker offers only active ones.
Future<List<PipelineSummary>> _loadActive() async {
final all = await widget.repository.listPipelines();
return all.where((pipeline) => !pipeline.archived).toList(growable: false);
}
void _retry() => setState(() => _pipelines = _loadActive());
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Dialog(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 480, maxHeight: 560),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text('Choose a pipeline', style: theme.textTheme.titleLarge),
const Padding(padding: EdgeInsets.only(top: 12)),
TextField(
key: const Key('new-run-search'),
decoration: const InputDecoration(
hintText: 'Search pipelines',
prefixIcon: Icon(Icons.search),
),
onChanged: (value) => setState(() => _query = value),
),
const Padding(padding: EdgeInsets.only(top: 8)),
Flexible(child: _body(context)),
],
),
),
),
);
}
Widget _body(BuildContext context) {
return FutureBuilder<List<PipelineSummary>>(
future: _pipelines,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Padding(
padding: EdgeInsets.all(24),
child: Center(child: CircularProgressIndicator()),
);
}
if (snapshot.hasError) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
describeRunPipelineError(snapshot.error!),
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
TextButton(onPressed: _retry, child: const Text('Retry')),
],
);
}
final active = snapshot.data ?? const <PipelineSummary>[];
if (active.isEmpty) {
return const _Notice('No active pipelines.');
}
final matches = active
.where((pipeline) => pipelineMatchesQuery(pipeline, _query))
.toList(growable: false);
if (matches.isEmpty) {
return const _Notice('No pipeline matches the search.');
}
return ListView(
shrinkWrap: true,
children: [
for (final pipeline in matches)
ListTile(
key: ValueKey<String>('new-run-pipeline-${pipeline.id}'),
title: Text(
pipeline.displayName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(
'v${pipeline.version} · ${pipeline.stages} stages',
),
onTap: () => Navigator.of(context).pop(pipeline.id),
),
],
);
},
);
}
}
class _Notice extends StatelessWidget {
const _Notice(this.message);
final String message;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.all(16),
child: Text(message, style: TextStyle(color: Theme.of(context).hintColor)),
);
}