304 lines
9.4 KiB
Dart
304 lines
9.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../changes/changes.dart';
|
|
import 'run_detail_tab_bodies.dart';
|
|
import 'run_field_body.dart';
|
|
import '../../../ui/layout/sticky_section.dart';
|
|
import 'run_detail_visit_artifacts.dart';
|
|
import 'run_detail_visit_definition.dart';
|
|
import 'run_detail_visit_facts.dart';
|
|
import 'run_detail_visit_session.dart';
|
|
|
|
/// The visit pane's recorded sections, in the Android audit order the web
|
|
/// client follows: the turn's Input and Output, its Artifacts, the files this
|
|
/// visit changed, its Session and the authored Definition.
|
|
enum RunVisitSection {
|
|
summary('Summary', Icons.summarize_outlined, CupertinoIcons.doc_text),
|
|
more('More', Icons.more_horiz, CupertinoIcons.ellipsis_circle),
|
|
input('Input', Icons.input, CupertinoIcons.arrow_down_doc),
|
|
output('Output', Icons.output, CupertinoIcons.arrow_up_doc),
|
|
artifacts('Artifacts', Icons.inventory_2_outlined, CupertinoIcons.cube_box),
|
|
changes(
|
|
'Changes',
|
|
Icons.difference_outlined,
|
|
CupertinoIcons.arrow_right_arrow_left,
|
|
),
|
|
session('Session', Icons.forum_outlined, CupertinoIcons.chat_bubble_2),
|
|
definition(
|
|
'Definition',
|
|
Icons.description_outlined,
|
|
CupertinoIcons.doc_plaintext,
|
|
);
|
|
|
|
const RunVisitSection(this.label, this.icon, this.cupertinoIcon);
|
|
|
|
final String label;
|
|
|
|
/// The section's glyph, so a tab is recognisable at a glance.
|
|
final IconData icon;
|
|
final IconData cupertinoIcon;
|
|
}
|
|
|
|
/// The visit pane's native tab strip: a Material segmented button or a Cupertino
|
|
/// segmented control. It scrolls instead of squeezing the labels when a narrow
|
|
/// pane or scaled text cannot fit them.
|
|
class RunVisitSectionStrip extends StatelessWidget {
|
|
const RunVisitSectionStrip({
|
|
super.key,
|
|
required this.selected,
|
|
required this.onSelected,
|
|
});
|
|
|
|
final RunVisitSection selected;
|
|
final ValueChanged<RunVisitSection> onSelected;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino = usesCupertinoHost(context);
|
|
// A full-width bar under the section, as the run's own tabs on a phone.
|
|
final divider = cupertino
|
|
? CupertinoColors.separator.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.outlineVariant;
|
|
return DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
border: Border(top: BorderSide(color: divider, width: 0.5)),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(8, 8, 8, 8),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: KeyedSubtree(
|
|
key: const Key('run-visit-tabs'),
|
|
child: cupertino ? _cupertinoControl() : _materialControl(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _materialControl() => SegmentedButton<RunVisitSection>(
|
|
segments: [
|
|
for (final section in shownVisitSections)
|
|
ButtonSegment(value: section, label: _label(section)),
|
|
],
|
|
selected: {selected},
|
|
showSelectedIcon: false,
|
|
expandedInsets: EdgeInsets.zero,
|
|
onSelectionChanged: (selection) => onSelected(selection.single),
|
|
);
|
|
|
|
Widget _cupertinoControl() => CupertinoSegmentedControl<RunVisitSection>(
|
|
// The strip already insets 16; the control's default inset would push
|
|
// the tabs out of line with the content.
|
|
padding: EdgeInsets.zero,
|
|
groupValue: selected,
|
|
onValueChanged: onSelected,
|
|
children: {
|
|
for (final section in shownVisitSections)
|
|
section: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 2),
|
|
child: _label(section),
|
|
),
|
|
},
|
|
);
|
|
|
|
Widget _label(RunVisitSection section) => KeyedSubtree(
|
|
key: ValueKey('run-visit-tab-${section.name}'),
|
|
// Six sections share the width; a long label shrinks rather than clips.
|
|
child: FittedBox(
|
|
fit: BoxFit.scaleDown,
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Builder(
|
|
builder: (context) => Icon(
|
|
usesCupertinoHost(context) ? section.cupertinoIcon : section.icon,
|
|
size: 18,
|
|
),
|
|
),
|
|
Text(section.label, maxLines: 1, softWrap: false),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// The stage page's tabs: Summary (Input and Output), Artifacts, Changes and
|
|
/// Session. The finer sections stay addressable.
|
|
const shownVisitSections = [
|
|
RunVisitSection.summary,
|
|
RunVisitSection.artifacts,
|
|
RunVisitSection.changes,
|
|
RunVisitSection.session,
|
|
];
|
|
|
|
/// The tab that shows [section].
|
|
RunVisitSection visitTabFor(RunVisitSection section) => switch (section) {
|
|
RunVisitSection.input || RunVisitSection.output => RunVisitSection.summary,
|
|
// The stage's definition lives on the pipeline, not on a run's visit.
|
|
RunVisitSection.more || RunVisitSection.definition => RunVisitSection.session,
|
|
_ => section,
|
|
};
|
|
|
|
/// The selected section's body for one recorded visit.
|
|
Widget runVisitSectionBody({
|
|
required RunVisitSection section,
|
|
required JsonMap run,
|
|
required JsonMap step,
|
|
required int visitIndex,
|
|
required String stageKey,
|
|
required List<JsonMap> runSteps,
|
|
required ApiGateway gateway,
|
|
required ValueChanged<JsonMap> onRunChanged,
|
|
required String configuredEndpoint,
|
|
required bool cupertino,
|
|
}) {
|
|
Widget body(RunVisitSection section) => runVisitSectionBody(
|
|
section: section,
|
|
run: run,
|
|
step: step,
|
|
visitIndex: visitIndex,
|
|
stageKey: stageKey,
|
|
runSteps: runSteps,
|
|
gateway: gateway,
|
|
onRunChanged: onRunChanged,
|
|
configuredEndpoint: configuredEndpoint,
|
|
cupertino: cupertino,
|
|
);
|
|
switch (section) {
|
|
case RunVisitSection.summary:
|
|
// Input then Output, each a sticky collapsible with a copy button.
|
|
return _VisitSummary(
|
|
key: ValueKey('run-visit-summary-$visitIndex'),
|
|
input: step['input'],
|
|
output: step['output'],
|
|
cupertino: cupertino,
|
|
);
|
|
case RunVisitSection.more:
|
|
return body(RunVisitSection.session);
|
|
case RunVisitSection.input:
|
|
return runDetailFieldTab(
|
|
tabKey: 'visit-input',
|
|
value: step['input'],
|
|
empty: visitEmptyInput,
|
|
cupertino: cupertino,
|
|
);
|
|
case RunVisitSection.output:
|
|
return runDetailFieldTab(
|
|
tabKey: 'visit-output',
|
|
value: step['output'],
|
|
empty: visitEmptyOutput,
|
|
cupertino: cupertino,
|
|
);
|
|
case RunVisitSection.artifacts:
|
|
return RunVisitArtifacts(
|
|
step: step,
|
|
visitIndex: visitIndex,
|
|
runSteps: runSteps,
|
|
configuredEndpoint: configuredEndpoint,
|
|
);
|
|
case RunVisitSection.changes:
|
|
// Only this visit's own capture; the run's final state is the run's
|
|
// Changes tab.
|
|
final viewer = ChangesViewer(
|
|
key: ValueKey('run-visit-changes-$visitIndex'),
|
|
steps: [step],
|
|
showSummary: false,
|
|
);
|
|
return cupertino
|
|
? Builder(
|
|
builder: (context) =>
|
|
Theme(data: hostTextTheme(context), child: viewer),
|
|
)
|
|
: viewer;
|
|
case RunVisitSection.session:
|
|
return RunVisitSession(
|
|
run: run,
|
|
step: step,
|
|
gateway: gateway,
|
|
onRunChanged: onRunChanged,
|
|
configuredEndpoint: configuredEndpoint,
|
|
);
|
|
case RunVisitSection.definition:
|
|
return RunVisitDefinition(run: run, stageKey: stageKey);
|
|
}
|
|
}
|
|
|
|
class _VisitSummary extends StatefulWidget {
|
|
const _VisitSummary({
|
|
super.key,
|
|
required this.input,
|
|
required this.output,
|
|
required this.cupertino,
|
|
});
|
|
|
|
final dynamic input;
|
|
final dynamic output;
|
|
final bool cupertino;
|
|
|
|
@override
|
|
State<_VisitSummary> createState() => _VisitSummaryState();
|
|
}
|
|
|
|
class _VisitSummaryState extends State<_VisitSummary> {
|
|
final Set<String> _closed = {};
|
|
String? _copied;
|
|
|
|
Future<void> _copy(String name, dynamic value) async {
|
|
await Clipboard.setData(ClipboardData(text: runFieldCopyText(value)));
|
|
if (mounted) setState(() => _copied = name);
|
|
}
|
|
|
|
Widget _section(String name, dynamic value, String empty) {
|
|
final copy = widget.cupertino
|
|
? CupertinoButton(
|
|
key: ValueKey('run-visit-copy-$name'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
onPressed: () => _copy(name, value),
|
|
child: Icon(
|
|
_copied == name
|
|
? CupertinoIcons.checkmark_alt
|
|
: CupertinoIcons.doc_on_doc,
|
|
semanticLabel: 'Copy $name',
|
|
),
|
|
)
|
|
: IconButton(
|
|
key: ValueKey('run-visit-copy-$name'),
|
|
tooltip: 'Copy $name',
|
|
onPressed: () => _copy(name, value),
|
|
icon: Icon(_copied == name ? Icons.check : Icons.copy),
|
|
);
|
|
final open = !_closed.contains(name);
|
|
return StickySection(
|
|
key: ValueKey('run-visit-section-$name'),
|
|
title: name,
|
|
open: open,
|
|
onToggle: () => setState(() {
|
|
if (!_closed.remove(name)) _closed.add(name);
|
|
}),
|
|
trailing: [copy],
|
|
body: Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
|
child: RunFieldBody(
|
|
value: value,
|
|
empty: empty,
|
|
cupertino: widget.cupertino,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => CustomScrollView(
|
|
key: const Key('run-visit-body-summary'),
|
|
slivers: [
|
|
_section('Input', widget.input, visitEmptyInput),
|
|
_section('Output', widget.output, visitEmptyOutput),
|
|
],
|
|
);
|
|
}
|