feat(app): chat row refusals can be dismissed with OK
This commit is contained in:
@@ -166,10 +166,18 @@ class ChatCupertinoMessage extends StatelessWidget {
|
||||
/// first few words. Full width also stops a long refusal from turning a single
|
||||
/// Material row into a column taller than the viewport.
|
||||
class ChatRowError extends StatelessWidget {
|
||||
const ChatRowError({super.key, required this.message, this.messageKey});
|
||||
const ChatRowError({
|
||||
super.key,
|
||||
required this.message,
|
||||
this.messageKey,
|
||||
this.onDismiss,
|
||||
});
|
||||
|
||||
final String message;
|
||||
|
||||
/// Clears this refusal; its control reads the web report's `OK`.
|
||||
final VoidCallback? onDismiss;
|
||||
|
||||
/// Key placed on the message paragraph itself, so a test can assert that the
|
||||
/// rendered text did not exceed its line limit.
|
||||
final Key? messageKey;
|
||||
@@ -185,9 +193,30 @@ class ChatRowError extends StatelessWidget {
|
||||
: TextStyle(color: Theme.of(context).colorScheme.error);
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 12),
|
||||
child: DefaultTextStyle.merge(
|
||||
style: style,
|
||||
child: Text(message, key: messageKey),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: DefaultTextStyle.merge(
|
||||
style: style,
|
||||
child: Text(message, key: messageKey),
|
||||
),
|
||||
),
|
||||
if (onDismiss != null)
|
||||
Semantics(
|
||||
button: true,
|
||||
label: 'Dismiss refusal',
|
||||
excludeSemantics: true,
|
||||
child: cupertino
|
||||
? CupertinoButton(
|
||||
padding: const EdgeInsetsDirectional.only(start: 8),
|
||||
minimumSize: Size.zero,
|
||||
onPressed: onDismiss,
|
||||
child: const Text('OK'),
|
||||
)
|
||||
: TextButton(onPressed: onDismiss, child: const Text('OK')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ class ChatSessionsBody extends StatelessWidget {
|
||||
required this.onClearSearch,
|
||||
required this.isUnseen,
|
||||
required this.errorFor,
|
||||
this.onDismissError,
|
||||
});
|
||||
|
||||
final List<JsonMap> sessions;
|
||||
@@ -41,6 +42,7 @@ class ChatSessionsBody extends StatelessWidget {
|
||||
final VoidCallback onClearSearch;
|
||||
final bool Function(JsonMap) isUnseen;
|
||||
final String? Function(String sessionId) errorFor;
|
||||
final ValueChanged<String>? onDismissError;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -89,6 +91,7 @@ class ChatSessionsBody extends StatelessWidget {
|
||||
onClearSearch: clearSearch,
|
||||
isUnseen: isUnseen,
|
||||
errorFor: errorFor,
|
||||
onDismissError: onDismissError,
|
||||
);
|
||||
}
|
||||
return MaterialSessionList(
|
||||
@@ -104,6 +107,7 @@ class ChatSessionsBody extends StatelessWidget {
|
||||
onClearSearch: clearSearch,
|
||||
isUnseen: isUnseen,
|
||||
errorFor: errorFor,
|
||||
onDismissError: onDismissError,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,11 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
/// The row an action failed on; the message is the server's own words.
|
||||
String? errorFor(String sessionId) => _actionErrors[sessionId];
|
||||
|
||||
/// The operator acknowledged [sessionId]'s refusal; nothing is sent.
|
||||
void dismissError(String sessionId) {
|
||||
if (_actionErrors.remove(sessionId) != null) _notify();
|
||||
}
|
||||
|
||||
/// The last hidden session, while its Undo is still offered.
|
||||
String? get lastHidden => _lastHidden;
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
},
|
||||
isUnseen: _controller.isUnseen,
|
||||
errorFor: _controller.errorFor,
|
||||
onDismissError: _controller.dismissError,
|
||||
),
|
||||
// The web's hide report is a fixed overlay: replacing or
|
||||
// growing it must never move the list or overflow the screen.
|
||||
|
||||
@@ -23,6 +23,7 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
required this.onClearSearch,
|
||||
required this.isUnseen,
|
||||
required this.errorFor,
|
||||
this.onDismissError,
|
||||
});
|
||||
|
||||
final List<ChatSessionSection> sections;
|
||||
@@ -37,6 +38,7 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
final VoidCallback? onClearSearch;
|
||||
final bool Function(JsonMap) isUnseen;
|
||||
final String? Function(String sessionId) errorFor;
|
||||
final ValueChanged<String>? onDismissError;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -88,7 +90,11 @@ class CupertinoSessionList extends StatelessWidget {
|
||||
onHide: onHide,
|
||||
),
|
||||
if (error != null)
|
||||
ChatRowError(message: error, messageKey: Key('chat-row-error-$id')),
|
||||
ChatRowError(
|
||||
message: error,
|
||||
messageKey: Key('chat-row-error-$id'),
|
||||
onDismiss: onDismissError == null ? null : () => onDismissError!(id),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class MaterialSessionList extends StatelessWidget {
|
||||
required this.onClearSearch,
|
||||
required this.isUnseen,
|
||||
required this.errorFor,
|
||||
this.onDismissError,
|
||||
});
|
||||
|
||||
final List<ChatSessionSection> sections;
|
||||
@@ -37,6 +38,7 @@ class MaterialSessionList extends StatelessWidget {
|
||||
final VoidCallback? onClearSearch;
|
||||
final bool Function(JsonMap) isUnseen;
|
||||
final String? Function(String sessionId) errorFor;
|
||||
final ValueChanged<String>? onDismissError;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -102,7 +104,11 @@ class MaterialSessionList extends StatelessWidget {
|
||||
onHide: onHide,
|
||||
),
|
||||
if (error != null)
|
||||
ChatRowError(message: error, messageKey: Key('chat-row-error-$id')),
|
||||
ChatRowError(
|
||||
message: error,
|
||||
messageKey: Key('chat-row-error-$id'),
|
||||
onDismiss: onDismissError == null ? null : () => onDismissError!(id),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,6 +175,13 @@ void main() {
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(gateway.count('chat_sessions'), 1);
|
||||
|
||||
// OK acknowledges the refusal locally; nothing else is sent.
|
||||
final sent = gateway.calls.length;
|
||||
await tester.tap(find.text('OK'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-row-error-s2')), findsNothing);
|
||||
expect(gateway.calls.length, sent);
|
||||
});
|
||||
|
||||
testWidgets('a create reply without chat_session shows the web wording', (
|
||||
|
||||
Reference in New Issue
Block a user