From 3b6fda4fa521eb8cd2873948a6e18de4ae6aa7c1 Mon Sep 17 00:00:00 2001 From: Srinath Narayanan Date: Wed, 3 Feb 2021 10:46:51 -0800 Subject: [PATCH] Changes to notebook publish pane (#419) * Changes to publish pane * fixed format errors * fixed failing test Co-authored-by: Tanuj Mittal --- .../Panes/PublishNotebookPaneAdapter.tsx | 16 ++++++++++------ .../Panes/PublishNotebookPaneComponent.tsx | 9 ++++++--- .../PublishNotebookPaneComponent.test.tsx.snap | 17 +++++++++-------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Explorer/Panes/PublishNotebookPaneAdapter.tsx b/src/Explorer/Panes/PublishNotebookPaneAdapter.tsx index 0822e7aeb..5c1313020 100644 --- a/src/Explorer/Panes/PublishNotebookPaneAdapter.tsx +++ b/src/Explorer/Panes/PublishNotebookPaneAdapter.tsx @@ -70,7 +70,7 @@ export class PublishNotebookPaneAdapter implements ReactAdapter { onChangeDescription: (newValue: string) => (this.description = newValue), onChangeTags: (newValue: string) => (this.tags = newValue), onChangeImageSrc: (newValue: string) => (this.imageSrc = newValue), - onError: this.createFormErrorForLargeImageSelection, + onError: this.createFormError, clearFormError: this.clearFormError, }; @@ -146,11 +146,15 @@ export class PublishNotebookPaneAdapter implements ReactAdapter { let startKey: number; - try { - if (!this.name || !this.description || !this.author) { - throw new Error("Name, description, and author are required"); - } + if (!this.name || !this.description || !this.author || !this.imageSrc) { + const formError = `Failed to publish ${this.name} to gallery`; + const formErrorDetail = "Name, description, author and cover image are required"; + this.createFormError(formError, formErrorDetail, "PublishNotebookPaneAdapter/submit"); + this.isExecuting = false; + return; + } + try { startKey = traceStart(Action.NotebooksGalleryPublish, { databaseAccountName: this.container.databaseAccount()?.name, defaultExperience: this.container.defaultExperience(), @@ -217,7 +221,7 @@ export class PublishNotebookPaneAdapter implements ReactAdapter { this.close(); } - private createFormErrorForLargeImageSelection = (formError: string, formErrorDetail: string, area: string): void => { + private createFormError = (formError: string, formErrorDetail: string, area: string): void => { this.formError = formError; this.formErrorDetail = formErrorDetail; handleError(formErrorDetail, area, formError); diff --git a/src/Explorer/Panes/PublishNotebookPaneComponent.tsx b/src/Explorer/Panes/PublishNotebookPaneComponent.tsx index 5c8697ec7..4d6278d27 100644 --- a/src/Explorer/Panes/PublishNotebookPaneComponent.tsx +++ b/src/Explorer/Panes/PublishNotebookPaneComponent.tsx @@ -54,7 +54,7 @@ export class PublishNotebookPaneComponent extends React.Component { this.props.onChangeImageSrc(newValue); this.setState({ imageSrc: newValue }); @@ -140,7 +141,7 @@ export class PublishNotebookPaneComponent extends React.Component ({ text: value, key: value })), onChange: async (event, options) => { + this.setState({ imageSrc: undefined }); + this.props.onChangeImageSrc(undefined); this.props.clearFormError(); if (options.text === ImageTypes.TakeScreenshot) { try { diff --git a/src/Explorer/Panes/__snapshots__/PublishNotebookPaneComponent.test.tsx.snap b/src/Explorer/Panes/__snapshots__/PublishNotebookPaneComponent.test.tsx.snap index 4e8441fef..e9be0d964 100644 --- a/src/Explorer/Panes/__snapshots__/PublishNotebookPaneComponent.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/PublishNotebookPaneComponent.test.tsx.snap @@ -52,28 +52,29 @@ exports[`PublishNotebookPaneComponent renders 1`] = ` -