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

275 lines
8.9 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);
// The facts take what they need, up to 40% of the height (then scroll);
// the section fills everything else, so the tabs always end at the
// bottom of the screen however short the facts or the section are.
return LayoutBuilder(
builder: (context, constraints) => Column(
key: const Key('run-visit-pane'),
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ConstrainedBox(
constraints: BoxConstraints(maxHeight: constraints.maxHeight * 0.4),
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(
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),
),
),
],
),
);
}
/// Keep stage identity visually distinct from the visit/run coordinates.
/// Back is the page bar's; this heading is the selected recorded stage.
Widget _bar(_VisitStyle style) {
final runId = '${widget.run['id'] ?? ''}'.trim();
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(0, 8, 0, 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Semantics(
container: true,
header: true,
identifier: 'run-stage-heading',
child: Text(
widget.visit.stage,
key: const Key('run-visit-title'),
style: style.stageTitle,
softWrap: true,
),
),
const SizedBox(height: 4),
Wrap(
spacing: 12,
runSpacing: 4,
children: [
if (widget.visit.sequence != null)
Text('Visit ${widget.visit.sequence}', style: style.muted),
if (runId.isNotEmpty) Text('Run $runId', style: style.muted),
],
),
],
),
);
}
}
/// 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,
required this.stageTitle,
});
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,
stageTitle: theme.textTheme.navLargeTitleTextStyle,
);
}
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(),
stageTitle: theme.textTheme.headlineSmall ?? const TextStyle(),
);
}
final TextStyle value;
final TextStyle muted;
final TextStyle heading;
final TextStyle stageTitle;
}