Files
pipelines/app/lib/features/runs/ui/run_detail_visit.dart
T

243 lines
7.5 KiB
Dart

import '../../../ui/status/run_status_icon.dart';
import '../../graph/widgets/graph_stage_node.dart' show graphStatusState;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import 'run_detail_content.dart';
import 'run_detail_visit_facts.dart';
import 'run_detail_visit_sections.dart';
/// The selected recorded visit inside the Timeline tab.
///
/// It leads with the visit's own headline facts, then native tabbed sections.
/// A fact the reply did not record is not drawn at all; a blank verdict or
/// diagnostic is not rendered as an empty decision.
class RunVisitPane extends StatefulWidget {
const RunVisitPane({
super.key,
required this.run,
required this.visit,
required this.visitIndex,
required this.step,
required this.runSteps,
required this.gateway,
required this.onRunChanged,
required this.configuredEndpoint,
required this.cupertino,
required this.onClose,
});
final JsonMap run;
final DetailVisit visit;
/// The visit's index in [runSteps], so the artifacts section can open exactly
/// this visit's gallery group.
final int visitIndex;
final JsonMap step;
final List<JsonMap> runSteps;
/// The app's shared gateway and the accepted-detail fold for the session's
/// export-only repair. The visit never opens its own socket.
final ApiGateway gateway;
final ValueChanged<JsonMap> onRunChanged;
final String configuredEndpoint;
final bool cupertino;
final VoidCallback onClose;
@override
State<RunVisitPane> createState() => _RunVisitPaneState();
}
class _RunVisitPaneState extends State<RunVisitPane> {
RunVisitSection _section = RunVisitSection.summary;
@override
void didUpdateWidget(covariant RunVisitPane oldWidget) {
super.didUpdateWidget(oldWidget);
// A different visit starts at its first section, like a newly opened pane.
if (oldWidget.visit.sequence != widget.visit.sequence ||
oldWidget.visit.stage != widget.visit.stage) {
_section = RunVisitSection.summary;
}
}
@override
Widget build(BuildContext context) {
final style = _VisitStyle.of(context);
final facts = detailVisitFacts(widget.step);
final verdict = detailVisitVerdict(widget.step);
final diagnostic = detailVisitDiagnostic(widget.step);
return Column(
key: const Key('run-visit-pane'),
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Flexible(
flex: 2,
fit: FlexFit.loose,
child: SingleChildScrollView(
key: const Key('run-visit-facts'),
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_bar(style),
_FactGrid(facts: facts, style: style),
if (verdict != null) ...[
const SizedBox(height: 8),
Text('Verdict', style: style.heading),
if (verdict.option != null) Text(verdict.option!),
if (verdict.reason != null)
Text(verdict.reason!, style: style.value),
],
if (diagnostic != null) ...[
const SizedBox(height: 8),
Text('Diagnostic', style: style.heading),
Text(diagnostic, style: style.value),
],
],
),
),
),
Expanded(
flex: 5,
child: runVisitSectionBody(
section: _section,
run: widget.run,
step: widget.step,
visitIndex: widget.visitIndex,
stageKey: widget.visit.stage,
runSteps: widget.runSteps,
gateway: widget.gateway,
onRunChanged: widget.onRunChanged,
configuredEndpoint: widget.configuredEndpoint,
cupertino: widget.cupertino,
),
),
// The sections are tabs at the bottom, under what they show.
SafeArea(
top: false,
child: RunVisitSectionStrip(
selected: _section,
onSelected: (section) => setState(() => _section = section),
),
),
],
);
}
/// The visit's name; Back is the page bar's.
Widget _bar(_VisitStyle style) => Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text(
widget.visit.title,
key: const Key('run-visit-title'),
style: style.heading,
),
);
}
/// The visit's facts several to a line: status and outcome as coloured
/// pills, a long value (the model) on a line of its own.
class _FactGrid extends StatelessWidget {
const _FactGrid({required this.facts, required this.style});
final List<VisitFact> facts;
final _VisitStyle style;
static String _stateOf(VisitFact fact) {
final value = fact.value.trim().toLowerCase();
if (fact.label == 'Outcome') {
if (value == 'error' || value == 'failed' || value == 'blocked') {
return 'failed';
}
if (value == 'success') return 'succeeded';
return 'running';
}
return graphStatusState(fact.value);
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 4),
child: Wrap(
key: const Key('run-visit-facts-grid'),
spacing: 16,
runSpacing: 8,
children: [
for (final fact in facts)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(fact.label, style: style.muted),
const SizedBox(height: 2),
if (fact.label == 'Status' || fact.label == 'Outcome')
_pill(context, fact)
else
Text(fact.value, style: style.value),
],
),
],
),
);
}
Widget _pill(BuildContext context, VisitFact fact) {
final color = runStatusColor(_stateOf(fact)).resolveFrom(context);
return DecoratedBox(
decoration: ShapeDecoration(
color: color.withValues(alpha: 0.16),
shape: const StadiumBorder(),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
child: Text(
fact.value,
style: style.value.copyWith(
color: color,
fontWeight: FontWeight.w700,
),
),
),
);
}
}
/// Host text roles only: no palette, font family or explicit size.
class _VisitStyle {
const _VisitStyle({
required this.value,
required this.muted,
required this.heading,
});
factory _VisitStyle.of(BuildContext context) {
if (usesCupertinoHost(context)) {
final theme = CupertinoTheme.of(context);
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return _VisitStyle(
value: theme.textTheme.textStyle,
muted: theme.textTheme.textStyle.copyWith(color: secondary),
heading: theme.textTheme.navTitleTextStyle,
);
}
final theme = Theme.of(context);
return _VisitStyle(
value: theme.textTheme.bodyMedium ?? const TextStyle(),
muted: (theme.textTheme.bodySmall ?? const TextStyle()).copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
heading: theme.textTheme.titleSmall ?? const TextStyle(),
);
}
final TextStyle value;
final TextStyle muted;
final TextStyle heading;
}