Show definition and run warnings in app summaries
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.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}) {
|
||||
if (widget.source.trim().isEmpty) {
|
||||
_result = Future.value({'type': 'validated'});
|
||||
return;
|
||||
}
|
||||
final cache = _checks[widget.gateway] ??= {};
|
||||
if (retry) cache.remove(widget.source);
|
||||
if (!cache.containsKey(widget.source) && cache.length >= 16) {
|
||||
cache.remove(cache.keys.first);
|
||||
}
|
||||
_result = cache.putIfAbsent(
|
||||
widget.source,
|
||||
() => Future.sync(
|
||||
() => widget.gateway.call('validate', {'source': widget.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: usesCupertinoHost(context)
|
||||
? CupertinoButton(
|
||||
onPressed: () => setState(() => _load(retry: true)),
|
||||
child: const Text('Retry validation'),
|
||||
)
|
||||
: TextButton(
|
||||
onPressed: () => setState(() => _load(retry: true)),
|
||||
child: const Text('Retry validation'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import '../pipeline_models.dart';
|
||||
import '../pipeline_query.dart';
|
||||
import '../pipelines_controller.dart';
|
||||
import 'pipeline_controls.dart';
|
||||
import 'pipeline_definition_validation.dart';
|
||||
import 'pipeline_detail_styles.dart';
|
||||
|
||||
/// The Summary's facts grid.
|
||||
@@ -63,6 +64,7 @@ class PipelineSummaryView extends StatelessWidget {
|
||||
style: pipelineMutedStyle(context),
|
||||
),
|
||||
),
|
||||
PipelineDefinitionValidation(gateway: gateway, source: detail.source),
|
||||
_fields(context),
|
||||
SchedulePipelineSection(
|
||||
gateway: gateway,
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'run_detail_visit_facts.dart';
|
||||
import 'run_field_body.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../../ui/layout/facts_grid.dart';
|
||||
import '../../../ui/layout/warnings_section.dart';
|
||||
import '../../../ui/layout/sticky_section.dart';
|
||||
import '../../../ui/text/live_elapsed_builder.dart';
|
||||
import '../../../ui/text/monospace.dart';
|
||||
@@ -64,6 +65,9 @@ Widget runDetailSummaryTab({
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: WarningsSection(messages: warningMessages(run['warnings'])),
|
||||
),
|
||||
// The facts sit on the page as one grid, the same on both hosts: no
|
||||
// grouped card, so a single fact starts at the leading edge.
|
||||
SliverToBoxAdapter(
|
||||
|
||||
Reference in New Issue
Block a user