diff --git a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart index 2c65c062..e951bd65 100644 --- a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart +++ b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart @@ -1,3 +1,4 @@ +import '../../../../ui/layout/section_heading.dart'; import 'package:flutter/cupertino.dart'; import '../../../../core/api_gateway.dart'; @@ -61,10 +62,14 @@ class CupertinoSessionList extends StatelessWidget { return [ for (final group in groups) CupertinoListSection.insetGrouped( - header: Text( - groups.length > 1 - ? '${section.title} · ${group.directory.isEmpty ? 'No directory' : group.directory}' - : section.title, + // Styled as a section divider, not as another chat row. + header: Builder( + builder: (context) => Text( + groups.length > 1 + ? '${section.title} · ${group.directory.isEmpty ? 'No directory' : group.directory}' + : section.title, + style: SectionHeadingStyle.of(context).title, + ), ), children: [for (final session in group.sessions) ..._row(session)], ), diff --git a/app/lib/features/chat/ui/sessions/session_list_material.dart b/app/lib/features/chat/ui/sessions/session_list_material.dart index c0140999..72241529 100644 --- a/app/lib/features/chat/ui/sessions/session_list_material.dart +++ b/app/lib/features/chat/ui/sessions/session_list_material.dart @@ -1,3 +1,4 @@ +import '../../../../ui/layout/section_heading.dart'; import 'package:flutter/material.dart'; import '../../../../core/api_gateway.dart'; @@ -44,7 +45,7 @@ class MaterialSessionList extends StatelessWidget { Widget build(BuildContext context) { return ListView( children: [ - for (final section in sections) _section(section), + for (final section in sections) _section(context, section), if (emptyMessage != null) ListTile( title: Text(emptyMessage!), @@ -59,10 +60,16 @@ class MaterialSessionList extends StatelessWidget { ); } - Widget _section(ChatSessionSection section) { + Widget _section(BuildContext context, ChatSessionSection section) { final groups = groupChatSessions(section.sessions); + final heading = SectionHeadingStyle.of(context); return ExpansionTile( - title: Text(section.title), + // Styled as a section divider, not as another chat row. + title: Text(section.title, style: heading.title), + backgroundColor: heading.background.withValues(alpha: 0.35), + collapsedBackgroundColor: heading.background, + shape: Border(left: BorderSide(color: heading.accent, width: 3)), + collapsedShape: Border(left: BorderSide(color: heading.accent, width: 3)), initiallyExpanded: true, children: [ for (final group in groups) ...[ @@ -72,6 +79,7 @@ class MaterialSessionList extends StatelessWidget { leading: const Icon(Icons.folder_outlined), title: Text( group.directory.isEmpty ? 'No directory' : group.directory, + style: heading.title.copyWith(fontWeight: FontWeight.w600), ), ), // Material's native list separator between rows in a group, the diff --git a/app/lib/features/graph/widgets/stage_definition_view.dart b/app/lib/features/graph/widgets/stage_definition_view.dart index 7a7b6a88..e962c7e6 100644 --- a/app/lib/features/graph/widgets/stage_definition_view.dart +++ b/app/lib/features/graph/widgets/stage_definition_view.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/text/markdown_source_view.dart'; +import '../../chat/ui/transcript/chat_markdown_view.dart'; import '../../../core/api_gateway.dart'; import '../../../ui/adaptive/host.dart'; import '../domain/graph_protocol.dart'; @@ -32,7 +33,7 @@ const String rawStageDefinitionTitle = 'Raw stage definition'; /// fetched and no run visit is read, so the pane cannot imply that the stage /// executed. Unknown stage declarations get an explicit missing state; every /// declared stage also keeps its exact JSON below the structured fields. -class StageDefinitionView extends StatelessWidget { +class StageDefinitionView extends StatefulWidget { const StageDefinitionView({ super.key, required this.graph, @@ -48,11 +49,21 @@ class StageDefinitionView extends StatelessWidget { final String pipelineName; final int version; + @override + State createState() => _StageDefinitionViewState(); +} + +class _StageDefinitionViewState extends State { + // One switch for every authored text block; raw is the exact text. + bool _raw = true; + String get _identity => - '${pipelineName.isEmpty ? 'Pipeline' : pipelineName} \u00b7 v$version'; + '${widget.pipelineName.isEmpty ? 'Pipeline' : widget.pipelineName} \u00b7 v${widget.version}'; @override Widget build(BuildContext context) { + final graph = widget.graph; + final stageKey = widget.stageKey; final style = _StageDefinitionStyle.of(context); final stage = stageDefinitionFor(graph, stageKey); final terminal = isTerminalTarget(stageKey); @@ -67,6 +78,13 @@ class StageDefinitionView extends StatelessWidget { children: [ Text(_identity, style: style.muted), const SizedBox(height: 16), + if (fields.any((field) => field.block)) ...[ + MarkdownModeSwitch( + raw: _raw, + onChanged: (raw) => setState(() => _raw = raw), + ), + const SizedBox(height: 16), + ], if (stage == null && !terminal) Text(unknownStageDefinition, style: style.value) else ...[ @@ -75,7 +93,7 @@ class StageDefinitionView extends StatelessWidget { const SizedBox(height: 16), ], for (final field in fields) - _StageDefinitionFieldView(field: field, style: style), + _StageDefinitionFieldView(field: field, style: style, raw: _raw), if (terminal && fields.isEmpty) Text(noStageDefinitionDetails, style: style.muted), if (stage != null) ...[ @@ -140,10 +158,15 @@ Future openStageDefinition( /// One labelled field: a compact row for scalars, a selectable block when the /// value is multi-line authored text. class _StageDefinitionFieldView extends StatelessWidget { - const _StageDefinitionFieldView({required this.field, required this.style}); + const _StageDefinitionFieldView({ + required this.field, + required this.style, + required this.raw, + }); final StageDefinitionField field; final _StageDefinitionStyle style; + final bool raw; @override Widget build(BuildContext context) { @@ -155,14 +178,10 @@ class _StageDefinitionFieldView extends StatelessWidget { Text(field.label, style: style.label), const SizedBox(height: 4), // An authored text block (a prompt) is markdown: rendered or raw. - if (field.block) - MarkdownSourceView( - text: field.value, - raw: _SelectableDefinitionText( - value: field.value, - style: style.value, - ), - ) + if (field.block && raw) + _SelectableDefinitionText(value: field.value, style: style.value) + else if (field.block) + ChatMarkdownView(text: field.value) else Text(field.value, style: style.value), ], diff --git a/app/lib/features/schedules/ui/pipeline/schedule_pipeline_row.dart b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_row.dart index 8d6ae20a..cc7d18ee 100644 --- a/app/lib/features/schedules/ui/pipeline/schedule_pipeline_row.dart +++ b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_row.dart @@ -1,5 +1,8 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../../ui/adaptive/host.dart'; + import '../../domain/saved_schedule.dart'; import '../list/schedule_list_format.dart'; import 'schedule_pipeline_styles.dart'; @@ -28,46 +31,59 @@ class SchedulePipelineRow extends StatelessWidget { @override Widget build(BuildContext context) { final id = schedule.id; + final body = schedulePipelineBodyStyle(context); + final title = body?.copyWith(fontWeight: FontWeight.w700); return Padding( key: scheduleRowKey(id), - padding: const EdgeInsets.fromLTRB(16, 12, 16, 12), + padding: const EdgeInsets.fromLTRB(16, 12, 16, 8), child: Semantics( container: true, child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ + // The name, bold, with its state as a coloured pill. Row( - crossAxisAlignment: CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( - child: Text( - scheduleDisplayName(schedule), - style: schedulePipelineBodyStyle(context), - ), + child: Text(scheduleDisplayName(schedule), style: title), ), const SizedBox(width: 8), - Text( - scheduleStatusLabel(schedule), - style: schedulePipelineStatusStyle(context, schedule.enabled), + _StatusPill(enabled: schedule.enabled), + ], + ), + const SizedBox(height: 8), + // Labelled facts several to a line: when, which version, next. + Wrap( + spacing: 16, + runSpacing: 6, + children: [ + _Fact( + icon: Icons.schedule, + cupertinoIcon: CupertinoIcons.clock, + label: 'When', + value: scheduleRuleSummary(schedule), + ), + _Fact( + icon: Icons.push_pin_outlined, + cupertinoIcon: CupertinoIcons.pin, + label: 'Version', + value: schedulePinnedVersionValue(schedule), + ), + _Fact( + icon: Icons.event_outlined, + cupertinoIcon: CupertinoIcons.calendar, + label: 'Next', + value: scheduleNextDueValue(schedule), ), ], ), - const SizedBox(height: 4), - Text( - 'Pinned ${schedulePinnedVersionValue(schedule)} · ' - '${scheduleRuleSummary(schedule)}', - style: schedulePipelineMutedStyle(context), - ), if (schedule.prompt.isNotEmpty) ...[ - const SizedBox(height: 4), - Text(schedule.prompt, style: schedulePipelineBodyStyle(context)), + const SizedBox(height: 8), + // The prompt it sends, as a quote under the facts. + _Quote(text: schedule.prompt, style: body), ], const SizedBox(height: 4), - Text( - '$scheduleNextPrefix${scheduleNextDueValue(schedule)}', - style: schedulePipelineMutedStyle(context), - ), - const SizedBox(height: 4), Wrap( spacing: 8, runSpacing: 4, @@ -112,3 +128,98 @@ class SchedulePipelineRow extends StatelessWidget { ); } } + +/// Enabled (green) or Paused (grey). +class _StatusPill extends StatelessWidget { + const _StatusPill({required this.enabled}); + + final bool enabled; + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoHost(context); + final color = enabled + ? (cupertino + ? CupertinoColors.systemGreen.resolveFrom(context) + : Colors.green.shade700) + : (cupertino + ? CupertinoColors.secondaryLabel.resolveFrom(context) + : Theme.of(context).colorScheme.onSurfaceVariant); + return DecoratedBox( + decoration: ShapeDecoration( + color: color.withValues(alpha: 0.14), + shape: const StadiumBorder(), + ), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), + child: Text( + enabled ? 'Enabled' : 'Paused', + style: TextStyle( + color: color, + fontWeight: FontWeight.w700, + fontSize: 12, + ), + ), + ), + ); + } +} + +/// One labelled fact: an icon, a bold label and its value. +class _Fact extends StatelessWidget { + const _Fact({ + required this.icon, + required this.cupertinoIcon, + required this.label, + required this.value, + }); + + final IconData icon; + final IconData cupertinoIcon; + final String label; + final String value; + + @override + Widget build(BuildContext context) { + final muted = schedulePipelineMutedStyle(context); + final cupertino = usesCupertinoHost(context); + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(cupertino ? cupertinoIcon : icon, size: 16, color: muted?.color), + const SizedBox(width: 4), + Text('$label ', style: muted?.copyWith(fontWeight: FontWeight.w700)), + Flexible(child: Text(value, style: muted)), + ], + ); + } +} + +/// The schedule's prompt as a quote: a side bar and up to three lines. +class _Quote extends StatelessWidget { + const _Quote({required this.text, required this.style}); + + final String text; + final TextStyle? style; + + @override + Widget build(BuildContext context) { + final line = usesCupertinoHost(context) + ? CupertinoColors.separator.resolveFrom(context) + : Theme.of(context).colorScheme.outlineVariant; + return DecoratedBox( + decoration: BoxDecoration( + border: Border(left: BorderSide(color: line, width: 3)), + ), + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 10), + child: Text( + text, + maxLines: 3, + overflow: TextOverflow.ellipsis, + style: style, + ), + ), + ); + } +} diff --git a/app/lib/ui/layout/section_heading.dart b/app/lib/ui/layout/section_heading.dart new file mode 100644 index 00000000..87c855c6 --- /dev/null +++ b/app/lib/ui/layout/section_heading.dart @@ -0,0 +1,101 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../adaptive/host.dart'; + +/// The look every section title shares, so it reads as a divider and not as +/// another row: a tinted strip with an accent bar, a bold title and a hairline +/// underneath. +class SectionHeadingStyle { + const SectionHeadingStyle({ + required this.background, + required this.accent, + required this.title, + required this.line, + }); + + final Color background; + final Color accent; + final TextStyle title; + final Color line; + + static SectionHeadingStyle of(BuildContext context) { + if (usesCupertinoHost(context)) { + final base = CupertinoTheme.of(context).textTheme.textStyle; + return SectionHeadingStyle( + background: CupertinoColors.secondarySystemGroupedBackground + .resolveFrom(context), + accent: CupertinoTheme.of(context).primaryColor, + title: base.copyWith( + fontWeight: FontWeight.w700, + color: CupertinoColors.label.resolveFrom(context), + ), + line: CupertinoColors.separator.resolveFrom(context), + ); + } + final scheme = Theme.of(context).colorScheme; + return SectionHeadingStyle( + background: scheme.surfaceContainerHigh, + accent: scheme.primary, + title: (Theme.of(context).textTheme.titleSmall ?? const TextStyle()) + .copyWith(fontWeight: FontWeight.w700, color: scheme.onSurface), + line: scheme.outlineVariant, + ); + } +} + +/// A section title strip: [title], then any [trailing] controls. +class SectionHeading extends StatelessWidget { + const SectionHeading({ + super.key, + required this.title, + this.leading, + this.trailing = const [], + this.titleColor, + this.padding = const EdgeInsetsDirectional.only(start: 12, end: 8), + this.minHeight = 40, + }); + + final String title; + final Widget? leading; + final List trailing; + final Color? titleColor; + final EdgeInsetsGeometry padding; + final double minHeight; + + @override + Widget build(BuildContext context) { + final style = SectionHeadingStyle.of(context); + return DecoratedBox( + decoration: BoxDecoration( + color: style.background, + border: Border( + left: BorderSide(color: style.accent, width: 3), + bottom: BorderSide(color: style.line, width: 0.5), + ), + ), + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: minHeight), + child: Padding( + padding: padding, + child: Row( + children: [ + if (leading != null) ...[leading!, const SizedBox(width: 8)], + Expanded( + child: Text( + title, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: titleColor == null + ? style.title + : style.title.copyWith(color: titleColor), + ), + ), + ...trailing, + ], + ), + ), + ), + ); + } +} diff --git a/app/lib/ui/layout/sticky_section.dart b/app/lib/ui/layout/sticky_section.dart index b1de4dba..f5d58761 100644 --- a/app/lib/ui/layout/sticky_section.dart +++ b/app/lib/ui/layout/sticky_section.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import '../adaptive/host.dart'; import '../motion/motion.dart'; +import 'section_heading.dart'; /// A collapsible section for a [CustomScrollView]: its title stays pinned at /// the top while its content scrolls under it, so it can always be closed @@ -87,24 +88,24 @@ class StickySectionTitle extends StatelessWidget { @override Widget build(BuildContext context) { final cupertino = usesCupertinoHost(context); - final background = cupertino - ? CupertinoColors.systemGroupedBackground.resolveFrom(context) - : Theme.of(context).colorScheme.surface; + // The shared section-title look: it reads as a divider, not a row. + final heading = SectionHeadingStyle.of(context); final muted = cupertino ? CupertinoColors.secondaryLabel.resolveFrom(context) : Theme.of(context).colorScheme.onSurfaceVariant; - final style = TextStyle( - fontWeight: FontWeight.w600, - color: - color ?? - (cupertino - ? CupertinoColors.label.resolveFrom(context) - : Theme.of(context).colorScheme.onSurface), - ); - return ColoredBox( - color: background, + final style = color == null + ? heading.title + : heading.title.copyWith(color: color); + return DecoratedBox( + decoration: BoxDecoration( + color: heading.background, + border: Border( + left: BorderSide(color: heading.accent, width: 3), + bottom: BorderSide(color: heading.line, width: 0.5), + ), + ), child: Padding( - padding: const EdgeInsetsDirectional.only(start: 16, end: 8), + padding: const EdgeInsetsDirectional.only(start: 13, end: 8), child: Row( children: [ Expanded( diff --git a/app/lib/ui/text/markdown_source_view.dart b/app/lib/ui/text/markdown_source_view.dart index 5ea05a0c..2b124f61 100644 --- a/app/lib/ui/text/markdown_source_view.dart +++ b/app/lib/ui/text/markdown_source_view.dart @@ -14,7 +14,6 @@ class MarkdownSourceView extends StatefulWidget { /// The exact text as the screen already showed it. final Widget raw; - @override State createState() => _MarkdownSourceViewState(); } @@ -25,14 +24,39 @@ class _MarkdownSourceViewState extends State { void _set(bool raw) => setState(() => _raw = raw); + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + MarkdownModeSwitch(raw: _raw, onChanged: _set), + const SizedBox(height: 8), + if (_raw) widget.raw else ChatMarkdownView(text: widget.text), + ], + ); + } +} + +/// The Rendered | Raw switch for markdown text; one switch can govern a +/// whole page of fields. +class MarkdownModeSwitch extends StatelessWidget { + const MarkdownModeSwitch({ + super.key, + required this.raw, + required this.onChanged, + }); + + final bool raw; + final ValueChanged onChanged; + @override Widget build(BuildContext context) { final cupertino = usesCupertinoHost(context); - final control = cupertino + return cupertino ? CupertinoSlidingSegmentedControl( key: const Key('markdown-source-mode'), - groupValue: _raw, - onValueChanged: (raw) => _set(raw ?? false), + groupValue: raw, + onValueChanged: (value) => onChanged(value ?? false), children: const {false: Text('Rendered'), true: Text('Raw')}, ) : SegmentedButton( @@ -42,16 +66,8 @@ class _MarkdownSourceViewState extends State { ButtonSegment(value: false, label: Text('Rendered')), ButtonSegment(value: true, label: Text('Raw')), ], - selected: {_raw}, - onSelectionChanged: (value) => _set(value.single), + selected: {raw}, + onSelectionChanged: (value) => onChanged(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 c13293da..d3742485 100644 --- a/app/test/features/graph/widgets/stage_definition_view_test.dart +++ b/app/test/features/graph/widgets/stage_definition_view_test.dart @@ -282,6 +282,23 @@ void main() { expect(outcomes.strutStyle, raw.strutStyle); }); + testWidgets('one Rendered/Raw switch governs the whole definition', ( + tester, + ) async { + await tester.pumpWidget(_material(_view())); + expect(find.byKey(const Key('markdown-source-mode')), findsOneWidget); + expect(_text('Plan the change.'), findsOneWidget); + await tester.tap(find.text('Rendered')); + await tester.pumpAndSettle(); + expect( + find + .byType(SelectableText) + .evaluate() + .map((e) => (e.widget as SelectableText).data), + isNot(contains('Plan the change.')), + ); + }); + test('field labels are the web words', () { expect(stageConfigLabel('budget_usd'), 'Budget (USD)'); expect(stageConfigLabel('budget_tokens'), 'Budget (tokens)'); diff --git a/app/test/features/pipelines/pipeline_summary_schedules_test.dart b/app/test/features/pipelines/pipeline_summary_schedules_test.dart index 027e2e11..d40b575c 100644 --- a/app/test/features/pipelines/pipeline_summary_schedules_test.dart +++ b/app/test/features/pipelines/pipeline_summary_schedules_test.dart @@ -61,7 +61,7 @@ void main() { expect(find.text('Schedules (1)'), findsOneWidget); expect(find.text('Research batteries'), findsOneWidget); expect( - find.text('Pinned v3 · Every 24h · mon, wed · Europe/London'), + find.text('Every 24h · mon, wed · Europe/London'), findsOneWidget, ); expect(find.byKey(scheduleAddKey), findsOneWidget); diff --git a/app/test/features/schedules/ui/pipeline/schedule_pipeline_section_test.dart b/app/test/features/schedules/ui/pipeline/schedule_pipeline_section_test.dart index fdf3ce8d..f22edb0b 100644 --- a/app/test/features/schedules/ui/pipeline/schedule_pipeline_section_test.dart +++ b/app/test/features/schedules/ui/pipeline/schedule_pipeline_section_test.dart @@ -47,18 +47,18 @@ void main() { expect(find.text('Schedules (2)'), findsOneWidget); expect(find.text('Research batteries'), findsOneWidget); expect( - find.text('Pinned v2 · Every 24h · mon, wed · Europe/London'), + find.text('Every 24h · mon, wed · Europe/London'), findsOneWidget, ); - expect(find.text('Next: Paused'), findsOneWidget); + expect(find.text('Paused'), findsWidgets); expect(find.text('Nightly report'), findsOneWidget); expect( - find.text('Pinned v5 · 10:00, 18:30 · Server timezone'), + find.text('10:00, 18:30 · Server timezone'), findsOneWidget, ); expect(find.text('Enabled'), findsOneWidget); - expect(find.text('Paused'), findsOneWidget); - expect(find.text('Next: Paused'), findsOneWidget); + expect(find.text('Paused'), findsWidgets); + expect(find.text('Paused'), findsWidgets); expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget); expect(find.byKey(scheduleRowToggleKey(9)), findsOneWidget); expect(gateway.calls.map((call) => call.type), ['list_schedules']); @@ -244,8 +244,8 @@ void main() { final call = gateway.callsOf('save_schedule').single; expect(call.fields.containsKey('request_key'), isFalse); expect(call.fields['schedule'], {...original, 'enabled': false}); - expect(find.text('Paused'), findsOneWidget); - expect(find.text('Next: Paused'), findsOneWidget); + expect(find.text('Paused'), findsWidgets); + expect(find.text('Paused'), findsWidgets); expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget); expect(find.text('Enable'), findsOneWidget); expect(gateway.calls.map((call) => call.type), [