Skip to content

Commit

Permalink
Change IPyWidgets CDN error message links to buttons (#5395)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl authored Apr 2, 2021
1 parent a04003a commit b1f70d0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/5352.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When 3rd party CDN downloads need to be enabled for ipywidgets support, display More Info and Enable Downloads buttons instead of embedding them as links in the message.
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@
"DataScience.useCDNForWidgets": "Widgets require us to download supporting files from a 3rd party website. Click [here](https://aka.ms/PVSCIPyWidgets) for more information.",
"DataScience.loadThirdPartyWidgetScriptsPostEnabled": "Please restart the Kernel when changing the setting 'jupyter.widgetScriptSources'.",
"DataScience.enableCDNForWidgetsSettingHtml": "Widgets require us to download supporting files from a 3rd party website. Click <a href='https://command:jupyter.enableLoadingWidgetScriptsFromThirdPartySource'>here</a> to enable this or click <a href='https://aka.ms/PVSCIPyWidgets'>here</a> for more information. (Error loading {0}:{1}).",
"DataScience.enableCDNForWidgetsSetting": "Widgets require us to download supporting files from a 3rd party website. Click [here](command:jupyter.enableLoadingWidgetScriptsFromThirdPartySource) to enable this or click [here](https://aka.ms/PVSCIPyWidgets) for more information. (Error loading {0}:{1}).",
"DataScience.enableCDNForWidgetsSetting": "Widgets require us to download supporting files from a 3rd party website. (Error loading {0}:{1}).",
"DataScience.enableCDNForWidgetsButton": "Enable Downloads",
"DataScience.widgetScriptNotFoundOnCDNWidgetMightNotWork": "Unable to load a compatible version of the widget '{0}'. Expected behavior may be affected.",
"DataScience.unhandledMessage": "Unhandled kernel message from a widget: {0} : {1}",
"DataScience.qgridWidgetScriptVersionCompatibilityWarning": "Unable to load a compatible version of the widget 'qgrid'. Consider downgrading to version 1.1.1.",
Expand Down
2 changes: 1 addition & 1 deletion package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@
"DataScience.useCDNForWidgets": "控件需要从第三方网站下载支持文件。点击[这里](https://aka.ms/PVSCIPyWidgets)获取更多信息。",
"DataScience.loadThirdPartyWidgetScriptsPostEnabled": "改变 \"jupyter.widgetScriptSources\" 的设置后请重新启动内核。",
"DataScience.enableCDNForWidgetsSettingHtml": "控件需要从第三方网站下载支持文件。点击<a href='https://command:jupyter.enableLoadingWidgetScriptsFromThirdPartySource'>这里</a>启用此功能,或点击<a href='https://aka.ms/PVSCIPyWidgets'>这里</a>获取更多信息。(加载错误 {0}:{1})。",
"DataScience.enableCDNForWidgetsSetting": "控件需要从第三方网站下载支持文件。点击[这里](command:jupyter.enableLoadingWidgetScriptsFromThirdPartySource)启用此功能,或点击[这里](https://aka.ms/PVSCIPyWidgets)获取更多信息。(加载错误 {0}:{1})。",
"DataScience.enableCDNForWidgetsSetting": "控件需要从第三方网站下载支持文件。(加载错误 {0}:{1})。",
"DataScience.widgetScriptNotFoundOnCDNWidgetMightNotWork": "无法加载 '{0}' 控件的兼容版本。预期行为可能会受到影响。",
"DataScience.unhandledMessage": "来自控件未处理的内核消息:{0} : {1}",
"DataScience.qgridWidgetScriptVersionCompatibilityWarning": "无法加载 'qgrid' 控件的兼容版本,请考虑降级到 1.1.1 版本。",
Expand Down
2 changes: 1 addition & 1 deletion src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
[DSCommands.SaveAsNotebookNonCustomEditor]: [INotebookModel, Uri];
[DSCommands.OpenNotebookNonCustomEditor]: [Uri];
[DSCommands.LatestExtension]: [string];
[DSCommands.EnableLoadingWidgetsFrom3rdPartySource]: [undefined | never];
[DSCommands.EnableLoadingWidgetsFrom3rdPartySource]: [];
[DSCommands.TrustNotebook]: [undefined | never | Uri];
[DSCommands.NotebookTrusted]: [];
[DSCommands.NotebookEditorExpandAllCells]: [];
Expand Down
4 changes: 3 additions & 1 deletion src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,11 @@ export namespace DataScience {

export const enableCDNForWidgetsSetting = localize(
'DataScience.enableCDNForWidgetsSetting',
'Widgets require us to download supporting files from a 3rd party website. Click [here](command:jupyter.enableLoadingWidgetScriptsFromThirdPartySource) to enable this or click [here](https://aka.ms/PVSCIPyWidgets) for more information. (Error loading {0}:{1}).'
'Widgets require us to download supporting files from a 3rd party website. (Error loading {0}:{1}).'
);

export const enableCDNForWidgetsButton = localize('DataScience.enableCDNForWidgetsButton', 'Enable Downloads');

export const unhandledMessage = localize(
'DataScience.unhandledMessage',
'Unhandled kernel message from a widget: {0} : {1}'
Expand Down
23 changes: 19 additions & 4 deletions src/client/datascience/ipywidgets/commonMessageCoordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
LoadIPyWidgetClassLoadAction,
NotifyIPyWidgeWidgetVersionNotSupportedAction
} from '../../../datascience-ui/interactive-common/redux/reducers/types';
import { IApplicationShell, IWorkspaceService } from '../../common/application/types';
import { IApplicationShell, ICommandManager, IWorkspaceService } from '../../common/application/types';
import { STANDARD_OUTPUT_CHANNEL } from '../../common/constants';
import { traceError, traceInfo } from '../../common/logger';
import { IFileSystem } from '../../common/platform/types';
Expand All @@ -30,7 +30,7 @@ import { IInterpreterService } from '../../interpreter/contracts';
import { IServiceContainer } from '../../ioc/types';
import { sendTelemetryEvent } from '../../telemetry';
import { getTelemetrySafeHashedString } from '../../telemetry/helpers';
import { Telemetry } from '../constants';
import { Commands, Telemetry } from '../constants';
import { InteractiveWindowMessages } from '../interactive-common/interactiveWindowTypes';
import { INotebookProvider } from '../types';
import { IPyWidgetMessageDispatcherFactory } from './ipyWidgetMessageDispatcherFactory';
Expand All @@ -50,6 +50,7 @@ export class CommonMessageCoordinator {
private ipyWidgetMessageDispatcher?: IIPyWidgetMessageDispatcher;
private ipyWidgetScriptSource?: IPyWidgetScriptSource;
private appShell: IApplicationShell;
private commandManager: ICommandManager;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private postEmitter: EventEmitter<{ message: string; payload: any }>;
private disposables: IDisposableRegistry;
Expand All @@ -71,6 +72,7 @@ export class CommonMessageCoordinator {
this.disposables = this.serviceContainer.get<IDisposableRegistry>(IDisposableRegistry);
this.jupyterOutput = this.serviceContainer.get<IOutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
this.appShell = this.serviceContainer.get<IApplicationShell>(IApplicationShell, IApplicationShell);
this.commandManager = this.serviceContainer.get<ICommandManager>(ICommandManager);
}

public static async create(
Expand Down Expand Up @@ -136,16 +138,29 @@ export class CommonMessageCoordinator {
payload.moduleName,
payload.moduleVersion
);
this.appShell.showErrorMessage(errorMessage).then(noop, noop);
} else if (!payload.cdnsUsed) {
const moreInfo = localize.Common.moreInfo();
const enableDownloads = localize.DataScience.enableCDNForWidgetsButton();
errorMessage = localize.DataScience.enableCDNForWidgetsSetting().format(
payload.moduleName,
payload.moduleVersion
);
this.appShell.showErrorMessage(errorMessage, ...[enableDownloads, moreInfo]).then((selection) => {
switch (selection) {
case moreInfo:
this.appShell.openUrl('https://aka.ms/PVSCIPyWidgets');
break;
case enableDownloads:
void this.commandManager.executeCommand(Commands.EnableLoadingWidgetsFrom3rdPartySource);
break;
default:
break;
}
}, noop);
}
traceError(`Widget load failure ${errorMessage}`, payload);

this.appShell.showErrorMessage(errorMessage).then(noop, noop);

sendTelemetryEvent(Telemetry.IPyWidgetLoadFailure, 0, {
isOnline: payload.isOnline,
moduleHash: getTelemetrySafeHashedString(payload.moduleName),
Expand Down

0 comments on commit b1f70d0

Please sign in to comment.