133 lines
3.9 KiB
Dart
133 lines
3.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import 'run_detail_tab_bodies.dart';
|
|
import 'run_detail_tab_strip.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, its Session and
|
|
/// the authored Definition.
|
|
enum RunVisitSection {
|
|
input('Input'),
|
|
output('Output'),
|
|
artifacts('Artifacts'),
|
|
session('Session'),
|
|
definition('Definition');
|
|
|
|
const RunVisitSection(this.label);
|
|
|
|
final String label;
|
|
}
|
|
|
|
/// 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);
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: ScrollWhenOverflowing(
|
|
child: KeyedSubtree(
|
|
key: const Key('run-visit-tabs'),
|
|
child: cupertino ? _cupertinoControl() : _materialControl(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _materialControl() => SegmentedButton<RunVisitSection>(
|
|
segments: [
|
|
for (final section in RunVisitSection.values)
|
|
ButtonSegment(value: section, label: _label(section)),
|
|
],
|
|
selected: {selected},
|
|
showSelectedIcon: false,
|
|
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 RunVisitSection.values)
|
|
section: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
child: _label(section),
|
|
),
|
|
},
|
|
);
|
|
|
|
Widget _label(RunVisitSection section) => KeyedSubtree(
|
|
key: ValueKey('run-visit-tab-${section.name}'),
|
|
child: Text(section.label, maxLines: 1, softWrap: false),
|
|
);
|
|
}
|
|
|
|
/// 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,
|
|
}) {
|
|
switch (section) {
|
|
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.session:
|
|
return RunVisitSession(
|
|
run: run,
|
|
step: step,
|
|
gateway: gateway,
|
|
onRunChanged: onRunChanged,
|
|
configuredEndpoint: configuredEndpoint,
|
|
);
|
|
case RunVisitSection.definition:
|
|
return RunVisitDefinition(run: run, stageKey: stageKey);
|
|
}
|
|
}
|