Batch of small fixes for RightPaneForm and AddDatabasePane components (#780)

This commit is contained in:
victor-meng 2021-05-12 17:12:03 -07:00 committed by GitHub
parent 2f6dbd83f3
commit 14e58e5519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 44 additions and 65 deletions

View File

@ -19,4 +19,14 @@ describe("ThroughputInput Pane", () => {
it("should render Default properly", () => { it("should render Default properly", () => {
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
it("should switch mode properly", () => {
wrapper.find('[aria-label="Manual mode"]').simulate("change");
expect(wrapper.find('[aria-label="Throughput header"]').at(0).text()).toBe(
"Container throughput (400 - unlimited RU/s)"
);
wrapper.find('[aria-label="Autoscale mode"]').simulate("change");
expect(wrapper.find('[aria-label="Throughput header"]').at(0).text()).toBe("Container throughput (autoscale)");
});
}); });

View File

@ -101,7 +101,7 @@ export const ThroughputInput: FunctionComponent<ThroughputInputProps> = ({
<div className="throughputInputContainer throughputInputSpacing"> <div className="throughputInputContainer throughputInputSpacing">
<Stack horizontal> <Stack horizontal>
<span className="mandatoryStar">*&nbsp;</span> <span className="mandatoryStar">*&nbsp;</span>
<Text variant="small" style={{ lineHeight: "20px", fontWeight: 600 }}> <Text aria-label="Throughput header" variant="small" style={{ lineHeight: "20px", fontWeight: 600 }}>
{getThroughputLabelText()} {getThroughputLabelText()}
</Text> </Text>
<InfoTooltip>{PricingUtils.getRuToolTipText()}</InfoTooltip> <InfoTooltip>{PricingUtils.getRuToolTipText()}</InfoTooltip>

View File

@ -25,6 +25,7 @@ exports[`ThroughputInput Pane should render Default properly 1`] = `
*  * 
</span> </span>
<Text <Text
aria-label="Throughput header"
key=".0:$.1" key=".0:$.1"
style={ style={
Object { Object {
@ -35,6 +36,7 @@ exports[`ThroughputInput Pane should render Default properly 1`] = `
variant="small" variant="small"
> >
<span <span
aria-label="Throughput header"
className="css-54" className="css-54"
style={ style={
Object { Object {

View File

@ -1988,7 +1988,7 @@ export default class Explorer {
"Add " + getDatabaseName(), "Add " + getDatabaseName(),
<AddDatabasePanel <AddDatabasePanel
explorer={this} explorer={this}
openNotificationConsole={this.expandConsole} openNotificationConsole={() => this.expandConsole()}
closePanel={this.closeSidePanel} closePanel={this.closeSidePanel}
/> />
); );

View File

@ -48,7 +48,6 @@ export const AddDatabasePanel: FunctionComponent<AddDatabasePaneProps> = ({
const [databaseCreateNewShared, setDatabaseCreateNewShared] = useState<boolean>( const [databaseCreateNewShared, setDatabaseCreateNewShared] = useState<boolean>(
subscriptionType !== SubscriptionType.EA && !isServerlessAccount() subscriptionType !== SubscriptionType.EA && !isServerlessAccount()
); );
const [formErrorsDetails, setFormErrorsDetails] = useState<string>();
const [formErrors, setFormErrors] = useState<string>(""); const [formErrors, setFormErrors] = useState<string>("");
const [isExecuting, setIsExecuting] = useState<boolean>(false); const [isExecuting, setIsExecuting] = useState<boolean>(false);
@ -128,7 +127,6 @@ export const AddDatabasePanel: FunctionComponent<AddDatabasePaneProps> = ({
setIsExecuting(false); setIsExecuting(false);
const errorMessage = getErrorMessage(error); const errorMessage = getErrorMessage(error);
setFormErrors(errorMessage); setFormErrors(errorMessage);
setFormErrorsDetails(errorMessage);
const addDatabasePaneFailedMessage = { const addDatabasePaneFailedMessage = {
...addDatabasePaneMessage, ...addDatabasePaneMessage,
offerThroughput, offerThroughput,
@ -167,7 +165,6 @@ export const AddDatabasePanel: FunctionComponent<AddDatabasePaneProps> = ({
const props: RightPaneFormProps = { const props: RightPaneFormProps = {
expandConsole: openNotificationConsole, expandConsole: openNotificationConsole,
formError: formErrors, formError: formErrors,
formErrorDetail: formErrorsDetails,
isExecuting, isExecuting,
submitButtonText: "OK", submitButtonText: "OK",
onSubmit, onSubmit,

View File

@ -8,7 +8,6 @@ export interface PanelInfoErrorProps {
link?: string; link?: string;
linkText?: string; linkText?: string;
openNotificationConsole?: () => void; openNotificationConsole?: () => void;
formError?: boolean;
} }
export const PanelInfoErrorComponent: React.FunctionComponent<PanelInfoErrorProps> = ({ export const PanelInfoErrorComponent: React.FunctionComponent<PanelInfoErrorProps> = ({
@ -18,7 +17,6 @@ export const PanelInfoErrorComponent: React.FunctionComponent<PanelInfoErrorProp
link, link,
linkText, linkText,
openNotificationConsole, openNotificationConsole,
formError = true,
}: PanelInfoErrorProps): JSX.Element => { }: PanelInfoErrorProps): JSX.Element => {
let icon: JSX.Element; let icon: JSX.Element;
if (messageType === "error") { if (messageType === "error") {
@ -30,25 +28,23 @@ export const PanelInfoErrorComponent: React.FunctionComponent<PanelInfoErrorProp
} }
return ( return (
formError && ( <Stack className="panelInfoErrorContainer" horizontal verticalAlign="center">
<Stack className="panelInfoErrorContainer" horizontal verticalAlign="center"> {icon}
{icon} <span className="panelWarningErrorDetailsLinkContainer">
<span className="panelWarningErrorDetailsLinkContainer"> <Text className="panelWarningErrorMessage" variant="small" aria-label="message">
<Text className="panelWarningErrorMessage" variant="small" aria-label="message"> {message}
{message} {link && linkText && (
{link && linkText && ( <Link target="_blank" href={link}>
<Link target="_blank" href={link}> {linkText}
{linkText} </Link>
</Link>
)}
</Text>
{showErrorDetails && (
<a className="paneErrorLink" role="link" onClick={openNotificationConsole}>
More details
</a>
)} )}
</span> </Text>
</Stack> {showErrorDetails && (
) <a className="paneErrorLink" role="link" onClick={openNotificationConsole}>
More details
</a>
)}
</span>
</Stack>
); );
}; };

View File

@ -9,7 +9,6 @@ const expandConsole = jest.fn();
const props = { const props = {
expandConsole, expandConsole,
formError: "", formError: "",
formErrorDetail: "",
isExecuting: false, isExecuting: false,
submitButtonText: "Load", submitButtonText: "Load",
onSubmit, onSubmit,

View File

@ -1,12 +1,11 @@
import React, { FunctionComponent, ReactNode } from "react"; import React, { FunctionComponent, ReactNode } from "react";
import { PanelFooterComponent } from "../PanelFooterComponent"; import { PanelFooterComponent } from "../PanelFooterComponent";
import { PanelInfoErrorComponent, PanelInfoErrorProps } from "../PanelInfoErrorComponent"; import { PanelInfoErrorComponent } from "../PanelInfoErrorComponent";
import { PanelLoadingScreen } from "../PanelLoadingScreen"; import { PanelLoadingScreen } from "../PanelLoadingScreen";
export interface RightPaneFormProps { export interface RightPaneFormProps {
expandConsole: () => void; expandConsole: () => void;
formError: string; formError: string;
formErrorDetail: string;
isExecuting: boolean; isExecuting: boolean;
onSubmit: () => void; onSubmit: () => void;
submitButtonText: string; submitButtonText: string;
@ -17,7 +16,6 @@ export interface RightPaneFormProps {
export const RightPaneForm: FunctionComponent<RightPaneFormProps> = ({ export const RightPaneForm: FunctionComponent<RightPaneFormProps> = ({
expandConsole, expandConsole,
formError, formError,
formErrorDetail,
isExecuting, isExecuting,
onSubmit, onSubmit,
submitButtonText, submitButtonText,
@ -29,18 +27,17 @@ export const RightPaneForm: FunctionComponent<RightPaneFormProps> = ({
onSubmit(); onSubmit();
}; };
const panelInfoErrorProps: PanelInfoErrorProps = {
messageType: "error",
message: formError,
formError: formError !== "",
showErrorDetails: formErrorDetail !== "",
openNotificationConsole: expandConsole,
};
return ( return (
<> <>
<PanelInfoErrorComponent {...panelInfoErrorProps} />
<form className="panelFormWrapper" onSubmit={handleOnSubmit}> <form className="panelFormWrapper" onSubmit={handleOnSubmit}>
{formError && (
<PanelInfoErrorComponent
messageType="error"
message={formError}
showErrorDetails={true}
openNotificationConsole={expandConsole}
/>
)}
{children} {children}
{!isSubmitButtonHidden && <PanelFooterComponent buttonLabel={submitButtonText} />} {!isSubmitButtonHidden && <PanelFooterComponent buttonLabel={submitButtonText} />}
</form> </form>

View File

@ -4,18 +4,10 @@ exports[`Right Pane Form should render Default properly 1`] = `
<RightPaneForm <RightPaneForm
expandConsole={[MockFunction]} expandConsole={[MockFunction]}
formError="" formError=""
formErrorDetail=""
isExecuting={false} isExecuting={false}
onSubmit={[MockFunction]} onSubmit={[MockFunction]}
submitButtonText="Load" submitButtonText="Load"
> >
<PanelInfoErrorComponent
formError={false}
message=""
messageType="error"
openNotificationConsole={[MockFunction]}
showErrorDetails={false}
/>
<form <form
className="panelFormWrapper" className="panelFormWrapper"
onSubmit={[Function]} onSubmit={[Function]}

View File

@ -18,7 +18,6 @@ export const SettingsPane: FunctionComponent<SettingsPaneProps> = ({
expandConsole, expandConsole,
closePanel, closePanel,
}: SettingsPaneProps) => { }: SettingsPaneProps) => {
const [formErrors, setFormErrors] = useState<string>("");
const [isExecuting, setIsExecuting] = useState<boolean>(false); const [isExecuting, setIsExecuting] = useState<boolean>(false);
const [pageOption, setPageOption] = useState<string>( const [pageOption, setPageOption] = useState<string>(
LocalStorageUtility.getEntryNumber(StorageKey.ActualItemPerPage) === Constants.Queries.unlimitedItemsPerPage LocalStorageUtility.getEntryNumber(StorageKey.ActualItemPerPage) === Constants.Queries.unlimitedItemsPerPage
@ -50,7 +49,6 @@ export const SettingsPane: FunctionComponent<SettingsPaneProps> = ({
const shouldShowParallelismOption = userContext.apiType !== "Gremlin"; const shouldShowParallelismOption = userContext.apiType !== "Gremlin";
const handlerOnSubmit = (e: MouseEvent<HTMLButtonElement>) => { const handlerOnSubmit = (e: MouseEvent<HTMLButtonElement>) => {
setFormErrors("");
setIsExecuting(true); setIsExecuting(true);
LocalStorageUtility.setEntryNumber( LocalStorageUtility.setEntryNumber(
@ -104,8 +102,7 @@ export const SettingsPane: FunctionComponent<SettingsPaneProps> = ({
const genericPaneProps: RightPaneFormProps = { const genericPaneProps: RightPaneFormProps = {
expandConsole, expandConsole,
formError: formErrors, formError: "",
formErrorDetail: "",
isExecuting, isExecuting,
submitButtonText: "Apply", submitButtonText: "Apply",
onSubmit: () => handlerOnSubmit(undefined), onSubmit: () => handlerOnSubmit(undefined),

View File

@ -4,7 +4,6 @@ exports[`Settings Pane should render Default properly 1`] = `
<RightPaneForm <RightPaneForm
expandConsole={[Function]} expandConsole={[Function]}
formError="" formError=""
formErrorDetail=""
isExecuting={false} isExecuting={false}
onSubmit={[Function]} onSubmit={[Function]}
submitButtonText="Apply" submitButtonText="Apply"
@ -152,7 +151,6 @@ exports[`Settings Pane should render Gremlin properly 1`] = `
<RightPaneForm <RightPaneForm
expandConsole={[Function]} expandConsole={[Function]}
formError="" formError=""
formErrorDetail=""
isExecuting={false} isExecuting={false}
onSubmit={[Function]} onSubmit={[Function]}
submitButtonText="Apply" submitButtonText="Apply"

View File

@ -22,15 +22,12 @@ export const UploadFilePane: FunctionComponent<UploadFilePanelProps> = ({
const [files, setFiles] = useState<FileList>(); const [files, setFiles] = useState<FileList>();
const [formErrors, setFormErrors] = useState<string>(""); const [formErrors, setFormErrors] = useState<string>("");
const [formErrorsDetails, setFormErrorsDetails] = useState<string>("");
const [isExecuting, setIsExecuting] = useState<boolean>(false); const [isExecuting, setIsExecuting] = useState<boolean>(false);
const submit = () => { const submit = () => {
setFormErrors(""); setFormErrors("");
setFormErrorsDetails("");
if (!files || files.length === 0) { if (!files || files.length === 0) {
setFormErrors("No file specified"); setFormErrors("No file specified. Please input a file.");
setFormErrorsDetails("No file specified. Please input a file.");
logConsoleError(`${errorMessage} -- No file specified. Please input a file.`); logConsoleError(`${errorMessage} -- No file specified. Please input a file.`);
return; return;
} }
@ -49,7 +46,6 @@ export const UploadFilePane: FunctionComponent<UploadFilePanelProps> = ({
}, },
(error: string) => { (error: string) => {
setFormErrors(errorMessage); setFormErrors(errorMessage);
setFormErrorsDetails(`${errorMessage}: ${error}`);
logConsoleError(`${errorMessage} ${file.name}: ${error}`); logConsoleError(`${errorMessage} ${file.name}: ${error}`);
} }
) )
@ -85,7 +81,6 @@ export const UploadFilePane: FunctionComponent<UploadFilePanelProps> = ({
const genericPaneProps: RightPaneFormProps = { const genericPaneProps: RightPaneFormProps = {
expandConsole, expandConsole,
formError: formErrors, formError: formErrors,
formErrorDetail: formErrorsDetails,
isExecuting: isExecuting, isExecuting: isExecuting,
submitButtonText: "Upload", submitButtonText: "Upload",
onSubmit: submit, onSubmit: submit,

View File

@ -15,15 +15,14 @@ export const UploadItemsPane: FunctionComponent<UploadItemsPaneProps> = ({ explo
const [files, setFiles] = useState<FileList>(); const [files, setFiles] = useState<FileList>();
const [uploadFileData, setUploadFileData] = useState<UploadDetailsRecord[]>([]); const [uploadFileData, setUploadFileData] = useState<UploadDetailsRecord[]>([]);
const [formError, setFormError] = useState<string>(""); const [formError, setFormError] = useState<string>("");
const [formErrorDetail, setFormErrorDetail] = useState<string>("");
const [isExecuting, setIsExecuting] = useState<boolean>(); const [isExecuting, setIsExecuting] = useState<boolean>();
const onSubmit = () => { const onSubmit = () => {
setFormError(""); setFormError("");
if (!files || files.length === 0) { if (!files || files.length === 0) {
setFormError("No files specified"); setFormError("No files were specified. Please input at least one file.");
setFormErrorDetail("No files were specified. Please input at least one file.");
logConsoleError("Could not upload items -- No files were specified. Please input at least one file."); logConsoleError("Could not upload items -- No files were specified. Please input at least one file.");
return;
} }
const selectedCollection = explorer.findSelectedCollection(); const selectedCollection = explorer.findSelectedCollection();
@ -40,7 +39,6 @@ export const UploadItemsPane: FunctionComponent<UploadItemsPaneProps> = ({ explo
(error: Error) => { (error: Error) => {
const errorMessage = getErrorMessage(error); const errorMessage = getErrorMessage(error);
setFormError(errorMessage); setFormError(errorMessage);
setFormErrorDetail(errorMessage);
} }
) )
.finally(() => { .finally(() => {
@ -55,7 +53,6 @@ export const UploadItemsPane: FunctionComponent<UploadItemsPaneProps> = ({ explo
const genericPaneProps: RightPaneFormProps = { const genericPaneProps: RightPaneFormProps = {
expandConsole: () => explorer.expandConsole(), expandConsole: () => explorer.expandConsole(),
formError, formError,
formErrorDetail,
isExecuting: isExecuting, isExecuting: isExecuting,
submitButtonText: "Upload", submitButtonText: "Upload",
onSubmit, onSubmit,

View File

@ -4,7 +4,6 @@ exports[`Upload Items Pane should render Default properly 1`] = `
<RightPaneForm <RightPaneForm
expandConsole={[Function]} expandConsole={[Function]}
formError="" formError=""
formErrorDetail=""
onSubmit={[Function]} onSubmit={[Function]}
submitButtonText="Upload" submitButtonText="Upload"
> >