diff --git a/app/lib/features/graph/widgets/stage_definition_view.dart b/app/lib/features/graph/widgets/stage_definition_view.dart index e86a31a1..7a7b6a88 100644 --- a/app/lib/features/graph/widgets/stage_definition_view.dart +++ b/app/lib/features/graph/widgets/stage_definition_view.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../ui/text/markdown_source_view.dart'; import '../../../core/api_gateway.dart'; import '../../../ui/adaptive/host.dart'; import '../domain/graph_protocol.dart'; @@ -153,8 +154,15 @@ class _StageDefinitionFieldView extends StatelessWidget { children: [ Text(field.label, style: style.label), const SizedBox(height: 4), + // An authored text block (a prompt) is markdown: rendered or raw. if (field.block) - _SelectableDefinitionText(value: field.value, style: style.value) + MarkdownSourceView( + text: field.value, + raw: _SelectableDefinitionText( + value: field.value, + style: style.value, + ), + ) else Text(field.value, style: style.value), ], diff --git a/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart b/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart index 34702135..471fc3ff 100644 --- a/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart +++ b/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart @@ -10,6 +10,7 @@ import '../pipeline_models.dart'; import '../pipelines_controller.dart'; import '../ui/run_pipeline_action.dart'; import 'pipeline_controls.dart'; +import '../../../ui/text/markdown_source_view.dart'; import 'pipeline_detail_styles.dart'; import 'pipeline_graph_tab.dart'; import 'pipeline_summary_view.dart'; @@ -395,7 +396,14 @@ class _PipelineDetailPanelState extends State { if (detail.source.isEmpty) Text('No source recorded.', style: pipelineMutedStyle(context)) else - SelectableText(detail.source, style: pipelineValueStyle(context)), + // The definition is markdown: rendered, or its raw text. + MarkdownSourceView( + text: detail.source, + raw: SelectableText( + detail.source, + style: pipelineValueStyle(context), + ), + ), ], ); } diff --git a/app/lib/ui/text/markdown_source_view.dart b/app/lib/ui/text/markdown_source_view.dart new file mode 100644 index 00000000..5ea05a0c --- /dev/null +++ b/app/lib/ui/text/markdown_source_view.dart @@ -0,0 +1,57 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../features/chat/ui/transcript/chat_markdown_view.dart'; +import '../adaptive/host.dart'; + +/// Authored markdown (a pipeline's source, a stage's prompt) shown rendered, +/// with a switch to the raw text. +class MarkdownSourceView extends StatefulWidget { + const MarkdownSourceView({super.key, required this.text, required this.raw}); + + final String text; + + /// The exact text as the screen already showed it. + final Widget raw; + + + @override + State createState() => _MarkdownSourceViewState(); +} + +class _MarkdownSourceViewState extends State { + // Raw first: the exact text the screen always showed. + bool _raw = true; + + void _set(bool raw) => setState(() => _raw = raw); + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoHost(context); + final control = cupertino + ? CupertinoSlidingSegmentedControl( + key: const Key('markdown-source-mode'), + groupValue: _raw, + onValueChanged: (raw) => _set(raw ?? false), + children: const {false: Text('Rendered'), true: Text('Raw')}, + ) + : SegmentedButton( + key: const Key('markdown-source-mode'), + showSelectedIcon: false, + segments: const [ + ButtonSegment(value: false, label: Text('Rendered')), + ButtonSegment(value: true, label: Text('Raw')), + ], + selected: {_raw}, + onSelectionChanged: (value) => _set(value.single), + ); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + control, + const SizedBox(height: 8), + if (_raw) widget.raw else ChatMarkdownView(text: widget.text), + ], + ); + } +} diff --git a/app/test/features/graph/widgets/stage_definition_view_test.dart b/app/test/features/graph/widgets/stage_definition_view_test.dart index d226e467..c13293da 100644 --- a/app/test/features/graph/widgets/stage_definition_view_test.dart +++ b/app/test/features/graph/widgets/stage_definition_view_test.dart @@ -84,6 +84,10 @@ void main() { testWidgets('the raw section keeps unknown fields exact and selectable', ( tester, ) async { + // Tall enough that the raw section below the prompt is built. + tester.view.physicalSize = const Size(800, 2000); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); await tester.pumpWidget(_material(_view())); expect(_text(rawStageDefinitionTitle), findsOneWidget); diff --git a/app/test/ui/text/markdown_source_view_test.dart b/app/test/ui/text/markdown_source_view_test.dart new file mode 100644 index 00000000..ce577363 --- /dev/null +++ b/app/test/ui/text/markdown_source_view_test.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart'; +import 'package:pipelines_app/ui/text/markdown_source_view.dart'; + +void main() { + testWidgets('markdown starts raw and switches to rendered and back', ( + tester, + ) async { + const source = '# stage Plan\n\nDraft the **plan**.'; + await tester.pumpWidget( + const MaterialApp( + home: Scaffold( + body: MarkdownSourceView( + text: source, + raw: SelectableText(source, key: Key('raw')), + ), + ), + ), + ); + expect(find.byKey(const Key('raw')), findsOneWidget); + expect(find.byType(ChatMarkdownView), findsNothing); + + await tester.tap(find.text('Rendered')); + await tester.pumpAndSettle(); + expect(find.byType(ChatMarkdownView), findsOneWidget); + expect(find.byKey(const Key('raw')), findsNothing); + + await tester.tap(find.text('Raw')); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('raw')), findsOneWidget); + }); +}