2020-05-26 03:30:55 +01:00
|
|
|
import * as _ from "underscore";
|
|
|
|
import * as Q from "q";
|
|
|
|
import * as ko from "knockout";
|
|
|
|
|
|
|
|
import * as ViewModels from "../../Contracts/ViewModels";
|
|
|
|
import * as DataModels from "../../Contracts/DataModels";
|
|
|
|
import TabsBase from "./TabsBase";
|
|
|
|
|
|
|
|
import NewCellIcon from "../../../images/notebook/Notebook-insert-cell.svg";
|
|
|
|
import CutIcon from "../../../images/notebook/Notebook-cut.svg";
|
|
|
|
import CopyIcon from "../../../images/notebook/Notebook-copy.svg";
|
|
|
|
import PasteIcon from "../../../images/notebook/Notebook-paste.svg";
|
|
|
|
import RunIcon from "../../../images/notebook/Notebook-run.svg";
|
|
|
|
import RunAllIcon from "../../../images/notebook/Notebook-run-all.svg";
|
|
|
|
import RestartIcon from "../../../images/notebook/Notebook-restart.svg";
|
|
|
|
import SaveIcon from "../../../images/save-cosmos.svg";
|
|
|
|
import ClearAllOutputsIcon from "../../../images/notebook/Notebook-clear-all-outputs.svg";
|
|
|
|
import InterruptKernelIcon from "../../../images/notebook/Notebook-stop.svg";
|
|
|
|
import KillKernelIcon from "../../../images/notebook/Notebook-stop.svg";
|
2020-09-08 18:44:46 +01:00
|
|
|
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
2020-05-26 03:30:55 +01:00
|
|
|
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
|
|
|
import { Areas, ArmApiVersions } from "../../Common/Constants";
|
|
|
|
import { CommandBarComponentButtonFactory } from "../Menus/CommandBar/CommandBarComponentButtonFactory";
|
|
|
|
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
|
2020-08-03 23:11:07 +01:00
|
|
|
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
|
2020-05-26 03:30:55 +01:00
|
|
|
import { NotebookComponentAdapter } from "../Notebook/NotebookComponent/NotebookComponentAdapter";
|
|
|
|
import { NotebookConfigurationUtils } from "../../Utils/NotebookConfigurationUtils";
|
|
|
|
import { KernelSpecsDisplay, NotebookClientV2 } from "../Notebook/NotebookClientV2";
|
2020-08-06 20:03:46 +01:00
|
|
|
import { configContext } from "../../ConfigContext";
|
2020-07-20 18:59:40 +01:00
|
|
|
import Explorer from "../Explorer";
|
2020-07-27 22:05:25 +01:00
|
|
|
import { NotebookContentItem } from "../Notebook/NotebookContentItem";
|
|
|
|
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
|
2020-08-11 17:27:57 +01:00
|
|
|
import { toJS, stringifyNotebook } from "@nteract/commutable";
|
2020-05-26 03:30:55 +01:00
|
|
|
|
2020-07-27 22:05:25 +01:00
|
|
|
export interface NotebookTabOptions extends ViewModels.TabOptions {
|
|
|
|
account: DataModels.DatabaseAccount;
|
|
|
|
masterKey: string;
|
|
|
|
container: Explorer;
|
|
|
|
notebookContentItem: NotebookContentItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class NotebookTabV2 extends TabsBase {
|
2020-05-26 03:30:55 +01:00
|
|
|
private static clientManager: NotebookClientV2;
|
2020-07-20 18:59:40 +01:00
|
|
|
private container: Explorer;
|
2020-05-26 03:30:55 +01:00
|
|
|
public notebookPath: ko.Observable<string>;
|
|
|
|
private selectedSparkPool: ko.Observable<string>;
|
|
|
|
private notebookComponentAdapter: NotebookComponentAdapter;
|
|
|
|
|
2020-07-27 22:05:25 +01:00
|
|
|
constructor(options: NotebookTabOptions) {
|
2020-05-26 03:30:55 +01:00
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.container = options.container;
|
|
|
|
|
|
|
|
if (!NotebookTabV2.clientManager) {
|
|
|
|
NotebookTabV2.clientManager = new NotebookClientV2({
|
|
|
|
connectionInfo: this.container.notebookServerInfo(),
|
|
|
|
databaseAccountName: this.container.databaseAccount().name,
|
|
|
|
defaultExperience: this.container.defaultExperience(),
|
2021-01-20 15:15:01 +00:00
|
|
|
contentProvider: this.container.notebookManager?.notebookContentProvider,
|
2020-05-26 03:30:55 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.notebookPath = ko.observable(options.notebookContentItem.path);
|
|
|
|
|
|
|
|
this.container.notebookServerInfo.subscribe((newValue: DataModels.NotebookWorkspaceConnectionInfo) => {
|
|
|
|
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, "New notebook server info received.");
|
|
|
|
});
|
|
|
|
|
|
|
|
this.notebookComponentAdapter = new NotebookComponentAdapter({
|
|
|
|
contentItem: options.notebookContentItem,
|
|
|
|
notebooksBasePath: this.container.getNotebookBasePath(),
|
|
|
|
notebookClient: NotebookTabV2.clientManager,
|
2021-01-20 15:15:01 +00:00
|
|
|
onUpdateKernelInfo: this.onKernelUpdate,
|
2020-05-26 03:30:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
this.selectedSparkPool = ko.observable<string>(null);
|
|
|
|
this.container &&
|
|
|
|
this.container.arcadiaToken.subscribe(async () => {
|
|
|
|
const currentKernel = this.notebookComponentAdapter.getCurrentKernelName();
|
|
|
|
if (!currentKernel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await this.configureServiceEndpoints(currentKernel);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public onCloseTabButtonClick(): Q.Promise<any> {
|
|
|
|
const cleanup = () => {
|
|
|
|
this.notebookComponentAdapter.notebookShutdown();
|
|
|
|
this.isActive(false);
|
|
|
|
super.onCloseTabButtonClick();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.notebookComponentAdapter.isContentDirty()) {
|
|
|
|
this.container.showOkCancelModalDialog(
|
|
|
|
"Close without saving?",
|
|
|
|
`File has unsaved changes, close without saving?`,
|
|
|
|
"Close",
|
|
|
|
cleanup,
|
|
|
|
"Cancel",
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
return Q.resolve(null);
|
|
|
|
} else {
|
|
|
|
cleanup();
|
|
|
|
return Q.resolve(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async reconfigureServiceEndpoints() {
|
|
|
|
if (!this.notebookComponentAdapter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return await this.configureServiceEndpoints(this.notebookComponentAdapter.getCurrentKernelName());
|
|
|
|
}
|
|
|
|
|
2020-07-20 18:59:40 +01:00
|
|
|
protected getContainer(): Explorer {
|
2020-05-26 03:30:55 +01:00
|
|
|
return this.container;
|
|
|
|
}
|
|
|
|
|
2020-07-27 22:05:25 +01:00
|
|
|
protected getTabsButtons(): CommandButtonComponentProps[] {
|
2020-05-26 03:30:55 +01:00
|
|
|
const availableKernels = NotebookTabV2.clientManager.getAvailableKernelSpecs();
|
|
|
|
|
|
|
|
const saveLabel = "Save";
|
2020-08-11 17:27:57 +01:00
|
|
|
const copyToLabel = "Copy to ...";
|
2020-06-30 19:47:21 +01:00
|
|
|
const publishLabel = "Publish to gallery";
|
2020-05-26 03:30:55 +01:00
|
|
|
const workspaceLabel = "No Workspace";
|
|
|
|
const kernelLabel = "No Kernel";
|
|
|
|
const runLabel = "Run";
|
|
|
|
const runActiveCellLabel = "Run Active Cell";
|
|
|
|
const runAllLabel = "Run All";
|
|
|
|
const interruptKernelLabel = "Interrupt Kernel";
|
|
|
|
const killKernelLabel = "Halt Kernel";
|
|
|
|
const restartKernelLabel = "Restart Kernel";
|
|
|
|
const clearLabel = "Clear outputs";
|
|
|
|
const newCellLabel = "New Cell";
|
|
|
|
const cellTypeLabel = "Cell Type";
|
|
|
|
const codeLabel = "Code";
|
|
|
|
const markdownLabel = "Markdown";
|
|
|
|
const rawLabel = "Raw";
|
|
|
|
const copyLabel = "Copy";
|
|
|
|
const cutLabel = "Cut";
|
|
|
|
const pasteLabel = "Paste";
|
|
|
|
const undoLabel = "Undo";
|
|
|
|
const redoLabel = "Redo";
|
|
|
|
const cellCodeType = "code";
|
|
|
|
const cellMarkdownType = "markdown";
|
|
|
|
const cellRawType = "raw";
|
2020-08-17 19:39:11 +01:00
|
|
|
|
|
|
|
const saveButtonChildren = [];
|
|
|
|
if (this.container.notebookManager?.gitHubOAuthService.isLoggedIn()) {
|
|
|
|
saveButtonChildren.push({
|
|
|
|
iconName: "Copy",
|
|
|
|
onCommandClick: () => this.copyNotebook(),
|
|
|
|
commandButtonLabel: copyToLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: copyToLabel,
|
2020-08-17 19:39:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.container.isGalleryPublishEnabled()) {
|
|
|
|
saveButtonChildren.push({
|
|
|
|
iconName: "PublishContent",
|
|
|
|
onCommandClick: async () => await this.publishToGallery(),
|
|
|
|
commandButtonLabel: publishLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: publishLabel,
|
2020-08-17 19:39:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-27 22:05:25 +01:00
|
|
|
let buttons: CommandButtonComponentProps[] = [
|
2020-05-26 03:30:55 +01:00
|
|
|
{
|
|
|
|
iconSrc: SaveIcon,
|
|
|
|
iconAlt: saveLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookSave(),
|
|
|
|
commandButtonLabel: saveLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2020-06-30 19:47:21 +01:00
|
|
|
ariaLabel: saveLabel,
|
2020-08-17 19:39:11 +01:00
|
|
|
children: saveButtonChildren.length && [
|
|
|
|
{
|
|
|
|
iconName: "Save",
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookSave(),
|
|
|
|
commandButtonLabel: saveLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: saveLabel,
|
2020-08-17 19:39:11 +01:00
|
|
|
},
|
2021-01-20 15:15:01 +00:00
|
|
|
...saveButtonChildren,
|
|
|
|
],
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: null,
|
|
|
|
iconAlt: kernelLabel,
|
|
|
|
onCommandClick: () => {},
|
|
|
|
commandButtonLabel: null,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: availableKernels.length < 1,
|
|
|
|
isDropdown: true,
|
|
|
|
dropdownPlaceholder: kernelLabel,
|
|
|
|
dropdownSelectedKey: this.notebookComponentAdapter.getSelectedKernelName(), //this.currentKernelName,
|
|
|
|
dropdownWidth: 100,
|
|
|
|
children: availableKernels.map(
|
|
|
|
(kernel: KernelSpecsDisplay) =>
|
|
|
|
({
|
|
|
|
iconSrc: null,
|
|
|
|
iconAlt: kernel.displayName,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookChangeKernel(kernel.name),
|
|
|
|
commandButtonLabel: kernel.displayName,
|
|
|
|
dropdownItemKey: kernel.name,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: kernel.displayName,
|
2020-07-27 22:05:25 +01:00
|
|
|
} as CommandButtonComponentProps)
|
2020-05-26 03:30:55 +01:00
|
|
|
),
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: kernelLabel,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: RunIcon,
|
|
|
|
iconAlt: runLabel,
|
|
|
|
onCommandClick: () => {
|
|
|
|
this.notebookComponentAdapter.notebookRunAndAdvance();
|
|
|
|
this.traceTelemetry(Action.ExecuteCell);
|
|
|
|
},
|
|
|
|
commandButtonLabel: runLabel,
|
|
|
|
ariaLabel: runLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
iconSrc: RunIcon,
|
|
|
|
iconAlt: runActiveCellLabel,
|
|
|
|
onCommandClick: () => {
|
|
|
|
this.notebookComponentAdapter.notebookRunAndAdvance();
|
|
|
|
this.traceTelemetry(Action.ExecuteCell);
|
|
|
|
},
|
|
|
|
commandButtonLabel: runActiveCellLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: runActiveCellLabel,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: RunAllIcon,
|
|
|
|
iconAlt: runAllLabel,
|
|
|
|
onCommandClick: () => {
|
|
|
|
this.notebookComponentAdapter.notebookRunAll();
|
|
|
|
this.traceTelemetry(Action.ExecuteAllCells);
|
|
|
|
},
|
|
|
|
commandButtonLabel: runAllLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: runAllLabel,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: InterruptKernelIcon,
|
|
|
|
iconAlt: interruptKernelLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookInterruptKernel(),
|
|
|
|
commandButtonLabel: interruptKernelLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: interruptKernelLabel,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: KillKernelIcon,
|
|
|
|
iconAlt: killKernelLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookKillKernel(),
|
|
|
|
commandButtonLabel: killKernelLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: killKernelLabel,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: RestartIcon,
|
|
|
|
iconAlt: restartKernelLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookRestartKernel(),
|
|
|
|
commandButtonLabel: restartKernelLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: restartKernelLabel,
|
|
|
|
},
|
|
|
|
],
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: ClearAllOutputsIcon,
|
|
|
|
iconAlt: clearLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookClearAllOutputs(),
|
|
|
|
commandButtonLabel: clearLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
ariaLabel: clearLabel,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: NewCellIcon,
|
|
|
|
iconAlt: newCellLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookInsertBelow(),
|
|
|
|
commandButtonLabel: newCellLabel,
|
|
|
|
ariaLabel: newCellLabel,
|
|
|
|
hasPopup: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
disabled: false,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
CommandBarComponentButtonFactory.createDivider(),
|
|
|
|
{
|
|
|
|
iconSrc: null,
|
|
|
|
iconAlt: null,
|
|
|
|
onCommandClick: () => {},
|
|
|
|
commandButtonLabel: null,
|
|
|
|
ariaLabel: cellTypeLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
|
|
|
isDropdown: true,
|
|
|
|
dropdownPlaceholder: cellTypeLabel,
|
|
|
|
dropdownSelectedKey: this.notebookComponentAdapter.getActiveCellTypeStr(),
|
|
|
|
dropdownWidth: 110,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
iconSrc: null,
|
|
|
|
iconAlt: null,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookChangeCellType(cellCodeType),
|
|
|
|
commandButtonLabel: codeLabel,
|
|
|
|
ariaLabel: codeLabel,
|
|
|
|
dropdownItemKey: cellCodeType,
|
|
|
|
hasPopup: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
disabled: false,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: null,
|
|
|
|
iconAlt: null,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookChangeCellType(cellMarkdownType),
|
|
|
|
commandButtonLabel: markdownLabel,
|
|
|
|
ariaLabel: markdownLabel,
|
|
|
|
dropdownItemKey: cellMarkdownType,
|
|
|
|
hasPopup: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
disabled: false,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: null,
|
|
|
|
iconAlt: null,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookChangeCellType(cellRawType),
|
|
|
|
commandButtonLabel: rawLabel,
|
|
|
|
ariaLabel: rawLabel,
|
|
|
|
dropdownItemKey: cellRawType,
|
|
|
|
hasPopup: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
],
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: CopyIcon,
|
|
|
|
iconAlt: copyLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebokCopy(),
|
|
|
|
commandButtonLabel: copyLabel,
|
|
|
|
ariaLabel: copyLabel,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: false,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
iconSrc: CopyIcon,
|
|
|
|
iconAlt: copyLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebokCopy(),
|
|
|
|
commandButtonLabel: copyLabel,
|
|
|
|
ariaLabel: copyLabel,
|
|
|
|
hasPopup: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
disabled: false,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: CutIcon,
|
|
|
|
iconAlt: cutLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookCut(),
|
|
|
|
commandButtonLabel: cutLabel,
|
|
|
|
ariaLabel: cutLabel,
|
|
|
|
hasPopup: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
disabled: false,
|
2020-05-26 03:30:55 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
iconSrc: PasteIcon,
|
|
|
|
iconAlt: pasteLabel,
|
|
|
|
onCommandClick: () => this.notebookComponentAdapter.notebookPaste(),
|
|
|
|
commandButtonLabel: pasteLabel,
|
|
|
|
ariaLabel: pasteLabel,
|
|
|
|
hasPopup: false,
|
2021-01-20 15:15:01 +00:00
|
|
|
disabled: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-05-26 03:30:55 +01:00
|
|
|
// TODO: Uncomment when undo/redo is reimplemented in nteract
|
|
|
|
];
|
|
|
|
|
|
|
|
if (this.container.hasStorageAnalyticsAfecFeature()) {
|
2020-07-27 22:05:25 +01:00
|
|
|
const arcadiaWorkspaceDropdown: CommandButtonComponentProps = {
|
2020-05-26 03:30:55 +01:00
|
|
|
iconSrc: null,
|
|
|
|
iconAlt: workspaceLabel,
|
|
|
|
ariaLabel: workspaceLabel,
|
|
|
|
onCommandClick: () => {},
|
|
|
|
commandButtonLabel: null,
|
|
|
|
hasPopup: false,
|
|
|
|
disabled: this.container.arcadiaWorkspaces.length < 1,
|
|
|
|
isDropdown: false,
|
|
|
|
isArcadiaPicker: true,
|
|
|
|
arcadiaProps: {
|
|
|
|
selectedSparkPool: this.selectedSparkPool(),
|
|
|
|
workspaces: this.container.arcadiaWorkspaces(),
|
|
|
|
onSparkPoolSelect: this.onSparkPoolSelect,
|
|
|
|
onCreateNewWorkspaceClicked: () => {
|
|
|
|
this.container.createWorkspace();
|
|
|
|
},
|
|
|
|
onCreateNewSparkPoolClicked: (workspaceResourceId: string) => {
|
|
|
|
this.container.createSparkPool(workspaceResourceId);
|
2021-01-20 15:15:01 +00:00
|
|
|
},
|
|
|
|
},
|
2020-05-26 03:30:55 +01:00
|
|
|
};
|
|
|
|
buttons.splice(1, 0, arcadiaWorkspaceDropdown);
|
|
|
|
}
|
|
|
|
return buttons;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected buildCommandBarOptions(): void {
|
|
|
|
this.updateNavbarWithTabsButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
private onSparkPoolSelect = (evt: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>, item: any) => {
|
|
|
|
if (!item || !item.text) {
|
|
|
|
this.selectedSparkPool(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.container &&
|
|
|
|
this.container.arcadiaWorkspaces &&
|
|
|
|
this.container.arcadiaWorkspaces() &&
|
2021-01-20 15:15:01 +00:00
|
|
|
this.container.arcadiaWorkspaces().forEach(async (workspace) => {
|
2020-05-26 03:30:55 +01:00
|
|
|
if (workspace && workspace.name && workspace.sparkPools) {
|
2021-01-20 15:15:01 +00:00
|
|
|
const selectedPoolIndex = _.findIndex(workspace.sparkPools, (pool) => pool && pool.name === item.text);
|
2020-05-26 03:30:55 +01:00
|
|
|
if (selectedPoolIndex >= 0) {
|
|
|
|
const selectedPool = workspace.sparkPools[selectedPoolIndex];
|
|
|
|
if (selectedPool && selectedPool.name) {
|
|
|
|
this.container.sparkClusterConnectionInfo({
|
|
|
|
userName: undefined,
|
|
|
|
password: undefined,
|
|
|
|
endpoints: [
|
|
|
|
{
|
2020-08-06 20:03:46 +01:00
|
|
|
endpoint: `https://${workspace.name}.${configContext.ARCADIA_LIVY_ENDPOINT_DNS_ZONE}/livyApi/versions/${ArmApiVersions.arcadiaLivy}/sparkPools/${selectedPool.name}/`,
|
2021-01-20 15:15:01 +00:00
|
|
|
kind: DataModels.SparkClusterEndpointKind.Livy,
|
|
|
|
},
|
|
|
|
],
|
2020-05-26 03:30:55 +01:00
|
|
|
});
|
|
|
|
this.selectedSparkPool(item.text);
|
|
|
|
await this.reconfigureServiceEndpoints();
|
|
|
|
this.container.sparkClusterConnectionInfo.valueHasMutated();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
private onKernelUpdate = async () => {
|
2021-01-20 15:15:01 +00:00
|
|
|
await this.configureServiceEndpoints(this.notebookComponentAdapter.getCurrentKernelName()).catch((reason) => {
|
2020-05-26 03:30:55 +01:00
|
|
|
/* Erroring is ok here */
|
|
|
|
});
|
|
|
|
this.updateNavbarWithTabsButtons();
|
|
|
|
};
|
|
|
|
|
|
|
|
private async configureServiceEndpoints(kernelName: string) {
|
|
|
|
const notebookConnectionInfo = this.container && this.container.notebookServerInfo();
|
|
|
|
const sparkClusterConnectionInfo = this.container && this.container.sparkClusterConnectionInfo();
|
|
|
|
await NotebookConfigurationUtils.configureServiceEndpoints(
|
|
|
|
this.notebookPath(),
|
|
|
|
notebookConnectionInfo,
|
|
|
|
kernelName,
|
|
|
|
sparkClusterConnectionInfo
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-11 08:37:05 +01:00
|
|
|
private publishToGallery = async () => {
|
2020-06-30 19:47:21 +01:00
|
|
|
const notebookContent = this.notebookComponentAdapter.getContent();
|
2020-08-11 08:37:05 +01:00
|
|
|
await this.container.publishNotebook(
|
2020-07-23 08:43:53 +01:00
|
|
|
notebookContent.name,
|
|
|
|
notebookContent.content,
|
|
|
|
this.notebookComponentAdapter.getNotebookParentElement()
|
|
|
|
);
|
2020-06-30 19:47:21 +01:00
|
|
|
};
|
|
|
|
|
2020-08-11 17:27:57 +01:00
|
|
|
private copyNotebook = () => {
|
|
|
|
const notebookContent = this.notebookComponentAdapter.getContent();
|
|
|
|
let content: string;
|
|
|
|
if (typeof notebookContent.content === "string") {
|
|
|
|
content = notebookContent.content;
|
|
|
|
} else {
|
|
|
|
content = stringifyNotebook(toJS(notebookContent.content));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.container.copyNotebook(notebookContent.name, content);
|
|
|
|
};
|
|
|
|
|
2020-05-26 03:30:55 +01:00
|
|
|
private traceTelemetry(actionType: number) {
|
|
|
|
TelemetryProcessor.trace(actionType, ActionModifiers.Mark, {
|
|
|
|
databaseAccountName: this.container.databaseAccount() && this.container.databaseAccount().name,
|
|
|
|
defaultExperience: this.container.defaultExperience && this.container.defaultExperience(),
|
2021-01-20 15:15:01 +00:00
|
|
|
dataExplorerArea: Areas.Notebook,
|
2020-05-26 03:30:55 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|