Skip to content

Commit df5f24a

Browse files
authored
chore(auto-updates): show toast when app is updated COMPASS-7686 (#5718)
* show toast on restart * show progress toast for all updates * broadcast event * use success toast variant * hide toasts * better click * better name
1 parent b970e12 commit df5f24a

File tree

7 files changed

+113
-25
lines changed

7 files changed

+113
-25
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { CompassBrowser } from '../compass-browser';
2+
import * as Selectors from '../selectors';
3+
4+
export async function hideAllVisibleToasts(
5+
browser: CompassBrowser
6+
): Promise<void> {
7+
const toastContainer = await browser.$(Selectors.LGToastContainer);
8+
const isToastContainerVisible = await toastContainer.isDisplayed();
9+
if (!isToastContainerVisible) {
10+
return;
11+
}
12+
// LG toasts are stacked in scroll container and we need to close them all.
13+
const toasts = await toastContainer.$$('div');
14+
for (const toast of toasts) {
15+
await browser.hover(Selectors.LGToastContainer);
16+
const isToastVisible = await toast.isDisplayed();
17+
if (!isToastVisible) {
18+
continue;
19+
}
20+
await browser.clickVisible(toast.$(Selectors.LGToastCloseButton));
21+
await toast.waitForExist({ reverse: true });
22+
}
23+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ export * from './create-index';
6666
export * from './drop-index';
6767
export * from './hide-index';
6868
export * from './unhide-index';
69+
export * from './hide-visible-toasts';

packages/compass-e2e-tests/helpers/commands/show-shell.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export async function showShell(browser: CompassBrowser): Promise<void> {
77
await retryWithBackoff(async function () {
88
const shellContentElement = await browser.$(Selectors.ShellContent);
99
if (!(await shellContentElement.isDisplayed())) {
10+
// The toasts may be covering the shell, so we need to close them.
11+
await browser.hideAllVisibleToasts();
1012
await browser.clickVisible(Selectors.ShellExpandButton);
1113
}
1214

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const SettingsInputElement = (settingName: string): string => {
1111
return `${SettingsModal} [data-testid="${settingName}"]`;
1212
};
1313

14+
// LG Toasts container (these test ids are used by LG in the toast and are not in the code anywhere).
15+
export const LGToastContainer = '[data-testid="lg-toast-scroll-container"]';
16+
export const LGToastCloseButton = '[data-testid="lg-toast-dismiss-button"]';
17+
1418
// Welcome Modal
1519
export const WelcomeModal = '[data-testid="welcome-modal"]';
1620
export const CloseWelcomeModalButton =

packages/compass/src/app/components/update-toasts.tsx

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ import {
66
palette,
77
useDarkMode,
88
cx,
9+
Link,
910
} from '@mongodb-js/compass-components';
1011
import { openToast } from '@mongodb-js/compass-components';
1112

1213
const containerStyles = css({
1314
display: 'flex',
1415
flexDirection: 'row',
15-
div: {
16-
display: 'flex',
17-
flexDirection: 'column',
18-
margin: 'auto',
19-
padding: spacing[1],
20-
},
16+
gap: spacing[100],
2117
});
2218

2319
const textStyles = css({
@@ -38,18 +34,38 @@ const buttonDarkStyles = css({
3834
color: palette.blue.light1,
3935
});
4036

37+
const linkStyles = css({
38+
whiteSpace: 'nowrap',
39+
textDecoration: 'none !important',
40+
span: {
41+
color: palette.blue.base,
42+
},
43+
svg: {
44+
color: palette.blue.base,
45+
},
46+
});
47+
48+
const linkDarkStyles = css({
49+
span: {
50+
color: palette.blue.light1,
51+
},
52+
svg: {
53+
color: palette.blue.light1,
54+
},
55+
});
56+
4157
const RestartCompassToastContent = ({
42-
updatedVersion,
58+
newVersion,
4359
onUpdateClicked,
4460
}: {
45-
updatedVersion: string;
61+
newVersion: string;
4662
onUpdateClicked: () => void;
4763
}) => {
4864
const darkmode = useDarkMode();
4965
return (
5066
<div className={containerStyles}>
5167
<Body className={textStyles}>
52-
Compass update {updatedVersion} has finished downloading
68+
Compass update {newVersion} has finished downloading
5369
</Body>
5470
<button
5571
className={cx(buttonStyles, darkmode && buttonDarkStyles)}
@@ -61,37 +77,66 @@ const RestartCompassToastContent = ({
6177
);
6278
};
6379

64-
export function onAutoupdateStarted() {
65-
openToast('update-download', {
80+
const UpdateInstalledToastContent = ({
81+
newVersion,
82+
}: {
83+
newVersion: string;
84+
}) => {
85+
const darkmode = useDarkMode();
86+
return (
87+
<div className={containerStyles}>
88+
<Body className={textStyles}>
89+
Compass {newVersion} is installed successfully
90+
</Body>
91+
<Link
92+
as="a"
93+
className={cx(linkStyles, darkmode && linkDarkStyles)}
94+
href={`https://github.com/mongodb-js/compass/releases/tag/v${newVersion}`}
95+
>
96+
Release notes
97+
</Link>
98+
</div>
99+
);
100+
};
101+
102+
export function onAutoupdateStarted({ newVersion }: { newVersion: string }) {
103+
openToast('compass-update-started', {
66104
variant: 'progress',
67-
title: 'Compass update is in progress',
105+
title: `Compass ${newVersion} is downloading`,
68106
});
69107
}
70108
export function onAutoupdateFailed() {
71-
openToast('update-download', {
109+
openToast('compass-update-failed', {
72110
variant: 'warning',
73111
title: 'Failed to download Compass update',
74112
description: 'Downloading a newer Compass version failed',
75113
});
76114
}
77115
export function onAutoupdateSuccess({
78-
updatedVersion,
116+
newVersion,
79117
onUpdate,
80118
onDismiss,
81119
}: {
82-
updatedVersion: string;
120+
newVersion: string;
83121
onUpdate: () => void;
84122
onDismiss: () => void;
85123
}) {
86-
openToast('update-download', {
87-
variant: 'note',
124+
openToast('compass-update-succeeded', {
125+
variant: 'success',
88126
title: '',
89127
description: (
90128
<RestartCompassToastContent
91-
updatedVersion={updatedVersion}
129+
newVersion={newVersion}
92130
onUpdateClicked={onUpdate}
93131
/>
94132
),
95133
onClose: onDismiss,
96134
});
97135
}
136+
export function onAutoupdateInstalled({ newVersion }: { newVersion: string }) {
137+
openToast('compass-update-restarted', {
138+
variant: 'success',
139+
title: '',
140+
description: <UpdateInstalledToastContent newVersion={newVersion} />,
141+
});
142+
}

packages/compass/src/app/index.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import { setupIntercom } from '@mongodb-js/compass-intercom';
7272
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
7373
import {
7474
onAutoupdateFailed,
75+
onAutoupdateInstalled,
7576
onAutoupdateStarted,
7677
onAutoupdateSuccess,
7778
} from './components/update-toasts';
@@ -301,14 +302,16 @@ const app = {
301302
// Autoupdate handlers
302303
ipcRenderer?.on(
303304
'autoupdate:update-download-in-progress',
304-
onAutoupdateStarted
305+
(_, { newVersion }: { newVersion: string }) => {
306+
onAutoupdateStarted({ newVersion });
307+
}
305308
);
306309
ipcRenderer?.on('autoupdate:update-download-failed', onAutoupdateFailed);
307310
ipcRenderer?.on(
308311
'autoupdate:update-download-success',
309-
(_, { updatedVersion }: { updatedVersion: string }) => {
312+
(_, { newVersion }: { newVersion: string }) => {
310313
onAutoupdateSuccess({
311-
updatedVersion,
314+
newVersion,
312315
onUpdate: () => {
313316
void ipcRenderer?.call(
314317
'autoupdate:update-download-restart-confirmed'
@@ -332,6 +335,15 @@ const app = {
332335
throw new Error('fake exception');
333336
});
334337
}
338+
339+
if (semver.gt(APP_VERSION, state.previousVersion)) {
340+
// Wait a bit before showing the update toast.
341+
setTimeout(() => {
342+
onAutoupdateInstalled({
343+
newVersion: APP_VERSION,
344+
});
345+
}, 2000);
346+
}
335347
},
336348
};
337349

packages/compass/src/main/auto-update-manager.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,10 @@ const STATE_UPDATE: Record<
358358

359359
this.maybeInterrupt();
360360

361-
if (isDownloadForManualCheck) {
362-
ipcMain?.broadcast('autoupdate:update-download-in-progress');
363-
}
361+
ipcMain?.broadcast('autoupdate:update-download-in-progress', {
362+
newVersion: updateInfo.to,
363+
});
364+
364365
autoUpdater.checkForUpdates();
365366
},
366367
},
@@ -380,7 +381,7 @@ const STATE_UPDATE: Record<
380381
this.maybeInterrupt();
381382

382383
ipcMain?.broadcast('autoupdate:update-download-success', {
383-
updatedVersion: updateInfo.to,
384+
newVersion: updateInfo.to,
384385
});
385386
},
386387
},

0 commit comments

Comments
 (0)