mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 23:16:56 +00:00
Remove injected cell before download (#467)
* remove newcell on download * addressed pr comments
This commit is contained in:
parent
d314a20b81
commit
3a1841ad3c
@ -15,7 +15,6 @@ import { Dialog, DialogProps, TextFieldProps } from "../Dialog";
|
|||||||
import { NotebookMetadataComponent } from "./NotebookMetadataComponent";
|
import { NotebookMetadataComponent } from "./NotebookMetadataComponent";
|
||||||
import "./NotebookViewerComponent.less";
|
import "./NotebookViewerComponent.less";
|
||||||
import Explorer from "../../Explorer";
|
import Explorer from "../../Explorer";
|
||||||
import { NotebookV4 } from "@nteract/commutable/lib/v4";
|
|
||||||
import { SessionStorageUtility } from "../../../Shared/StorageUtility";
|
import { SessionStorageUtility } from "../../../Shared/StorageUtility";
|
||||||
import { DialogHost } from "../../../Utils/GalleryUtils";
|
import { DialogHost } from "../../../Utils/GalleryUtils";
|
||||||
import { getErrorMessage, getErrorStack, handleError } from "../../../Common/ErrorHandlingUtils";
|
import { getErrorMessage, getErrorStack, handleError } from "../../../Common/ErrorHandlingUtils";
|
||||||
@ -103,7 +102,7 @@ export class NotebookViewerComponent
|
|||||||
);
|
);
|
||||||
|
|
||||||
const notebook: Notebook = await response.json();
|
const notebook: Notebook = await response.json();
|
||||||
this.removeNotebookViewerLink(notebook, this.props.galleryItem?.newCellId);
|
GalleryUtils.removeNotebookViewerLink(notebook, this.props.galleryItem?.newCellId);
|
||||||
this.notebookComponentBootstrapper.setContent("json", notebook);
|
this.notebookComponentBootstrapper.setContent("json", notebook);
|
||||||
this.setState({ content: notebook, showProgressBar: false });
|
this.setState({ content: notebook, showProgressBar: false });
|
||||||
|
|
||||||
@ -133,17 +132,6 @@ export class NotebookViewerComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeNotebookViewerLink = (notebook: Notebook, newCellId: string): void => {
|
|
||||||
if (!newCellId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const notebookV4 = notebook as NotebookV4;
|
|
||||||
if (notebookV4 && notebookV4.cells[0].source[0].search(newCellId)) {
|
|
||||||
delete notebookV4.cells[0];
|
|
||||||
notebook = notebookV4;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public render(): JSX.Element {
|
public render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div className="notebookViewerContainer">
|
<div className="notebookViewerContainer">
|
||||||
|
@ -13,6 +13,8 @@ import { getErrorMessage, getErrorStack, handleError } from "../Common/ErrorHand
|
|||||||
import { HttpStatusCodes } from "../Common/Constants";
|
import { HttpStatusCodes } from "../Common/Constants";
|
||||||
import { trace, traceFailure, traceStart, traceSuccess } from "../Shared/Telemetry/TelemetryProcessor";
|
import { trace, traceFailure, traceStart, traceSuccess } from "../Shared/Telemetry/TelemetryProcessor";
|
||||||
import { Action, ActionModifiers } from "../Shared/Telemetry/TelemetryConstants";
|
import { Action, ActionModifiers } from "../Shared/Telemetry/TelemetryConstants";
|
||||||
|
import { Notebook } from "@nteract/commutable";
|
||||||
|
import { NotebookV4 } from "@nteract/commutable/lib/v4";
|
||||||
|
|
||||||
const defaultSelectedAbuseCategory = "Other";
|
const defaultSelectedAbuseCategory = "Other";
|
||||||
const abuseCategories: IChoiceGroupOption[] = [
|
const abuseCategories: IChoiceGroupOption[] = [
|
||||||
@ -243,7 +245,10 @@ export function downloadItem(
|
|||||||
throw new Error(`Received HTTP ${response.status} when fetching ${data.name}`);
|
throw new Error(`Received HTTP ${response.status} when fetching ${data.name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await container.importAndOpenContent(data.name, response.data);
|
const notebook = JSON.parse(response.data) as Notebook;
|
||||||
|
removeNotebookViewerLink(notebook, data.newCellId);
|
||||||
|
|
||||||
|
await container.importAndOpenContent(data.name, JSON.stringify(notebook));
|
||||||
NotificationConsoleUtils.logConsoleMessage(
|
NotificationConsoleUtils.logConsoleMessage(
|
||||||
ConsoleDataType.Info,
|
ConsoleDataType.Info,
|
||||||
`Successfully downloaded ${name} to My Notebooks`
|
`Successfully downloaded ${name} to My Notebooks`
|
||||||
@ -281,6 +286,17 @@ export function downloadItem(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const removeNotebookViewerLink = (notebook: Notebook, newCellId: string): void => {
|
||||||
|
if (!newCellId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const notebookV4 = notebook as NotebookV4;
|
||||||
|
if (notebookV4?.cells[0]?.source[0]?.search(newCellId)) {
|
||||||
|
notebookV4.cells.splice(0, 1);
|
||||||
|
notebook = notebookV4;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export async function favoriteItem(
|
export async function favoriteItem(
|
||||||
container: Explorer,
|
container: Explorer,
|
||||||
junoClient: JunoClient,
|
junoClient: JunoClient,
|
||||||
|
Loading…
Reference in New Issue
Block a user