2021-02-02 22:23:42 +00:00
|
|
|
import { autoBindMethodsForReact } from 'class-autobind-decorator';
|
2021-07-22 23:04:56 +00:00
|
|
|
import React, { Fragment, PureComponent, ReactNode } from 'react';
|
2022-02-22 13:19:04 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-07-22 23:04:56 +00:00
|
|
|
|
2022-02-02 15:54:05 +00:00
|
|
|
import { AUTOBIND_CFG, SortOrder } from '../../common/constants';
|
2021-07-22 23:04:56 +00:00
|
|
|
import { isGrpcRequest } from '../../models/grpc-request';
|
2021-08-20 15:12:36 +00:00
|
|
|
import { isRemoteProject } from '../../models/project';
|
2021-07-22 23:04:56 +00:00
|
|
|
import { Request, RequestAuthentication, RequestBody, RequestHeader, RequestParameter } from '../../models/request';
|
|
|
|
import { Settings } from '../../models/settings';
|
|
|
|
import { isCollection, isDesign } from '../../models/workspace';
|
2022-02-22 13:19:04 +00:00
|
|
|
import { RootState } from '../redux/modules';
|
|
|
|
import { selectActiveEnvironment, selectActiveRequest, selectActiveRequestResponses, selectActiveResponse, selectActiveUnitTestResult, selectActiveWorkspace, selectEnvironments, selectLoadStartTime, selectRequestVersions, selectResponseDownloadPath, selectResponseFilter, selectResponseFilterHistory, selectResponsePreviewMode, selectSettings } from '../redux/selectors';
|
|
|
|
import { selectSidebarChildren, selectSidebarFilter } from '../redux/sidebar-selectors';
|
2021-09-27 13:47:22 +00:00
|
|
|
import { EnvironmentsDropdown } from './dropdowns/environments-dropdown';
|
|
|
|
import { SyncDropdown } from './dropdowns/sync-dropdown';
|
|
|
|
import { ErrorBoundary } from './error-boundary';
|
2021-12-08 03:11:04 +00:00
|
|
|
import { showCookiesModal } from './modals/cookies-modal';
|
2021-09-27 13:47:22 +00:00
|
|
|
import { PageLayout } from './page-layout';
|
|
|
|
import { GrpcRequestPane } from './panes/grpc-request-pane';
|
|
|
|
import { GrpcResponsePane } from './panes/grpc-response-pane';
|
|
|
|
import { RequestPane } from './panes/request-pane';
|
|
|
|
import { ResponsePane } from './panes/response-pane';
|
2021-07-29 05:12:59 +00:00
|
|
|
import { SidebarChildren } from './sidebar/sidebar-children';
|
2021-09-27 13:47:22 +00:00
|
|
|
import { SidebarFilter } from './sidebar/sidebar-filter';
|
|
|
|
import { WorkspacePageHeader } from './workspace-page-header';
|
2022-02-02 15:54:05 +00:00
|
|
|
import type { HandleActivityChange, WrapperProps } from './wrapper';
|
2020-04-26 20:33:39 +00:00
|
|
|
|
2022-02-22 13:19:04 +00:00
|
|
|
interface Props extends ReturnType<typeof mapStateToProps> {
|
2021-05-12 06:35:00 +00:00
|
|
|
forceRefreshKey: number;
|
|
|
|
gitSyncDropdown: ReactNode;
|
2022-02-02 15:54:05 +00:00
|
|
|
handleActivityChange: HandleActivityChange;
|
2021-05-12 06:35:00 +00:00
|
|
|
handleChangeEnvironment: Function;
|
|
|
|
handleDeleteResponse: Function;
|
|
|
|
handleDeleteResponses: Function;
|
|
|
|
handleForceUpdateRequest: (r: Request, patch: Partial<Request>) => Promise<Request>;
|
2021-05-18 20:32:18 +00:00
|
|
|
handleForceUpdateRequestHeaders: (r: Request, headers: RequestHeader[]) => Promise<Request>;
|
2021-05-12 06:35:00 +00:00
|
|
|
handleImport: Function;
|
|
|
|
handleRequestCreate: () => void;
|
|
|
|
handleRequestGroupCreate: () => void;
|
|
|
|
handleSendAndDownloadRequestWithActiveEnvironment: (filepath?: string) => Promise<void>;
|
|
|
|
handleSendRequestWithActiveEnvironment: () => void;
|
|
|
|
handleSetActiveResponse: Function;
|
|
|
|
handleSetPreviewMode: Function;
|
|
|
|
handleSetResponseFilter: (filter: string) => void;
|
|
|
|
handleShowRequestSettingsModal: Function;
|
|
|
|
handleSidebarSort: (sortOrder: SortOrder) => void;
|
|
|
|
handleUpdateRequestAuthentication: (r: Request, auth: RequestAuthentication) => Promise<Request>;
|
|
|
|
handleUpdateRequestBody: (r: Request, body: RequestBody) => Promise<Request>;
|
2021-05-18 20:32:18 +00:00
|
|
|
handleUpdateRequestHeaders: (r: Request, headers: RequestHeader[]) => Promise<Request>;
|
2021-05-12 06:35:00 +00:00
|
|
|
handleUpdateRequestMethod: (r: Request, method: string) => Promise<Request>;
|
2021-05-18 20:32:18 +00:00
|
|
|
handleUpdateRequestParameters: (r: Request, params: RequestParameter[]) => Promise<Request>;
|
2021-05-12 06:35:00 +00:00
|
|
|
handleUpdateRequestUrl: (r: Request, url: string) => Promise<Request>;
|
|
|
|
handleUpdateSettingsUseBulkHeaderEditor: Function;
|
|
|
|
handleUpdateSettingsUseBulkParametersEditor: (useBulkParametersEditor: boolean) => Promise<Settings>;
|
|
|
|
wrapperProps: WrapperProps;
|
|
|
|
}
|
2020-04-26 20:33:39 +00:00
|
|
|
|
2021-02-02 22:23:42 +00:00
|
|
|
@autoBindMethodsForReact(AUTOBIND_CFG)
|
2022-02-22 13:19:04 +00:00
|
|
|
class UnconnectedWrapperDebug extends PureComponent<Props> {
|
2020-04-26 20:33:39 +00:00
|
|
|
_renderPageHeader() {
|
2022-02-02 15:54:05 +00:00
|
|
|
const { gitSyncDropdown, handleActivityChange, wrapperProps: {
|
|
|
|
vcs,
|
|
|
|
activeWorkspace,
|
|
|
|
activeWorkspaceMeta,
|
|
|
|
activeProject,
|
|
|
|
syncItems,
|
|
|
|
isLoggedIn,
|
|
|
|
} } = this.props;
|
2021-06-22 20:45:30 +00:00
|
|
|
|
2021-06-30 07:47:17 +00:00
|
|
|
if (!activeWorkspace) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-03-17 22:37:32 +00:00
|
|
|
const collection = isCollection(activeWorkspace);
|
2021-06-22 20:45:30 +00:00
|
|
|
|
|
|
|
let insomniaSync: ReactNode = null;
|
2021-08-20 15:12:36 +00:00
|
|
|
if (isLoggedIn && collection && isRemoteProject(activeProject) && vcs) {
|
2021-06-22 20:45:30 +00:00
|
|
|
insomniaSync = <SyncDropdown
|
|
|
|
workspace={activeWorkspace}
|
|
|
|
workspaceMeta={activeWorkspaceMeta}
|
2021-08-20 15:12:36 +00:00
|
|
|
project={activeProject}
|
2021-06-22 20:45:30 +00:00
|
|
|
vcs={vcs}
|
2021-08-07 08:03:56 +00:00
|
|
|
syncItems={syncItems}
|
|
|
|
/>;
|
2021-06-22 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 15:54:05 +00:00
|
|
|
const gitSync = isDesign(activeWorkspace) && gitSyncDropdown;
|
2021-06-22 20:45:30 +00:00
|
|
|
const sync = insomniaSync || gitSync;
|
|
|
|
|
2020-04-26 20:33:39 +00:00
|
|
|
return (
|
2021-02-02 23:19:22 +00:00
|
|
|
<WorkspacePageHeader
|
|
|
|
handleActivityChange={handleActivityChange}
|
2021-07-26 10:05:45 +00:00
|
|
|
gridRight={sync}
|
2020-04-26 20:33:39 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-02 00:55:22 +00:00
|
|
|
_renderPageSidebar() {
|
2020-04-26 20:33:39 +00:00
|
|
|
const {
|
2022-02-22 13:19:04 +00:00
|
|
|
activeEnvironment,
|
|
|
|
activeWorkspace,
|
|
|
|
environments,
|
2020-04-26 20:33:39 +00:00
|
|
|
handleChangeEnvironment,
|
2020-11-02 00:55:22 +00:00
|
|
|
handleRequestCreate,
|
|
|
|
handleRequestGroupCreate,
|
2020-12-01 00:37:57 +00:00
|
|
|
handleSidebarSort,
|
2022-02-22 13:19:04 +00:00
|
|
|
settings,
|
|
|
|
sidebarChildren,
|
|
|
|
sidebarFilter,
|
2020-11-02 00:55:22 +00:00
|
|
|
} = this.props;
|
|
|
|
const {
|
|
|
|
handleActivateRequest,
|
|
|
|
handleCopyAsCurl,
|
|
|
|
handleCreateRequest,
|
|
|
|
handleCreateRequestGroup,
|
|
|
|
handleDuplicateRequest,
|
|
|
|
handleDuplicateRequestGroup,
|
|
|
|
handleGenerateCode,
|
|
|
|
handleSetRequestGroupCollapsed,
|
|
|
|
handleSetRequestPinned,
|
|
|
|
handleSetSidebarFilter,
|
|
|
|
} = this.props.wrapperProps;
|
2021-06-30 07:47:17 +00:00
|
|
|
|
|
|
|
if (!activeWorkspace) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-11-02 00:55:22 +00:00
|
|
|
return (
|
2021-05-12 06:35:00 +00:00
|
|
|
<Fragment>
|
2020-11-02 00:55:22 +00:00
|
|
|
<div className="sidebar__menu">
|
|
|
|
<EnvironmentsDropdown
|
|
|
|
handleChangeEnvironment={handleChangeEnvironment}
|
|
|
|
activeEnvironment={activeEnvironment}
|
|
|
|
environments={environments}
|
|
|
|
workspace={activeWorkspace}
|
|
|
|
environmentHighlightColorStyle={settings.environmentHighlightColorStyle}
|
|
|
|
hotKeyRegistry={settings.hotKeyRegistry}
|
|
|
|
/>
|
2021-12-08 03:11:04 +00:00
|
|
|
<button className="btn btn--super-compact" onClick={showCookiesModal}>
|
2020-11-02 00:55:22 +00:00
|
|
|
<div className="sidebar__menu__thing">
|
|
|
|
<span>Cookies</span>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<SidebarFilter
|
|
|
|
key={`${activeWorkspace._id}::filter`}
|
|
|
|
onChange={handleSetSidebarFilter}
|
|
|
|
requestCreate={handleRequestCreate}
|
|
|
|
requestGroupCreate={handleRequestGroupCreate}
|
2020-12-01 00:37:57 +00:00
|
|
|
sidebarSort={handleSidebarSort}
|
2020-11-02 00:55:22 +00:00
|
|
|
filter={sidebarFilter || ''}
|
|
|
|
hotKeyRegistry={settings.hotKeyRegistry}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<SidebarChildren
|
|
|
|
childObjects={sidebarChildren}
|
|
|
|
handleActivateRequest={handleActivateRequest}
|
|
|
|
handleCreateRequest={handleCreateRequest}
|
|
|
|
handleCreateRequestGroup={handleCreateRequestGroup}
|
|
|
|
handleSetRequestGroupCollapsed={handleSetRequestGroupCollapsed}
|
|
|
|
handleSetRequestPinned={handleSetRequestPinned}
|
|
|
|
handleDuplicateRequest={handleDuplicateRequest}
|
|
|
|
handleDuplicateRequestGroup={handleDuplicateRequestGroup}
|
|
|
|
handleGenerateCode={handleGenerateCode}
|
|
|
|
handleCopyAsCurl={handleCopyAsCurl}
|
|
|
|
filter={sidebarFilter || ''}
|
|
|
|
hotKeyRegistry={settings.hotKeyRegistry}
|
|
|
|
/>
|
2021-05-12 06:35:00 +00:00
|
|
|
</Fragment>
|
2020-11-02 00:55:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-19 00:13:24 +00:00
|
|
|
_renderRequestPane() {
|
2020-11-02 00:55:22 +00:00
|
|
|
const {
|
2022-02-22 13:19:04 +00:00
|
|
|
activeEnvironment,
|
|
|
|
activeRequest,
|
|
|
|
activeWorkspace,
|
2020-11-02 00:55:22 +00:00
|
|
|
forceRefreshKey,
|
2020-04-26 20:33:39 +00:00
|
|
|
handleForceUpdateRequest,
|
|
|
|
handleForceUpdateRequestHeaders,
|
|
|
|
handleImport,
|
|
|
|
handleSendAndDownloadRequestWithActiveEnvironment,
|
|
|
|
handleSendRequestWithActiveEnvironment,
|
|
|
|
handleUpdateRequestAuthentication,
|
|
|
|
handleUpdateRequestBody,
|
|
|
|
handleUpdateRequestHeaders,
|
|
|
|
handleUpdateRequestMethod,
|
|
|
|
handleUpdateRequestParameters,
|
|
|
|
handleUpdateRequestUrl,
|
|
|
|
handleUpdateSettingsUseBulkHeaderEditor,
|
2020-08-03 10:13:08 +00:00
|
|
|
handleUpdateSettingsUseBulkParametersEditor,
|
2022-02-22 13:19:04 +00:00
|
|
|
responseDownloadPath,
|
|
|
|
settings,
|
2020-04-26 20:33:39 +00:00
|
|
|
} = this.props;
|
|
|
|
const {
|
|
|
|
handleCreateRequestForWorkspace,
|
|
|
|
handleGenerateCodeForActiveRequest,
|
|
|
|
handleUpdateDownloadPath,
|
|
|
|
handleUpdateRequestMimeType,
|
|
|
|
headerEditorKey,
|
|
|
|
} = this.props.wrapperProps;
|
|
|
|
|
2021-06-30 07:47:17 +00:00
|
|
|
if (!activeWorkspace) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-11-02 00:55:22 +00:00
|
|
|
// activeRequest being truthy only needs to be checked for isGrpcRequest (for now)
|
|
|
|
// The RequestPane and ResponsePane components already handle the case where activeRequest is null
|
|
|
|
if (activeRequest && isGrpcRequest(activeRequest)) {
|
2020-11-02 22:09:45 +00:00
|
|
|
return (
|
2020-11-02 00:55:22 +00:00
|
|
|
<ErrorBoundary showAlert>
|
2020-11-19 00:13:24 +00:00
|
|
|
<GrpcRequestPane
|
|
|
|
activeRequest={activeRequest}
|
2020-12-17 11:38:21 +00:00
|
|
|
environmentId={activeEnvironment ? activeEnvironment._id : ''}
|
|
|
|
workspaceId={activeWorkspace._id}
|
2021-05-12 06:35:00 +00:00
|
|
|
forceRefreshKey={forceRefreshKey}
|
2020-11-02 00:55:22 +00:00
|
|
|
settings={settings}
|
|
|
|
/>
|
|
|
|
</ErrorBoundary>
|
2020-11-19 00:13:24 +00:00
|
|
|
);
|
|
|
|
}
|
2020-04-26 20:33:39 +00:00
|
|
|
|
2020-11-19 00:13:24 +00:00
|
|
|
return (
|
|
|
|
<ErrorBoundary showAlert>
|
|
|
|
<RequestPane
|
|
|
|
downloadPath={responseDownloadPath}
|
|
|
|
environmentId={activeEnvironment ? activeEnvironment._id : ''}
|
|
|
|
forceRefreshCounter={forceRefreshKey}
|
|
|
|
forceUpdateRequest={handleForceUpdateRequest}
|
|
|
|
forceUpdateRequestHeaders={handleForceUpdateRequestHeaders}
|
|
|
|
handleCreateRequest={handleCreateRequestForWorkspace}
|
|
|
|
handleGenerateCode={handleGenerateCodeForActiveRequest}
|
|
|
|
handleImport={handleImport}
|
|
|
|
handleSend={handleSendRequestWithActiveEnvironment}
|
|
|
|
handleSendAndDownload={handleSendAndDownloadRequestWithActiveEnvironment}
|
|
|
|
handleUpdateDownloadPath={handleUpdateDownloadPath}
|
|
|
|
headerEditorKey={headerEditorKey}
|
|
|
|
request={activeRequest}
|
|
|
|
settings={settings}
|
|
|
|
updateRequestAuthentication={handleUpdateRequestAuthentication}
|
|
|
|
updateRequestBody={handleUpdateRequestBody}
|
|
|
|
updateRequestHeaders={handleUpdateRequestHeaders}
|
|
|
|
updateRequestMethod={handleUpdateRequestMethod}
|
|
|
|
updateRequestMimeType={handleUpdateRequestMimeType}
|
|
|
|
updateRequestParameters={handleUpdateRequestParameters}
|
|
|
|
updateRequestUrl={handleUpdateRequestUrl}
|
|
|
|
updateSettingsUseBulkHeaderEditor={handleUpdateSettingsUseBulkHeaderEditor}
|
|
|
|
updateSettingsUseBulkParametersEditor={handleUpdateSettingsUseBulkParametersEditor}
|
|
|
|
workspace={activeWorkspace}
|
|
|
|
/>
|
|
|
|
</ErrorBoundary>
|
|
|
|
);
|
|
|
|
}
|
2020-04-26 20:33:39 +00:00
|
|
|
|
2020-11-19 00:13:24 +00:00
|
|
|
_renderResponsePane() {
|
|
|
|
const {
|
|
|
|
forceRefreshKey,
|
|
|
|
handleDeleteResponse,
|
|
|
|
handleDeleteResponses,
|
|
|
|
handleSetActiveResponse,
|
|
|
|
handleSetPreviewMode,
|
|
|
|
handleSetResponseFilter,
|
|
|
|
handleShowRequestSettingsModal,
|
|
|
|
activeEnvironment,
|
|
|
|
activeRequest,
|
|
|
|
activeRequestResponses,
|
|
|
|
activeResponse,
|
|
|
|
activeUnitTestResult,
|
|
|
|
loadStartTime,
|
|
|
|
requestVersions,
|
|
|
|
responseFilter,
|
|
|
|
responseFilterHistory,
|
|
|
|
responsePreviewMode,
|
|
|
|
settings,
|
2022-02-22 13:19:04 +00:00
|
|
|
} = this.props;
|
2020-11-19 00:13:24 +00:00
|
|
|
|
|
|
|
// activeRequest being truthy only needs to be checked for isGrpcRequest (for now)
|
|
|
|
// The RequestPane and ResponsePane components already handle the case where activeRequest is null
|
|
|
|
if (activeRequest && isGrpcRequest(activeRequest)) {
|
|
|
|
return (
|
2020-11-02 00:55:22 +00:00
|
|
|
<ErrorBoundary showAlert>
|
2020-11-19 00:13:24 +00:00
|
|
|
<GrpcResponsePane
|
|
|
|
activeRequest={activeRequest}
|
2021-05-12 06:35:00 +00:00
|
|
|
forceRefreshKey={forceRefreshKey}
|
2020-11-02 00:55:22 +00:00
|
|
|
/>
|
|
|
|
</ErrorBoundary>
|
2020-11-19 00:13:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ErrorBoundary showAlert>
|
|
|
|
<ResponsePane
|
|
|
|
disableHtmlPreviewJs={settings.disableHtmlPreviewJs}
|
|
|
|
disableResponsePreviewLinks={settings.disableResponsePreviewLinks}
|
|
|
|
editorFontSize={settings.editorFontSize}
|
|
|
|
environment={activeEnvironment}
|
|
|
|
filter={responseFilter}
|
|
|
|
filterHistory={responseFilterHistory}
|
|
|
|
handleDeleteResponse={handleDeleteResponse}
|
|
|
|
handleDeleteResponses={handleDeleteResponses}
|
|
|
|
handleSetActiveResponse={handleSetActiveResponse}
|
|
|
|
handleSetFilter={handleSetResponseFilter}
|
|
|
|
handleSetPreviewMode={handleSetPreviewMode}
|
|
|
|
handleShowRequestSettings={handleShowRequestSettingsModal}
|
|
|
|
hotKeyRegistry={settings.hotKeyRegistry}
|
|
|
|
loadStartTime={loadStartTime}
|
|
|
|
previewMode={responsePreviewMode}
|
|
|
|
request={activeRequest}
|
|
|
|
requestVersions={requestVersions}
|
|
|
|
response={activeResponse}
|
|
|
|
responses={activeRequestResponses}
|
|
|
|
unitTestResult={activeUnitTestResult}
|
|
|
|
/>
|
|
|
|
</ErrorBoundary>
|
2020-11-02 00:55:22 +00:00
|
|
|
);
|
|
|
|
}
|
2020-04-26 20:33:39 +00:00
|
|
|
|
2020-11-02 00:55:22 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<PageLayout
|
|
|
|
wrapperProps={this.props.wrapperProps}
|
2021-02-02 23:19:22 +00:00
|
|
|
renderPageHeader={this._renderPageHeader}
|
2020-11-02 00:55:22 +00:00
|
|
|
renderPageSidebar={this._renderPageSidebar}
|
2020-11-19 00:13:24 +00:00
|
|
|
renderPaneOne={this._renderRequestPane}
|
|
|
|
renderPaneTwo={this._renderResponsePane}
|
2020-04-26 20:33:39 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-02-22 13:19:04 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (state: RootState) => ({
|
|
|
|
activeEnvironment: selectActiveEnvironment(state),
|
|
|
|
activeRequest: selectActiveRequest(state),
|
|
|
|
activeRequestResponses: selectActiveRequestResponses(state),
|
|
|
|
activeResponse: selectActiveResponse(state),
|
|
|
|
activeUnitTestResult: selectActiveUnitTestResult(state),
|
|
|
|
activeWorkspace: selectActiveWorkspace(state),
|
|
|
|
environments: selectEnvironments(state),
|
|
|
|
loadStartTime: selectLoadStartTime(state),
|
|
|
|
requestVersions: selectRequestVersions(state),
|
|
|
|
responseDownloadPath: selectResponseDownloadPath(state),
|
|
|
|
responseFilter: selectResponseFilter(state),
|
|
|
|
responseFilterHistory: selectResponseFilterHistory(state),
|
|
|
|
responsePreviewMode: selectResponsePreviewMode(state),
|
|
|
|
settings: selectSettings(state),
|
|
|
|
sidebarChildren: selectSidebarChildren(state),
|
|
|
|
sidebarFilter: selectSidebarFilter(state),
|
|
|
|
});
|
|
|
|
|
|
|
|
export const WrapperDebug = connect(mapStateToProps)(UnconnectedWrapperDebug);
|