150 lines
4.7 KiB
Dart
150 lines
4.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../../../ui/adaptive/host.dart';
|
|
import '../../artifacts/domain/artifact_record.dart';
|
|
import '../../artifacts/domain/artifact_url.dart';
|
|
import '../../artifacts/ui/artifact_external_open.dart';
|
|
import 'run_detail_visit_session_state.dart';
|
|
|
|
/// The visit's recorded session pointer and, when the visit exported one, a
|
|
/// read-only external open of that document.
|
|
///
|
|
/// The state comes from [detailVisitSession], so a legacy `session.html`, a
|
|
/// repair, a still-running session and a failed one each report what the server
|
|
/// recorded. The open goes through the landed safe-link helper: the recorded url
|
|
/// is resolved by [resolveArtifactUrl] and passed to [openArtifactExternally]
|
|
/// without being fetched, rewritten or previewed. A refusal is reported.
|
|
class RunVisitSession extends StatefulWidget {
|
|
const RunVisitSession({
|
|
super.key,
|
|
required this.step,
|
|
required this.configuredEndpoint,
|
|
this.openExternal = openArtifactExternally,
|
|
});
|
|
|
|
final JsonMap step;
|
|
final String configuredEndpoint;
|
|
final ArtifactExternalOpen openExternal;
|
|
|
|
@override
|
|
State<RunVisitSession> createState() => _RunVisitSessionState();
|
|
}
|
|
|
|
class _RunVisitSessionState extends State<RunVisitSession> {
|
|
String? _status;
|
|
|
|
Future<void> _open(ResolvedArtifactUrl resolved) async {
|
|
final opened = await widget.openExternal(resolved.uri);
|
|
if (!mounted) return;
|
|
setState(
|
|
() => _status = opened
|
|
? 'Link opened externally.'
|
|
: 'Could not open the link.',
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final session = detailVisitSession(widget.step);
|
|
final export = session.export;
|
|
final resolved = export == null
|
|
? null
|
|
: resolveArtifactUrl(widget.configuredEndpoint, export.artifact.url);
|
|
final note = export?.statusNote;
|
|
final children = <Widget>[
|
|
if (session.sessionId != null)
|
|
_SessionFact(label: 'Session', value: session.sessionId!),
|
|
if (export != null) ...[
|
|
if (note != null) Text(note),
|
|
if (resolved == null)
|
|
const Text(visitSessionEndpointMissing)
|
|
else
|
|
_openButton(export.artifact, resolved),
|
|
] else
|
|
Text(session.message),
|
|
if (_status != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 8),
|
|
child: Semantics(liveRegion: true, child: Text(_status!)),
|
|
),
|
|
];
|
|
if (usesCupertinoHost(context)) {
|
|
return ListView(
|
|
key: const Key('run-visit-body-session'),
|
|
children: [
|
|
CupertinoListSection.insetGrouped(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: _spaced(children),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
return ListView(
|
|
key: const Key('run-visit-body-session'),
|
|
padding: const EdgeInsets.all(16),
|
|
children: _spaced(children),
|
|
);
|
|
}
|
|
|
|
Widget _openButton(ArtifactRecord export, ResolvedArtifactUrl resolved) {
|
|
final label = 'Open ${export.name.isEmpty ? 'session.html' : export.name}';
|
|
if (usesCupertinoHost(context)) {
|
|
return CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: () => _open(resolved),
|
|
child: Text(label),
|
|
);
|
|
}
|
|
return Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: TextButton(onPressed: () => _open(resolved), child: Text(label)),
|
|
);
|
|
}
|
|
|
|
List<Widget> _spaced(List<Widget> children) => [
|
|
for (var index = 0; index < children.length; index += 1) ...[
|
|
if (index > 0) const SizedBox(height: 8),
|
|
children[index],
|
|
],
|
|
];
|
|
}
|
|
|
|
class _SessionFact extends StatelessWidget {
|
|
const _SessionFact({required this.label, required this.value});
|
|
|
|
final String label;
|
|
final String value;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final cupertino = CupertinoTheme.of(context);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: usesCupertinoHost(context)
|
|
? cupertino.textTheme.tabLabelTextStyle.copyWith(
|
|
color: CupertinoColors.secondaryLabel.resolveFrom(context),
|
|
)
|
|
: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(value),
|
|
],
|
|
);
|
|
}
|
|
}
|