-
Notifications
You must be signed in to change notification settings - Fork 37
Use toast notification for preview changes #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,18 +253,45 @@ export async function applyPackageChanges( | |
| return false; | ||
| } | ||
|
|
||
| let previewAllNotification: string | undefined; | ||
|
|
||
| try { | ||
| if (!skipConfirmation) { | ||
| const previewJobs: IPreviewJob[] = []; | ||
|
|
||
| // Emit notification about the preview jobs | ||
| previewAllNotification = Notification.emit( | ||
| 'Previewing package changes', | ||
| 'in-progress', | ||
| { | ||
| autoClose: false | ||
| } | ||
| ); | ||
|
|
||
| const removePreview = await pkgModel.dry_run_preview( | ||
| toRemove, | ||
| 'remove', | ||
| theEnvironment | ||
| ); | ||
| const updatePreview = await pkgModel.dry_run_preview( | ||
| toUpdate, | ||
| 'update', | ||
| theEnvironment | ||
| ); | ||
| const installPreview = await pkgModel.dry_run_preview( | ||
| toInstall, | ||
| 'install', | ||
| theEnvironment | ||
| ); | ||
|
|
||
| if (toRemove.length > 0) { | ||
| previewJobs.push({ | ||
| section: { | ||
| id: 'remove', | ||
| title: 'Remove packages', | ||
| requestedPackages: toRemove.map(specBaseName) | ||
| }, | ||
| promise: pkgModel.dry_run_preview(toRemove, 'remove', theEnvironment) | ||
| promise: Promise.resolve(removePreview) | ||
| }); | ||
| } | ||
| if (toUpdate.length > 0) { | ||
|
|
@@ -274,7 +301,7 @@ export async function applyPackageChanges( | |
| title: 'Update packages', | ||
| requestedPackages: toUpdate.map(specBaseName) | ||
| }, | ||
| promise: pkgModel.dry_run_preview(toUpdate, 'update', theEnvironment) | ||
| promise: Promise.resolve(updatePreview) | ||
| }); | ||
| } | ||
| if (toInstall.length > 0) { | ||
|
|
@@ -284,22 +311,37 @@ export async function applyPackageChanges( | |
| title: 'Install packages', | ||
| requestedPackages: toInstall.map(specBaseName) | ||
| }, | ||
| promise: pkgModel.dry_run_preview( | ||
| toInstall, | ||
| 'install', | ||
| theEnvironment | ||
| ) | ||
| promise: Promise.resolve(installPreview) | ||
| }); | ||
| } | ||
|
|
||
| const confirmed = await openPackagePreviewDialog({ | ||
| title: 'Preview package changes', | ||
| jobs: previewJobs, | ||
| acceptLabel: 'Apply' | ||
| }); | ||
| if ( | ||
| !removePreview.has_side_effects && | ||
| !updatePreview.has_side_effects && | ||
| !installPreview.has_side_effects | ||
| ) { | ||
| Notification.update({ | ||
| id: previewAllNotification, | ||
| message: 'No additional changes needed, applying changes...', | ||
| type: 'success', | ||
| autoClose: 2000 | ||
| }); | ||
| } | ||
|
|
||
| if (!confirmed) { | ||
| return false; | ||
| if ( | ||
| removePreview.has_side_effects || | ||
| updatePreview.has_side_effects || | ||
| installPreview.has_side_effects | ||
| ) { | ||
| const confirmed = await openPackagePreviewDialog({ | ||
| title: 'Preview package changes', | ||
| jobs: previewJobs, | ||
| acceptLabel: 'Apply' | ||
| }); | ||
|
|
||
| if (!confirmed) { | ||
|
RRosio marked this conversation as resolved.
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -313,6 +355,9 @@ export async function applyPackageChanges( | |
| } | ||
| }); | ||
|
|
||
| if (previewAllNotification) { | ||
| Notification.dismiss(previewAllNotification); | ||
| } | ||
| toastId = Notification.emit('Starting packages actions', 'in-progress'); | ||
|
|
||
| if (toRemove.length > 0) { | ||
|
|
@@ -361,17 +406,43 @@ export async function applyPackageChanges( | |
|
|
||
| return true; | ||
| } catch (error) { | ||
| console.error('Error when applying package changes: ', error); | ||
| const fullError = formatPreviewErrorForDialog(error); | ||
| const firstNewLine = fullError.indexOf('\n'); | ||
| const firstLine = | ||
| firstNewLine === -1 ? fullError : fullError.slice(0, firstNewLine); | ||
|
|
||
| if (error !== 'cancelled') { | ||
| console.error(error); | ||
| if (toastId) { | ||
| if (previewAllNotification) { | ||
| Notification.dismiss(previewAllNotification); | ||
| } | ||
| Notification.update({ | ||
| id: toastId, | ||
| message: (error as any).message, | ||
| message: firstLine, | ||
| type: 'error', | ||
| autoClose: 0 | ||
| autoClose: false, | ||
| actions: [ | ||
| { | ||
| label: 'Show details', | ||
| callback: () => { | ||
| openPreviewErrorDialog(fullError); | ||
| } | ||
| } | ||
| ] | ||
| }); | ||
| } else { | ||
| Notification.error((error as any).message); | ||
| Notification.emit(firstLine, 'error', { | ||
| autoClose: false, | ||
| actions: [ | ||
| { | ||
|
Comment on lines
437
to
+441
|
||
| label: 'Show details', | ||
| callback: () => { | ||
| openPreviewErrorDialog(fullError); | ||
| } | ||
| } | ||
| ] | ||
| }); | ||
| } | ||
|
|
||
| // Emit failed signal | ||
|
|
@@ -381,13 +452,16 @@ export async function applyPackageChanges( | |
| status: 'failed', | ||
| details: { | ||
| packagesAffected: selectedPackages.length, | ||
| error: (error as any).message | ||
| error: firstLine | ||
| } | ||
| }); | ||
| } else { | ||
| if (toastId) { | ||
| Notification.dismiss(toastId); | ||
| } | ||
| if (previewAllNotification) { | ||
| Notification.dismiss(previewAllNotification); | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three
dry_run_previewcalls are awaited sequentially, which increases latency compared to the previous behavior where the dialog loaded previews concurrently viaPromise.all. Consider running these previews in parallel (e.g.,await Promise.all([...])) and then using the results forhas_side_effectschecks / job data.