Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
"react-dom": "^17.0.2",
"react-hook-form": "^7.12.1",
"react-redux": "^7.2.6",
"react-router-dom": "^6.3.0",
"react-sortable-hoc": "^2.0.0",
"react-tabs": "^3.2.3",
"react-use": "^17.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/ui/components/wrapper-debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,4 @@ const mapStateToProps = (state: RootState) => ({
sidebarFilter: selectSidebarFilter(state),
});

export const WrapperDebug = connect(mapStateToProps)(UnconnectedWrapperDebug);
export default connect(mapStateToProps)(UnconnectedWrapperDebug);
2 changes: 2 additions & 0 deletions packages/insomnia/src/ui/components/wrapper-design.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,5 @@ export const WrapperDesign: FC<Props> = ({
/>
);
};

export default WrapperDesign;
2 changes: 2 additions & 0 deletions packages/insomnia/src/ui/components/wrapper-unit-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,5 @@ const mapStateToProps = (state: RootState) => ({
});

export const WrapperUnitTest = connect(mapStateToProps)(UnconnectedWrapperUnitTest);

export default WrapperUnitTest;
204 changes: 142 additions & 62 deletions packages/insomnia/src/ui/components/wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { autoBindMethodsForReact } from 'class-autobind-decorator';
import * as importers from 'insomnia-importers';
import React, { Fragment, PureComponent, Ref } from 'react';
import React, { Fragment, lazy, PureComponent, Ref, Suspense } from 'react';
import { useSelector } from 'react-redux';
import { Route, Routes, useNavigate } from 'react-router-dom';

import type { GlobalActivity } from '../../common/constants';
import {
Expand Down Expand Up @@ -31,6 +33,7 @@ import { VCS } from '../../sync/vcs/vcs';
import { CookieModifyModal } from '../components/modals/cookie-modify-modal';
import { AppProps } from '../containers/app';
import { GrpcDispatchModalWrapper } from '../context/grpc';
import { selectActiveActivity } from '../redux/selectors';
import { DropdownButton } from './base/dropdown/dropdown-button';
import GitSyncDropdown from './dropdowns/git-sync-dropdown';
import { ErrorBoundary } from './error-boundary';
Expand Down Expand Up @@ -72,10 +75,51 @@ import { WorkspaceDuplicateModal } from './modals/workspace-duplicate-modal';
import { WorkspaceEnvironmentsEditModal } from './modals/workspace-environments-edit-modal';
import { WorkspaceSettingsModal } from './modals/workspace-settings-modal';
import { WrapperModal } from './modals/wrapper-modal';
import { WrapperDebug } from './wrapper-debug';
import { WrapperDesign } from './wrapper-design';
import WrapperHome from './wrapper-home';
import { WrapperUnitTest } from './wrapper-unit-test';

const lazyWithPreload = (
importFn: () => Promise<{ default: React.ComponentType<any> }>
): [
React.LazyExoticComponent<React.ComponentType<any>>,
() => Promise<{
default: React.ComponentType<any>;
}>
] => {
const LazyComponent = lazy(importFn);
const preload = () => importFn();

return [LazyComponent, preload];
};

const [WrapperHome, preloadWrapperHome] = lazyWithPreload(
() => import('./wrapper-home')
);
const [WrapperDebug, preloadWrapperDebug] = lazyWithPreload(
() => import('./wrapper-debug')
);
const [WrapperDesign, preloadWrapperDesign] = lazyWithPreload(
() => import('./wrapper-design')
);
const [WrapperUnitTest, preloadWrapperUnitTest] = lazyWithPreload(
() => import('./wrapper-unit-test')
);

preloadWrapperHome();
preloadWrapperDebug();
preloadWrapperDesign();
preloadWrapperUnitTest();

const ActivityRouter = () => {
const activity = useSelector(selectActiveActivity);
const navigate = useNavigate();

React.useEffect(() => {
if (activity) {
navigate(activity);
}
}, [activity, navigate]);

return null;
};
Comment on lines +111 to +122
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to list or link to the future work to untangle this workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added next steps on the pr details!


const spectral = initializeSpectral();

Expand Down Expand Up @@ -442,7 +486,6 @@ export class Wrapper extends PureComponent<WrapperProps, State> {
activeWorkspace,
activeApiSpec,
activeWorkspaceClientCertificates,
activeActivity,
gitVCS,
handleActivateRequest,
handleExportRequestsToFile,
Expand Down Expand Up @@ -589,63 +632,100 @@ export class Wrapper extends PureComponent<WrapperProps, State> {
</GrpcDispatchModalWrapper>
</ErrorBoundary>
</div>
<Fragment key={`views::${this.state.activeGitBranch}`}>
{(activeActivity === ACTIVITY_HOME || !activeWorkspace) && (
<WrapperHome
wrapperProps={this.props}
/>
)}

{activeActivity === ACTIVITY_SPEC && (
<WrapperDesign
gitSyncDropdown={gitSyncDropdown}
handleActivityChange={this._handleWorkspaceActivityChange}
wrapperProps={this.props}
/>
)}

{activeActivity === ACTIVITY_UNIT_TEST && (
<WrapperUnitTest
gitSyncDropdown={gitSyncDropdown}
wrapperProps={this.props}
handleActivityChange={this._handleWorkspaceActivityChange}
>
{sidebarChildren}
</WrapperUnitTest>
)}

{activeActivity === ACTIVITY_DEBUG && (
<WrapperDebug
forceRefreshKey={this.state.forceRefreshKey}
gitSyncDropdown={gitSyncDropdown}
handleActivityChange={this._handleWorkspaceActivityChange}
handleChangeEnvironment={this._handleChangeEnvironment}
handleDeleteResponse={this._handleDeleteResponse}
handleDeleteResponses={this._handleDeleteResponses}
handleForceUpdateRequest={this._handleForceUpdateRequest}
handleForceUpdateRequestHeaders={this._handleForceUpdateRequestHeaders}
handleImport={this._handleImport}
handleRequestCreate={this._handleCreateRequestInWorkspace}
handleRequestGroupCreate={this._handleCreateRequestGroupInWorkspace}
handleSendAndDownloadRequestWithActiveEnvironment={this._handleSendAndDownloadRequestWithActiveEnvironment}
handleSendRequestWithActiveEnvironment={this._handleSendRequestWithActiveEnvironment}
handleSetActiveResponse={this._handleSetActiveResponse}
handleSetPreviewMode={this._handleSetPreviewMode}
handleSetResponseFilter={this._handleSetResponseFilter}
handleShowRequestSettingsModal={this._handleShowRequestSettingsModal}
handleSidebarSort={handleSidebarSort}
handleUpdateRequestAuthentication={Wrapper._handleUpdateRequestAuthentication}
handleUpdateRequestBody={Wrapper._handleUpdateRequestBody}
handleUpdateRequestHeaders={Wrapper._handleUpdateRequestHeaders}
handleUpdateRequestMethod={Wrapper._handleUpdateRequestMethod}
handleUpdateRequestParameters={Wrapper._handleUpdateRequestParameters}
handleUpdateRequestUrl={Wrapper._handleUpdateRequestUrl}
handleUpdateSettingsUseBulkHeaderEditor={this._handleUpdateSettingsUseBulkHeaderEditor}
handleUpdateSettingsUseBulkParametersEditor={this._handleUpdateSettingsUseBulkParametersEditor}
wrapperProps={this.props}
/>
)}
</Fragment>
<Routes>
<Route
path="*"
element={
<Suspense fallback={<div />}>
<WrapperHome wrapperProps={this.props} />
</Suspense>
}
/>
<Route
path={ACTIVITY_UNIT_TEST}
element={
<Suspense fallback={<div />}>
<WrapperUnitTest
gitSyncDropdown={gitSyncDropdown}
wrapperProps={this.props}
handleActivityChange={this._handleWorkspaceActivityChange}
>
{sidebarChildren}
</WrapperUnitTest>
</Suspense>
}
/>
<Route
path={ACTIVITY_SPEC}
element={
<Suspense fallback={<div />}>
<WrapperDesign
gitSyncDropdown={gitSyncDropdown}
handleActivityChange={this._handleWorkspaceActivityChange}
wrapperProps={this.props}
/>
</Suspense>
}
/>
<Route
path={ACTIVITY_DEBUG}
element={
<Suspense fallback={<div />}>
<WrapperDebug
forceRefreshKey={this.state.forceRefreshKey}
gitSyncDropdown={gitSyncDropdown}
handleActivityChange={this._handleWorkspaceActivityChange}
handleChangeEnvironment={this._handleChangeEnvironment}
handleDeleteResponse={this._handleDeleteResponse}
handleDeleteResponses={this._handleDeleteResponses}
handleForceUpdateRequest={this._handleForceUpdateRequest}
handleForceUpdateRequestHeaders={
this._handleForceUpdateRequestHeaders
}
handleImport={this._handleImport}
handleRequestCreate={this._handleCreateRequestInWorkspace}
handleRequestGroupCreate={
this._handleCreateRequestGroupInWorkspace
}
handleSendAndDownloadRequestWithActiveEnvironment={
this._handleSendAndDownloadRequestWithActiveEnvironment
}
handleSendRequestWithActiveEnvironment={
this._handleSendRequestWithActiveEnvironment
}
handleSetActiveResponse={this._handleSetActiveResponse}
handleSetPreviewMode={this._handleSetPreviewMode}
handleSetResponseFilter={this._handleSetResponseFilter}
handleShowRequestSettingsModal={
this._handleShowRequestSettingsModal
}
handleSidebarSort={handleSidebarSort}
handleUpdateRequestAuthentication={
Wrapper._handleUpdateRequestAuthentication
}
handleUpdateRequestBody={Wrapper._handleUpdateRequestBody}
handleUpdateRequestHeaders={
Wrapper._handleUpdateRequestHeaders
}
handleUpdateRequestMethod={Wrapper._handleUpdateRequestMethod}
handleUpdateRequestParameters={
Wrapper._handleUpdateRequestParameters
}
handleUpdateRequestUrl={Wrapper._handleUpdateRequestUrl}
handleUpdateSettingsUseBulkHeaderEditor={
this._handleUpdateSettingsUseBulkHeaderEditor
}
handleUpdateSettingsUseBulkParametersEditor={
this._handleUpdateSettingsUseBulkParametersEditor
}
wrapperProps={this.props}
/>
</Suspense>
}
/>
</Routes>
<ActivityRouter />
</Fragment>
);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/insomnia/src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { applyColorScheme } from '../plugins/misc';
import App from './containers/app';
import { init as initStore } from './redux/modules';
import { initializeSentry } from './sentry';
import { MemoryRouter as Router } from 'react-router-dom';

import './css/index.less'; // this import must come after `App`. the reason is not yet known.

Expand Down Expand Up @@ -42,7 +43,9 @@ document.title = getProductName();
const render = App => {
ReactDOM.render(
<Provider store={store}>
<App />
<Router>
<App />
</Router>
</Provider>,
document.getElementById('root'),
);
Expand Down