135 lines
3.9 KiB
Dart
135 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/api_gateway.dart';
|
|
import '../domain/run_models.dart';
|
|
import 'run_changes_action.dart';
|
|
import 'run_detail_content.dart';
|
|
|
|
/// The runs detail with standard Material controls.
|
|
Widget buildMaterialRunDetail({
|
|
required BuildContext context,
|
|
required JsonMap run,
|
|
required Widget headerActions,
|
|
required bool detailLoading,
|
|
required String? error,
|
|
required bool copying,
|
|
required String? copyStatus,
|
|
required VoidCallback onBack,
|
|
required VoidCallback onCopy,
|
|
}) {
|
|
final theme = Theme.of(context);
|
|
final prompt = detailPrompt(run);
|
|
final visits = detailTimeline(run['steps']);
|
|
final metrics = detailUsageMetrics(run['usage']);
|
|
return ListView(
|
|
key: ValueKey<String>('run-detail-${run['id']}'),
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: [
|
|
TextButton.icon(
|
|
onPressed: onBack,
|
|
icon: const Icon(Icons.arrow_back),
|
|
label: const Text('Back to list'),
|
|
),
|
|
if (showRunChangesAction(run)) RunChangesButton(run: run),
|
|
],
|
|
),
|
|
Text(detailTitle(run), style: theme.textTheme.headlineSmall),
|
|
const SizedBox(height: 8),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 4,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: [
|
|
Chip(label: Text(runStatusLabel(run))),
|
|
Text('Run ${run['id']}'),
|
|
Text('Pipeline ${detailPipeline(run)}'),
|
|
headerActions,
|
|
],
|
|
),
|
|
if (detailLoading) const _Notice('Refreshing run details…'),
|
|
if (error != null) _Notice(error),
|
|
if (prompt != null) ...[
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
'Original prompt',
|
|
style: theme.textTheme.titleMedium,
|
|
),
|
|
),
|
|
IconButton(
|
|
tooltip: 'Copy prompt',
|
|
onPressed: copying ? null : onCopy,
|
|
icon: const Icon(Icons.copy),
|
|
),
|
|
],
|
|
),
|
|
SelectableText(prompt),
|
|
if (copyStatus != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Semantics(liveRegion: true, child: Text(copyStatus)),
|
|
),
|
|
],
|
|
_fieldSection('Input', run['input'], 'No input recorded.'),
|
|
_fieldSection('Output', run['output'], 'No output recorded.'),
|
|
Text('Timeline', style: theme.textTheme.titleLarge),
|
|
if (visits.isEmpty)
|
|
const Text('No visits recorded.')
|
|
else
|
|
...visits.map(
|
|
(visit) => ListTile(
|
|
leading: const Icon(Icons.circle_outlined),
|
|
title: Text(visit.title),
|
|
subtitle: Text(visit.subtitle),
|
|
),
|
|
),
|
|
ExpansionTile(
|
|
title: const Text('Metrics'),
|
|
children: [
|
|
if (metrics.isEmpty)
|
|
const Padding(
|
|
padding: EdgeInsets.all(16),
|
|
child: Text('No reported usage.'),
|
|
)
|
|
else
|
|
...metrics.map(
|
|
(metric) => ListTile(
|
|
title: Text(metric.label),
|
|
subtitle: Text(metric.value),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _fieldSection(String title, dynamic value, String empty) {
|
|
final text = detailEmpty(value) ? empty : detailJson(value);
|
|
return ExpansionTile(
|
|
title: Text(title),
|
|
children: [
|
|
Padding(padding: const EdgeInsets.all(16), child: SelectableText(text)),
|
|
],
|
|
);
|
|
}
|
|
|
|
class _Notice extends StatelessWidget {
|
|
const _Notice(this.text);
|
|
final String text;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
child: Semantics(liveRegion: true, child: Text(text)),
|
|
);
|
|
}
|