Refactor conditional element syntax

This commit is contained in:
Gregory Schier 2017-05-17 09:30:03 -07:00
parent 6aecf5d764
commit 184d9a203a
14 changed files with 105 additions and 108 deletions

View File

@ -54,13 +54,13 @@ class EnvironmentsDropdown extends PureComponent {
<Dropdown {...other} className={classnames(className, 'wide')}>
<DropdownButton className="btn btn--super-compact no-wrap">
<div className="sidebar__menu__thing">
{!activeEnvironment && subEnvironments.length ? (
{(!activeEnvironment && subEnvironments.length) && (
<Tooltip message="No environments active. Please select one to use."
className="space-right"
position="right">
<i className="fa fa-exclamation-triangle notice"/>
</Tooltip>
) : null }
)}
<div className="sidebar__menu__thing__text">
{description}
</div>

View File

@ -136,14 +136,13 @@ class WorkspaceDropdown extends PureComponent {
{/* Not Logged In */}
{!this.state.loggedIn ? (
{!this.state.loggedIn && (
<DropdownItem key="login" onClick={this._handleShowLogin}>
<i className="fa fa-sign-in"/> Log In
</DropdownItem>
) : null
}
)}
{!this.state.loggedIn ? (
{!this.state.loggedIn && (
<DropdownItem key="invite"
buttonClass={Link}
href="https://insomnia.rest/pricing/"
@ -151,8 +150,7 @@ class WorkspaceDropdown extends PureComponent {
<i className="fa fa-users"/> Upgrade to Plus
<i className="fa fa-star notice fa-outline txt-lg"/>
</DropdownItem>
) : null
}
)}
</Dropdown>
);
}

View File

@ -319,30 +319,30 @@ class OAuth2 extends PureComponent {
<div className="pad-top-sm">
{/* Handle major errors */}
{error ? (
{error && (
<p className="notice warning margin-bottom">
{error}
</p>
) : null}
)}
{/* Handle minor errors */}
{tok && tok.error ? (
{(tok && tok.error) && (
<div className="notice error margin-bottom">
<h2 className="no-margin-top txt-lg force-wrap">
{tok.error}
</h2>
<p>
{tok.errorDescription || 'no description provided'}
{tok.errorUri ? (
{tok.errorUri && (
<span>&nbsp;
<Link href={tok.errorUri} title={tok.errorUri}>
<i className="fa fa-question-circle"/>
</Link>
</span>
) : null}
)}
</p>
</div>
) : null}
)}
<div className="form-control form-control--outlined">
<label>
<small>
@ -364,11 +364,11 @@ class OAuth2 extends PureComponent {
</label>
</div>
<div className="pad-top text-right">
{tok ? (
{tok && (
<button className="btn btn--clicky" onClick={this._handleClearTokens}>
Clear Tokens
</button>
) : null}
)}
&nbsp;&nbsp;
<button className="btn btn--clicky"
onClick={this._handleRefreshToken}

View File

@ -83,7 +83,7 @@ class CookiesEditor extends PureComponent {
})}
</tbody>
</table>
{cookies.length === 0 ? (
{cookies.length === 0 && (
<div className="pad faint italic text-center">
<p>
I couldn't find any cookies for you.
@ -95,7 +95,7 @@ class CookiesEditor extends PureComponent {
</button>
</p>
</div>
) : null}
)}
</div>
);
}

View File

@ -213,7 +213,7 @@ class KeyValueEditorRow extends PureComponent {
)}
</div>
{multipart ? (
{multipart && (
!hideButtons ? (
<Dropdown right>
<DropdownButton className="tall">
@ -231,8 +231,7 @@ class KeyValueEditorRow extends PureComponent {
<i className="fa fa-empty"/>
</button>
)
) : null
}
)}
{!hideButtons ? (
<Button onClick={this._handleDisableChange}
@ -247,7 +246,7 @@ class KeyValueEditorRow extends PureComponent {
<button><i className="fa fa-empty"/></button>
)}
{!noDelete ? (
{!noDelete && (
!hideButtons ? (
<PromptButton key={Math.random()}
tabIndex={-1}
@ -262,7 +261,7 @@ class KeyValueEditorRow extends PureComponent {
<i className="fa fa-empty"/>
</button>
)
) : null}
)}
</div>
</li>
);

View File

@ -118,7 +118,7 @@ class RequestCreateModal extends PureComponent {
onChange={this._handleChangeSelectedMethod}
/>
</div>
{!this._shouldNotHaveBody() ? (
{!this._shouldNotHaveBody() && (
<div className="form-control form-control--no-label" style={{width: 'auto'}}>
<ContentTypeDropdown className="btn btn--clicky no-wrap"
right
@ -130,7 +130,7 @@ class RequestCreateModal extends PureComponent {
<i className="fa fa-caret-down"></i>
</ContentTypeDropdown>
</div>
) : null}
)}
</div>
</form>
</ModalBody>

View File

@ -51,12 +51,12 @@ class RequestRenderErrorModal extends PureComponent {
Failed to render <strong>{fullPath}</strong> prior to sending
</p>
<div className="pad-top-sm">
{error.path.match(/^body/) ? (
{error.path.match(/^body/) && (
<button className="btn btn--clicky margin-right-sm"
onClick={this._handleShowRequestSettings}>
Adjust Render Settings
</button>
) : null}
)}
<Link button
href="https://insomnia.rest/documentation/templating/"
className="btn btn--clicky">

View File

@ -246,13 +246,13 @@ class RequestSwitcherModal extends PureComponent {
return (
<li key={r._id}>
<Button onClick={this._activateRequest} value={r} className={buttonClasses}>
{requestGroup ? (
{requestGroup && (
<div className="pull-right faint italic">
{requestGroup.name}
&nbsp;&nbsp;
<i className="fa fa-folder-o"></i>
</div>
) : null}
)}
<MethodTag method={r.method}/>
<strong>{r.name}</strong>
</Button>
@ -260,10 +260,11 @@ class RequestSwitcherModal extends PureComponent {
);
})}
{matchedRequests.length && matchedWorkspaces.length
? <div className="pad-left pad-right"><hr/></div>
: null
}
{matchedRequests.length && matchedWorkspaces.length && (
<div className="pad-left pad-right">
<hr/>
</div>
)}
{matchedWorkspaces.map((w, i) => {
const buttonClasses = classnames(
@ -283,7 +284,7 @@ class RequestSwitcherModal extends PureComponent {
})}
</ul>
{!matchedRequests.length && !matchedWorkspaces.length ? (
{(!matchedRequests.length && !matchedWorkspaces.length) && (
<div className="text-center">
<p>
No matches found for <strong>{searchString}</strong>
@ -295,7 +296,7 @@ class RequestSwitcherModal extends PureComponent {
Create a request named {searchString}
</button>
</div>
) : null}
)}
</ModalBody>
</Modal>
);

View File

@ -244,13 +244,13 @@ class WorkspaceEnvironmentsEditModal extends PureComponent {
onSubmit={name => this._handleChangeEnvironmentName(activeEnvironment, name)}
value={activeEnvironment ? activeEnvironment.name : ''}/>
</h1>
{rootEnvironment !== activeEnvironment ? (
{rootEnvironment !== activeEnvironment && (
<PromptButton className="btn btn--clicky"
confirmMessage="Confirm"
onClick={this._handleDeleteEnvironment}>
<i className="fa fa-trash-o"/> Delete
</PromptButton>
) : null}
)}
</div>
<div className="env-modal__editor">
<EnvironmentEditor

View File

@ -23,9 +23,11 @@ class WorkspaceShareSettingsModal extends PureComponent {
_handleSubmit (e) {
e.preventDefault();
}
_handleClose () {
this.hide();
}
_setModalRef (n) {
this.modal = n;
}
@ -154,11 +156,11 @@ class WorkspaceShareSettingsModal extends PureComponent {
<i className="fa fa-users"/> Share with <strong>{team.name}</strong>
</DropdownItem>
))}
{teams.length === 0 ? (
{teams.length === 0 && (
<DropdownItem disabled onClick={this._handleShareWithTeam}>
<i className="fa fa-warning"/> You have no teams
</DropdownItem>
) : null}
)}
<DropdownDivider>Other</DropdownDivider>
<DropdownItem addIcon buttonClass={PromptButton}
confirmMessage="Really make private?"

View File

@ -259,11 +259,11 @@ class ResponsePane extends PureComponent {
<span className="bubble">{cookieHeaders.length}</span>) : null}
</Button>
</Tab>
{response.timeline && response.timeline.length ? (
{response.timeline && response.timeline.length && (
<Tab>
<Button onClick={this._trackTab} value="Timeline">Timeline</Button>
</Tab>
) : null}
)}
</TabList>
<TabPanel>
<ResponseViewer
@ -305,7 +305,7 @@ class ResponsePane extends PureComponent {
/>
</div>
</TabPanel>
{response.timeline && response.timeline.length ? (
{(response.timeline && response.timeline.length) && (
<TabPanel>
<ResponseTimelineViewer
key={response._id}
@ -315,7 +315,7 @@ class ResponsePane extends PureComponent {
editorIndentSize={editorIndentSize}
/>
</TabPanel>
) : null }
)}
</Tabs>
<ResponseTimer
handleCancel={cancelCurrentRequest}

View File

@ -103,7 +103,7 @@ class TagEditor extends PureComponent {
</select>
</label>
</div>
{(!isFound || isFlexible) ? (
{(!isFound || isFlexible) && (
<div className="form-control form-control--outlined">
<Input
key={selectValue}
@ -114,7 +114,7 @@ class TagEditor extends PureComponent {
onChange={this._update}
/>
</div>
) : null}
)}
<div className="form-control form-control--outlined">
<label>Live Preview
{error

View File

@ -82,7 +82,7 @@ class VariableEditor extends PureComponent {
</select>
</label>
</div>
{isOther ? (
{isOther && (
<div className="form-control form-control--outlined">
<Input
forceEditor
@ -92,7 +92,7 @@ class VariableEditor extends PureComponent {
onChange={this._update}
/>
</div>
) : null}
)}
<div className="form-control form-control--outlined">
<label>Live Preview
{error

View File

@ -36,13 +36,13 @@ class ResponseCookiesViewer extends PureComponent {
return (
<div>
{noticeMessage ? (
{noticeMessage && (
<div className="notice info margin-bottom no-margin-top">
<p>
Automatic {noticeMessage} of cookies was disabled at the time this request was made
</p>
</div>
) : null}
)}
<table className="table--fancy table--striped">
<thead>
@ -52,10 +52,7 @@ class ResponseCookiesViewer extends PureComponent {
</tr>
</thead>
<tbody>
{!headers.length
? this.renderRow(null, -1)
: headers.map(this.renderRow)
}
{!headers.length ? this.renderRow(null, -1) : headers.map(this.renderRow)}
</tbody>
</table>
<p className="pad-top">