insomnia/packages/insomnia-app/app/ui/components/page-layout.js
Gregory Schier 3883dc6feb
POC for Unit Test UI (#2315)
* Start working on insomnia-testing package to generate Mocha code

* Moved some things around

* Integration tests and ability to run multiple files

* Fix integration tests

* Rename runSuite to runMochaTests

* Add types for test results

* Fix lint errors

* Play with Chia assertions

* insomnia and chai globals, plus a bunch of improvements

* Stub chai and axios Flow types

* Ability to reference requests by ID

* Fix chai flow-typed location

* Address PR comments (small tweaks)

* Basic UI going

* Lots and lots and lots

* Pretty-much done with the unit test UI

* Minor CSS tweak

* Activity bar triple toggle and more

* Minor tweak

* Unit Test and Suite deletion

* Bump Designer version

* Fix eslint stuff

* Fix insomnia-testing tests

* Fix tests

* lib@2.2.9

* Remove tests tab from response pane

* Hook up Insomnia networking

* Fix linting

* Bump version for alpha

* Remove extra ActivityToggleSwitch

* Remove unused import

* Add test:pre-release script that excludes CLI tests

* Less repetition

* Clean some things up

* Tweaks after self-cr

* Undo request ID tag

* Swap out switch for new activity toggle component

* Extra check

* Remove dead code

* Delete dead test

* Oops, revert example code

* PR feedback

* More PR comment addresses
2020-07-01 14:17:14 -07:00

151 lines
4.8 KiB
JavaScript

// @flow
import * as React from 'react';
import autobind from 'autobind-decorator';
import type { WrapperProps } from './wrapper';
import classnames from 'classnames';
import ErrorBoundary from './error-boundary';
import Sidebar from './sidebar/sidebar';
import { isInsomnia } from '../../common/constants';
type Props = {
wrapperProps: WrapperProps,
// Render props
renderPageSidebar?: () => React.Node,
renderPageHeader?: () => React.Node,
renderPageBody?: () => React.Node,
};
type State = {};
@autobind
class PageLayout extends React.PureComponent<Props, State> {
// Special request updaters
_handleStartDragSidebar(e: Event): void {
e.preventDefault();
const { handleStartDragSidebar } = this.props.wrapperProps;
handleStartDragSidebar();
}
render() {
const { renderPageBody, renderPageHeader, renderPageSidebar, wrapperProps } = this.props;
const {
activity,
activeEnvironment,
activeGitRepository,
activeWorkspace,
gitVCS,
handleInitializeEntities,
handleResetDragSidebar,
handleSetActiveEnvironment,
handleSetActiveWorkspace,
handleSetSidebarRef,
handleShowSettingsModal,
isLoading,
paneHeight,
paneWidth,
settings,
sidebarHidden,
sidebarWidth,
syncItems,
unseenWorkspaces,
vcs,
workspaces,
} = wrapperProps;
const realSidebarWidth = sidebarHidden ? 0 : sidebarWidth;
const gridRows = `auto minmax(0, ${paneHeight}fr) 0 minmax(0, ${1 - paneHeight}fr)`;
const gridColumns =
`auto ${realSidebarWidth}rem 0 ` +
`minmax(0, ${paneWidth}fr) 0 minmax(0, ${1 - paneWidth}fr)`;
return (
<div
key="wrapper"
id="wrapper"
className={classnames('wrapper', { 'wrapper--vertical': settings.forceVerticalLayout })}
style={{
gridTemplateColumns: gridColumns,
gridTemplateRows: gridRows,
boxSizing: 'border-box',
borderTop:
activeEnvironment &&
activeEnvironment.color &&
settings.environmentHighlightColorStyle === 'window-top'
? '5px solid ' + activeEnvironment.color
: null,
borderBottom:
activeEnvironment &&
activeEnvironment.color &&
settings.environmentHighlightColorStyle === 'window-bottom'
? '5px solid ' + activeEnvironment.color
: null,
borderLeft:
activeEnvironment &&
activeEnvironment.color &&
settings.environmentHighlightColorStyle === 'window-left'
? '5px solid ' + activeEnvironment.color
: null,
borderRight:
activeEnvironment &&
activeEnvironment.color &&
settings.environmentHighlightColorStyle === 'window-right'
? '5px solid ' + activeEnvironment.color
: null,
}}>
{renderPageHeader && <ErrorBoundary showAlert>{renderPageHeader()}</ErrorBoundary>}
{renderPageSidebar && (
<ErrorBoundary showAlert>
<Sidebar
ref={handleSetSidebarRef}
activeEnvironment={activeEnvironment}
activeGitRepository={activeGitRepository}
enableSyncBeta={settings.enableSyncBeta}
environmentHighlightColorStyle={settings.environmentHighlightColorStyle}
handleInitializeEntities={handleInitializeEntities}
handleSetActiveEnvironment={handleSetActiveEnvironment}
handleSetActiveWorkspace={handleSetActiveWorkspace}
hidden={sidebarHidden || false}
hotKeyRegistry={settings.hotKeyRegistry}
isLoading={isLoading}
showEnvironmentsModal={this._handleShowEnvironmentsModal}
syncItems={syncItems}
unseenWorkspaces={unseenWorkspaces}
vcs={vcs}
gitVCS={gitVCS}
width={sidebarWidth}
workspace={activeWorkspace}
workspaces={workspaces}>
{renderPageSidebar()}
{!isInsomnia(activity) && (
<div className="sidebar__footer">
<button
className="btn btn--compact wide row-spaced"
onClick={handleShowSettingsModal}>
Preferences <i className="fa fa-gear" />
</button>
</div>
)}
</Sidebar>
<div className="drag drag--sidebar">
<div
onDoubleClick={handleResetDragSidebar}
onMouseDown={this._handleStartDragSidebar}
/>
</div>
</ErrorBoundary>
)}
{renderPageBody && <ErrorBoundary showAlert>{renderPageBody()}</ErrorBoundary>}
</div>
);
}
}
export default PageLayout;