Support showing only notebook output scenario (#177)
* Enable hiding prompt when hiding inputs (so that only output is showing) * Fix format * Rename variable * Use nteract prompt instead of copying source
This commit is contained in:
parent
832f8d560d
commit
26c832437b
|
@ -30,6 +30,7 @@ export interface NotebookViewerComponentProps {
|
||||||
isFavorite?: boolean;
|
isFavorite?: boolean;
|
||||||
backNavigationText: string;
|
backNavigationText: string;
|
||||||
hideInputs?: boolean;
|
hideInputs?: boolean;
|
||||||
|
hidePrompts?: boolean;
|
||||||
onBackClick: () => void;
|
onBackClick: () => void;
|
||||||
onTagClick: (tag: string) => void;
|
onTagClick: (tag: string) => void;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +149,8 @@ export class NotebookViewerComponent extends React.Component<
|
||||||
{this.state.showProgressBar && <ProgressIndicator />}
|
{this.state.showProgressBar && <ProgressIndicator />}
|
||||||
|
|
||||||
{this.notebookComponentBootstrapper.renderComponent(NotebookReadOnlyRenderer, {
|
{this.notebookComponentBootstrapper.renderComponent(NotebookReadOnlyRenderer, {
|
||||||
hideInputs: this.props.hideInputs
|
hideInputs: this.props.hideInputs,
|
||||||
|
hidePrompts: this.props.hidePrompts
|
||||||
})}
|
})}
|
||||||
|
|
||||||
{this.state.dialogProps && <DialogComponent {...this.state.dialogProps} />}
|
{this.state.dialogProps && <DialogComponent {...this.state.dialogProps} />}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import "./base.css";
|
||||||
import "./default.css";
|
import "./default.css";
|
||||||
|
|
||||||
import { CodeCell, RawCell, Cells, MarkdownCell } from "@nteract/stateful-components";
|
import { CodeCell, RawCell, Cells, MarkdownCell } from "@nteract/stateful-components";
|
||||||
|
import Prompt, { PassedPromptProps } from "@nteract/stateful-components/lib/inputs/prompt";
|
||||||
import { AzureTheme } from "./AzureTheme";
|
import { AzureTheme } from "./AzureTheme";
|
||||||
|
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
|
@ -15,6 +16,7 @@ import "./NotebookReadOnlyRenderer.less";
|
||||||
export interface NotebookRendererProps {
|
export interface NotebookRendererProps {
|
||||||
contentRef: any;
|
contentRef: any;
|
||||||
hideInputs?: boolean;
|
hideInputs?: boolean;
|
||||||
|
hidePrompts?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PassedEditorProps {
|
interface PassedEditorProps {
|
||||||
|
@ -38,6 +40,29 @@ class NotebookReadOnlyRenderer extends React.Component<NotebookRendererProps> {
|
||||||
loadTransform(this.props as any);
|
loadTransform(this.props as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private renderPrompt(id: string, contentRef: string): JSX.Element {
|
||||||
|
if (this.props.hidePrompts) {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Prompt id={id} contentRef={contentRef}>
|
||||||
|
{(props: PassedPromptProps) => {
|
||||||
|
if (props.status === "busy") {
|
||||||
|
return <React.Fragment>{"[*]"}</React.Fragment>;
|
||||||
|
}
|
||||||
|
if (props.status === "queued") {
|
||||||
|
return <React.Fragment>{"[…]"}</React.Fragment>;
|
||||||
|
}
|
||||||
|
if (typeof props.executionCount === "number") {
|
||||||
|
return <React.Fragment>{`[${props.executionCount}]`}</React.Fragment>;
|
||||||
|
}
|
||||||
|
return <React.Fragment>{"[ ]"}</React.Fragment>;
|
||||||
|
}}
|
||||||
|
</Prompt>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render(): JSX.Element {
|
render(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div className="NotebookReadOnlyRender">
|
<div className="NotebookReadOnlyRender">
|
||||||
|
@ -46,6 +71,7 @@ class NotebookReadOnlyRenderer extends React.Component<NotebookRendererProps> {
|
||||||
code: ({ id, contentRef }: { id: any; contentRef: ContentRef }) => (
|
code: ({ id, contentRef }: { id: any; contentRef: ContentRef }) => (
|
||||||
<CodeCell id={id} contentRef={contentRef}>
|
<CodeCell id={id} contentRef={contentRef}>
|
||||||
{{
|
{{
|
||||||
|
prompt: (props: { id: string; contentRef: string }) => this.renderPrompt(props.id, props.contentRef),
|
||||||
editor: {
|
editor: {
|
||||||
codemirror: (props: PassedEditorProps) =>
|
codemirror: (props: PassedEditorProps) =>
|
||||||
this.props.hideInputs ? <></> : <CodeMirrorEditor {...props} readOnly={"nocursor"} />
|
this.props.hideInputs ? <></> : <CodeMirrorEditor {...props} readOnly={"nocursor"} />
|
||||||
|
|
|
@ -35,13 +35,19 @@ const onInit = async () => {
|
||||||
const galleryItemJunoResponse = await junoClient.getNotebookInfo(galleryItemId);
|
const galleryItemJunoResponse = await junoClient.getNotebookInfo(galleryItemId);
|
||||||
galleryItem = galleryItemJunoResponse.data;
|
galleryItem = galleryItemJunoResponse.data;
|
||||||
}
|
}
|
||||||
render(notebookUrl, backNavigationText, hideInputs, galleryItem, onBackClick);
|
|
||||||
|
// The main purpose of hiding the prompt is to hide everything when hiding inputs.
|
||||||
|
// It is generally not very useful to just hide the prompt.
|
||||||
|
const hidePrompts = hideInputs;
|
||||||
|
|
||||||
|
render(notebookUrl, backNavigationText, hideInputs, hidePrompts, galleryItem, onBackClick);
|
||||||
};
|
};
|
||||||
|
|
||||||
const render = (
|
const render = (
|
||||||
notebookUrl: string,
|
notebookUrl: string,
|
||||||
backNavigationText: string,
|
backNavigationText: string,
|
||||||
hideInputs: boolean,
|
hideInputs?: boolean,
|
||||||
|
hidePrompts?: boolean,
|
||||||
galleryItem?: IGalleryItem,
|
galleryItem?: IGalleryItem,
|
||||||
onBackClick?: () => void
|
onBackClick?: () => void
|
||||||
) => {
|
) => {
|
||||||
|
@ -51,6 +57,7 @@ const render = (
|
||||||
galleryItem,
|
galleryItem,
|
||||||
backNavigationText,
|
backNavigationText,
|
||||||
hideInputs,
|
hideInputs,
|
||||||
|
hidePrompts,
|
||||||
onBackClick: onBackClick,
|
onBackClick: onBackClick,
|
||||||
onTagClick: undefined
|
onTagClick: undefined
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue