feat(app): add native authored stage definition pane

This commit is contained in:
2026-10-21 22:26:34 +01:00
parent 76fb2cdd87
commit d88213deb4
7 changed files with 1529 additions and 0 deletions
@@ -0,0 +1,241 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../domain/graph_protocol.dart';
import '../domain/stage_definition.dart';
/// Wording for a stage that this pinned definition does not declare.
const String unknownStageDefinition =
'This stage is not declared in this pipeline version. '
'No definition has been reconstructed.';
/// The web pane's message when a node has no recorded stage or incoming routes.
const String noStageDefinitionDetails = 'No details recorded for this node.';
/// Terminals are definition targets; this pane never presents one as evidence.
const String terminalDefinitionNote =
'Success and Failure are definition targets, not recorded visits. '
'This pane shows where the definition routes.';
/// The raw section's heading: unknown stage fields stay visible and selectable.
const String rawStageDefinitionTitle = 'Raw stage definition';
/// A read-only native view of one stage's declared definition.
///
/// [graph] is the graph pinned for exactly [pipelineId]/[version] and
/// [stageKey] is a node key (a stage or `#success`/`#failure`). Nothing is
/// fetched and no run visit is read, so the pane cannot imply that the stage
/// executed. Unknown stage declarations get an explicit missing state; every
/// declared stage also keeps its exact JSON below the structured fields.
class StageDefinitionView extends StatelessWidget {
const StageDefinitionView({
super.key,
required this.graph,
required this.stageKey,
required this.pipelineId,
required this.pipelineName,
required this.version,
});
final JsonMap graph;
final String stageKey;
final int pipelineId;
final String pipelineName;
final int version;
String get _identity =>
'${pipelineName.isEmpty ? 'Pipeline' : pipelineName} \u00b7 v$version';
@override
Widget build(BuildContext context) {
final style = _StageDefinitionStyle.of(context);
final stage = stageDefinitionFor(graph, stageKey);
final terminal = isTerminalTarget(stageKey);
final fields = stage != null
? stageDefinitionFields(stage)
: terminal
? terminalDefinitionFields(graph, stageKey)
: const <StageDefinitionField>[];
return ListView(
padding: const EdgeInsets.all(16),
children: [
Text(_identity, style: style.muted),
const SizedBox(height: 16),
if (stage == null && !terminal)
Text(unknownStageDefinition, style: style.value)
else ...[
if (terminal) ...[
Text(terminalDefinitionNote, style: style.muted),
const SizedBox(height: 16),
],
for (final field in fields)
_StageDefinitionFieldView(field: field, style: style),
if (terminal && fields.isEmpty)
Text(noStageDefinitionDetails, style: style.muted),
if (stage != null) ...[
const SizedBox(height: 8),
Text(rawStageDefinitionTitle, style: style.heading),
const SizedBox(height: 8),
_SelectableDefinitionText(
value: const JsonEncoder.withIndent(' ').convert(stage),
style: style.value,
),
],
],
],
);
}
}
/// Opens the platform's native full-screen stage-definition page.
///
/// The page owns the single navigation bar and its standard back control; the
/// caller only supplies the pinned graph and identity. This is the hook the
/// pipeline graph uses when a node is selected.
Future<void> openStageDefinition(
BuildContext context, {
required JsonMap graph,
required String stageKey,
required int pipelineId,
required String pipelineName,
required int version,
}) {
final view = StageDefinitionView(
graph: graph,
stageKey: stageKey,
pipelineId: pipelineId,
pipelineName: pipelineName,
version: version,
);
final settings = RouteSettings(
name: 'stage-definition/$pipelineId/$version/$stageKey',
);
// A terminal is a definition target, not its protocol key: the web pane
// titles it with `nodeDisplayLabel` (`Failure`/`Success`).
final title = '${nodeDisplayLabel(stageKey)} definition';
final route = usesCupertinoHost(context)
? CupertinoPageRoute<void>(
settings: settings,
builder: (_) => CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(middle: Text(title)),
child: SafeArea(child: view),
),
)
: MaterialPageRoute<void>(
settings: settings,
builder: (_) => Scaffold(
appBar: AppBar(title: Text(title)),
body: SafeArea(child: view),
),
);
return Navigator.of(context).push(route);
}
/// One labelled field: a compact row for scalars, a selectable block when the
/// value is multi-line authored text.
class _StageDefinitionFieldView extends StatelessWidget {
const _StageDefinitionFieldView({required this.field, required this.style});
final StageDefinitionField field;
final _StageDefinitionStyle style;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(field.label, style: style.label),
const SizedBox(height: 4),
if (field.block)
_SelectableDefinitionText(value: field.value, style: style.value)
else
Text(field.value, style: style.value),
],
),
);
}
}
/// Authored definition text in the host's selectable body.
///
/// The semantic leaf carries the exact value: Flutter web maps a
/// [SelectableText] to an empty read-only field, so without this a screen
/// reader (and a browser check) sees only its label. The child keeps native
/// pointer selection and the host's system typography.
///
/// The strut is derived from that same host style and forced, so a glyph the
/// host font lacks (the outcomes arrow `→` is one example) cannot pull in a
/// fallback font with taller metrics and double-space only that block. It is
/// the host's own line metrics, not a font override or a fixed height.
class _SelectableDefinitionText extends StatelessWidget {
const _SelectableDefinitionText({required this.value, required this.style});
final String value;
final TextStyle style;
@override
Widget build(BuildContext context) {
return Semantics(
label: value,
child: ExcludeSemantics(
child: SelectableText(
value,
style: style,
strutStyle: StrutStyle.fromTextStyle(style, forceStrutHeight: true),
),
),
);
}
}
/// Host text roles only: no palette, font family or explicit size.
class _StageDefinitionStyle {
const _StageDefinitionStyle({
required this.label,
required this.value,
required this.muted,
required this.heading,
});
factory _StageDefinitionStyle.of(BuildContext context) {
if (usesCupertinoHost(context)) {
final theme = CupertinoTheme.of(context);
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
return _StageDefinitionStyle(
label: theme.textTheme.tabLabelTextStyle.copyWith(color: secondary),
// SelectableText needs a style it can merge into the default text
// style; Cupertino's textStyle is a complete style with `inherit: false`
// and no baseline.
value: theme.textTheme.textStyle.copyWith(inherit: true),
muted: theme.textTheme.textStyle.copyWith(
inherit: true,
color: secondary,
),
heading: theme.textTheme.navTitleTextStyle,
);
}
final theme = Theme.of(context);
return _StageDefinitionStyle(
label: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
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 label;
final TextStyle value;
final TextStyle muted;
final TextStyle heading;
}