diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index edde7596..b8aa6b5a 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -1,7 +1,6 @@ import '../../shell/destination.dart'; import '../../shell/detail_page.dart'; import '../../shell/list_detail.dart'; -import '../../ui/adaptive/floating_bar_layout.dart'; import '../../ui/adaptive/host.dart'; import 'dart:async'; @@ -242,19 +241,17 @@ class _ChatScreenState extends State { ? const SizedBox.shrink() : _thread(selected, () => Navigator.of(context).maybePop()), ); - // The shell's body now reaches the top edge; until the session list pads - // itself by the bar (owned by the chat lane), it keeps starting below it. - final list = BelowTopBar( - child: ChatSessionsScreen( - gateway: widget.gateway, - embedded: true, - syncToken: widget.syncToken, - controller: _sessions, - onOpen: _open, - onSessions: _adoptRows, - activeSessionId: selected, - publishShellBar: true, - ), + // The session list pads its first row by the bar's height itself, so it + // scrolls behind the shell's floating bar like the other lists. + final list = ChatSessionsScreen( + gateway: widget.gateway, + embedded: true, + syncToken: widget.syncToken, + controller: _sessions, + onOpen: _open, + onSessions: _adoptRows, + activeSessionId: selected, + publishShellBar: true, ); if (!beside) return list; return ListDetailPanes( diff --git a/app/lib/features/chat/ui/sessions/session_actions.dart b/app/lib/features/chat/ui/sessions/session_actions.dart index 6db76281..3bec0fb4 100644 --- a/app/lib/features/chat/ui/sessions/session_actions.dart +++ b/app/lib/features/chat/ui/sessions/session_actions.dart @@ -5,6 +5,7 @@ import '../../../../core/api_gateway.dart'; import '../../domain/chat_sessions.dart'; import 'chat_adaptive.dart'; import 'session_row_style.dart'; +import '../../../../ui/layout/app_overflow_menu.dart'; enum SessionAction { star, rename, close, reopen, hide } @@ -29,54 +30,19 @@ class SessionActionsButton extends StatelessWidget { @override Widget build(BuildContext context) { - final label = sessionActionsLabel(session, duplicateTitles); - if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) { - // Its own node, so the row's merged label never swallows the button. - return Semantics( - container: true, - label: label, - button: true, - child: CupertinoButton( - padding: EdgeInsets.zero, - onPressed: () => _showSheet(context), - child: const Icon(CupertinoIcons.ellipsis), - ), - ); - } - return PopupMenuButton( - tooltip: label, - onSelected: onSelected, - itemBuilder: (context) => _menuItems(session), + return AppOverflowMenu( + cupertino: chatControlsStyleOf(context) == ChatControlsStyle.cupertino, + label: sessionActionsLabel(session, duplicateTitles), + sheetTitle: chatSessionTitle(session), + actions: [ + for (final item in _items(session)) + AppMenuAction(value: item.action, label: item.label), + ], + onSelected: (_, action) => onSelected(action), ); } - - Future _showSheet(BuildContext context) async { - final action = await showCupertinoModalPopup( - context: context, - builder: (sheetContext) => CupertinoActionSheet( - title: Text(chatSessionTitle(session)), - actions: [ - for (final item in _items(session)) - CupertinoActionSheetAction( - onPressed: () => Navigator.pop(sheetContext, item.action), - child: Text(item.label), - ), - ], - cancelButton: CupertinoActionSheetAction( - onPressed: () => Navigator.pop(sheetContext), - child: const Text('Cancel'), - ), - ), - ); - if (action != null && context.mounted) onSelected(action); - } } -List> _menuItems(JsonMap session) => [ - for (final item in _items(session)) - PopupMenuItem(value: item.action, child: Text(item.label)), -]; - List<({SessionAction action, String label})> _items(JsonMap session) { final isClosed = session['closed_at'] != null; return [ 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 85d78872..6f85e87e 100644 --- a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart +++ b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart @@ -1,5 +1,4 @@ import '../../../../ui/layout/collapsible_list_section.dart'; -import '../../../../ui/theme/app_theme.dart'; import 'package:flutter/cupertino.dart'; import '../../../../core/api_gateway.dart'; @@ -8,7 +7,6 @@ import 'chat_adaptive.dart'; import 'chat_sessions_body.dart'; import 'session_actions.dart'; import 'session_row_content.dart'; -import 'session_row_style.dart'; import '../../../../ui/adaptive/floating_bar_layout.dart'; class CupertinoSessionList extends StatelessWidget { @@ -76,43 +74,45 @@ class CupertinoSessionList extends StatelessWidget { count: section.sessions.length, initiallyOpen: section.title != 'Closed', children: [ - for (final group in groups) - CupertinoListSection.insetGrouped( - backgroundColor: AppColors.groupedBackground, - header: groups.length > 1 - ? Text( - group.directory.isEmpty - ? 'No directory' - : group.directory, - ) - : null, - children: [ - for (final session in group.sessions) ..._row(session), - ], - ), + for (final group in groups) ...[ + if (groups.length > 1) + _DirectoryHeader( + group.directory.isEmpty ? 'No directory' : group.directory, + ), + for (var i = 0; i < group.sessions.length; i++) + ..._row( + group.sessions[i], + divider: i < group.sessions.length - 1, + ), + ], ], ), ]; } - /// The tile plus its refusal. `CupertinoListTile` forces its subtitle to one - /// ellipsised line, so the server's words go in their own full-width row - /// inside the same native card. - List _row(JsonMap session) { + /// The row plus its refusal, the server's words in their own full-width + /// row under it. + List _row(JsonMap session, {required bool divider}) { final id = '${session['id'] ?? ''}'; final error = errorFor(id); return [ - _CupertinoSessionRow( + ChatSessionRow( session: session, selected: id == activeSessionId, duplicateTitles: duplicateTitles, unseen: isUnseen(session), + // A refusal below the row separates it instead. + divider: divider && error == null, onOpen: onOpen, - onRename: onRename, - onClose: onClose, - onReopen: onReopen, - onStar: onStar, - onHide: onHide, + onAction: (action) => _dispatch( + action, + session, + onStar: onStar, + onRename: onRename, + onClose: onClose, + onReopen: onReopen, + onHide: onHide, + ), ), if (error != null) ChatRowError( @@ -124,101 +124,50 @@ class CupertinoSessionList extends StatelessWidget { } } -class _CupertinoSessionRow extends StatelessWidget { - const _CupertinoSessionRow({ - required this.session, - required this.selected, - required this.duplicateTitles, - required this.unseen, - required this.onOpen, - required this.onRename, - required this.onClose, - required this.onReopen, - required this.onStar, - required this.onHide, - }); +/// Routes a row's menu choice to the list's callbacks. +void _dispatch( + SessionAction action, + JsonMap session, { + required ValueChanged onStar, + required ValueChanged onRename, + required ValueChanged onClose, + required ValueChanged onReopen, + required ValueChanged onHide, +}) { + switch (action) { + case SessionAction.star: + onStar(session); + case SessionAction.rename: + onRename(session); + case SessionAction.close: + onClose(session); + case SessionAction.reopen: + onReopen(session); + case SessionAction.hide: + onHide(session); + } +} - final JsonMap session; - final bool selected; - final Set duplicateTitles; - final bool unseen; - final ValueChanged onOpen; - final ValueChanged onRename; - final ValueChanged onClose; - final ValueChanged onReopen; - final ValueChanged onStar; - final ValueChanged onHide; +/// A directory's name above its chats, like a grouped table's header. +class _DirectoryHeader extends StatelessWidget { + const _DirectoryHeader(this.directory); + + final String directory; @override Widget build(BuildContext context) { - final id = '${session['id'] ?? ''}'; - final closed = chatSessionRowStatus(session, unseen: false) == 'Closed'; - // A contact-list row, the same pieces as the Material row. The grouped - // list owns the separators and the tile its native text styles; the - // leading slot is widened to hold the avatar. - // A narrow pane (a wide window's list beside its detail, or its opening - // animation) drops the avatar and tightens the tile's insets, so the - // menu stays reachable and the title keeps some width. - return LayoutBuilder( - builder: (context, constraints) { - final avatar = constraints.maxWidth >= _avatarMinWidth; - return Semantics( - selected: selected, - child: CupertinoListTile( - key: Key('chat-row-$id'), - backgroundColor: selected - ? CupertinoColors.tertiarySystemFill.resolveFrom(context) - : null, - padding: avatar - ? null - : const EdgeInsetsDirectional.only(start: 8, end: 4), - leadingSize: avatar ? 40 : 28, - leading: avatar - ? ChatSessionAvatar( - session: session, - running: session['running'] == true && !unseen, - selected: selected, - ) - : null, - title: ChatSessionTitleLine( - title: chatSessionTitle(session), - recency: relativeChatSessionTime(session['updated_at']), - unread: unseen && !closed, - starred: session['starred'] == true, - ), - subtitle: ChatSessionSubtitleLine( - text: chatSessionSubtitle(session), - unread: unseen && !closed, - closed: closed, - ), - trailing: SessionActionsButton( - key: Key('chat-actions-$id'), - session: session, - duplicateTitles: duplicateTitles, - onSelected: _select, - ), - onTap: () => onOpen(session), - ), - ); - }, + final style = CupertinoTheme.of(context).textTheme.textStyle.copyWith( + fontSize: 13, + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ); + return Padding( + padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 6), + child: Text( + directory, + style: style, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), ); } - - /// The tile width below which the row is compact: no avatar, tight insets. - static const double _avatarMinWidth = 240; - - void _select(SessionAction action) { - switch (action) { - case SessionAction.star: - onStar(session); - case SessionAction.rename: - onRename(session); - case SessionAction.close: - onClose(session); - case SessionAction.reopen: - onReopen(session); - case SessionAction.hide: - onHide(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 7bc71973..3a37c0d4 100644 --- a/app/lib/features/chat/ui/sessions/session_list_material.dart +++ b/app/lib/features/chat/ui/sessions/session_list_material.dart @@ -8,7 +8,6 @@ import 'chat_adaptive.dart'; import 'chat_sessions_body.dart'; import 'session_actions.dart'; import 'session_row_content.dart'; -import 'session_row_style.dart'; class MaterialSessionList extends StatelessWidget { const MaterialSessionList({ @@ -83,35 +82,38 @@ class MaterialSessionList extends StatelessWidget { style: heading.title.copyWith(fontWeight: FontWeight.w600), ), ), - // Material's native list separator between rows in a group, the - // counterpart of the inset group's hairline on Cupertino. The group - // header still owns the boundary between directories. - for (var i = 0; i < group.sessions.length; i++) ...[ - if (i > 0) const Divider(height: 1), - ..._row(group.sessions[i]), - ], + // Inset dividers between the rows of a group; the group header + // owns the boundary between directories. + for (var i = 0; i < group.sessions.length; i++) + ..._row(group.sessions[i], divider: i < group.sessions.length - 1), ], ], ); } - /// The tile plus its refusal at full width (a long sentence in `subtitle` + /// The row plus its refusal at full width (a long sentence in a subtitle /// made the row taller than the viewport at 320px with 2x text). - List _row(JsonMap session) { + List _row(JsonMap session, {required bool divider}) { final id = '${session['id'] ?? ''}'; final error = errorFor(id); return [ - _MaterialSessionRow( + ChatSessionRow( session: session, selected: id == activeSessionId, duplicateTitles: duplicateTitles, unseen: isUnseen(session), + // A refusal below the row separates it instead. + divider: divider && error == null, onOpen: onOpen, - onRename: onRename, - onClose: onClose, - onReopen: onReopen, - onStar: onStar, - onHide: onHide, + onAction: (action) => _dispatch( + action, + session, + onStar: onStar, + onRename: onRename, + onClose: onClose, + onReopen: onReopen, + onHide: onHide, + ), ), if (error != null) ChatRowError( @@ -123,99 +125,26 @@ class MaterialSessionList extends StatelessWidget { } } -class _MaterialSessionRow extends StatelessWidget { - const _MaterialSessionRow({ - required this.session, - required this.selected, - required this.duplicateTitles, - required this.unseen, - required this.onOpen, - required this.onRename, - required this.onClose, - required this.onReopen, - required this.onStar, - required this.onHide, - }); - - final JsonMap session; - final bool selected; - final Set duplicateTitles; - final bool unseen; - final ValueChanged onOpen; - final ValueChanged onRename; - final ValueChanged onClose; - final ValueChanged onReopen; - final ValueChanged onStar; - final ValueChanged onHide; - - @override - Widget build(BuildContext context) { - final id = '${session['id'] ?? ''}'; - final theme = Theme.of(context); - final closed = chatSessionRowStatus(session, unseen: false) == 'Closed'; - // A contact-list row, the same pieces as the Cupertino row: the harness - // avatar, the title with its time, one muted line, and the actions menu. - // ListTile asserts when its trailing control leaves the title no width. - // A narrow pane (a wide window's list beside its detail, or its opening - // animation) drops the avatar and tightens the tile's insets, so the - // menu stays reachable and the title keeps some width. - return LayoutBuilder( - builder: (context, constraints) { - final narrow = constraints.maxWidth < _avatarMinWidth; - return ListTile( - key: Key('chat-row-$id'), - selected: selected, - selectedTileColor: theme.colorScheme.secondaryContainer, - selectedColor: theme.colorScheme.onSecondaryContainer, - contentPadding: narrow - ? const EdgeInsetsDirectional.only(start: 8) - : null, - horizontalTitleGap: narrow ? 4 : null, - leading: narrow - ? null - : ChatSessionAvatar( - session: session, - running: session['running'] == true && !unseen, - selected: selected, - ), - title: ChatSessionTitleLine( - title: chatSessionTitle(session), - recency: relativeChatSessionTime(session['updated_at']), - unread: unseen && !closed, - starred: session['starred'] == true, - ), - subtitle: ChatSessionSubtitleLine( - text: chatSessionSubtitle(session), - unread: unseen && !closed, - closed: closed, - ), - trailing: SessionActionsButton( - key: Key('chat-actions-$id'), - session: session, - duplicateTitles: duplicateTitles, - onSelected: _select, - ), - onTap: () => onOpen(session), - ); - }, - ); - } - - /// The tile width below which the row is compact: no avatar, tight insets. - static const double _avatarMinWidth = 240; - - void _select(SessionAction action) { - switch (action) { - case SessionAction.star: - onStar(session); - case SessionAction.rename: - onRename(session); - case SessionAction.close: - onClose(session); - case SessionAction.reopen: - onReopen(session); - case SessionAction.hide: - onHide(session); - } +/// Routes a row's menu choice to the list's callbacks. +void _dispatch( + SessionAction action, + JsonMap session, { + required ValueChanged onStar, + required ValueChanged onRename, + required ValueChanged onClose, + required ValueChanged onReopen, + required ValueChanged onHide, +}) { + switch (action) { + case SessionAction.star: + onStar(session); + case SessionAction.rename: + onRename(session); + case SessionAction.close: + onClose(session); + case SessionAction.reopen: + onReopen(session); + case SessionAction.hide: + onHide(session); } } diff --git a/app/lib/features/chat/ui/sessions/session_row_content.dart b/app/lib/features/chat/ui/sessions/session_row_content.dart index d430842a..88e2a4e8 100644 --- a/app/lib/features/chat/ui/sessions/session_row_content.dart +++ b/app/lib/features/chat/ui/sessions/session_row_content.dart @@ -2,12 +2,134 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../../core/api_gateway.dart'; +import '../../../../ui/layout/app_list_avatar.dart'; +import '../../../../ui/layout/app_list_row.dart'; +import '../../domain/chat_sessions.dart'; import 'chat_adaptive.dart'; +import 'session_actions.dart'; import 'session_harness_icon.dart'; +import 'session_row_style.dart'; -/// Row pieces shared by the Material and Cupertino chat lists. Each list puts -/// them in its native tile's slots: the avatar leads, the title line and the -/// subtitle line fill the text column, and the actions menu trails. +/// One chat in the list, in the app's shared row on both hosts: the harness +/// avatar, the title with its recency, one muted line, and the actions menu. +/// +/// An unread chat is emphasised (heavier title, accent time) with an accent +/// dot ending its line; a starred chat shows a small star after its title; a +/// running chat carries an activity badge on its avatar. A narrow pane drops +/// the avatar and time but keeps the menu, the list's only way to its actions. +class ChatSessionRow extends StatelessWidget { + const ChatSessionRow({ + super.key, + required this.session, + required this.onOpen, + required this.onAction, + this.selected = false, + this.unseen = false, + this.divider = true, + this.duplicateTitles = const {}, + }); + + final JsonMap session; + final ValueChanged onOpen; + final ValueChanged onAction; + final bool selected; + final bool unseen; + final bool divider; + final Set duplicateTitles; + + @override + Widget build(BuildContext context) { + final id = '${session['id'] ?? ''}'; + final cupertino = + chatControlsStyleOf(context) == ChatControlsStyle.cupertino; + final closed = chatSessionRowStatus(session, unseen: false) == 'Closed'; + final unread = unseen && !closed; + final accent = cupertino + ? CupertinoTheme.of(context).primaryColor + : Theme.of(context).colorScheme.primary; + final text = chatSessionSubtitle(session); + return AppListRow( + key: Key('chat-row-$id'), + cupertino: cupertino, + selected: selected, + emphasized: unread, + divider: divider, + keepMenuWhenCompact: true, + onTap: () => onOpen(session), + leading: ChatSessionAvatar( + session: session, + running: session['running'] == true && !unseen, + selected: selected, + ), + // The star rides in the title's own text, so a narrow row ellipsises + // them together. + title: Text.rich( + TextSpan( + text: chatSessionTitle(session), + children: [ + if (session['starred'] == true) + WidgetSpan( + alignment: PlaceholderAlignment.middle, + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 4), + child: _Star(cupertino: cupertino, color: accent), + ), + ), + ], + ), + ), + time: relativeChatSessionTime(session['updated_at']), + // `Closed` leads the line of a closed chat, then the model and folder. + subtitle: Text.rich( + TextSpan( + children: [ + if (closed) + const TextSpan( + text: 'Closed', + style: TextStyle(fontWeight: FontWeight.w600), + ), + if (closed && text.isNotEmpty) const TextSpan(text: ' · '), + TextSpan(text: text), + ], + ), + ), + subtitleTrailing: unread + ? AppListStatusDot( + key: const Key('chat-row-unread'), + color: accent, + semanticLabel: 'New', + size: 10, + ) + : null, + menu: SessionActionsButton( + key: Key('chat-actions-$id'), + session: session, + duplicateTitles: duplicateTitles, + onSelected: onAction, + ), + ); + } +} + +/// As tall as the title's text, so it follows text scaling. +class _Star extends StatelessWidget { + const _Star({required this.cupertino, required this.color}); + + final bool cupertino; + final Color color; + + @override + Widget build(BuildContext context) { + final size = DefaultTextStyle.of(context).style.fontSize ?? 14; + return Icon( + cupertino ? CupertinoIcons.star_fill : Icons.star, + key: const Key('chat-row-starred'), + size: MediaQuery.textScalerOf(context).scale(size), + color: color, + semanticLabel: 'Starred', + ); + } +} /// The chat's harness mark in a filled circle, like a contact avatar. A /// running chat carries a small activity badge on the avatar's corner instead @@ -43,26 +165,18 @@ class ChatSessionAvatar extends StatelessWidget { : scheme.surfaceContainerHighest; mark = selected ? scheme.onPrimaryContainer : scheme.onSurfaceVariant; } - final avatar = CircleAvatar( - backgroundColor: fill, + return AppListAvatar( + foreground: mark, + background: fill, + badge: running + ? Semantics( + key: const Key('chat-row-working'), + label: 'Chat is working', + child: _WorkingBadge(cupertino: cupertino), + ) + : null, child: SessionHarnessIcon(session: session, color: mark), ); - if (!running) return avatar; - return Stack( - clipBehavior: Clip.none, - children: [ - avatar, - PositionedDirectional( - end: -2, - bottom: -2, - child: Semantics( - key: const Key('chat-row-working'), - label: 'Chat is working', - child: _WorkingBadge(cupertino: cupertino), - ), - ), - ], - ); } } @@ -90,152 +204,3 @@ class _WorkingBadge extends StatelessWidget { ); } } - -/// The title with its recency at the trailing edge. An unread chat's title is -/// bold and its time takes the accent, so it stands out at a glance; a starred -/// chat shows a small star after its title. -class ChatSessionTitleLine extends StatelessWidget { - const ChatSessionTitleLine({ - super.key, - required this.title, - required this.recency, - this.unread = false, - this.starred = false, - }); - - final String title; - final String recency; - final bool unread; - final bool starred; - - @override - Widget build(BuildContext context) { - final cupertino = - chatControlsStyleOf(context) == ChatControlsStyle.cupertino; - final accent = cupertino - ? CupertinoTheme.of(context).primaryColor - : Theme.of(context).colorScheme.primary; - final secondary = cupertino - ? CupertinoColors.secondaryLabel.resolveFrom(context) - : Theme.of(context).colorScheme.onSurfaceVariant; - final timeStyle = - (cupertino - ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle - : Theme.of(context).textTheme.bodySmall) - ?.copyWith( - color: unread ? accent : secondary, - fontWeight: unread ? FontWeight.w600 : null, - ); - final star = Icon( - cupertino ? CupertinoIcons.star_fill : Icons.star, - key: const Key('chat-row-starred'), - // As tall as the title's text, so it follows text scaling. - size: DefaultTextStyle.of(context).style.fontSize, - color: accent, - semanticLabel: 'Starred', - ); - // The star rides in the title's own text, so a narrow row ellipsises - // them together; the time keeps at most about half the line. - return LayoutBuilder( - builder: (context, constraints) => Row( - children: [ - Expanded( - child: Text.rich( - TextSpan( - text: title, - children: [ - if (starred) - WidgetSpan( - alignment: PlaceholderAlignment.middle, - child: Padding( - padding: const EdgeInsetsDirectional.only(start: 4), - child: star, - ), - ), - ], - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontWeight: unread ? FontWeight.w700 : FontWeight.w500, - ), - ), - ), - if (recency.isNotEmpty) - ConstrainedBox( - constraints: BoxConstraints(maxWidth: constraints.maxWidth / 2), - child: Padding( - padding: const EdgeInsetsDirectional.only(start: 8), - child: Text( - recency, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: timeStyle, - ), - ), - ), - ], - ), - ); - } -} - -/// One muted line: `Closed` first when the chat is closed, then the model and -/// folder, with an accent dot at the end while the chat has unread content. -class ChatSessionSubtitleLine extends StatelessWidget { - const ChatSessionSubtitleLine({ - super.key, - required this.text, - this.unread = false, - this.closed = false, - }); - - final String text; - final bool unread; - final bool closed; - - @override - Widget build(BuildContext context) { - final cupertino = - chatControlsStyleOf(context) == ChatControlsStyle.cupertino; - final accent = cupertino - ? CupertinoTheme.of(context).primaryColor - : Theme.of(context).colorScheme.primary; - return Row( - children: [ - Expanded( - child: Text.rich( - TextSpan( - children: [ - if (closed) - const TextSpan( - text: 'Closed', - style: TextStyle(fontWeight: FontWeight.w600), - ), - if (closed && text.isNotEmpty) const TextSpan(text: ' · '), - TextSpan(text: text), - ], - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - if (unread) - Padding( - padding: const EdgeInsetsDirectional.only(start: 8), - child: Semantics( - key: const Key('chat-row-unread'), - label: 'New', - child: DecoratedBox( - decoration: BoxDecoration( - color: accent, - shape: BoxShape.circle, - ), - child: const SizedBox.square(dimension: 10), - ), - ), - ), - ], - ); - } -} diff --git a/app/lib/features/pipelines/widgets/pipeline_list_panel.dart b/app/lib/features/pipelines/widgets/pipeline_list_panel.dart index 4c0d1087..e234bcb9 100644 --- a/app/lib/features/pipelines/widgets/pipeline_list_panel.dart +++ b/app/lib/features/pipelines/widgets/pipeline_list_panel.dart @@ -1,4 +1,5 @@ -import '../../../ui/theme/app_theme.dart'; +import '../../../ui/layout/app_list_avatar.dart'; +import '../../../ui/layout/app_list_row.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -138,21 +139,9 @@ class PipelineListPanel extends StatelessWidget { if (empty == null) return _withoutRows(header, const SizedBox.shrink()); return _withoutRows(header, _empty(context, empty)); } - // A list pane beside a detail can be very narrow (a 640px window leaves - // it ~130px): there the rows drop the identity icon and chevron so the - // name keeps the width. - return LayoutBuilder( - builder: (context, constraints) { - final compact = constraints.maxWidth < _compactRowWidth; - return useCupertinoControls(context) - ? _cupertinoList(context, header, items, compact: compact) - : _materialList(context, header, items, compact: compact); - }, - ); + return _list(context, header, items); } - static const double _compactRowWidth = 220; - Widget _centered(BuildContext context, List messages) { return Center( child: Padding( @@ -195,213 +184,69 @@ class PipelineListPanel extends StatelessWidget { ); } - Widget _materialList( + /// The rows in the app's shared list row. A list pane beside a detail can + /// be very narrow (a 640px window leaves it ~130px): there a row drops its + /// avatar and time so the name keeps the width. + Widget _list( BuildContext context, List header, - List items, { - required bool compact, - }) { + List items, + ) { final now = DateTime.now(); + final cupertino = useCupertinoControls(context); // The default padding is the media padding: the controls start below the // top bar and the last row clears the floating tab bar. - return ListView.separated( + return ListView.builder( key: const Key('pipeline-list'), itemCount: header.length + items.length, - separatorBuilder: (context, index) => index < header.length - ? const SizedBox.shrink() - : const Divider(height: 1), itemBuilder: (context, index) { if (index < header.length) return header[index]; final pipeline = items[index - header.length]; - return ListTile( + final run = controller.runsLoaded + ? controller.latestRuns[pipeline.id] + : null; + final badge = run == null ? null : runBadge(run, now); + return AppListRow( key: Key('pipeline-row-${pipeline.id}'), + cupertino: cupertino, selected: controller.selectedId == pipeline.id, - selectedTileColor: Theme.of(context).colorScheme.secondaryContainer, - selectedColor: Theme.of(context).colorScheme.onSecondaryContainer, + divider: index < header.length + items.length - 1, onTap: () => controller.openPipeline(pipeline.id, version: pipeline.version), - contentPadding: const EdgeInsets.symmetric( - horizontal: kPipelineListInset, - ), - visualDensity: VisualDensity.compact, - leading: compact ? null : _pipelineIdentityIcon(context, pipeline), - title: _rowTitle(context, pipeline, now: now, compact: compact), - subtitle: _rowMetadata(context, pipeline, now, compact: compact), - trailing: compact ? null : const Icon(Icons.chevron_right), + leading: _pipelineIdentityIcon(context, pipeline, cupertino), + title: Text(pipeline.displayName), + time: badge?.ranAgo, + subtitleLeading: badge == null + ? null + : AppListStatusDot( + key: Key('pipeline-status-${pipeline.id}'), + color: runStatusColor(badge.state).resolveFrom(context), + semanticLabel: runStateLabel(badge.state), + ), + subtitle: Text(_rowMetadata(pipeline)), + // A narrow pane keeps the latest state, the useful decision signal; + // stage counts, schedules and version live in the detail instead. + // Do not turn an in-flight or failed run-history read into a false + // no-runs claim: the line stays blank until history is known. + compactSubtitle: badge == null + ? const SizedBox.shrink() + : Text(runStateLabel(badge.state)), ); }, ); } - Widget _cupertinoList( - BuildContext context, - List header, - List items, { - required bool compact, - }) { - final now = DateTime.now(); - return ListView( - key: const Key('pipeline-list'), - children: [ - ...header, - CupertinoListSection.insetGrouped( - backgroundColor: AppColors.groupedBackground, - children: [ - for (final pipeline in items) - Semantics( - selected: controller.selectedId == pipeline.id, - child: CupertinoListTile( - key: Key('pipeline-row-${pipeline.id}'), - backgroundColor: controller.selectedId == pipeline.id - ? CupertinoColors.tertiarySystemFill.resolveFrom(context) - : null, - leading: compact - ? null - : _pipelineIdentityIcon(context, pipeline), - title: _rowTitle( - context, - pipeline, - now: now, - compact: compact, - ), - subtitle: _rowMetadata( - context, - pipeline, - now, - compact: compact, - ), - trailing: compact ? null : const CupertinoListTileChevron(), - onTap: () => controller.openPipeline( - pipeline.id, - version: pipeline.version, - ), - ), - ), - ], - ), - ], - ); - } - - /// The row's title line: its name and, when known, its latest run's age. - /// A narrow split pane keeps the name alone; the detail preserves identity. - Widget _rowTitle( - BuildContext context, - PipelineSummary pipeline, { - required DateTime now, - required bool compact, - }) { - final muted = _mutedStyle(context); - if (compact) { - return Text( - pipeline.displayName, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: const TextStyle(fontWeight: FontWeight.w600), - ); - } - final run = controller.runsLoaded - ? controller.latestRuns[pipeline.id] - : null; - final ranAgo = run == null ? null : runBadge(run, now).ranAgo; - return Row( - children: [ - Expanded( - child: Text( - pipeline.displayName, - maxLines: 1, - overflow: TextOverflow.ellipsis, - // Weight only: the native tile owns size and the selected colour. - style: const TextStyle(fontWeight: FontWeight.w600), - ), - ), - if (ranAgo != null) ...[ - const SizedBox(width: 8), - Text(ranAgo, style: muted, maxLines: 1), - ], - ], - ); - } - - /// The row's one muted subtitle: latest-run state, stage count, and schedules. - Widget _rowMetadata( - BuildContext context, - PipelineSummary pipeline, - DateTime now, { - required bool compact, - }) { - final style = _mutedStyle(context); + /// The row's one muted subtitle: stage count and schedules. + String _rowMetadata(PipelineSummary pipeline) { final schedules = switch (pipeline.scheduleState) { PipelineScheduleState.scheduled => pipeline.scheduleLabel, PipelineScheduleState.unscheduled => '0 schedules', PipelineScheduleState.unclassified => '', }; - final what = [ + return [ pipelineStageSummary(pipeline), if (schedules.isNotEmpty) schedules, ].join(' · '); - final run = controller.runsLoaded - ? controller.latestRuns[pipeline.id] - : null; - final badge = run == null ? null : runBadge(run, now); - // A 640px window can leave this pane about 130px wide. At that size the - // latest state is the useful decision signal; stage counts, timestamps, - // graph cues and version live in the selected pipeline's detail instead. - if (compact) { - // Do not turn an in-flight or failed run-history read into a false - // no-runs claim. The normal row also stays blank until history is known. - if (badge == null) return const SizedBox.shrink(); - return Semantics( - label: runStateLabel(badge.state), - child: Row( - children: [ - RunStatusIcon( - state: badge.state, - label: runStateLabel(badge.state), - size: 14, - ), - const SizedBox(width: 4), - Expanded( - child: Text( - runStateLabel(badge.state), - style: style, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - ], - ), - ); - } - return Row( - children: [ - if (badge != null) ...[ - Semantics( - label: runStateLabel(badge.state), - child: ExcludeSemantics( - child: Container( - key: Key('pipeline-status-${pipeline.id}'), - width: 8, - height: 8, - decoration: BoxDecoration( - color: runStatusColor(badge.state).resolveFrom(context), - shape: BoxShape.circle, - ), - ), - ), - ), - const SizedBox(width: 6), - ], - Expanded( - child: Text( - what, - style: style, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - ], - ); } TextStyle? _mutedStyle(BuildContext context) { @@ -416,27 +261,31 @@ class PipelineListPanel extends StatelessWidget { ); } - Widget _pipelineIdentityIcon(BuildContext context, PipelineSummary pipeline) { - final scheme = Theme.of(context).colorScheme; - final colors = [scheme.primary, scheme.secondary, scheme.tertiary]; - final color = colors[pipeline.id.abs() % colors.length]; - final name = pipeline.displayName.trimLeft(); - final initial = name.isEmpty - ? '?' - : String.fromCharCode(name.runes.first).toUpperCase(); + /// The pipeline's initial on a tint picked from its id, so neighbouring + /// pipelines are told apart at a glance. + Widget _pipelineIdentityIcon( + BuildContext context, + PipelineSummary pipeline, + bool cupertino, + ) { + final List colors; + if (cupertino) { + colors = [ + CupertinoTheme.of(context).primaryColor, + CupertinoColors.systemIndigo.resolveFrom(context), + CupertinoColors.systemTeal.resolveFrom(context), + ]; + } else { + final scheme = Theme.of(context).colorScheme; + colors = [scheme.primary, scheme.secondary, scheme.tertiary]; + } return Semantics( label: 'Pipeline ${pipeline.displayName}', child: ExcludeSemantics( - child: Container( + child: AppListAvatar.initial( + pipeline.displayName, key: Key('pipeline-avatar-${pipeline.id}'), - width: 40, - height: 40, - alignment: Alignment.center, - decoration: BoxDecoration( - color: color.withValues(alpha: 0.14), - shape: BoxShape.circle, - ), - child: Text(initial, style: TextStyle(color: color)), + color: colors[pipeline.id.abs() % colors.length], ), ), ); diff --git a/app/lib/features/runs/ui/run_more_menu.dart b/app/lib/features/runs/ui/run_more_menu.dart index 00cffee8..43c80012 100644 --- a/app/lib/features/runs/ui/run_more_menu.dart +++ b/app/lib/features/runs/ui/run_more_menu.dart @@ -1,6 +1,7 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../ui/layout/app_overflow_menu.dart'; + import '../../../core/api_gateway.dart'; import '../../schedules/ui/run/schedule_run_action.dart'; import '../actions/retry_action.dart'; @@ -93,51 +94,14 @@ class _RunMoreMenuState extends State { @override Widget build(BuildContext context) { - final items = _items; - if (items.isEmpty) return const SizedBox.shrink(); - if (!widget.cupertino) { - return PopupMenuButton<_RunMoreItem>( - key: widget.menuKey, - icon: const Icon(Icons.more_vert), - tooltip: 'More actions', - onSelected: (item) => _pick(context, item), - itemBuilder: (_) => [ - for (final (item, label) in items) - PopupMenuItem(key: _keyOf(item), value: item, child: Text(label)), - ], - ); - } - return Semantics( - button: true, - label: 'More actions', - excludeSemantics: true, - child: CupertinoButton( - key: widget.menuKey, - padding: EdgeInsets.zero, - minimumSize: const Size.square(kMinInteractiveDimensionCupertino), - onPressed: () async { - final picked = await showCupertinoModalPopup<_RunMoreItem>( - context: context, - builder: (sheet) => CupertinoActionSheet( - actions: [ - for (final (item, label) in items) - CupertinoActionSheetAction( - key: _keyOf(item), - onPressed: () => Navigator.of(sheet).pop(item), - child: Text(label), - ), - ], - cancelButton: CupertinoActionSheetAction( - isDefaultAction: true, - onPressed: () => Navigator.of(sheet).pop(), - child: const Text('Cancel'), - ), - ), - ); - if (picked != null && context.mounted) _pick(context, picked); - }, - child: const Icon(CupertinoIcons.ellipsis_circle), - ), + return AppOverflowMenu<_RunMoreItem>( + key: widget.menuKey, + cupertino: widget.cupertino, + actions: [ + for (final (item, label) in _items) + AppMenuAction(key: _keyOf(item), value: item, label: label), + ], + onSelected: _pick, ); } } diff --git a/app/lib/features/runs/ui/runs_list.dart b/app/lib/features/runs/ui/runs_list.dart index 38ca31a8..b6c38534 100644 --- a/app/lib/features/runs/ui/runs_list.dart +++ b/app/lib/features/runs/ui/runs_list.dart @@ -1,3 +1,5 @@ +import '../../../ui/layout/app_list_avatar.dart'; +import '../../../ui/layout/app_list_row.dart'; import '../../../ui/layout/section_heading.dart'; import '../../../ui/motion/motion.dart'; import 'package:flutter/cupertino.dart'; @@ -177,9 +179,12 @@ class RunsList extends StatelessWidget { ), ); } + // The last run of a day (before the next heading) has no divider. + final next = index - header.length + 1; + final last = next >= entries.length || entries[next].run == null; return Arrival( id: '${entry.run!['id']}', - child: _runTile(context, entry.run!), + child: _runTile(context, entry.run!, divider: !last), ); }, ); @@ -262,10 +267,11 @@ class RunsList extends StatelessWidget { ), ); - Widget _runTile(BuildContext context, JsonMap run) { + Widget _runTile(BuildContext context, JsonMap run, {bool divider = true}) { final id = run['id']; return RunListRow( run: run, + divider: divider, selected: id == controller.selectedRunId, now: DateTime.now(), onTap: id is num ? () => onSelected(id) : null, @@ -276,17 +282,16 @@ class RunsList extends StatelessWidget { } } -/// One run in the list, with a status avatar, title/time, and one muted fact -/// line. Its detail retains the full timestamp, path, and other diagnostics. +/// One run in the list: a status avatar, title/time, and one muted fact +/// line in the app's shared row. Its detail retains the full timestamp, +/// path, and other diagnostics. class RunListRow extends StatelessWidget { - /// The narrowest row that still shows its own actions menu. - static const double _menuMinRowWidth = 280; - const RunListRow({ super.key, required this.run, required this.now, this.selected = false, + this.divider = true, this.onTap, this.gateway, this.onRunChanged, @@ -296,6 +301,9 @@ class RunListRow extends StatelessWidget { final JsonMap run; final DateTime now; final bool selected; + + /// False for the last row before a day heading or the end of the list. + final bool divider; final VoidCallback? onTap; final ApiGateway? gateway; final ValueChanged? onRunChanged; @@ -319,22 +327,6 @@ class RunListRow extends StatelessWidget { : pipeline.isEmpty ? 'Pipeline unavailable' : pipeline; - final secondary = cupertino - ? CupertinoColors.secondaryLabel.resolveFrom(context) - : Theme.of(context).colorScheme.onSurfaceVariant; - final nativeStyle = cupertino - ? CupertinoTheme.of(context).textTheme.textStyle - : Theme.of(context).textTheme.bodyMedium ?? const TextStyle(); - final base = !cupertino && selected - ? nativeStyle.copyWith( - color: Theme.of(context).colorScheme.onSecondaryContainer, - ) - : nativeStyle; - final titleStyle = base.copyWith(fontWeight: FontWeight.w600); - final small = base.copyWith( - color: secondary, - fontSize: (base.fontSize ?? 14) - 1, - ); final scheduled = run['scheduled'] == true; final subtitle = [ ?pipelineLabel, @@ -342,164 +334,41 @@ class RunListRow extends StatelessWidget { ?facts.duration, ?facts.progress, ].join(' · '); - final relativeTime = formatRanAgo('${run['created_at'] ?? ''}', now); - Widget body(bool withMenu, bool compact) => Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsetsDirectional.only(end: 12), - child: _RunStatusAvatar( - state: runStateOf(run['status']), - label: runStatusLabel(run), - ), - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: compact - ? [ - Text( - title, - style: titleStyle, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - const SizedBox(height: 2), - Text( - // The stored pipeline name is a fallback when the API - // has no human-readable pipeline title. Avoid repeating - // it if it already supplies the row title. - [ - ?pipelineLabel, - if (scheduled) 'Scheduled', - if (run['executing'] == true && facts.progress != null) - facts.progress!, - if (pipelineLabel == null && facts.duration != null) - facts.duration!, - ].join(' · '), - style: small, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ] - : [ - // The time keeps at most 40% of the line, so very large - // text in a narrow row ellipsises instead of overflowing. - LayoutBuilder( - builder: (context, constraints) => Row( - children: [ - Expanded( - child: Text( - title, - style: titleStyle, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - if (relativeTime != null) - ConstrainedBox( - constraints: BoxConstraints( - maxWidth: constraints.maxWidth * 0.4, - ), - child: Padding( - padding: const EdgeInsetsDirectional.only( - start: 8, - ), - child: Text( - relativeTime, - style: small, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ), - ), - ], - ), - ), - const SizedBox(height: 2), - Text( - subtitle, - style: small, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - ], - ), - ), - if (withMenu && - gateway != null && - onRunChanged != null && - showRunMoreMenu(run)) - RunMoreMenu( - run: run, - gateway: gateway!, - onRunChanged: onRunChanged!, - onRunOpened: onRunOpened, - cupertino: cupertino, - menuKey: ValueKey('run-list-more-menu-$id'), - ), - ], - ); - // A narrow list pane beside the open run leaves the row no room for a - // second control (a tap on its centre would land on the menu); the open - // run's detail beside it carries the same menu. - final padded = Padding( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10), - child: LayoutBuilder( - builder: (context, constraints) { - final compact = constraints.maxWidth < _menuMinRowWidth; - return body(!compact, compact); - }, - ), - ); - return Semantics( + // A narrow pane keeps the decision facts: the pipeline, and progress + // while executing (duration only when there is no pipeline to show). + final compactSubtitle = [ + ?pipelineLabel, + if (scheduled) 'Scheduled', + if (run['executing'] == true && facts.progress != null) facts.progress!, + if (pipelineLabel == null && facts.duration != null) facts.duration!, + ].join(' · '); + final state = runStateOf(run['status']); + return AppListRow( + key: ValueKey('run-row-$id'), + cupertino: cupertino, selected: selected, - button: onTap != null, - child: cupertino - ? CupertinoButton( - key: ValueKey('run-row-$id'), - color: selected - ? CupertinoColors.tertiarySystemFill.resolveFrom(context) - : null, - padding: EdgeInsets.zero, - minimumSize: Size.zero, - pressedOpacity: 0.6, - onPressed: onTap, - child: DefaultTextStyle(style: base, child: padded), - ) - : Material( - key: ValueKey('run-row-surface-$id'), - color: selected - ? Theme.of(context).colorScheme.secondaryContainer - : Colors.transparent, - child: InkWell( - key: ValueKey('run-row-$id'), - onTap: onTap, - child: padded, - ), - ), - ); - } -} - -class _RunStatusAvatar extends StatelessWidget { - const _RunStatusAvatar({required this.state, required this.label}); - - final String state; - final String label; - - @override - Widget build(BuildContext context) { - final color = runStatusColor(state).resolveFrom(context); - return Container( - width: 36, - height: 36, - decoration: BoxDecoration( - color: color.withValues(alpha: 0.14), - shape: BoxShape.circle, + divider: divider, + onTap: onTap, + leading: AppListAvatar( + foreground: runStatusColor(state).resolveFrom(context), + child: RunStatusIcon(state: state, label: runStatusLabel(run)), ), - alignment: Alignment.center, - child: RunStatusIcon(state: state, label: label), + title: Text(title), + time: formatRanAgo('${run['created_at'] ?? ''}', now), + subtitle: Text(subtitle), + compactSubtitle: Text(compactSubtitle), + // A narrow list pane beside the open run leaves the row no room for a + // second control; the open run's detail beside it carries the same menu. + menu: gateway != null && onRunChanged != null && showRunMoreMenu(run) + ? RunMoreMenu( + run: run, + gateway: gateway!, + onRunChanged: onRunChanged!, + onRunOpened: onRunOpened, + cupertino: cupertino, + menuKey: ValueKey('run-list-more-menu-$id'), + ) + : null, ); } } diff --git a/app/lib/features/schedules/ui/list/schedule_list_format.dart b/app/lib/features/schedules/ui/list/schedule_list_format.dart index 46990bf2..e1a6d1d8 100644 --- a/app/lib/features/schedules/ui/list/schedule_list_format.dart +++ b/app/lib/features/schedules/ui/list/schedule_list_format.dart @@ -90,3 +90,32 @@ String scheduleCountLabel(int visible, int total) { if (visible != total) return '$visible of $total schedules'; return total == 1 ? '1 schedule' : '$total schedules'; } + +/// A row's short next-run word for its title line: `Paused`, `Not +/// scheduled`, `Next time unavailable`, or the local time as `22 Oct 09:00`. +String scheduleNextDueShort(SavedSchedule schedule) { + if (!schedule.enabled) return 'Paused'; + final value = schedule.nextDue; + if (value.isEmpty) return 'Not scheduled'; + final date = DateTime.tryParse(value); + if (date == null) return 'Next time unavailable'; + final local = date.toLocal(); + String two(int part) => part.toString().padLeft(2, '0'); + return '${local.day} ${_shortMonths[local.month - 1]} ' + '${two(local.hour)}:${two(local.minute)}'; +} + +const _shortMonths = [ + 'Jan', + 'Feb', + 'Mar', + 'Apr', + 'May', + 'Jun', + 'Jul', + 'Aug', + 'Sep', + 'Oct', + 'Nov', + 'Dec', +]; diff --git a/app/lib/features/schedules/ui/list/schedule_list_row.dart b/app/lib/features/schedules/ui/list/schedule_list_row.dart index 110fb2f9..1ded49e5 100644 --- a/app/lib/features/schedules/ui/list/schedule_list_row.dart +++ b/app/lib/features/schedules/ui/list/schedule_list_row.dart @@ -1,109 +1,74 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../../ui/layout/app_list_avatar.dart'; +import '../../../../ui/layout/app_list_row.dart'; import '../../domain/saved_schedule.dart'; import 'schedule_list_format.dart'; -/// One tappable saved-schedule row with the server's actual values. +/// One tappable saved schedule in the app's shared row: a clock avatar (tinted +/// while enabled), the name with its next run (or `Paused`), and one muted +/// line with the timer and the pinned pipeline version. The editor it opens +/// shows the prompt, workspace, timezone and exact due time. class ScheduleListRow extends StatelessWidget { const ScheduleListRow({ super.key, required this.schedule, required this.cupertino, required this.onOpen, + this.divider = true, }); final SavedSchedule schedule; final bool cupertino; final VoidCallback onOpen; + final bool divider; @override Widget build(BuildContext context) { - final content = Padding( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded(child: _details(context)), - const SizedBox(width: 8), - Icon( - cupertino ? CupertinoIcons.chevron_right : Icons.chevron_right, - color: _secondaryColor(context), - ), - ], + return AppListRow( + cupertino: cupertino, + divider: divider, + onTap: onOpen, + leading: ScheduleAvatar(schedule: schedule, cupertino: cupertino), + title: Text(scheduleDisplayName(schedule)), + time: scheduleNextDueShort(schedule), + subtitle: Text( + '${scheduleTimerValue(schedule)} · ' + '${schedulePipelineVersionValue(schedule)}', ), ); - if (cupertino) { - return CupertinoButton( - padding: EdgeInsets.zero, - alignment: Alignment.centerLeft, - onPressed: onOpen, - child: content, - ); - } - return InkWell(onTap: onOpen, child: content); } +} - Widget _details(BuildContext context) { - final prompt = schedule.prompt; - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Text( - scheduleDisplayName(schedule), - style: _titleStyle(context), - ), - ), - const SizedBox(width: 8), - Text(scheduleStatusLabel(schedule), style: _statusStyle(context)), - ], +/// A schedule's leading clock: green while enabled, grey while paused. The +/// state is also a word on the row (its time reads `Paused`), so colour is +/// never the only signal. +class ScheduleAvatar extends StatelessWidget { + const ScheduleAvatar({ + super.key, + required this.schedule, + required this.cupertino, + }); + + final SavedSchedule schedule; + final bool cupertino; + + @override + Widget build(BuildContext context) { + final Color? enabled = schedule.enabled + ? (cupertino + ? CupertinoColors.systemGreen.resolveFrom(context) + : Colors.green.shade700) + : null; + return Semantics( + label: scheduleStatusLabel(schedule), + child: ExcludeSemantics( + child: AppListAvatar( + foreground: enabled, + child: Icon(cupertino ? CupertinoIcons.clock : Icons.schedule), ), - if (prompt.isNotEmpty) ...[ - const SizedBox(height: 4), - Text(prompt, style: _bodyStyle(context)), - ], - const SizedBox(height: 6), - _meta(context, schedulePipelineVersionValue(schedule)), - _meta(context, 'Workspace: ${scheduleWorkspaceValue(schedule)}'), - _meta(context, 'Timer: ${scheduleTimerValue(schedule)}'), - _meta(context, 'Timezone: ${scheduleTimezoneValue(schedule)}'), - _meta(context, 'Next due: ${scheduleNextDueValue(schedule)}'), - ], + ), ); } - - Widget _meta(BuildContext context, String value) => - Text(value, style: _metaStyle(context)); - - TextStyle? _titleStyle(BuildContext context) => cupertino - ? CupertinoTheme.of(context).textTheme.navTitleTextStyle - : Theme.of(context).textTheme.titleMedium; - - TextStyle? _bodyStyle(BuildContext context) => - cupertino ? CupertinoTheme.of(context).textTheme.textStyle : null; - - TextStyle? _metaStyle(BuildContext context) => cupertino - ? CupertinoTheme.of( - context, - ).textTheme.tabLabelTextStyle.copyWith(color: _secondaryColor(context)) - : Theme.of( - context, - ).textTheme.bodySmall?.copyWith(color: _secondaryColor(context)); - - TextStyle? _statusStyle(BuildContext context) => - _metaStyle(context)?.copyWith(color: _statusColor(context)); - - Color _secondaryColor(BuildContext context) => cupertino - ? CupertinoColors.secondaryLabel.resolveFrom(context) - : Theme.of(context).colorScheme.onSurfaceVariant; - - Color _statusColor(BuildContext context) => schedule.enabled - ? (cupertino - ? CupertinoTheme.of(context).primaryColor - : Theme.of(context).colorScheme.primary) - : _secondaryColor(context); } diff --git a/app/lib/features/schedules/ui/list/schedule_list_view.dart b/app/lib/features/schedules/ui/list/schedule_list_view.dart index e3b82cc5..5d0aeb44 100644 --- a/app/lib/features/schedules/ui/list/schedule_list_view.dart +++ b/app/lib/features/schedules/ui/list/schedule_list_view.dart @@ -76,13 +76,11 @@ class SchedulesListView extends StatelessWidget { Widget _list(BuildContext context) { final schedules = controller.visibleSchedules; - return ListView.separated( + return ListView.builder( key: scheduleListKey, controller: scrollController, padding: const EdgeInsets.only(top: 4, bottom: 24), itemCount: schedules.length, - separatorBuilder: (context, index) => - cupertino ? _cupertinoSeparator(context) : const Divider(height: 1), itemBuilder: (context, index) { final schedule = schedules[index]; return ScheduleListRow( @@ -91,17 +89,13 @@ class SchedulesListView extends StatelessWidget { ), schedule: schedule, cupertino: cupertino, + divider: index < schedules.length - 1, onOpen: () => onOpen(schedule), ); }, ); } - Widget _cupertinoSeparator(BuildContext context) => Container( - height: 1 / MediaQuery.devicePixelRatioOf(context), - color: CupertinoColors.separator.resolveFrom(context), - ); - Widget _loadingState(BuildContext context) { return Center( child: Semantics( diff --git a/app/lib/features/schedules/ui/pipeline/schedule_pipeline_list_body.dart b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_list_body.dart index 40c8361f..55310f2c 100644 --- a/app/lib/features/schedules/ui/pipeline/schedule_pipeline_list_body.dart +++ b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_list_body.dart @@ -73,11 +73,12 @@ class SchedulePipelineListBody extends StatelessWidget { style: schedulePipelineMutedStyle(context), ), ), - for (var index = 0; index < schedules.length; index++) ...[ - _row(context, schedules[index]), - if (index < schedules.length - 1) - schedulePipelineSeparator(context), - ], + for (var index = 0; index < schedules.length; index++) + _row( + context, + schedules[index], + divider: index < schedules.length - 1, + ), ], ), ); @@ -115,10 +116,15 @@ class SchedulePipelineListBody extends StatelessWidget { ); } - Widget _row(BuildContext context, SavedSchedule schedule) { + Widget _row( + BuildContext context, + SavedSchedule schedule, { + required bool divider, + }) { final id = schedule.id; return SchedulePipelineRow( schedule: schedule, + divider: divider, busy: id != null && busyRows.contains(id), error: id == null ? null : rowErrors[id], onEdit: () => onEdit(schedule), 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 cc7d18ee..6dff8706 100644 --- a/app/lib/features/schedules/ui/pipeline/schedule_pipeline_row.dart +++ b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_row.dart @@ -1,15 +1,21 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../../ui/adaptive/host.dart'; - +import '../../../../ui/layout/app_list_row.dart'; +import '../../../../ui/layout/app_overflow_menu.dart'; import '../../domain/saved_schedule.dart'; import '../list/schedule_list_format.dart'; +import '../list/schedule_list_row.dart'; import 'schedule_pipeline_styles.dart'; import 'schedule_pipeline_wording.dart'; -/// One saved schedule in the pipeline Summary: name, state, pinned version and -/// timer words, the recorded due time, and its Edit/Pause-Enable/Delete actions. +enum _ScheduleAction { edit, toggle, delete } + +/// One saved schedule in the pipeline Summary, in the app's shared row: the +/// clock avatar, the name with its next run (or `Paused`), one muted line with +/// the pinned version and timer words, and an overflow menu with Edit, +/// Pause/Enable and Delete. A tap on the row edits it; a refused action's +/// message sits under the row. class SchedulePipelineRow extends StatelessWidget { const SchedulePipelineRow({ super.key, @@ -19,6 +25,7 @@ class SchedulePipelineRow extends StatelessWidget { required this.onToggle, required this.onDelete, this.error, + this.divider = false, }); final SavedSchedule schedule; @@ -27,199 +34,74 @@ class SchedulePipelineRow extends StatelessWidget { final VoidCallback onEdit; final VoidCallback onToggle; final VoidCallback onDelete; + final bool divider; @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, 8), - child: Semantics( - container: true, - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - // The name, bold, with its state as a coloured pill. - Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded( - child: Text(scheduleDisplayName(schedule), style: title), - ), - const SizedBox(width: 8), - _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), - ), - ], - ), - if (schedule.prompt.isNotEmpty) ...[ - const SizedBox(height: 8), - // The prompt it sends, as a quote under the facts. - _Quote(text: schedule.prompt, style: body), - ], - const SizedBox(height: 4), - Wrap( - spacing: 8, - runSpacing: 4, - children: [ - schedulePipelineTextButton( - context, - key: scheduleRowEditKey(id), - label: scheduleEditLabel, - onPressed: busy ? null : onEdit, - ), - schedulePipelineTextButton( - context, - key: scheduleRowToggleKey(id), - label: schedule.enabled - ? schedulePauseLabel - : scheduleEnableLabel, - onPressed: busy ? null : onToggle, - ), - schedulePipelineTextButton( - context, - key: scheduleRowDeleteKey(id), - label: scheduleDeleteLabel, - onPressed: busy ? null : onDelete, - ), - ], - ), - if (error case final text?) - Padding( - padding: const EdgeInsets.only(top: 4), - child: Semantics( - liveRegion: true, - child: Text( - text, - key: scheduleRowErrorKey(id), - style: schedulePipelineErrorStyle(context), - ), - ), - ), - ], - ), - ), - ); - } -} - -/// 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(), + final row = AppListRow( + cupertino: cupertino, + divider: divider && error == null, + onTap: busy ? null : onEdit, + leading: ScheduleAvatar(schedule: schedule, cupertino: cupertino), + title: Text(scheduleDisplayName(schedule)), + time: scheduleNextDueShort(schedule), + subtitle: Text( + '${schedulePinnedVersionValue(schedule)} · ' + '${scheduleRuleSummary(schedule)}', ), - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), - child: Text( - enabled ? 'Enabled' : 'Paused', - style: TextStyle( - color: color, - fontWeight: FontWeight.w700, - fontSize: 12, + // A narrow Summary still needs a way to pause or delete. + keepMenuWhenCompact: true, + menu: AppOverflowMenu<_ScheduleAction>( + key: scheduleRowMenuKey(id), + cupertino: cupertino, + enabled: !busy, + label: 'Schedule actions for ${scheduleDisplayName(schedule)}', + sheetTitle: scheduleDisplayName(schedule), + actions: [ + AppMenuAction( + key: scheduleRowEditKey(id), + value: _ScheduleAction.edit, + label: scheduleEditLabel, ), - ), + AppMenuAction( + key: scheduleRowToggleKey(id), + value: _ScheduleAction.toggle, + label: schedule.enabled ? schedulePauseLabel : scheduleEnableLabel, + ), + AppMenuAction( + key: scheduleRowDeleteKey(id), + value: _ScheduleAction.delete, + label: scheduleDeleteLabel, + destructive: true, + ), + ], + onSelected: (_, action) => switch (action) { + _ScheduleAction.edit => onEdit(), + _ScheduleAction.toggle => onToggle(), + _ScheduleAction.delete => onDelete(), + }, ), ); - } -} - -/// 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, + return Column( + key: scheduleRowKey(id), + crossAxisAlignment: CrossAxisAlignment.stretch, 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)), + row, + if (error case final text?) + Padding( + padding: const EdgeInsets.fromLTRB(16, 0, 16, 8), + child: Semantics( + liveRegion: true, + child: Text( + text, + key: scheduleRowErrorKey(id), + style: schedulePipelineErrorStyle(context), + ), + ), + ), ], ); } } - -/// 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/features/schedules/ui/pipeline/schedule_pipeline_styles.dart b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_styles.dart index 048cfdbd..c0b4a12a 100644 --- a/app/lib/features/schedules/ui/pipeline/schedule_pipeline_styles.dart +++ b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_styles.dart @@ -10,11 +10,6 @@ TextStyle? schedulePipelineHeadingStyle(BuildContext context) => ? CupertinoTheme.of(context).textTheme.navTitleTextStyle : Theme.of(context).textTheme.titleMedium; -TextStyle? schedulePipelineBodyStyle(BuildContext context) => - usesCupertinoHost(context) - ? CupertinoTheme.of(context).textTheme.textStyle - : Theme.of(context).textTheme.bodyLarge; - TextStyle? schedulePipelineMutedStyle(BuildContext context) { if (usesCupertinoHost(context)) { return CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith( @@ -59,13 +54,3 @@ Widget schedulePipelineTextButton( } return TextButton(key: key, onPressed: onPressed, child: Text(label)); } - -Widget schedulePipelineSeparator(BuildContext context) { - if (usesCupertinoHost(context)) { - return Container( - height: 1 / MediaQuery.devicePixelRatioOf(context), - color: CupertinoColors.separator.resolveFrom(context), - ); - } - return const Divider(height: 1); -} diff --git a/app/lib/features/schedules/ui/pipeline/schedule_pipeline_wording.dart b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_wording.dart index d1c5c022..1abcf429 100644 --- a/app/lib/features/schedules/ui/pipeline/schedule_pipeline_wording.dart +++ b/app/lib/features/schedules/ui/pipeline/schedule_pipeline_wording.dart @@ -32,6 +32,10 @@ const scheduleDeleteErrorKey = ValueKey('schedule-delete-error'); ValueKey scheduleRowKey(int? id) => ValueKey('schedule-pipeline-row-${id ?? 'unknown'}'); + +/// The row's overflow menu, which holds Edit, Pause/Enable and Delete. +ValueKey scheduleRowMenuKey(int? id) => + ValueKey('schedule-pipeline-menu-${id ?? 'unknown'}'); ValueKey scheduleRowEditKey(int? id) => ValueKey('schedule-pipeline-edit-${id ?? 'unknown'}'); ValueKey scheduleRowToggleKey(int? id) => diff --git a/app/lib/features/search/ui/cupertino_search_body.dart b/app/lib/features/search/ui/cupertino_search_body.dart index f27d2e8b..7ff2d235 100644 --- a/app/lib/features/search/ui/cupertino_search_body.dart +++ b/app/lib/features/search/ui/cupertino_search_body.dart @@ -2,11 +2,10 @@ import 'package:flutter/cupertino.dart'; import '../../../core/api_gateway.dart'; import '../domain/search_controller.dart'; -import '../domain/search_row.dart'; -import 'search_result_view.dart'; +import 'search_result_row.dart'; import 'search_layout.dart'; -/// The Cupertino search view: an optional status header and inset-grouped +/// The Cupertino search view: an optional status header and the shared list /// rows in one scroll view that runs behind the top bar, with standard /// activity and retry controls. class CupertinoSearchBody extends StatelessWidget { @@ -61,22 +60,14 @@ class CupertinoSearchBody extends StatelessWidget { ]; case SearchBodyKind.results: return [ - SliverToBoxAdapter( - child: CupertinoListSection.insetGrouped( - // The section sits on the page's own background (the shell's - // is not the grouped one), so it takes the bar pills' grey - // rather than a white card framed by a grey band. - backgroundColor: const Color(0x00000000), - decoration: BoxDecoration( - color: CupertinoColors.systemGrey6.resolveFrom(context), - borderRadius: const BorderRadius.all(Radius.circular(10)), - ), - // The column already keeps the bar's inset. - margin: const EdgeInsets.symmetric(vertical: 8), - children: [ - for (final hit in controller.shownResults) - _CupertinoResult(hit: hit, query: query, onOpen: onOpen), - ], + SliverList.builder( + itemCount: controller.shownResults.length, + itemBuilder: (context, index) => SearchResultRow( + hit: controller.shownResults[index], + query: query, + onOpen: onOpen, + cupertino: true, + divider: index < controller.shownResults.length - 1, ), ), ]; @@ -99,34 +90,6 @@ class CupertinoSearchBody extends StatelessWidget { } } -class _CupertinoResult extends StatelessWidget { - const _CupertinoResult({ - required this.hit, - required this.query, - required this.onOpen, - }); - - final JsonMap hit; - final String query; - final ValueChanged onOpen; - - @override - Widget build(BuildContext context) { - final row = searchRowView(hit, query); - return CupertinoListTile( - key: ValueKey('search.result.${hit['target']}'), - leading: - searchArtifactThumbnail(context, hit) ?? - Icon(searchCupertinoIcon('${hit['kind'] ?? ''}')), - leadingSize: 44, - trailing: searchArtifactActions(context, hit), - title: searchRowTitle(context, row), - subtitle: searchRowLine(context, row), - onTap: row.openable ? () => onOpen(hit) : null, - ); - } -} - class _CupertinoSearching extends StatelessWidget { const _CupertinoSearching(); diff --git a/app/lib/features/search/ui/material_search_body.dart b/app/lib/features/search/ui/material_search_body.dart index 9681b270..49f13d0a 100644 --- a/app/lib/features/search/ui/material_search_body.dart +++ b/app/lib/features/search/ui/material_search_body.dart @@ -2,8 +2,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../domain/search_controller.dart'; -import '../domain/search_row.dart'; -import 'search_result_view.dart'; +import 'search_result_row.dart'; import 'search_layout.dart'; /// The Material search view: an optional status header and a flat native @@ -54,10 +53,13 @@ class MaterialSearchBody extends StatelessWidget { return [ SliverList.builder( itemCount: controller.shownResults.length, - itemBuilder: (context, index) { - final hit = controller.shownResults[index]; - return _MaterialResult(hit: hit, query: query, onOpen: onOpen); - }, + itemBuilder: (context, index) => SearchResultRow( + hit: controller.shownResults[index], + query: query, + onOpen: onOpen, + cupertino: false, + divider: index < controller.shownResults.length - 1, + ), ), ]; case SearchBodyKind.empty: @@ -79,33 +81,6 @@ class MaterialSearchBody extends StatelessWidget { } } -class _MaterialResult extends StatelessWidget { - const _MaterialResult({ - required this.hit, - required this.query, - required this.onOpen, - }); - - final JsonMap hit; - final String query; - final ValueChanged onOpen; - - @override - Widget build(BuildContext context) { - final row = searchRowView(hit, query); - return ListTile( - key: ValueKey('search.result.${hit['target']}'), - leading: - searchArtifactThumbnail(context, hit) ?? - Icon(searchMaterialIcon('${hit['kind'] ?? ''}')), - trailing: searchArtifactActions(context, hit), - title: searchRowTitle(context, row), - subtitle: searchRowLine(context, row), - onTap: row.openable ? () => onOpen(hit) : null, - ); - } -} - class _Searching extends StatelessWidget { const _Searching(); diff --git a/app/lib/features/search/ui/search_result_row.dart b/app/lib/features/search/ui/search_result_row.dart new file mode 100644 index 00000000..5da536ca --- /dev/null +++ b/app/lib/features/search/ui/search_result_row.dart @@ -0,0 +1,96 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../../core/api_gateway.dart'; +import '../../../ui/layout/app_list_avatar.dart'; +import '../../../ui/layout/app_list_row.dart'; +import '../domain/search_row.dart'; +import 'search_result_view.dart'; + +/// One search hit in the app's shared row: the kind's icon (or an image +/// artifact's picture), the title with its recency, and one muted line that +/// names the kind and then shows the snippet (its first query occurrence +/// emphasised by weight, never by parsing server text as markup) or, without +/// one, the kind's own facts. An artifact hit's open choices are its menu. +class SearchResultRow extends StatelessWidget { + const SearchResultRow({ + super.key, + required this.hit, + required this.query, + required this.onOpen, + required this.cupertino, + this.divider = true, + }); + + final JsonMap hit; + final String query; + final ValueChanged onOpen; + final bool cupertino; + final bool divider; + + @override + Widget build(BuildContext context) { + final row = searchRowView(hit, query); + final kind = '${hit['kind'] ?? ''}'; + return AppListRow( + key: ValueKey('search.result.${hit['target']}'), + cupertino: cupertino, + divider: divider, + onTap: row.openable ? () => onOpen(hit) : null, + leading: + searchArtifactThumbnail(context, hit) ?? + AppListAvatar( + child: Icon( + cupertino ? searchCupertinoIcon(kind) : searchMaterialIcon(kind), + ), + ), + title: Text(row.title), + time: row.recency, + subtitle: Text.rich(_line(row)), + menu: searchArtifactActions(context, hit), + ); + } + + TextSpan _line(SearchRowView row) { + final snippet = row.snippet; + return TextSpan( + children: [ + TextSpan( + text: row.kindLabel, + style: const TextStyle(fontWeight: FontWeight.w600), + ), + const TextSpan(text: ' · '), + if (snippet == null) + TextSpan(text: row.secondary) + else + for (final span in row.snippetSpans) + TextSpan( + text: span.text, + style: span.matched + ? const TextStyle(fontWeight: FontWeight.bold) + : null, + ), + ], + ); + } +} + +IconData searchMaterialIcon(String kind) => switch (kind) { + 'pipeline' => Icons.account_tree_outlined, + 'version' => Icons.layers_outlined, + 'run' => Icons.play_circle_outline, + 'step' => Icons.arrow_forward, + 'field' => Icons.notes, + 'artifact' => Icons.attach_file, + _ => Icons.help_outline, +}; + +IconData searchCupertinoIcon(String kind) => switch (kind) { + 'pipeline' => CupertinoIcons.arrow_branch, + 'version' => CupertinoIcons.square_stack_3d_up, + 'run' => CupertinoIcons.play_circle, + 'step' => CupertinoIcons.arrow_right, + 'field' => CupertinoIcons.doc_text, + 'artifact' => CupertinoIcons.paperclip, + _ => CupertinoIcons.question_circle, +}; diff --git a/app/lib/features/search/ui/search_result_view.dart b/app/lib/features/search/ui/search_result_view.dart index 030068c5..4658a658 100644 --- a/app/lib/features/search/ui/search_result_view.dart +++ b/app/lib/features/search/ui/search_result_view.dart @@ -1,118 +1,14 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../../core/transport/pipelines_client.dart' show configuredGatewayEndpoint; -import '../../../ui/adaptive/host.dart'; +import '../../../ui/layout/app_list_avatar.dart'; +import '../../../ui/layout/app_overflow_menu.dart'; import '../../artifacts/domain/artifact_kind.dart'; import '../../artifacts/domain/artifact_record.dart'; import '../../artifacts/ui/artifact_tile.dart'; import '../../artifacts/ui/artifact_viewer_fetch.dart'; -import '../domain/search_row.dart'; - -/// A row's title line: the bold title and, at its trailing edge, a small tag -/// naming the kind. -Widget searchRowTitle(BuildContext context, SearchRowView row) => Row( - crossAxisAlignment: CrossAxisAlignment.start, - spacing: 8, - children: [ - Expanded( - child: Text( - row.title, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: const TextStyle(fontWeight: FontWeight.w600), - ), - ), - SearchKindTag(label: row.kindLabel), - ], -); - -/// A row's one muted line: recency, then the snippet (its first query -/// occurrence emphasised by weight, never by parsing server text as markup) -/// or, without one, the kind's own facts. -Widget searchRowLine(BuildContext context, SearchRowView row) { - final snippet = row.snippet; - final lead = row.recency == null ? '' : '${row.recency} · '; - final spans = [ - if (snippet == null) - TextSpan(text: '$lead${row.secondary}') - else ...[ - if (lead.isNotEmpty) TextSpan(text: lead), - for (final span in row.snippetSpans) - TextSpan( - text: span.text, - style: span.matched - ? const TextStyle(fontWeight: FontWeight.bold) - : null, - ), - ], - ]; - return Text.rich( - TextSpan(children: spans), - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: TextStyle(color: _muted(context)), - ); -} - -Color _muted(BuildContext context) => usesCupertinoHost(context) - ? CupertinoColors.secondaryLabel.resolveFrom(context) - : Theme.of(context).colorScheme.onSurfaceVariant; - -/// The result's kind as a small tinted capsule. -class SearchKindTag extends StatelessWidget { - const SearchKindTag({super.key, required this.label}); - - final String label; - - @override - Widget build(BuildContext context) { - final cupertino = usesCupertinoHost(context); - final Color fill; - final TextStyle? style; - if (cupertino) { - fill = CupertinoColors.tertiarySystemFill.resolveFrom(context); - style = CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith( - color: CupertinoColors.secondaryLabel.resolveFrom(context), - ); - } else { - final theme = Theme.of(context); - fill = theme.colorScheme.surfaceContainerHighest; - style = theme.textTheme.labelSmall?.copyWith( - color: theme.colorScheme.onSurfaceVariant, - ); - } - return DecoratedBox( - decoration: ShapeDecoration(color: fill, shape: const StadiumBorder()), - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), - child: Text(label, style: style), - ), - ); - } -} - -IconData searchMaterialIcon(String kind) => switch (kind) { - 'pipeline' => Icons.account_tree_outlined, - 'version' => Icons.layers_outlined, - 'run' => Icons.play_circle_outline, - 'step' => Icons.arrow_forward, - 'field' => Icons.notes, - 'artifact' => Icons.attach_file, - _ => Icons.help_outline, -}; - -IconData searchCupertinoIcon(String kind) => switch (kind) { - 'pipeline' => CupertinoIcons.arrow_branch, - 'version' => CupertinoIcons.square_stack_3d_up, - 'run' => CupertinoIcons.play_circle, - 'step' => CupertinoIcons.arrow_right, - 'field' => CupertinoIcons.doc_text, - 'artifact' => CupertinoIcons.paperclip, - _ => CupertinoIcons.question_circle, -}; /// What artifact hits need from the screen: the app's gateway (to resolve a /// thumbnail and look up a run's pipeline) and the screen's opener. @@ -152,9 +48,9 @@ Widget? searchArtifactThumbnail(BuildContext context, JsonMap hit) { return null; } return ClipRRect( - borderRadius: BorderRadius.circular(6), + borderRadius: BorderRadius.circular(8), child: SizedBox.square( - dimension: 44, + dimension: kAppListAvatarSize, child: ArtifactThumbnail( key: ValueKey('search.thumbnail.${hit['target']}'), artifact: record, @@ -213,45 +109,14 @@ Widget? searchArtifactActions(BuildContext context, JsonMap hit) { } } - const labels = { - _ArtifactOpen.stage: 'Open stage', - _ArtifactOpen.run: 'Open run', - _ArtifactOpen.pipeline: 'Open pipeline', - }; - final key = ValueKey('search.actions.${hit['target']}'); - if (usesCupertinoHost(context)) { - return CupertinoButton( - key: key, - padding: EdgeInsets.zero, - onPressed: () async { - final choice = await showCupertinoModalPopup<_ArtifactOpen>( - context: context, - builder: (sheet) => CupertinoActionSheet( - actions: [ - for (final entry in labels.entries) - CupertinoActionSheetAction( - onPressed: () => Navigator.pop(sheet, entry.key), - child: Text(entry.value), - ), - ], - cancelButton: CupertinoActionSheetAction( - onPressed: () => Navigator.pop(sheet), - child: const Text('Cancel'), - ), - ), - ); - if (choice != null) await pick(choice); - }, - child: const Icon(CupertinoIcons.ellipsis_circle), - ); - } - return PopupMenuButton<_ArtifactOpen>( - key: key, - tooltip: 'Open…', - onSelected: pick, - itemBuilder: (_) => [ - for (final entry in labels.entries) - PopupMenuItem(value: entry.key, child: Text(entry.value)), + return AppOverflowMenu<_ArtifactOpen>( + key: ValueKey('search.actions.${hit['target']}'), + label: 'Open…', + actions: const [ + AppMenuAction(value: _ArtifactOpen.stage, label: 'Open stage'), + AppMenuAction(value: _ArtifactOpen.run, label: 'Open run'), + AppMenuAction(value: _ArtifactOpen.pipeline, label: 'Open pipeline'), ], + onSelected: (_, choice) => pick(choice), ); } diff --git a/app/lib/ui/layout/app_list_avatar.dart b/app/lib/ui/layout/app_list_avatar.dart new file mode 100644 index 00000000..c987fe1a --- /dev/null +++ b/app/lib/ui/layout/app_list_avatar.dart @@ -0,0 +1,132 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../adaptive/host.dart'; + +/// The leading circle every list row uses, as large as a native contact +/// avatar ([CircleAvatar]'s default). +const double kAppListAvatarSize = 40; + +/// A list row's leading identity: an icon or an initial on a tinted circle, +/// with an optional corner badge (a chat's activity indicator). +/// +/// [foreground] colours the icon/initial; the circle is [background], or the +/// foreground at 14% when omitted, so a status colour reads as a soft tint. +class AppListAvatar extends StatelessWidget { + const AppListAvatar({ + super.key, + required this.child, + this.foreground, + this.background, + this.badge, + }); + + /// The first character of [name] (or `?`), large and bold enough to read + /// at a glance in the circle. + factory AppListAvatar.initial( + String name, { + Key? key, + required Color color, + Widget? badge, + }) { + final trimmed = name.trimLeft(); + final initial = trimmed.isEmpty + ? '?' + : String.fromCharCode(trimmed.runes.first).toUpperCase(); + return AppListAvatar( + key: key, + foreground: color, + badge: badge, + child: Text(initial), + ); + } + + final Widget child; + final Color? foreground; + final Color? background; + final Widget? badge; + + @override + Widget build(BuildContext context) { + final cupertino = usesCupertinoHost(context); + final mark = + foreground ?? + (cupertino + ? CupertinoColors.secondaryLabel.resolveFrom(context) + : Theme.of(context).colorScheme.onSurfaceVariant); + final fill = + background ?? + (foreground == null + ? (cupertino + ? CupertinoColors.systemGrey5.resolveFrom(context) + : Theme.of(context).colorScheme.surfaceContainerHighest) + : mark.withValues(alpha: 0.14)); + final initialStyle = + (cupertino + ? CupertinoTheme.of(context).textTheme.textStyle + : Theme.of(context).textTheme.titleMedium ?? const TextStyle()) + .copyWith( + color: mark, + fontSize: 18, + fontWeight: FontWeight.w700, + height: 1, + ); + final circle = SizedBox.square( + dimension: kAppListAvatarSize, + child: DecoratedBox( + decoration: BoxDecoration(color: fill, shape: BoxShape.circle), + child: Center( + // The glyph is identity, not reading text: it scales down to stay + // inside the circle under large text instead of overflowing it. + child: Padding( + padding: const EdgeInsets.all(8), + child: FittedBox( + fit: BoxFit.scaleDown, + child: IconTheme.merge( + data: IconThemeData(color: mark, size: 22), + child: DefaultTextStyle(style: initialStyle, child: child), + ), + ), + ), + ), + ), + ); + if (badge == null) return circle; + return Stack( + clipBehavior: Clip.none, + children: [ + circle, + PositionedDirectional(end: -2, bottom: -2, child: badge!), + ], + ); + } +} + +/// A small coloured dot that leads a row's subtitle (a latest-run state) or +/// trails it (unread). It follows text scaling and carries its own label. +class AppListStatusDot extends StatelessWidget { + const AppListStatusDot({ + super.key, + required this.color, + this.semanticLabel, + this.size = 8, + }); + + final Color color; + final String? semanticLabel; + final double size; + + @override + Widget build(BuildContext context) { + final dimension = MediaQuery.textScalerOf(context).scale(size); + final dot = DecoratedBox( + decoration: BoxDecoration(color: color, shape: BoxShape.circle), + child: SizedBox.square(dimension: dimension), + ); + if (semanticLabel == null) return ExcludeSemantics(child: dot); + return Semantics( + label: semanticLabel, + child: ExcludeSemantics(child: dot), + ); + } +} diff --git a/app/lib/ui/layout/app_list_row.dart b/app/lib/ui/layout/app_list_row.dart new file mode 100644 index 00000000..2859e592 --- /dev/null +++ b/app/lib/ui/layout/app_list_row.dart @@ -0,0 +1,333 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../adaptive/host.dart'; +import 'app_list_avatar.dart'; + +/// Below this row width (a list pane squeezed beside its detail) a row is +/// compact: no avatar, no time and (by default) no menu, so the title keeps +/// the width and a tap on the row never lands on a second control. +const double kAppListRowCompactWidth = 280; + +/// The rows' horizontal inset and the gap after the avatar. +const double kAppListRowInset = 16; +const double _avatarGap = 12; + +/// Keys on a row's highlight surface and inset divider, for tests. +const appListRowSurfaceKey = ValueKey('app-list-row-surface'); +const appListRowDividerKey = ValueKey('app-list-row-divider'); + +/// The app's one list row (runs, pipelines, chats, search results, +/// schedules), on both hosts. +/// +/// Layout: [leading] (an [AppListAvatar]), then a bold one-line [title] with +/// the [time] at its trailing edge, then one muted [subtitle] line (with an +/// optional [subtitleLeading] dot/prefix and [subtitleTrailing] mark), then +/// the optional [menu] (an `AppOverflowMenu`). An inset hairline [divider] +/// under the text column separates rows. Nothing has a fixed height: the row +/// grows with text scaling and every line ellipsises. +/// +/// [selected] paints the open row (Material `secondaryContainer`, Cupertino +/// `tertiarySystemFill`); [emphasized] marks unread/attention (a heavier +/// title and an accent time). Material rows ripple; Cupertino rows highlight +/// while pressed, like a native table cell. +class AppListRow extends StatelessWidget { + const AppListRow({ + super.key, + required this.title, + this.leading, + this.time, + this.subtitle, + this.compactSubtitle, + this.subtitleLeading, + this.subtitleTrailing, + this.menu, + this.onTap, + this.tapKey, + this.selected = false, + this.emphasized = false, + this.divider = true, + this.keepMenuWhenCompact = false, + this.compactWidth = kAppListRowCompactWidth, + this.cupertino, + }); + + final Widget title; + final Widget? leading; + final String? time; + final Widget? subtitle; + + /// Replaces [subtitle] in a compact row, which has less room for facts. + final Widget? compactSubtitle; + final Widget? subtitleLeading; + final Widget? subtitleTrailing; + final Widget? menu; + final VoidCallback? onTap; + + /// Placed on the tap target ([InkWell] / [GestureDetector]). + final Key? tapKey; + final bool selected; + final bool emphasized; + final bool divider; + + /// Keeps the menu in a compact row when the list has no other way to reach + /// the row's actions. + final bool keepMenuWhenCompact; + final double compactWidth; + + /// Overrides the host detection (some features pick a style per platform). + final bool? cupertino; + + /// The open row's fill on each host. + static Color selectedColor(BuildContext context, {required bool cupertino}) => + cupertino + ? CupertinoColors.tertiarySystemFill.resolveFrom(context) + : Theme.of(context).colorScheme.secondaryContainer; + + @override + Widget build(BuildContext context) { + final cupertino = this.cupertino ?? usesCupertinoHost(context); + final styles = _RowStyles.of( + context, + cupertino: cupertino, + selected: selected, + emphasized: emphasized, + ); + return Semantics( + container: true, + selected: selected, + button: onTap != null, + child: LayoutBuilder( + builder: (context, constraints) { + final compact = constraints.maxWidth < compactWidth; + final showLeading = leading != null && !compact; + final showMenu = menu != null && (!compact || keepMenuWhenCompact); + final start = compact ? 12.0 : kAppListRowInset; + final content = Padding( + padding: EdgeInsetsDirectional.only( + start: start, + end: showMenu ? 4 : kAppListRowInset, + top: 10, + bottom: 10, + ), + child: Row( + children: [ + if (showLeading) + Padding( + padding: const EdgeInsetsDirectional.only(end: _avatarGap), + child: leading, + ), + Expanded(child: _text(styles, compact)), + if (showMenu) + Padding( + padding: const EdgeInsetsDirectional.only(start: 4), + child: menu, + ), + ], + ), + ); + final surface = cupertino + ? _CupertinoRowSurface( + tapKey: tapKey, + onTap: onTap, + selected: selected, + child: content, + ) + : Material( + key: appListRowSurfaceKey, + color: selected + ? selectedColor(context, cupertino: false) + : Colors.transparent, + child: InkWell(key: tapKey, onTap: onTap, child: content), + ); + if (!divider) return surface; + final textStart = + start + (showLeading ? kAppListAvatarSize + _avatarGap : 0); + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + surface, + Padding( + padding: EdgeInsetsDirectional.only(start: textStart), + child: SizedBox( + key: appListRowDividerKey, + height: cupertino + ? 1 / MediaQuery.devicePixelRatioOf(context) + : 1, + child: ColoredBox(color: styles.divider), + ), + ), + ], + ); + }, + ), + ); + } + + Widget _text(_RowStyles styles, bool compact) { + final line = compact ? (compactSubtitle ?? subtitle) : subtitle; + final titleLine = LayoutBuilder( + // The time keeps at most 40% of the line, so very large text in a + // narrow row ellipsises instead of overflowing. + builder: (context, constraints) => Row( + children: [ + Expanded( + child: DefaultTextStyle( + style: styles.title, + maxLines: 1, + overflow: TextOverflow.ellipsis, + child: title, + ), + ), + if (!compact && time != null && time!.isNotEmpty) + ConstrainedBox( + constraints: BoxConstraints(maxWidth: constraints.maxWidth * 0.4), + child: Padding( + padding: const EdgeInsetsDirectional.only(start: 8), + child: Text( + time!, + style: styles.time, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ), + ), + ), + ], + ), + ); + if (line == null && subtitleLeading == null && subtitleTrailing == null) { + return titleLine; + } + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + titleLine, + const SizedBox(height: 2), + Row( + children: [ + if (subtitleLeading != null) + Padding( + padding: const EdgeInsetsDirectional.only(end: 6), + child: subtitleLeading, + ), + Expanded( + child: DefaultTextStyle( + style: styles.subtitle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + child: line ?? const SizedBox.shrink(), + ), + ), + if (subtitleTrailing != null) + Padding( + padding: const EdgeInsetsDirectional.only(start: 8), + child: subtitleTrailing, + ), + ], + ), + ], + ); + } +} + +/// The row's text styles, from the host's own type scale. +class _RowStyles { + const _RowStyles(this.title, this.subtitle, this.time, this.divider); + + factory _RowStyles.of( + BuildContext context, { + required bool cupertino, + required bool selected, + required bool emphasized, + }) { + final weight = emphasized ? FontWeight.w700 : FontWeight.w600; + if (cupertino) { + final theme = CupertinoTheme.of(context); + final base = theme.textTheme.textStyle; + final muted = CupertinoColors.secondaryLabel.resolveFrom(context); + final small = base.copyWith(fontSize: 15, color: muted); + return _RowStyles( + base.copyWith(fontWeight: weight, letterSpacing: 0), + small, + small.copyWith( + color: emphasized ? theme.primaryColor : muted, + fontWeight: emphasized ? FontWeight.w600 : null, + ), + CupertinoColors.separator.resolveFrom(context), + ); + } + final theme = Theme.of(context); + final scheme = theme.colorScheme; + final text = theme.textTheme; + final muted = scheme.onSurfaceVariant; + return _RowStyles( + (text.titleMedium ?? const TextStyle()).copyWith( + fontWeight: weight, + letterSpacing: 0, + color: selected ? scheme.onSecondaryContainer : scheme.onSurface, + ), + (text.bodyMedium ?? const TextStyle()).copyWith(color: muted), + (text.bodySmall ?? const TextStyle()).copyWith( + color: emphasized ? scheme.primary : muted, + fontWeight: emphasized ? FontWeight.w600 : null, + ), + scheme.outlineVariant, + ); + } + + final TextStyle title; + final TextStyle subtitle; + final TextStyle time; + final Color divider; +} + +/// A Cupertino table cell: highlights while pressed, tinted while selected. +class _CupertinoRowSurface extends StatefulWidget { + const _CupertinoRowSurface({ + required this.tapKey, + required this.onTap, + required this.selected, + required this.child, + }); + + final Key? tapKey; + final VoidCallback? onTap; + final bool selected; + final Widget child; + + @override + State<_CupertinoRowSurface> createState() => _CupertinoRowSurfaceState(); +} + +class _CupertinoRowSurfaceState extends State<_CupertinoRowSurface> { + bool _pressed = false; + + void _press(bool value) { + if (_pressed != value) setState(() => _pressed = value); + } + + @override + Widget build(BuildContext context) { + final color = _pressed + ? CupertinoColors.systemGrey4.resolveFrom(context) + : widget.selected + ? AppListRow.selectedColor(context, cupertino: true) + : const Color(0x00000000); + final enabled = widget.onTap != null; + return GestureDetector( + key: widget.tapKey, + behavior: HitTestBehavior.opaque, + onTap: widget.onTap, + onTapDown: enabled ? (_) => _press(true) : null, + onTapUp: enabled ? (_) => _press(false) : null, + onTapCancel: enabled ? () => _press(false) : null, + child: ColoredBox( + key: appListRowSurfaceKey, + color: color, + child: widget.child, + ), + ); + } +} diff --git a/app/lib/ui/layout/app_overflow_menu.dart b/app/lib/ui/layout/app_overflow_menu.dart new file mode 100644 index 00000000..3dee38ae --- /dev/null +++ b/app/lib/ui/layout/app_overflow_menu.dart @@ -0,0 +1,118 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../adaptive/host.dart'; + +/// One choice in an [AppOverflowMenu]. +class AppMenuAction { + const AppMenuAction({ + required this.value, + required this.label, + this.key, + this.destructive = false, + }); + + final T value; + final String label; + + /// Placed on the menu item (Material) or the sheet action (Cupertino), so a + /// test finds the same item on both hosts. + final Key? key; + + /// Shown in the destructive colour on Cupertino's action sheet. + final bool destructive; +} + +/// The app's one row/header overflow control: the host's "more" icon that +/// opens the row's secondary actions. +/// +/// Material shows a [PopupMenuButton] with [Icons.more_vert]; Cupertino shows +/// a [CupertinoButton] with [CupertinoIcons.ellipsis] that opens a +/// [CupertinoActionSheet] (with Cancel). Every list row and the run header use +/// this, so the overflow icon reads the same everywhere on a host. +class AppOverflowMenu extends StatelessWidget { + const AppOverflowMenu({ + super.key, + required this.actions, + required this.onSelected, + this.label = 'More actions', + this.sheetTitle, + this.enabled = true, + this.cupertino, + }); + + final List> actions; + + /// Called with the picked value once the menu or sheet has closed. + final void Function(BuildContext context, T value) onSelected; + + /// Tooltip (Material) and accessible label (both hosts). + final String label; + + /// The Cupertino sheet's title, usually the row's name. + final String? sheetTitle; + + final bool enabled; + + /// Overrides the host detection (some features pick a style per platform). + final bool? cupertino; + + @override + Widget build(BuildContext context) { + if (actions.isEmpty) return const SizedBox.shrink(); + if (!(cupertino ?? usesCupertinoHost(context))) { + return PopupMenuButton( + icon: const Icon(Icons.more_vert), + tooltip: label, + enabled: enabled, + onSelected: (value) => onSelected(context, value), + itemBuilder: (_) => [ + for (final action in actions) + PopupMenuItem( + key: action.key, + value: action.value, + child: Text(action.label), + ), + ], + ); + } + // Its own node, so a row's merged label never swallows the button. + return Semantics( + container: true, + button: true, + enabled: enabled, + label: label, + excludeSemantics: true, + child: CupertinoButton( + padding: EdgeInsets.zero, + minimumSize: const Size.square(kMinInteractiveDimensionCupertino), + onPressed: enabled ? () => _showSheet(context) : null, + child: const Icon(CupertinoIcons.ellipsis), + ), + ); + } + + Future _showSheet(BuildContext context) async { + final picked = await showCupertinoModalPopup( + context: context, + builder: (sheet) => CupertinoActionSheet( + title: sheetTitle == null ? null : Text(sheetTitle!), + actions: [ + for (final action in actions) + CupertinoActionSheetAction( + key: action.key, + isDestructiveAction: action.destructive, + onPressed: () => Navigator.of(sheet).pop(action.value), + child: Text(action.label), + ), + ], + cancelButton: CupertinoActionSheetAction( + isDefaultAction: true, + onPressed: () => Navigator.of(sheet).pop(), + child: const Text('Cancel'), + ), + ), + ); + if (picked != null && context.mounted) onSelected(context, picked); + } +} diff --git a/app/notes/app-list-row.md b/app/notes/app-list-row.md new file mode 100644 index 00000000..2f7e0196 --- /dev/null +++ b/app/notes/app-list-row.md @@ -0,0 +1,130 @@ +# One shared list row (style review batch 3: F6, F8 results, F16) + +Before this change Runs, Pipelines, Chat, Search results and Schedules each drew +rows differently (see `/tmp/app-style-review/report.md`). They now all use one +component, on both hosts. + +## Shared pieces (`lib/ui/layout/`) + +- `app_list_row.dart`, `AppListRow`: the leading slot, then a bold one-line + `title` with `time` on the same line (the time takes at most 40% of the + line), then one muted `subtitle` line with an optional `subtitleLeading` + (status dot) and `subtitleTrailing` (unread dot), then an optional `menu`. + - Styles come from the host's type scale. Material: title `titleMedium` w600 + (letter spacing 0), subtitle `bodyMedium`, time `bodySmall`, all in + `onSurfaceVariant`. Cupertino: title `textStyle` w600, subtitle and time + 15pt `secondaryLabel`. + - `selected`: Material `secondaryContainer` (title in + `onSecondaryContainer`), Cupertino `tertiarySystemFill`. + `AppListRow.selectedColor` gives the fill. Semantics are a container with + `selected` and `button`. + - `emphasized` (unread or attention): w700 title, accent time in w600. + - Tapping: Material uses `InkWell` on a `Material` surface. Cupertino uses a + `GestureDetector` that highlights `systemGrey4` while pressed, like a table + cell, and fades nothing. `tapKey` goes on the tap target. + - `divider` (default true): a hairline inset to the start of the text column. + Cupertino uses `separator` at 1 physical pixel; Material uses + `outlineVariant` at 1. Lists turn it off for the last row of a group. + - Compact mode: when the row is narrower than `kAppListRowCompactWidth` + (280), it drops the avatar, the time and the menu, and shows + `compactSubtitle` if one is given. `keepMenuWhenCompact` keeps the menu + (chat, pipeline schedules). + - No fixed heights. Padding is 16 horizontal and 10 vertical. At 2x text in + a 320px row everything ellipsises without overflowing. + - Test keys: `appListRowSurfaceKey` and `appListRowDividerKey`. +- `app_list_avatar.dart` + - `AppListAvatar` is a 40px circle (the `CircleAvatar` default) holding an + icon (22) or text. The circle is filled with the foreground at 14%, or a + neutral fill when there is no foreground. An optional corner `badge` is + supported. The glyph scales down to stay inside the circle at large text. + - `AppListAvatar.initial` shows the first letter in 18pt w700. It replaces + the pipelines initial that used to read as an empty circle. + - `AppListStatusDot` is a small dot that follows text scaling and can carry a + semantics label. +- `app_overflow_menu.dart`: `AppOverflowMenu` and `AppMenuAction` give the + app one overflow control. Material uses a `PopupMenuButton` with + `Icons.more_vert`. Cupertino uses a `CupertinoButton` with + `CupertinoIcons.ellipsis` that opens a `CupertinoActionSheet` with Cancel. + Item keys sit on the popup items or sheet actions on both hosts. Used by the + run menu (list rows and the run detail header), chat rows, search artifact + hits and pipeline schedule rows. + +## Migrated + +- Runs (`runs/ui/runs_list.dart`): `RunListRow` is a thin `AppListRow`. Its + leading slot is the status avatar. Rows are separated by inset dividers, + with no divider before a day heading. The key `run-row-` is now on the + row. `run-list-more-menu-` and the menu item keys are unchanged. + `run-row-surface-` is gone; use `appListRowSurfaceKey`. The run detail's + menu uses the same control, so its Cupertino icon changed from + `ellipsis_circle` to `ellipsis`. +- Pipelines (`pipelines/widgets/pipeline_list_panel.dart`): one list for both + hosts. The Cupertino inset-grouped section and the full-width Material + dividers are gone, and so is the chevron. The legible initial avatar keeps + the key `pipeline-avatar-`. The latest-run dot is now + `AppListStatusDot`, keeping `pipeline-status-`. Compact rows show the + latest state word. The compact threshold moved from 220 to 280. +- Chat (`chat/ui/sessions/session_row_content.dart` `ChatSessionRow`, used by + both `session_list_material.dart` and `session_list_cupertino.dart`): the + separate Material `ListTile` and Cupertino `CupertinoListTile` rows are gone. + The Cupertino list no longer uses inset groups; a directory header is now a + small grey label. All keys are kept: `chat-row-`, `chat-actions-`, + `chat-row-unread`, `chat-row-working` and `chat-row-starred`. Titles are now + w600, or w700 when unread (they were w500/w700). The menu stays when compact. +- Chat in the shell (`chat/screen.dart`): the `BelowTopBar` wrapper is + removed. The list pads itself by the bar height (Material through default + `ListView` padding, Cupertino explicitly), so it scrolls behind the bar like + the other lists. +- Search (`search/ui/search_result_row.dart` `SearchResultRow`, used by both + bodies): the leading slot is the kind icon in an avatar, or the image + thumbnail, now 40px. The recency is the time. The line starts with the kind + in bold ("Field · …"), then shows the snippet with the match in bold. + `SearchKindTag`, the two-line title and the Cupertino inset group are gone. + Artifact hits keep `search.actions.` and the tooltip "Open…". +- Schedules list (`schedules/ui/list/schedule_list_row.dart`): the six-line + block is now two lines. The clock avatar is green when enabled and grey when + paused, and also carries the status as its semantics label. The time is + `scheduleNextDueShort` ("22 Oct 09:00" or "Paused"). The line shows the + timer and the pipeline/version. The prompt, workspace, timezone and exact + due time are left to the editor the row opens. The list stays read-only and + has no menu: its tests require no Edit/Pause/Delete, and the list controller + has no mutations. +- Pipeline Summary schedules (`schedules/ui/pipeline/schedule_pipeline_row.dart`): + the same two lines, with the line "v2 · Every 24h · mon · Europe/London". + The inline Edit, Pause/Enable and Delete text buttons moved into an overflow + menu under a new key, `scheduleRowMenuKey(id)`. The item keys + `scheduleRowEditKey`, `scheduleRowToggleKey` and `scheduleRowDeleteKey` are + kept, and Delete is destructive. A busy row disables its menu and tap. A tap + on the row edits it. A refusal appears under the row with + `scheduleRowErrorKey`. + +## Tests + +- New: `test/ui/layout/app_list_row_test.dart` covers both hosts. It checks + the layout order, inset divider, tap, menu icon and items, the selected and + emphasised styles, compact mode, `keepMenuWhenCompact`, 320px at 2x in light + and dark, and the initial avatar. +- Updated for intentional changes: `list_detail_consistency_test`, + `pipelines_destination_test`, `chat_list_detail_test`, + `chat_active_selection_test`, `chat_session_row_layout_test`, + `chat_session_row_material_test`, `pipeline_list_composition_test` (inset + divider and legible avatar), `pipelines_adaptive_test`, + `pipelines_screen_test`, `pipeline_summary_schedules_test`, + `schedules_layout_test`, `schedule_pipeline_section_test` (actions open + through the menu) and `search_bar_layout_test`. + +## Evidence + +The captures are in `/tmp/wave2-d-evidence/`. They were taken with headless +Chrome using the reviewer's driver (a copy pointed at this worktree's tool +directory). The sources were: + +- `lib/main.dart` over the runs and pipelines fixture servers; +- the new `tool/app_host_probe_entry.dart`, which is the same composition with + `?host=cupertino`; +- `tool/chat_sessions_probe_entry.dart`, `tool/schedules_list_probe_app.dart`, + `tool/schedule_pipeline_probe_app.dart` and + `tool/search_selection_probe_entry.dart`. + +The captures were taken at 560 and 1200, in light and dark, on Material and +Cupertino. There was no device run, so Android and iOS are unverified. diff --git a/app/test/application/list_detail_consistency_test.dart b/app/test/application/list_detail_consistency_test.dart index 8ce214b7..ddc34efd 100644 --- a/app/test/application/list_detail_consistency_test.dart +++ b/app/test/application/list_detail_consistency_test.dart @@ -3,6 +3,7 @@ import 'dart:ui' show Tristate; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:pipelines_app/features/chat/screen.dart'; import 'package:pipelines_app/features/pipelines/screen.dart'; @@ -175,39 +176,24 @@ void main() { selected, reason: '$destination: $rowKey after opening $key', ); + // Every list uses the shared row and its highlight. final context = tester.element(row); - if (cupertino) { - final color = destination == 'Runs' - ? tester.widget(row).color - : tester.widget(row).backgroundColor; - expect( - color, - selected - ? CupertinoColors.tertiarySystemFill.resolveFrom( - context, - ) - : isNull, - ); - } else if (destination == 'Runs') { - final id = rowKey.split('-').last; - expect( - tester - .widget( - find.byKey(ValueKey('run-row-surface-$id')), + expect(tester.widget(row).selected, selected); + final surface = find.descendant( + of: row, + matching: find.byKey(appListRowSurfaceKey), + ); + expect( + cupertino + ? tester.widget(surface).color + : tester.widget(surface).color, + selected + ? AppListRow.selectedColor( + context, + cupertino: cupertino, ) - .color, - selected - ? Theme.of(context).colorScheme.secondaryContainer - : Colors.transparent, - ); - } else { - final tile = tester.widget(row); - expect(tile.selected, selected); - expect( - tile.selectedTileColor, - Theme.of(context).colorScheme.secondaryContainer, - ); - } + : const Color(0x00000000), + ); } } if (destination == 'Chat') { diff --git a/app/test/application/pipelines_destination_test.dart b/app/test/application/pipelines_destination_test.dart index 65010f09..cf310906 100644 --- a/app/test/application/pipelines_destination_test.dart +++ b/app/test/application/pipelines_destination_test.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/application/app_session.dart'; import 'package:pipelines_app/application/pipelines_destination.dart'; import 'package:pipelines_app/application/server_endpoint.dart'; @@ -202,7 +203,9 @@ void main() { await tester.pump(); expect(find.text('hash-alpha'), findsOneWidget); expect( - tester.widget(find.byKey(const Key('pipeline-row-1'))).selected, + tester + .widget(find.byKey(const Key('pipeline-row-1'))) + .selected, isTrue, ); @@ -229,7 +232,9 @@ void main() { expect(find.text('Reconnecting to Pipelines…'), findsNothing); expect(find.text('hash-alpha'), findsOneWidget); expect( - tester.widget(find.byKey(const Key('pipeline-row-1'))).selected, + tester + .widget(find.byKey(const Key('pipeline-row-1'))) + .selected, isTrue, reason: 'A reconnect must not remount the screen or drop the selection.', ); diff --git a/app/test/features/chat/chat_list_detail_test.dart b/app/test/features/chat/chat_list_detail_test.dart index 063c47be..523f2841 100644 --- a/app/test/features/chat/chat_list_detail_test.dart +++ b/app/test/features/chat/chat_list_detail_test.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart'; import 'package:pipelines_app/core/api_gateway.dart'; @@ -53,7 +54,7 @@ void main() { await _pumpShell(tester, size); expect(find.text('Select a chat to open it here.'), findsOneWidget); expect( - tester.widget(find.byKey(const Key('chat-row-a'))).selected, + tester.widget(find.byKey(const Key('chat-row-a'))).selected, isFalse, ); @@ -66,11 +67,11 @@ void main() { expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget); expect(find.text('Second chat'), findsOneWidget); expect( - tester.widget(find.byKey(const Key('chat-row-a'))).selected, + tester.widget(find.byKey(const Key('chat-row-a'))).selected, isTrue, ); expect( - tester.widget(find.byKey(const Key('chat-row-b'))).selected, + tester.widget(find.byKey(const Key('chat-row-b'))).selected, isFalse, ); // The shell bar keeps the list's controls; the pane bar has the chat's @@ -91,11 +92,11 @@ void main() { expect(find.byKey(const ValueKey('chat-thread-a')), findsNothing); expect(find.byKey(const ValueKey('chat-thread-b')), findsOneWidget); expect( - tester.widget(find.byKey(const Key('chat-row-a'))).selected, + tester.widget(find.byKey(const Key('chat-row-a'))).selected, isFalse, ); expect( - tester.widget(find.byKey(const Key('chat-row-b'))).selected, + tester.widget(find.byKey(const Key('chat-row-b'))).selected, isTrue, ); expect(navigator.canPop(), isFalse); @@ -123,7 +124,7 @@ void main() { await tester.pageBack(); await tester.pumpAndSettle(); expect( - tester.widget(find.byKey(const Key('chat-row-a'))).selected, + tester.widget(find.byKey(const Key('chat-row-a'))).selected, isFalse, ); diff --git a/app/test/features/chat/ui/sessions/chat_active_selection_test.dart b/app/test/features/chat/ui/sessions/chat_active_selection_test.dart index 7f6b9658..aa9fe47b 100644 --- a/app/test/features/chat/ui/sessions/chat_active_selection_test.dart +++ b/app/test/features/chat/ui/sessions/chat_active_selection_test.dart @@ -3,6 +3,7 @@ import 'dart:ui' show Tristate; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart'; import 'chat_test_harness.dart'; @@ -59,24 +60,23 @@ void main() { Tristate.isTrue, active, ); - if (cupertino) { - final tile = tester.widget(row); - expect( - tile.backgroundColor, - active - ? CupertinoColors.tertiarySystemFill.resolveFrom( - tester.element(row), - ) - : isNull, - ); - } else { - final tile = tester.widget(row); - expect(tile.selected, active); - expect( - tile.selectedTileColor, - Theme.of(tester.element(row)).colorScheme.secondaryContainer, - ); - } + expect(tester.widget(row).selected, active); + final surface = find.descendant( + of: row, + matching: find.byKey(appListRowSurfaceKey), + ); + final color = cupertino + ? tester.widget(surface).color + : tester.widget(surface).color; + expect( + color, + active + ? AppListRow.selectedColor( + tester.element(row), + cupertino: cupertino, + ) + : const Color(0x00000000), + ); } expectRow('a', true); diff --git a/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart b/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart index 88ab20a8..483ab04c 100644 --- a/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart @@ -1,12 +1,13 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_cupertino.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_row_style.dart'; -/// A grouped Cupertino list, the host the web client runs on macOS/iOS. +/// The Cupertino list, the host the web client runs on macOS/iOS. Future _pumpRows( WidgetTester tester, List sessions, { @@ -193,7 +194,7 @@ void main() { // Unread is bold with an accent time and dot; read rows are not. expect(_styleOf(tester, 'Unread chat').fontWeight, FontWeight.w700); - expect(_styleOf(tester, 'Read chat').fontWeight, FontWeight.w500); + expect(_styleOf(tester, 'Read chat').fontWeight, FontWeight.w600); expect(find.byKey(const Key('chat-row-unread')), findsOneWidget); final accent = CupertinoTheme.of( tester.element(find.text('5 min ago')), @@ -216,10 +217,10 @@ void main() { ), findsOneWidget, ); - expect(find.byType(CupertinoListTile), findsNWidgets(2)); + expect(find.byType(AppListRow), findsNWidgets(2)); expect( tester.getTopLeft(find.byKey(const Key('chat-row-s2'))).dy, - greaterThan( + greaterThanOrEqualTo( tester.getBottomLeft(find.byKey(const Key('chat-row-s1'))).dy, ), ); diff --git a/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart b/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart index 1c126c6c..03f05607 100644 --- a/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_list_material.dart'; import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart'; import 'expand_closed.dart'; -/// The Android host: a Material grouped list with its native separators. +/// The Android host: the Material list with the shared row's dividers. Future _pumpRows( WidgetTester tester, List sessions, { @@ -107,11 +108,16 @@ void main() { findsOneWidget, ); - // Native Material separators sit between rows, not around the group. - expect(find.byType(Divider), findsOneWidget); + // One inset divider between the rows, none after the last; it starts + // under the text, not at the edge. + expect(find.byKey(appListRowDividerKey), findsOneWidget); + expect( + tester.getTopLeft(find.byKey(appListRowDividerKey)).dx, + closeTo(title.left, 1), + ); expect( tester.getTopLeft(find.byKey(const Key('chat-row-s2'))).dy, - greaterThan( + greaterThanOrEqualTo( tester.getBottomLeft(find.byKey(const Key('chat-row-s1'))).dy, ), ); diff --git a/app/test/features/pipelines/pipeline_list_composition_test.dart b/app/test/features/pipelines/pipeline_list_composition_test.dart index 3590c662..858b6b1b 100644 --- a/app/test/features/pipelines/pipeline_list_composition_test.dart +++ b/app/test/features/pipelines/pipeline_list_composition_test.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/features/pipelines/screen.dart'; import 'package:pipelines_app/shell/detail_page.dart'; @@ -24,17 +25,32 @@ void main() { // Filter and sort are app-bar actions; no toolbar row without a filter. expect(find.byKey(const Key('pipeline-toolbar')), findsNothing); // Each pipeline has a deterministic tinted initial rather than one generic - // flow icon, while the title follows native ListTile spacing. + // flow icon, while the title follows the shared row's spacing. expect(find.byKey(const Key('pipeline-avatar-1')), findsOneWidget); expect( tester.getTopLeft(find.text('Alpha review')).dx, greaterThan(listLeft), ); + // Inset dividers between rows, none after the last. expect( - find.descendant(of: list, matching: find.byType(Divider)), + find.descendant(of: list, matching: find.byKey(appListRowDividerKey)), findsNWidgets(fixture.summaries.length - 1), ); + // The divider starts under the title, not at the list edge. + expect( + tester.getTopLeft(find.byKey(appListRowDividerKey).first).dx, + closeTo(tester.getTopLeft(find.text('Alpha review')).dx, 1), + ); + // The initial is legible: a 40px circle with a large glyph. + final avatar = find.byKey(const Key('pipeline-avatar-1')); + expect(tester.getSize(avatar), const Size.square(40)); + expect( + tester + .getSize(find.descendant(of: avatar, matching: find.text('A'))) + .height, + greaterThanOrEqualTo(14), + ); // The title's trailing time and the one muted facts line replace the old // version/id, run metadata, and graph stack. @@ -196,7 +212,7 @@ void main() { expect(tester.takeException(), isNull); }); - testWidgets('Cupertino keeps native tiles with the same row identity', ( + testWidgets('Cupertino keeps the shared row with the same row identity', ( tester, ) async { debugDefaultTargetPlatformOverride = TargetPlatform.iOS; @@ -211,7 +227,12 @@ void main() { ); await tester.pumpAndSettle(); - expect(find.byType(CupertinoListTile), findsWidgets); + expect( + tester + .widget(find.byKey(const Key('pipeline-row-1'))) + .cupertino, + isTrue, + ); expect(find.text('2 stages · 1 schedule'), findsOneWidget); expect(find.textContaining('v2 · #'), findsNothing); expect(find.byKey(const Key('pipeline-avatar-1')), findsOneWidget); diff --git a/app/test/features/pipelines/pipeline_summary_schedules_test.dart b/app/test/features/pipelines/pipeline_summary_schedules_test.dart index d40b575c..afe6179e 100644 --- a/app/test/features/pipelines/pipeline_summary_schedules_test.dart +++ b/app/test/features/pipelines/pipeline_summary_schedules_test.dart @@ -61,13 +61,18 @@ void main() { expect(find.text('Schedules (1)'), findsOneWidget); expect(find.text('Research batteries'), findsOneWidget); expect( - find.text('Every 24h · mon, wed · Europe/London'), + find.text('v3 · Every 24h · mon, wed · Europe/London'), findsOneWidget, ); expect(find.byKey(scheduleAddKey), findsOneWidget); + // Edit, Pause and Delete are the row's overflow menu. + await tester.tap(find.byKey(scheduleRowMenuKey(8))); + await tester.pumpAndSettle(); expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget); expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget); expect(find.byKey(scheduleRowDeleteKey(8)), findsOneWidget); + await tester.tapAt(const Offset(4, 4)); + await tester.pumpAndSettle(); expect(gateway.callsOf('list_schedules').single.fields, {'pipeline_id': 1}); await tester.tap(find.text('Source')); diff --git a/app/test/features/pipelines/pipelines_adaptive_test.dart b/app/test/features/pipelines/pipelines_adaptive_test.dart index d318b050..ddb8bfe6 100644 --- a/app/test/features/pipelines/pipelines_adaptive_test.dart +++ b/app/test/features/pipelines/pipelines_adaptive_test.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import '../../native_back.dart'; import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart'; import 'package:pipelines_app/features/pipelines/pipeline_repository.dart'; @@ -122,7 +123,13 @@ void main() { await tester.pumpAndSettle(); expect(find.byType(CupertinoPageScaffold), findsOneWidget); - expect(find.byType(CupertinoListTile), findsWidgets); + // The shared list row, in its Cupertino form. + expect( + tester + .widget(find.byKey(const Key('pipeline-row-1'))) + .cupertino, + isTrue, + ); expect(find.byType(CupertinoActionSheet), findsNothing); await tester.tap(find.byKey(const Key('pipeline-row-1'))); await tester.pumpAndSettle(); diff --git a/app/test/features/pipelines/pipelines_screen_test.dart b/app/test/features/pipelines/pipelines_screen_test.dart index 6f3fcec3..cb8a146b 100644 --- a/app/test/features/pipelines/pipelines_screen_test.dart +++ b/app/test/features/pipelines/pipelines_screen_test.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/pipelines/screen.dart'; @@ -129,7 +130,7 @@ void main() { await tester.tap(find.byTooltip('Refresh')); await tester.pumpAndSettle(); - final row = tester.widget( + final row = tester.widget( find.byKey(const Key('pipeline-row-1')), ); expect(row.selected, isTrue); diff --git a/app/test/features/schedules/ui/list/schedules_layout_test.dart b/app/test/features/schedules/ui/list/schedules_layout_test.dart index 374802c1..ad53a690 100644 --- a/app/test/features/schedules/ui/list/schedules_layout_test.dart +++ b/app/test/features/schedules/ui/list/schedules_layout_test.dart @@ -30,16 +30,15 @@ void main() { expect(find.text('2 schedules'), findsOneWidget); expect(find.textContaining('not pipeline definitions'), findsOneWidget); + // Two lines per row: the name with its next run, then the timer + // and pinned pipeline version. The editor holds the rest. expect(find.text('Research batteries'), findsOneWidget); - expect(find.text('Find battery chemistry sources'), findsOneWidget); - expect(find.text('Pipeline 4 · v2'), findsOneWidget); - expect(find.text('Workspace: /srv/research'), findsOneWidget); - expect(find.text('Timer: Every 24h · mon, wed'), findsOneWidget); - expect(find.text('Timezone: Europe/London'), findsOneWidget); + expect(find.text('22 Oct 09:00'), findsOneWidget); expect( - find.text('Next due: 2026-10-22 09:00 (your local time)'), + find.text('Every 24h · mon, wed · Pipeline 4 · v2'), findsOneWidget, ); + expect(find.text('Find battery chemistry sources'), findsNothing); await tester.scrollUntilVisible( find.text('Nightly report'), @@ -50,11 +49,8 @@ void main() { ), ); expect(find.text('Nightly report'), findsOneWidget); - expect(find.text('Pipeline 7 · v5'), findsOneWidget); - expect(find.text('Workspace: /srv/reports'), findsOneWidget); - expect(find.text('Timer: 10:00, 18:30'), findsOneWidget); - expect(find.text('Timezone: Server timezone'), findsOneWidget); - expect(find.text('Next due: Paused'), findsOneWidget); + expect(find.text('10:00, 18:30 · Pipeline 7 · v5'), findsOneWidget); + expect(find.text('Paused'), findsOneWidget); if (cupertino) { expect(find.byType(CupertinoSearchTextField), 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 f22edb0b..b6cad9b2 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 @@ -18,6 +18,20 @@ Future _tapSave(WidgetTester tester) async { await tester.pumpAndSettle(); } +/// Edit, Pause/Enable and Delete live in the row's overflow menu. +Future _openMenu(WidgetTester tester, int id) async { + await tester.ensureVisible(find.byKey(scheduleRowMenuKey(id))); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(scheduleRowMenuKey(id))); + await tester.pumpAndSettle(); +} + +Future _pick(WidgetTester tester, Key item, int id) async { + await _openMenu(tester, id); + await tester.tap(find.byKey(item)); + await tester.pumpAndSettle(); +} + void main() { testWidgets('lists this pipeline schedules with server values and states', ( tester, @@ -46,21 +60,24 @@ void main() { expect(find.text('Schedules (2)'), findsOneWidget); expect(find.text('Research batteries'), findsOneWidget); + // Two lines: the name with its next run, then version and timer words. expect( - find.text('Every 24h · mon, wed · Europe/London'), + find.text('v2 · Every 24h · mon, wed · Europe/London'), findsOneWidget, ); - expect(find.text('Paused'), findsWidgets); expect(find.text('Nightly report'), findsOneWidget); - expect( - find.text('10:00, 18:30 · Server timezone'), - findsOneWidget, - ); - expect(find.text('Enabled'), findsOneWidget); - expect(find.text('Paused'), findsWidgets); - expect(find.text('Paused'), findsWidgets); - expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget); + expect(find.text('v5 · 10:00, 18:30 · Server timezone'), findsOneWidget); + expect(find.bySemanticsLabel(RegExp('Enabled')), findsOneWidget); + expect(find.bySemanticsLabel(RegExp('Paused')), findsOneWidget); + expect(find.text('Paused'), findsOneWidget); + // The prompt and the inline text buttons are gone from the row. + expect(find.text('Edit'), findsNothing); + expect(find.byKey(scheduleRowMenuKey(8)), findsOneWidget); + await _openMenu(tester, 9); + expect(find.byKey(scheduleRowEditKey(9)), findsOneWidget); expect(find.byKey(scheduleRowToggleKey(9)), findsOneWidget); + expect(find.text('Enable'), findsOneWidget); + expect(find.byKey(scheduleRowDeleteKey(9)), findsOneWidget); expect(gateway.calls.map((call) => call.type), ['list_schedules']); expect(gateway.calls.single.fields, {'pipeline_id': 4}); }); @@ -187,7 +204,7 @@ void main() { }); await pumpScheduleSection(tester, gateway: gateway); - await tester.tap(find.byKey(scheduleRowEditKey(8))); + await _pick(tester, scheduleRowEditKey(8), 8); await tester.pumpAndSettle(); expect( tester @@ -238,14 +255,14 @@ void main() { }); await pumpScheduleSection(tester, gateway: gateway); - await tester.tap(find.byKey(scheduleRowToggleKey(8))); + await _pick(tester, scheduleRowToggleKey(8), 8); await tester.pumpAndSettle(); 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'), findsWidgets); - expect(find.text('Paused'), findsWidgets); + expect(find.text('Paused'), findsOneWidget); + await _openMenu(tester, 8); expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget); expect(find.text('Enable'), findsOneWidget); expect(gateway.calls.map((call) => call.type), [ @@ -264,11 +281,12 @@ void main() { }); await pumpScheduleSection(tester, gateway: gateway); - await tester.tap(find.byKey(scheduleRowToggleKey(8))); + await _pick(tester, scheduleRowToggleKey(8), 8); await tester.pumpAndSettle(); expect(find.byKey(scheduleRowErrorKey(8)), findsOneWidget); expect(find.text('conflict: revision 3 is stale'), findsOneWidget); + await _openMenu(tester, 8); expect(find.text('Pause'), findsOneWidget); expect(gateway.callsOf('list_schedules'), hasLength(1)); }); @@ -291,7 +309,7 @@ void main() { }); await pumpScheduleSection(tester, gateway: gateway); - await tester.tap(find.byKey(scheduleRowDeleteKey(8))); + await _pick(tester, scheduleRowDeleteKey(8), 8); await tester.pumpAndSettle(); expect(find.text('Delete Research batteries?'), findsOneWidget); expect( @@ -304,7 +322,7 @@ void main() { await tester.pumpAndSettle(); expect(gateway.callsOf('delete_schedule'), isEmpty); - await tester.tap(find.byKey(scheduleRowDeleteKey(8))); + await _pick(tester, scheduleRowDeleteKey(8), 8); await tester.pumpAndSettle(); await tester.tap(find.byKey(scheduleDeleteConfirmKey)); await tester.pumpAndSettle(); @@ -333,7 +351,7 @@ void main() { }); await pumpScheduleSection(tester, gateway: gateway); - await tester.tap(find.byKey(scheduleRowDeleteKey(8))); + await _pick(tester, scheduleRowDeleteKey(8), 8); await tester.pumpAndSettle(); await tester.tap(find.byKey(scheduleDeleteConfirmKey)); await tester.pumpAndSettle(); @@ -392,10 +410,10 @@ void main() { expect(tester.takeException(), isNull); expect(find.byKey(scheduleAddKey), findsOneWidget); - await tester.ensureVisible(find.byKey(scheduleRowDeleteKey(8))); - await tester.pumpAndSettle(); + await _openMenu(tester, 8); expect(find.byKey(scheduleRowEditKey(8)), findsOneWidget); expect(find.byKey(scheduleRowToggleKey(8)), findsOneWidget); + expect(find.byKey(scheduleRowDeleteKey(8)), findsOneWidget); expect(tester.takeException(), isNull); } }); diff --git a/app/test/features/search/search_bar_layout_test.dart b/app/test/features/search/search_bar_layout_test.dart index 1755044a..51b49e89 100644 --- a/app/test/features/search/search_bar_layout_test.dart +++ b/app/test/features/search/search_bar_layout_test.dart @@ -5,7 +5,7 @@ import 'package:pipelines_app/features/search/search_screen.dart'; import 'package:pipelines_app/features/search/ui/search_bar_controls.dart'; import 'package:pipelines_app/features/search/ui/search_bounds_note.dart'; import 'package:pipelines_app/features/search/ui/search_layout.dart'; -import 'package:pipelines_app/features/search/ui/search_result_view.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; import 'search_screen_test.dart' @@ -95,7 +95,7 @@ void main() { expect(find.textContaining('Results truncated'), findsOneWidget); }); - testWidgets('$host: rows show a bold title, a kind tag and one line', ( + testWidgets('$host: rows are the shared row: title, kind-led line', ( tester, ) async { _size(tester, 390); @@ -110,8 +110,10 @@ void main() { final row = find.byKey(const ValueKey('search.result.run:11:4:output')); expect(row, findsOneWidget); + expect(tester.widget(row).cupertino, cupertino); + // The kind leads the one muted line, before the snippet. expect( - find.descendant(of: row, matching: find.byType(SearchKindTag)), + find.descendant(of: row, matching: find.textContaining('Field · ')), findsOneWidget, ); expect( diff --git a/app/test/ui/layout/app_list_row_test.dart b/app/test/ui/layout/app_list_row_test.dart new file mode 100644 index 00000000..d10b3dd9 --- /dev/null +++ b/app/test/ui/layout/app_list_row_test.dart @@ -0,0 +1,281 @@ +import 'dart:ui' show Tristate; + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/layout/app_list_avatar.dart'; +import 'package:pipelines_app/ui/layout/app_list_row.dart'; +import 'package:pipelines_app/ui/layout/app_overflow_menu.dart'; + +const _longTitle = 'A row title long enough that it must ellipsise somewhere'; +const _longLine = 'a muted line of facts that is far too long for one line'; + +Widget _host(bool cupertino, Widget child, {Brightness? brightness}) { + final body = ListView(children: [child]); + return cupertino + ? CupertinoApp( + theme: CupertinoThemeData(brightness: brightness), + home: CupertinoPageScaffold(child: body), + ) + : MaterialApp( + theme: ThemeData(brightness: brightness ?? Brightness.light), + home: Scaffold(body: body), + ); +} + +void _size(WidgetTester tester, double width, {double textScale = 1}) { + tester.view.physicalSize = Size(width, 800); + tester.view.devicePixelRatio = 1; + tester.platformDispatcher.textScaleFactorTestValue = textScale; + addTearDown(tester.view.reset); + addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue); +} + +AppListRow _row({ + String title = 'Fixture run', + String? time = '9d ago', + bool selected = false, + bool emphasized = false, + bool divider = true, + VoidCallback? onTap, + void Function(String)? onPicked, +}) => AppListRow( + key: const Key('row'), + selected: selected, + emphasized: emphasized, + divider: divider, + onTap: onTap ?? () {}, + leading: const AppListAvatar( + key: Key('avatar'), + child: Icon(Icons.play_arrow), + ), + title: Text(title), + time: time, + subtitle: const Text('pipeline · 2 stages'), + compactSubtitle: const Text('Running'), + subtitleLeading: const AppListStatusDot( + key: Key('dot'), + color: Color(0xFF00AA00), + semanticLabel: 'Running', + ), + menu: AppOverflowMenu( + key: const Key('menu'), + sheetTitle: title, + actions: const [ + AppMenuAction(key: Key('menu-rename'), value: 'rename', label: 'Rename'), + AppMenuAction( + key: Key('menu-delete'), + value: 'delete', + label: 'Delete', + destructive: true, + ), + ], + onSelected: (_, value) => onPicked?.call(value), + ), +); + +TextStyle _paint(WidgetTester tester, String text) => + tester.renderObject(find.textContaining(text)).text.style!; + +void main() { + for (final cupertino in [false, true]) { + final host = cupertino ? 'Cupertino' : 'Material'; + + testWidgets('$host: avatar, title with time, one line, menu, divider', ( + tester, + ) async { + _size(tester, 560); + var taps = 0; + String? picked; + await tester.pumpWidget( + _host( + cupertino, + _row(onTap: () => taps++, onPicked: (value) => picked = value), + ), + ); + + final avatar = tester.getRect(find.byKey(const Key('avatar'))); + final title = tester.getRect(find.text('Fixture run')); + final time = tester.getRect(find.text('9d ago')); + final line = tester.getRect(find.text('pipeline · 2 stages')); + final menu = tester.getRect(find.byKey(const Key('menu'))); + expect(avatar.size, const Size.square(kAppListAvatarSize)); + expect(avatar.right, lessThanOrEqualTo(title.left)); + expect(time.left, greaterThan(title.right - 1)); + expect(time.center.dy, closeTo(title.center.dy, 3)); + expect(line.top, greaterThanOrEqualTo(title.bottom - 1)); + expect(menu.left, greaterThanOrEqualTo(time.right)); + expect(find.byKey(const Key('dot')), findsOneWidget); + // The title is bold, the line muted and smaller. + expect(_paint(tester, 'Fixture run').fontWeight, FontWeight.w600); + expect( + _paint(tester, 'pipeline').fontSize!, + lessThan(_paint(tester, 'Fixture run').fontSize!), + ); + // The inset divider starts under the text column. + final divider = tester.getRect(find.byKey(appListRowDividerKey)); + expect(divider.left, closeTo(title.left, 1)); + + await tester.tap(find.text('Fixture run')); + await tester.pumpAndSettle(); + expect(taps, 1); + + // One overflow icon per host; the menu items keep their keys. + expect( + find.descendant( + of: find.byKey(const Key('menu')), + matching: find.byIcon( + cupertino ? CupertinoIcons.ellipsis : Icons.more_vert, + ), + ), + findsOneWidget, + ); + await tester.tap(find.byKey(const Key('menu'))); + await tester.pumpAndSettle(); + expect(taps, 1, reason: 'the menu is its own control'); + if (cupertino) { + expect(find.byType(CupertinoActionSheet), findsOneWidget); + expect(find.text('Cancel'), findsOneWidget); + } else { + expect(find.byType(PopupMenuItem), findsNWidgets(2)); + } + await tester.tap(find.byKey(const Key('menu-delete'))); + await tester.pumpAndSettle(); + expect(picked, 'delete'); + }); + + testWidgets('$host: selected and emphasised rows', (tester) async { + _size(tester, 560); + await tester.pumpWidget( + _host(cupertino, _row(selected: true, emphasized: true)), + ); + final row = find.byKey(const Key('row')); + expect( + tester.getSemantics(row).flagsCollection.isSelected, + Tristate.isTrue, + ); + final surface = find.descendant( + of: row, + matching: find.byKey(appListRowSurfaceKey), + ); + final context = tester.element(row); + expect( + cupertino + ? tester.widget(surface).color + : tester.widget(surface).color, + AppListRow.selectedColor(context, cupertino: cupertino), + ); + final accent = cupertino + ? CupertinoTheme.of(context).primaryColor + : Theme.of(context).colorScheme.primary; + expect(_paint(tester, 'Fixture run').fontWeight, FontWeight.w700); + expect(_paint(tester, '9d ago').color, accent); + + await tester.pumpWidget(_host(cupertino, _row())); + expect( + cupertino + ? tester.widget(surface).color + : tester.widget(surface).color, + const Color(0x00000000), + ); + expect(_paint(tester, '9d ago').color, isNot(accent)); + }); + + testWidgets('$host: a narrow pane drops the avatar, time and menu', ( + tester, + ) async { + _size(tester, 240); + await tester.pumpWidget(_host(cupertino, _row())); + expect(find.byKey(const Key('avatar')), findsNothing); + expect(find.text('9d ago'), findsNothing); + expect(find.byKey(const Key('menu')), findsNothing); + expect(find.text('Running'), findsOneWidget); + expect(find.text('pipeline · 2 stages'), findsNothing); + expect(tester.takeException(), isNull); + }); + + testWidgets('$host: keepMenuWhenCompact keeps the menu', (tester) async { + _size(tester, 240); + await tester.pumpWidget( + _host( + cupertino, + AppListRow( + keepMenuWhenCompact: true, + title: const Text('Chat'), + menu: AppOverflowMenu( + key: const Key('menu'), + actions: const [AppMenuAction(value: 1, label: 'Star')], + onSelected: (_, _) {}, + ), + ), + ), + ); + expect(find.byKey(const Key('menu')), findsOneWidget); + }); + + for (final brightness in Brightness.values) { + testWidgets('$host ${brightness.name}: 320px at 2x text ellipsises ' + 'without overflow', (tester) async { + _size(tester, 320, textScale: 2); + await tester.pumpWidget( + _host( + cupertino, + brightness: brightness, + AppListRow( + key: const Key('row'), + onTap: () {}, + leading: const AppListAvatar( + key: Key('avatar'), + child: Text('P'), + ), + title: const Text(_longTitle), + time: '12 days ago', + subtitle: const Text(_longLine), + menu: AppOverflowMenu( + key: const Key('menu'), + actions: const [AppMenuAction(value: 1, label: 'Star')], + onSelected: (_, _) {}, + ), + ), + ), + ); + expect(tester.takeException(), isNull); + final title = tester.renderObject( + find.text(_longTitle), + ); + expect(title.maxLines, 1); + expect(title.didExceedMaxLines, isTrue); + final line = tester.renderObject(find.text(_longLine)); + expect(line.maxLines, 1); + expect(line.didExceedMaxLines, isTrue); + final row = tester.getRect(find.byKey(const Key('row'))); + expect( + tester.getRect(find.text('12 days ago')).right, + lessThanOrEqualTo(row.right), + ); + // The avatar keeps its size; its glyph scales down inside it. + expect( + tester.getSize(find.byKey(const Key('avatar'))), + const Size.square(kAppListAvatarSize), + ); + expect(find.byKey(const Key('menu')), findsOneWidget); + }); + } + } + + testWidgets('the initial avatar reads the first letter, upper case', ( + tester, + ) async { + await tester.pumpWidget( + MaterialApp( + home: Center( + child: AppListAvatar.initial(' beta flow', color: Colors.teal), + ), + ), + ); + expect(find.text('B'), findsOneWidget); + expect(_paint(tester, 'B').fontSize, 18); + expect(_paint(tester, 'B').fontWeight, FontWeight.w700); + }); +} diff --git a/app/tool/app_host_probe_entry.dart b/app/tool/app_host_probe_entry.dart new file mode 100644 index 00000000..306bbb6a --- /dev/null +++ b/app/tool/app_host_probe_entry.dart @@ -0,0 +1,26 @@ +// The normal application composition with an explicit host, for browser +// captures of the Cupertino app (the web build is Material by design, see +// `prefersCupertino`). +// +// Build and capture (from app/): +// flutter build web --target tool/app_host_probe_entry.dart \ +// -o build/probe-app-host +// serve it with the runs or pipelines fixture server +// (`tool/runs_probe_server.mjs`, `tool/pipelines_wiring_probe_server.mjs`) +// and open `/runs?host=cupertino`; without `host=cupertino` it is Material. +// +// It connects only to the page's own origin, like the web app. +import 'package:flutter/widgets.dart'; +import 'package:pipelines_app/application/app_url_strategy.dart'; +import 'package:pipelines_app/application/pipelines_app.dart'; +import 'package:pipelines_app/application/server_endpoint.dart'; + +void main() { + useAppUrlStrategy(); + runApp( + PipelinesApp( + server: ServerEndpoint.resolve(base: Uri.base, web: true), + cupertino: Uri.base.queryParameters['host'] == 'cupertino', + ), + ); +}