mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 09:20:16 +00:00
Copy To functionality for notebooks (#141)
* Add Copy To functionality for notebooks * Fix formatting * Fix linting errors * Fixes * Fix build failure * Rebase and address feedback * Increase test coverage
This commit is contained in:
@@ -30,6 +30,7 @@ import { configContext } from "../../ConfigContext";
|
||||
import Explorer from "../Explorer";
|
||||
import { NotebookContentItem } from "../Notebook/NotebookContentItem";
|
||||
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
|
||||
import { toJS, stringifyNotebook } from "@nteract/commutable";
|
||||
|
||||
export interface NotebookTabOptions extends ViewModels.TabOptions {
|
||||
account: DataModels.DatabaseAccount;
|
||||
@@ -122,6 +123,7 @@ export default class NotebookTabV2 extends TabsBase {
|
||||
const availableKernels = NotebookTabV2.clientManager.getAvailableKernelSpecs();
|
||||
|
||||
const saveLabel = "Save";
|
||||
const copyToLabel = "Copy to ...";
|
||||
const publishLabel = "Publish to gallery";
|
||||
const workspaceLabel = "No Workspace";
|
||||
const kernelLabel = "No Kernel";
|
||||
@@ -164,6 +166,14 @@ export default class NotebookTabV2 extends TabsBase {
|
||||
disabled: false,
|
||||
ariaLabel: saveLabel
|
||||
},
|
||||
{
|
||||
iconName: "Copy",
|
||||
onCommandClick: () => this.copyNotebook(),
|
||||
commandButtonLabel: copyToLabel,
|
||||
hasPopup: false,
|
||||
disabled: false,
|
||||
ariaLabel: copyToLabel
|
||||
},
|
||||
{
|
||||
iconName: "PublishContent",
|
||||
onCommandClick: async () => await this.publishToGallery(),
|
||||
@@ -465,6 +475,18 @@ export default class NotebookTabV2 extends TabsBase {
|
||||
);
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
private traceTelemetry(actionType: number) {
|
||||
TelemetryProcessor.trace(actionType, ActionModifiers.Mark, {
|
||||
databaseAccountName: this.container.databaseAccount() && this.container.databaseAccount().name,
|
||||
|
||||
Reference in New Issue
Block a user