mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-24 03:11:32 +00:00
[Preview this branch](https://cosmos-explorer-preview.azurewebsites.net/pull/762?feature.someFeatureFlagYouMightNeed=true) The main change in this PR fixes the snapshot functionality in the Publish pane-related components. Because the code cell outputs are now rendered in their own iframes for security reasons, a single snapshot of the notebook is no longer possible: each cell output takes its own snapshot and the snapshots are collated on the main notebook snapshot. - Move the snapshot functionality to notebook components: this removes the reference of the notebook DOM node that we must pass to the Publish pane via explorer. - Add slice in the state and actions in notebook redux for notebook snapshot requests and result - Add post robot message to take snapshots and receive results - Add logic in `NotebookRenderer` to wait for all output snapshots done before taking the main one collating. - Use `zustand` to share snapshot between Redux world and React world. This solves the issue of keeping the `PanelContainer` component generic, while being able to update its children (`PublishPanel` component) with the new snapshot. Additional changes: - Add `local()` in `@font-face` to check if font is already installed before downloading the font (must be done for Safari, but not Edge/Chrome) - Add "Export output to image" menu item in notebook cell, since each cell output can take its own snapshot (which can be downloaded) 
154 lines
3.6 KiB
TypeScript
154 lines
3.6 KiB
TypeScript
import { CellId } from "@nteract/commutable";
|
|
import { ContentRef } from "@nteract/core";
|
|
import { Action } from "../../../Shared/Telemetry/TelemetryConstants";
|
|
import { SnapshotFragment, SnapshotRequest } from "./types";
|
|
|
|
export const CLOSE_NOTEBOOK = "CLOSE_NOTEBOOK";
|
|
export interface CloseNotebookAction {
|
|
type: "CLOSE_NOTEBOOK";
|
|
payload: {
|
|
contentRef: ContentRef;
|
|
};
|
|
}
|
|
|
|
export const closeNotebook = (payload: { contentRef: ContentRef }): CloseNotebookAction => {
|
|
return {
|
|
type: CLOSE_NOTEBOOK,
|
|
payload,
|
|
};
|
|
};
|
|
|
|
export const EXECUTE_FOCUSED_CELL_AND_FOCUS_NEXT = "EXECUTE_FOCUSED_CELL_AND_FOCUS_NEXT";
|
|
export interface ExecuteFocusedCellAndFocusNextAction {
|
|
type: "EXECUTE_FOCUSED_CELL_AND_FOCUS_NEXT";
|
|
payload: {
|
|
contentRef: ContentRef;
|
|
};
|
|
}
|
|
|
|
export const executeFocusedCellAndFocusNext = (payload: {
|
|
contentRef: ContentRef;
|
|
}): ExecuteFocusedCellAndFocusNextAction => {
|
|
return {
|
|
type: EXECUTE_FOCUSED_CELL_AND_FOCUS_NEXT,
|
|
payload,
|
|
};
|
|
};
|
|
|
|
export const UPDATE_KERNEL_RESTART_DELAY = "UPDATE_KERNEL_RESTART_DELAY";
|
|
export interface UpdateKernelRestartDelayAction {
|
|
type: "UPDATE_KERNEL_RESTART_DELAY";
|
|
payload: {
|
|
delayMs: number;
|
|
};
|
|
}
|
|
|
|
export const UpdateKernelRestartDelay = (payload: { delayMs: number }): UpdateKernelRestartDelayAction => {
|
|
return {
|
|
type: UPDATE_KERNEL_RESTART_DELAY,
|
|
payload,
|
|
};
|
|
};
|
|
|
|
export const SET_HOVERED_CELL = "SET_HOVERED_CELL";
|
|
export interface SetHoveredCellAction {
|
|
type: "SET_HOVERED_CELL";
|
|
payload: {
|
|
cellId: CellId;
|
|
};
|
|
}
|
|
|
|
export const setHoveredCell = (payload: { cellId: CellId }): SetHoveredCellAction => {
|
|
return {
|
|
type: SET_HOVERED_CELL,
|
|
payload,
|
|
};
|
|
};
|
|
|
|
export const TRACE_NOTEBOOK_TELEMETRY = "TRACE_NOTEBOOK_TELEMETRY";
|
|
export interface TraceNotebookTelemetryAction {
|
|
type: "TRACE_NOTEBOOK_TELEMETRY";
|
|
payload: {
|
|
action: Action;
|
|
actionModifier?: string;
|
|
data?: any;
|
|
};
|
|
}
|
|
|
|
export const traceNotebookTelemetry = (payload: {
|
|
action: Action;
|
|
actionModifier?: string;
|
|
data?: any;
|
|
}): TraceNotebookTelemetryAction => {
|
|
return {
|
|
type: TRACE_NOTEBOOK_TELEMETRY,
|
|
payload,
|
|
};
|
|
};
|
|
|
|
export const STORE_CELL_OUTPUT_SNAPSHOT = "STORE_CELL_OUTPUT_SNAPSHOT";
|
|
export interface StoreCellOutputSnapshotAction {
|
|
type: "STORE_CELL_OUTPUT_SNAPSHOT";
|
|
payload: {
|
|
cellId: string;
|
|
snapshot: SnapshotFragment;
|
|
};
|
|
}
|
|
|
|
export const storeCellOutputSnapshot = (payload: {
|
|
cellId: string;
|
|
snapshot: SnapshotFragment;
|
|
}): StoreCellOutputSnapshotAction => {
|
|
return {
|
|
type: STORE_CELL_OUTPUT_SNAPSHOT,
|
|
payload,
|
|
};
|
|
};
|
|
|
|
export const STORE_NOTEBOOK_SNAPSHOT = "STORE_NOTEBOOK_SNAPSHOT";
|
|
export interface StoreNotebookSnapshotAction {
|
|
type: "STORE_NOTEBOOK_SNAPSHOT";
|
|
payload: {
|
|
imageSrc: string;
|
|
requestId: string;
|
|
};
|
|
}
|
|
|
|
export const storeNotebookSnapshot = (payload: {
|
|
imageSrc: string;
|
|
requestId: string;
|
|
}): StoreNotebookSnapshotAction => {
|
|
return {
|
|
type: STORE_NOTEBOOK_SNAPSHOT,
|
|
payload,
|
|
};
|
|
};
|
|
|
|
export const TAKE_NOTEBOOK_SNAPSHOT = "TAKE_NOTEBOOK_SNAPSHOT";
|
|
export interface TakeNotebookSnapshotAction {
|
|
type: "TAKE_NOTEBOOK_SNAPSHOT";
|
|
payload: SnapshotRequest;
|
|
}
|
|
|
|
export const takeNotebookSnapshot = (payload: SnapshotRequest): TakeNotebookSnapshotAction => {
|
|
return {
|
|
type: TAKE_NOTEBOOK_SNAPSHOT,
|
|
payload,
|
|
};
|
|
};
|
|
|
|
export const NOTEBOOK_SNAPSHOT_ERROR = "NOTEBOOK_SNAPSHOT_ERROR";
|
|
export interface NotebookSnapshotErrorAction {
|
|
type: "NOTEBOOK_SNAPSHOT_ERROR";
|
|
payload: {
|
|
error: string;
|
|
};
|
|
}
|
|
|
|
export const notebookSnapshotError = (payload: { error: string }): NotebookSnapshotErrorAction => {
|
|
return {
|
|
type: NOTEBOOK_SNAPSHOT_ERROR,
|
|
payload,
|
|
};
|
|
};
|