d1b05217c9
Keep the pipeline feature on its existing Material path because the app runs under MaterialApp and never selects Cupertino hosts. Preserve public cupertino parameters and required Cupertino icon values for later cleanup and shared controls.
112 lines
3.5 KiB
Dart
112 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../ui/layout/warnings_section.dart';
|
|
|
|
// The gateway bounds this cache to one server connection. Retain at most sixteen
|
|
// sources, so revisiting a Summary tab does not revalidate its unchanged version.
|
|
final _checks = Expando<Map<String, Future<JsonMap>>>();
|
|
|
|
class PipelineDefinitionValidation extends StatefulWidget {
|
|
const PipelineDefinitionValidation({
|
|
super.key,
|
|
required this.gateway,
|
|
required this.source,
|
|
});
|
|
|
|
final ApiGateway gateway;
|
|
final String source;
|
|
|
|
@override
|
|
State<PipelineDefinitionValidation> createState() =>
|
|
_PipelineDefinitionValidationState();
|
|
}
|
|
|
|
class _PipelineDefinitionValidationState
|
|
extends State<PipelineDefinitionValidation> {
|
|
late Future<JsonMap> _result;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_load();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant PipelineDefinitionValidation oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.source != widget.source ||
|
|
oldWidget.gateway != widget.gateway) {
|
|
_load();
|
|
}
|
|
}
|
|
|
|
void _load({bool retry = false}) {
|
|
final source = widget.source;
|
|
final gateway = widget.gateway;
|
|
if (source.trim().isEmpty) {
|
|
_result = Future.value({'type': 'validated'});
|
|
return;
|
|
}
|
|
final cache = _checks[gateway] ??= {};
|
|
if (retry) cache.remove(source);
|
|
if (!cache.containsKey(source) && cache.length >= 16) {
|
|
cache.remove(cache.keys.first);
|
|
}
|
|
_result = cache.putIfAbsent(
|
|
source,
|
|
// Primary summary sections enqueue their reads while mounting. The
|
|
// transport serializes replies, so optional validation waits until those
|
|
// reads have been queued. A microtask adds no lingering timer on dispose.
|
|
() =>
|
|
Future.microtask(() => gateway.call('validate', {'source': source})),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (widget.source.trim().isEmpty) return const SizedBox.shrink();
|
|
return FutureBuilder<JsonMap>(
|
|
future: _result,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState != ConnectionState.done) {
|
|
return const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Text('Checking definition…'),
|
|
);
|
|
}
|
|
final reply = snapshot.data;
|
|
final error = snapshot.hasError
|
|
? 'Could not check definition: ${snapshot.error}'
|
|
: '${reply?['error'] ?? ''}'.trim();
|
|
final messages = warningMessages(reply?['warnings']);
|
|
final validReply =
|
|
reply?['type'] == 'validated' || reply?['type'] == 'error';
|
|
final failure = error.isNotEmpty
|
|
? error
|
|
: !validReply
|
|
? 'The server did not return definition validation.'
|
|
: '';
|
|
if (messages.isEmpty && failure.isEmpty) return const SizedBox.shrink();
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
WarningsSection(
|
|
title: 'Definition warnings',
|
|
messages: [if (failure.isNotEmpty) failure, ...messages],
|
|
),
|
|
if (snapshot.hasError || !validReply)
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: TextButton(
|
|
onPressed: () => setState(() => _load(retry: true)),
|
|
child: const Text('Retry validation'),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|