Skip to content

Commit 3508451

Browse files
authored
fix: move the debug for me button to the connection error toast COMPASS-9746 (#7247)
* move the debug for me button to the connection error toast * no assistant in web for now * add ticket
1 parent 9411cc4 commit 3508451

File tree

8 files changed

+162
-127
lines changed

8 files changed

+162
-127
lines changed

packages/compass-components/src/hooks/use-toast.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type ToastProperties = Pick<
1717
| 'timeout'
1818
| 'dismissible'
1919
| 'onClose'
20+
| 'className'
2021
>;
2122

2223
const defaultToastProperties: Partial<ToastProperties> = {

packages/compass-connections/src/components/connection-status-notifications.tsx

Lines changed: 101 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
spacing,
99
openToast,
1010
closeToast,
11+
Icon,
12+
Button,
1113
} from '@mongodb-js/compass-components';
1214
import type { ConnectionInfo } from '@mongodb-js/connection-info';
1315
import { getConnectionTitle } from '@mongodb-js/connection-info';
@@ -38,74 +40,101 @@ export function getConnectingStatusText(connectionInfo: ConnectionInfo) {
3840

3941
type ConnectionErrorToastBodyProps = {
4042
info?: ConnectionInfo | null;
43+
error: Error;
4144
showReviewButton: boolean;
45+
showDebugButton: boolean;
4246
onReview: () => void;
47+
onDebug: () => void;
4348
};
4449

50+
const connectionErrorToastStyles = css({
51+
// the gap on the right after the buttons takes up a lot of space from the
52+
// description, so we remove it and add a little bit of margin elsewhere
53+
gap: 0,
54+
'[data-testid="lg-toast-content"] > div, [data-testid="lg-toast-content"] > div > p + p':
55+
{
56+
// don't cut off the glow of the button
57+
overflow: 'visible',
58+
},
59+
});
60+
4561
const connectionErrorToastBodyStyles = css({
4662
display: 'grid',
4763
gridAutoFlow: 'column',
4864
gap: spacing[200],
4965
});
5066

51-
const connectionErrorToastActionMessageStyles = css({});
67+
const connectionErrorActionsStyles = css({
68+
display: 'flex',
69+
flexDirection: 'column',
70+
textAlign: 'right',
71+
// replacing the gap with a margin so the button glow does not get cut off
72+
marginRight: spacing[100],
73+
gap: spacing[100],
74+
justifyContent: 'center',
75+
});
5276

53-
const connectionErrorTextStyles = css({
54-
overflow: 'hidden',
55-
textOverflow: 'ellipsis',
77+
const connectionErrorStyles = css({
78+
display: 'flex',
79+
flexDirection: 'column',
80+
});
81+
82+
const connectionErrorTitleStyles = css({
83+
fontWeight: 'bold',
84+
});
85+
86+
const debugActionStyles = css({
87+
display: 'flex',
88+
alignItems: 'center',
89+
gap: spacing[100],
90+
justifyContent: 'right',
91+
textWrap: 'nowrap',
5692
});
5793

5894
function ConnectionErrorToastBody({
5995
info,
96+
error,
6097
showReviewButton,
98+
showDebugButton,
6199
onReview,
100+
onDebug,
62101
}: ConnectionErrorToastBodyProps): React.ReactElement {
63102
return (
64103
<span className={connectionErrorToastBodyStyles}>
65-
<span
66-
data-testid="connection-error-text"
67-
className={connectionErrorTextStyles}
68-
>
69-
There was a problem connecting{' '}
70-
{info ? `to ${getConnectionTitle(info)}` : ''}
71-
</span>
72-
{info && showReviewButton && (
73-
<Link
74-
className={connectionErrorToastActionMessageStyles}
75-
hideExternalIcon={true}
76-
onClick={onReview}
77-
data-testid="connection-error-review"
104+
<span className={connectionErrorStyles}>
105+
<span
106+
data-testid="connection-error-title"
107+
className={connectionErrorTitleStyles}
78108
>
79-
REVIEW
80-
</Link>
81-
)}
82-
</span>
83-
);
84-
}
85-
86-
type ConnectionDebugToastBodyProps = {
87-
onDebug: () => void;
88-
};
89-
90-
function ConnectionDebugToastBody({
91-
onDebug,
92-
}: ConnectionDebugToastBodyProps): React.ReactElement {
93-
return (
94-
<span className={connectionErrorToastBodyStyles}>
95-
<span
96-
data-testid="connection-debug-text"
97-
className={connectionErrorTextStyles}
98-
>
99-
Diagnose the issue and explore solutions with the assistant
109+
{info ? getConnectionTitle(info) : 'Connection failed'}
110+
</span>
111+
<span data-testid="connection-error-text">{error.message}</span>
112+
</span>
113+
<span className={connectionErrorActionsStyles}>
114+
{info && showReviewButton && (
115+
<span>
116+
<Button
117+
onClick={onReview}
118+
data-testid="connection-error-review"
119+
size="small"
120+
>
121+
Review
122+
</Button>
123+
</span>
124+
)}
125+
{info && showDebugButton && (
126+
<span className={debugActionStyles}>
127+
<Icon glyph="Sparkle" size="small"></Icon>
128+
<Link
129+
hideExternalIcon={true}
130+
onClick={onDebug}
131+
data-testid="connection-error-debug"
132+
>
133+
Debug for me
134+
</Link>
135+
</span>
136+
)}
100137
</span>
101-
<Link
102-
className={connectionErrorToastActionMessageStyles}
103-
hideExternalIcon={true}
104-
onClick={onDebug}
105-
data-testid="connection-error-debug"
106-
>
107-
DEBUG FOR ME
108-
</Link>
109138
</span>
110139
);
111140
}
@@ -150,51 +179,50 @@ const openConnectionSucceededToast = (connectionInfo: ConnectionInfo) => {
150179
});
151180
};
152181

153-
const openConnectionFailedToast = (
182+
const openConnectionFailedToast = ({
183+
connectionInfo,
184+
error,
185+
showReviewButton,
186+
showDebugButton,
187+
onReviewClick,
188+
onDebugClick,
189+
}: {
154190
// Connection info might be missing if we failed connecting before we
155191
// could even resolve connection info. Currently the only case where this
156192
// can happen is autoconnect flow
157-
connectionInfo: ConnectionInfo | null | undefined,
158-
error: Error,
159-
showReviewButton: boolean,
160-
onReviewClick: () => void
161-
) => {
193+
connectionInfo: ConnectionInfo | null | undefined;
194+
error: Error;
195+
showReviewButton: boolean;
196+
showDebugButton: boolean;
197+
onReviewClick: () => void;
198+
onDebugClick: () => void;
199+
}) => {
162200
const failedToastId = connectionInfo?.id ?? 'failed';
163201

164-
// TODO(COMPASS-9746): close the existing connection toast and make a new one
165-
// for the failure so that the debug toast will appear below the failure one
166202
openToast(`connection-status--${failedToastId}`, {
167-
title: error.message,
203+
// we place the title inside the description to get the layout we need
204+
title: '',
168205
description: (
169206
<ConnectionErrorToastBody
170207
info={connectionInfo}
208+
error={error}
171209
showReviewButton={showReviewButton}
210+
showDebugButton={showDebugButton}
172211
onReview={() => {
173-
closeToast(`connection-status--${failedToastId}`);
212+
if (!showDebugButton) {
213+
// don't close the toast if there are two actions so that the user
214+
// can still use the other one
215+
closeToast(`connection-status--${failedToastId}`);
216+
}
174217
onReviewClick();
175218
}}
176-
/>
177-
),
178-
variant: 'warning',
179-
});
180-
};
181-
182-
const openDebugConnectionErrorToast = (
183-
connectionInfo: ConnectionInfo,
184-
error: Error,
185-
onDebugClick: () => void
186-
) => {
187-
openToast(`debug-connection-error--${connectionInfo.id}`, {
188-
title: 'Need help debugging your connection error?',
189-
description: (
190-
<ConnectionDebugToastBody
191219
onDebug={() => {
192-
closeToast(`debug-connection-error--${connectionInfo.id}`);
193220
onDebugClick();
194221
}}
195222
/>
196223
),
197-
variant: 'note',
224+
variant: 'warning',
225+
className: connectionErrorToastStyles,
198226
});
199227
};
200228

@@ -262,7 +290,6 @@ export function getNotificationTriggers() {
262290
openConnectionStartedToast,
263291
openConnectionSucceededToast,
264292
openConnectionFailedToast,
265-
openDebugConnectionErrorToast,
266293
openMaximumConnectionsReachedToast,
267294
closeConnectionStatusToast: (connectionId: string) => {
268295
return closeToast(`connection-status--${connectionId}`);

packages/compass-connections/src/stores/connections-store-redux.spec.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('CompassConnections store', function () {
150150
}
151151
});
152152

153-
it('should show debug toast in addition to the connection error toast if connection fails and the assistant is enabled', async function () {
153+
it('should show debug action in addition to review if connection fails and the assistant is enabled', async function () {
154154
const { connectionsStore } = renderCompassConnections({
155155
preferences: {
156156
enableAIAssistant: true,
@@ -169,8 +169,7 @@ describe('CompassConnections store', function () {
169169
});
170170

171171
await waitFor(() => {
172-
expect(screen.getByText('Need help debugging your connection error?'))
173-
.to.exist;
172+
expect(screen.getByText('Debug for me')).to.exist;
174173
});
175174
});
176175

packages/compass-connections/src/stores/connections-store-redux.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,24 +1270,29 @@ const connectionAttemptError = (
12701270
_getState,
12711271
{ track, getExtraConnectionData, compassAssistant }
12721272
) => {
1273-
const { openConnectionFailedToast, openDebugConnectionErrorToast } =
1274-
getNotificationTriggers();
1273+
const { openConnectionFailedToast } = getNotificationTriggers();
12751274

12761275
const isAssistanceEnabled = compassAssistant.getIsAssistantEnabled();
1277-
if (isAssistanceEnabled && connectionInfo) {
1278-
openDebugConnectionErrorToast(connectionInfo, err, () => {
1279-
compassAssistant.interpretConnectionError({
1280-
connectionInfo,
1281-
error: err,
1282-
});
1283-
});
1284-
}
12851276

12861277
const showReviewButton = !!connectionInfo && !connectionInfo.atlasMetadata;
1287-
openConnectionFailedToast(connectionInfo, err, showReviewButton, () => {
1288-
if (connectionInfo) {
1289-
dispatch(editConnection(connectionInfo.id));
1290-
}
1278+
openConnectionFailedToast({
1279+
connectionInfo,
1280+
error: err,
1281+
showReviewButton,
1282+
showDebugButton: isAssistanceEnabled,
1283+
onReviewClick() {
1284+
if (connectionInfo) {
1285+
dispatch(editConnection(connectionInfo.id));
1286+
}
1287+
},
1288+
onDebugClick() {
1289+
if (connectionInfo) {
1290+
compassAssistant.interpretConnectionError({
1291+
connectionInfo,
1292+
error: err,
1293+
});
1294+
}
1295+
},
12911296
});
12921297

12931298
track(

packages/compass-e2e-tests/helpers/commands/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export async function waitForConnectionResult(
170170
await browser
171171
.$(Selectors.ConnectionToastErrorText)
172172
.waitForDisplayed(waitOptions);
173-
return browser.$(Selectors.LGToastTitle).getText();
173+
return browser.$(Selectors.ConnectionToastErrorText).getText();
174174
} else {
175175
const exhaustiveCheck: never = connectionStatus;
176176
throw new Error(`Unhandled connectionStatus case: ${exhaustiveCheck}`);

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ export const ConnectionModalSaveButton = '[data-testid="save-button"]';
237237
export const connectionToastById = (connectionId: string) => {
238238
return `[data-testid="toast-connection-status--${connectionId}"]`;
239239
};
240+
export const ConnectionToastTitleText =
241+
'[data-testid="connection-error-title"]';
240242
export const ConnectionToastErrorText = '[data-testid="connection-error-text"]';
241243
export const ConnectionToastErrorReviewButton =
242244
'[data-testid="connection-error-review"]';

0 commit comments

Comments
 (0)