Skip to content

Commit

Permalink
Add hideInputs query param in notebookViewer and other minor updates (#…
Browse files Browse the repository at this point in the history
…82)

* Add hideInputs query param in notebookViewer

* Fix test and other minor changes

* Make GalleryHeaderComponent more functional
  • Loading branch information
gitanuj authored Jul 10, 2020
1 parent 9bdf7e0 commit dcd6e03
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 32 deletions.
66 changes: 46 additions & 20 deletions src/Explorer/Controls/Header/GalleryHeaderComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import * as React from "react";
import { Stack, Text, Separator, FontIcon, CommandButton, FontWeights } from "office-ui-fabric-react";
import { Stack, Text, Separator, FontIcon, CommandButton, FontWeights, ITextProps } from "office-ui-fabric-react";

export class GalleryHeaderComponent extends React.Component {
private static readonly headerText = "Microsoft Azure";
private static readonly azureText = "Microsoft Azure";
private static readonly cosmosdbText = "Cosmos DB";
private static readonly galleryText = "Gallery";
private static readonly loginText = "Log in";
private static readonly loginOnClick = () => (window.location.href = new URL("./", window.location.href).href);
private static readonly textStyle: React.CSSProperties = {
private static readonly openPortal = () => window.open("https://portal.azure.com", "_blank");
private static readonly openDataExplorer = () => (window.location.href = new URL("./", window.location.href).href);
private static readonly openGallery = () =>
(window.location.href = new URL("./galleryViewer.html", window.location.href).href);
private static readonly headerItemStyle: React.CSSProperties = {
color: "white"
};
private static readonly mainHeaderTextProps: ITextProps = {
style: GalleryHeaderComponent.headerItemStyle,
variant: "mediumPlus",
styles: {
root: {
fontWeight: FontWeights.semibold
}
}
};
private static readonly headerItemTextProps: ITextProps = { style: GalleryHeaderComponent.headerItemStyle };

private renderHeaderItem = (text: string, onClick: () => void, textProps: ITextProps): JSX.Element => {
return (
<CommandButton onClick={onClick} ariaLabel={text}>
<Text {...textProps}>{text}</Text>
</CommandButton>
);
};

public render(): JSX.Element {
return (
Expand All @@ -20,36 +41,41 @@ export class GalleryHeaderComponent extends React.Component {
verticalAlign="center"
>
<Stack.Item>
<Text
style={GalleryHeaderComponent.textStyle}
variant="mediumPlus"
styles={{ root: { fontWeight: FontWeights.semibold } }}
>
{GalleryHeaderComponent.headerText}
</Text>
{this.renderHeaderItem(
GalleryHeaderComponent.azureText,
GalleryHeaderComponent.openPortal,
GalleryHeaderComponent.mainHeaderTextProps
)}
</Stack.Item>
<Stack.Item>
<Separator vertical />
</Stack.Item>
<Stack.Item>
<Text style={GalleryHeaderComponent.textStyle}>{GalleryHeaderComponent.cosmosdbText}</Text>
{this.renderHeaderItem(
GalleryHeaderComponent.cosmosdbText,
GalleryHeaderComponent.openDataExplorer,
GalleryHeaderComponent.headerItemTextProps
)}
</Stack.Item>
<Stack.Item>
<FontIcon style={GalleryHeaderComponent.textStyle} iconName="ChevronRight" />
<FontIcon style={GalleryHeaderComponent.headerItemStyle} iconName="ChevronRight" />
</Stack.Item>
<Stack.Item>
<Text style={GalleryHeaderComponent.textStyle}>{GalleryHeaderComponent.galleryText}</Text>
{this.renderHeaderItem(
GalleryHeaderComponent.galleryText,
GalleryHeaderComponent.openGallery,
GalleryHeaderComponent.headerItemTextProps
)}
</Stack.Item>
<Stack.Item grow>
<></>
</Stack.Item>
<Stack.Item>
<CommandButton
style={GalleryHeaderComponent.textStyle}
text={GalleryHeaderComponent.loginText}
ariaLabel={GalleryHeaderComponent.loginText}
onClick={GalleryHeaderComponent.loginOnClick}
/>
{this.renderHeaderItem(
GalleryHeaderComponent.loginText,
GalleryHeaderComponent.openDataExplorer,
GalleryHeaderComponent.headerItemTextProps
)}
</Stack.Item>
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface NotebookViewerComponentProps {
galleryItem?: IGalleryItem;
isFavorite?: boolean;
backNavigationText: string;
hideInputs?: boolean;
onBackClick: () => void;
onTagClick: (tag: string) => void;
}
Expand Down Expand Up @@ -129,7 +130,9 @@ export class NotebookViewerComponent extends React.Component<NotebookViewerCompo
<></>
)}

{this.notebookComponentBootstrapper.renderComponent(NotebookReadOnlyRenderer, { hideInputs: false })}
{this.notebookComponentBootstrapper.renderComponent(NotebookReadOnlyRenderer, {
hideInputs: this.props.hideInputs
})}

{this.state.dialogProps && <DialogComponent {...this.state.dialogProps} />}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/GalleryViewer/galleryViewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0" />

<title>Gallery Viewer</title>
<link rel="shortcut icon" href="images/CosmosDB_rgb_ui_lighttheme.ico" type="image/x-icon" />
</head>

<body>
Expand Down
13 changes: 10 additions & 3 deletions src/NotebookViewer/NotebookViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,42 @@ import {
import { IGalleryItem, JunoClient } from "../Juno/JunoClient";
import * as GalleryUtils from "../Utils/GalleryUtils";
import { GalleryHeaderComponent } from "../Explorer/Controls/Header/GalleryHeaderComponent";
import { FileSystemUtil } from "../Explorer/Notebook/FileSystemUtil";

const onInit = async () => {
initializeIcons();
await initializeConfiguration();
const galleryViewerProps = GalleryUtils.getGalleryViewerProps(window.location.search);
const notebookViewerProps = GalleryUtils.getNotebookViewerProps(window.location.search);
const backNavigationText = galleryViewerProps.selectedTab && GalleryUtils.getTabTitle(galleryViewerProps.selectedTab);
const hideInputs = notebookViewerProps.hideInputs;

const notebookUrl = decodeURIComponent(notebookViewerProps.notebookUrl);
render(notebookUrl, backNavigationText);
render(notebookUrl, backNavigationText, hideInputs);

const galleryItemId = notebookViewerProps.galleryItemId;
if (galleryItemId) {
const junoClient = new JunoClient();
const notebook = await junoClient.getNotebook(galleryItemId);
render(notebookUrl, backNavigationText, notebook.data);
render(notebookUrl, backNavigationText, hideInputs, notebook.data);
}
};

const render = (notebookUrl: string, backNavigationText: string, galleryItem?: IGalleryItem) => {
const render = (notebookUrl: string, backNavigationText: string, hideInputs: boolean, galleryItem?: IGalleryItem) => {
const props: NotebookViewerComponentProps = {
junoClient: galleryItem ? new JunoClient() : undefined,
notebookUrl,
galleryItem,
backNavigationText,
hideInputs,
onBackClick: undefined,
onTagClick: undefined
};

if (galleryItem) {
document.title = FileSystemUtil.stripExtension(galleryItem.name, "ipynb");
}

const element = (
<>
<header>
Expand Down
2 changes: 1 addition & 1 deletion src/NotebookViewer/notebookViewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0" />

<title>Notebook Viewer</title>
<link rel="shortcut icon" href="images/CosmosDB_rgb_ui_lighttheme.ico" type="image/x-icon" />
</head>

<body>
Expand Down
10 changes: 6 additions & 4 deletions src/Utils/GalleryUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,23 @@ describe("GalleryUtils", () => {
selectedTab,
sortBy,
searchText: decodeURIComponent(searchText)
});
} as GalleryUtils.GalleryViewerProps);
});

it("getNotebookViewerProps gets notebook viewer props correctly", () => {
const notebookUrl = "https%3A%2F%2Fnotebook.url";
const galleryItemId = "1234-abcd-efgh";
const hideInputs = "true";

const response = GalleryUtils.getNotebookViewerProps(
`?${GalleryUtils.NotebookViewerParams.NotebookUrl}=${notebookUrl}&${GalleryUtils.NotebookViewerParams.GalleryItemId}=${galleryItemId}`
`?${GalleryUtils.NotebookViewerParams.NotebookUrl}=${notebookUrl}&${GalleryUtils.NotebookViewerParams.GalleryItemId}=${galleryItemId}&${GalleryUtils.NotebookViewerParams.HideInputs}=${hideInputs}`
);

expect(response).toEqual({
notebookUrl: decodeURIComponent(notebookUrl),
galleryItemId
});
galleryItemId,
hideInputs: true
} as GalleryUtils.NotebookViewerProps);
});

it("getTabTitle returns correct title for official samples", () => {
Expand Down
7 changes: 5 additions & 2 deletions src/Utils/GalleryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export interface DialogEnabledComponent {

export enum NotebookViewerParams {
NotebookUrl = "notebookUrl",
GalleryItemId = "galleryItemId"
GalleryItemId = "galleryItemId",
HideInputs = "hideInputs"
}

export interface NotebookViewerProps {
notebookUrl: string;
galleryItemId: string;
hideInputs: boolean;
}

export enum GalleryViewerParams {
Expand Down Expand Up @@ -244,7 +246,8 @@ export function getNotebookViewerProps(search: string): NotebookViewerProps {
const params = new URLSearchParams(search);
return {
notebookUrl: params.get(NotebookViewerParams.NotebookUrl),
galleryItemId: params.get(NotebookViewerParams.GalleryItemId)
galleryItemId: params.get(NotebookViewerParams.GalleryItemId),
hideInputs: JSON.parse(params.get(NotebookViewerParams.HideInputs))
};
}

Expand Down

0 comments on commit dcd6e03

Please sign in to comment.