diff --git a/src/Explorer/Panes/CopyNotebookPane.tsx b/src/Explorer/Panes/CopyNotebookPane.tsx index 62ad1c6c7..586af6318 100644 --- a/src/Explorer/Panes/CopyNotebookPane.tsx +++ b/src/Explorer/Panes/CopyNotebookPane.tsx @@ -6,17 +6,8 @@ import { JunoClient, IPinnedRepo } from "../../Juno/JunoClient"; import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils"; import Explorer from "../Explorer"; import { GenericRightPaneComponent, GenericRightPaneProps } from "./GenericRightPaneComponent"; -import { - Stack, - Label, - Text, - Dropdown, - IDropdownProps, - IDropdownOption, - SelectableOptionMenuItemType, - IRenderFunction, - ISelectableOption -} from "office-ui-fabric-react"; +import { CopyNotebookPaneComponent, CopyNotebookPaneProps } from "./CopyNotebookPaneComponent"; +import { IDropdownOption } from "office-ui-fabric-react"; import { GitHubOAuthService } from "../../GitHub/GitHubOAuthService"; import { HttpStatusCodes } from "../../Common/Constants"; import * as GitHubUtils from "../../Utils/GitHubUtils"; @@ -60,9 +51,8 @@ export class CopyNotebookPaneAdapter implements ReactAdapter { return undefined; } - const props: GenericRightPaneProps = { + const genericPaneProps: GenericRightPaneProps = { container: this.container, - content: this.createContent(), formError: this.formError, formErrorDetail: this.formErrorDetail, id: "copynotebookpane", @@ -73,7 +63,17 @@ export class CopyNotebookPaneAdapter implements ReactAdapter { onSubmit: () => this.submit() }; - return ; + const copyNotebookPaneProps: CopyNotebookPaneProps = { + name: this.name, + pinnedRepos: this.pinnedRepos, + onDropDownChange: this.onDropDownChange + }; + + return ( + + + + ); } public triggerRender(): void { @@ -181,91 +181,6 @@ export class CopyNotebookPaneAdapter implements ReactAdapter { return this.container.uploadFile(this.name, this.content, parent); }; - private createContent = (): JSX.Element => { - const dropDownProps: IDropdownProps = { - label: "Location", - ariaLabel: "Location", - placeholder: "Select an option", - onRenderTitle: this.onRenderDropDownTitle, - onRenderOption: this.onRenderDropDownOption, - options: this.getDropDownOptions(), - onChange: this.onDropDownChange - }; - - return ( -
- - - - {this.name} - - - - -
- ); - }; - - private onRenderDropDownTitle: IRenderFunction = (options: IDropdownOption[]): JSX.Element => { - return {options.length && options[0].title}; - }; - - private onRenderDropDownOption: IRenderFunction = (option: ISelectableOption): JSX.Element => { - return {option.text}; - }; - - private getDropDownOptions = (): IDropdownOption[] => { - const options: IDropdownOption[] = []; - - options.push({ - key: "MyNotebooks-Item", - text: ResourceTreeAdapter.MyNotebooksTitle, - title: ResourceTreeAdapter.MyNotebooksTitle, - data: { - type: "MyNotebooks" - } as Location - }); - - if (this.pinnedRepos && this.pinnedRepos.length > 0) { - options.push({ - key: "GitHub-Header-Divider", - text: undefined, - itemType: SelectableOptionMenuItemType.Divider - }); - - options.push({ - key: "GitHub-Header", - text: ResourceTreeAdapter.GitHubReposTitle, - itemType: SelectableOptionMenuItemType.Header - }); - - this.pinnedRepos.forEach(pinnedRepo => { - const repoFullName = GitHubUtils.toRepoFullName(pinnedRepo.owner, pinnedRepo.name); - options.push({ - key: `GitHub-Repo-${repoFullName}`, - text: repoFullName, - disabled: true - }); - - pinnedRepo.branches.forEach(branch => - options.push({ - key: `GitHub-Repo-${repoFullName}-${branch.name}`, - text: `${CopyNotebookPaneAdapter.BranchNameWhiteSpace}${branch.name}`, - title: `${repoFullName} - ${branch.name}`, - data: { - type: "GitHub", - owner: pinnedRepo.owner, - repo: pinnedRepo.name, - branch: branch.name - } as Location - }) - ); - }); - } - - return options; - }; - private onDropDownChange = (_: React.FormEvent, option?: IDropdownOption): void => { this.selectedLocation = option?.data; }; diff --git a/src/Explorer/Panes/CopyNotebookPaneComponent.tsx b/src/Explorer/Panes/CopyNotebookPaneComponent.tsx new file mode 100644 index 000000000..da3e87958 --- /dev/null +++ b/src/Explorer/Panes/CopyNotebookPaneComponent.tsx @@ -0,0 +1,119 @@ +import * as GitHubUtils from "../../Utils/GitHubUtils"; +import * as React from "react"; +import { IPinnedRepo } from "../../Juno/JunoClient"; +import { ResourceTreeAdapter } from "../Tree/ResourceTreeAdapter"; +import { + Stack, + Label, + Text, + Dropdown, + IDropdownProps, + IDropdownOption, + SelectableOptionMenuItemType, + IRenderFunction, + ISelectableOption +} from "office-ui-fabric-react"; + +interface Location { + type: "MyNotebooks" | "GitHub"; + + // GitHub + owner?: string; + repo?: string; + branch?: string; +} + +export interface CopyNotebookPaneProps { + name: string; + pinnedRepos: IPinnedRepo[]; + onDropDownChange: (_: React.FormEvent, option?: IDropdownOption) => void; +} + +export class CopyNotebookPaneComponent extends React.Component { + private static readonly BranchNameWhiteSpace = " "; + + public render(): JSX.Element { + const dropDownProps: IDropdownProps = { + label: "Location", + ariaLabel: "Location", + placeholder: "Select an option", + onRenderTitle: this.onRenderDropDownTitle, + onRenderOption: this.onRenderDropDownOption, + options: this.getDropDownOptions(), + onChange: this.props.onDropDownChange + }; + + return ( +
+ + + + {this.props.name} + + + + +
+ ); + } + + private onRenderDropDownTitle: IRenderFunction = (options: IDropdownOption[]): JSX.Element => { + return {options.length && options[0].title}; + }; + + private onRenderDropDownOption: IRenderFunction = (option: ISelectableOption): JSX.Element => { + return {option.text}; + }; + + private getDropDownOptions = (): IDropdownOption[] => { + const options: IDropdownOption[] = []; + + options.push({ + key: "MyNotebooks-Item", + text: ResourceTreeAdapter.MyNotebooksTitle, + title: ResourceTreeAdapter.MyNotebooksTitle, + data: { + type: "MyNotebooks" + } as Location + }); + + if (this.props.pinnedRepos && this.props.pinnedRepos.length > 0) { + options.push({ + key: "GitHub-Header-Divider", + text: undefined, + itemType: SelectableOptionMenuItemType.Divider + }); + + options.push({ + key: "GitHub-Header", + text: ResourceTreeAdapter.GitHubReposTitle, + itemType: SelectableOptionMenuItemType.Header + }); + + this.props.pinnedRepos.forEach(pinnedRepo => { + const repoFullName = GitHubUtils.toRepoFullName(pinnedRepo.owner, pinnedRepo.name); + options.push({ + key: `GitHub-Repo-${repoFullName}`, + text: repoFullName, + disabled: true + }); + + pinnedRepo.branches.forEach(branch => + options.push({ + key: `GitHub-Repo-${repoFullName}-${branch.name}`, + text: `${CopyNotebookPaneComponent.BranchNameWhiteSpace}${branch.name}`, + title: `${repoFullName} - ${branch.name}`, + data: { + type: "GitHub", + owner: pinnedRepo.owner, + repo: pinnedRepo.name, + branch: branch.name + } as Location + }) + ); + }); + } + + return options; + }; +} diff --git a/src/Explorer/Panes/GenericRightPaneComponent.tsx b/src/Explorer/Panes/GenericRightPaneComponent.tsx index f4e4d2285..30f278349 100644 --- a/src/Explorer/Panes/GenericRightPaneComponent.tsx +++ b/src/Explorer/Panes/GenericRightPaneComponent.tsx @@ -8,7 +8,6 @@ import Explorer from "../Explorer"; export interface GenericRightPaneProps { container: Explorer; - content: JSX.Element; formError: string; formErrorDetail: string; id: string; @@ -57,18 +56,18 @@ export class GenericRightPaneComponent extends React.Component
- {this.createPanelHeader()} - {this.createErrorSection()} - {this.props.content} - {this.createPanelFooter()} + {this.renderPanelHeader()} + {this.renderErrorSection()} + {this.props.children} + {this.renderPanelFooter()}
- {this.createLoadingScreen()} + {this.renderLoadingScreen()} ); } - private createPanelHeader = (): JSX.Element => { + private renderPanelHeader = (): JSX.Element => { return (
{this.props.title} @@ -84,7 +83,7 @@ export class GenericRightPaneComponent extends React.Component { + private renderErrorSection = (): JSX.Element => { return (