import { autoBindMethodsForReact } from 'class-autobind-decorator'; import React, { Fragment, PureComponent, ReactNode } from 'react'; import { connect } from 'react-redux'; import { AUTOBIND_CFG, SortOrder } from '../../common/constants'; import { isGrpcRequest } from '../../models/grpc-request'; import { isRemoteProject } from '../../models/project'; import { Request, RequestAuthentication, RequestBody, RequestHeader, RequestParameter } from '../../models/request'; import { Settings } from '../../models/settings'; import { isCollection, isDesign } from '../../models/workspace'; 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'; import { EnvironmentsDropdown } from './dropdowns/environments-dropdown'; import { SyncDropdown } from './dropdowns/sync-dropdown'; import { ErrorBoundary } from './error-boundary'; import { showCookiesModal } from './modals/cookies-modal'; 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'; import { SidebarChildren } from './sidebar/sidebar-children'; import { SidebarFilter } from './sidebar/sidebar-filter'; import { WorkspacePageHeader } from './workspace-page-header'; import type { HandleActivityChange, WrapperProps } from './wrapper'; interface Props extends ReturnType { forceRefreshKey: number; gitSyncDropdown: ReactNode; handleActivityChange: HandleActivityChange; handleChangeEnvironment: Function; handleDeleteResponse: Function; handleDeleteResponses: Function; handleForceUpdateRequest: (r: Request, patch: Partial) => Promise; handleForceUpdateRequestHeaders: (r: Request, headers: RequestHeader[]) => Promise; handleImport: Function; handleRequestCreate: () => void; handleRequestGroupCreate: () => void; handleSendAndDownloadRequestWithActiveEnvironment: (filepath?: string) => Promise; handleSendRequestWithActiveEnvironment: () => void; handleSetActiveResponse: Function; handleSetPreviewMode: Function; handleSetResponseFilter: (filter: string) => void; handleShowRequestSettingsModal: Function; handleSidebarSort: (sortOrder: SortOrder) => void; handleUpdateRequestAuthentication: (r: Request, auth: RequestAuthentication) => Promise; handleUpdateRequestBody: (r: Request, body: RequestBody) => Promise; handleUpdateRequestHeaders: (r: Request, headers: RequestHeader[]) => Promise; handleUpdateRequestMethod: (r: Request, method: string) => Promise; handleUpdateRequestParameters: (r: Request, params: RequestParameter[]) => Promise; handleUpdateRequestUrl: (r: Request, url: string) => Promise; handleUpdateSettingsUseBulkHeaderEditor: Function; handleUpdateSettingsUseBulkParametersEditor: (useBulkParametersEditor: boolean) => Promise; wrapperProps: WrapperProps; } @autoBindMethodsForReact(AUTOBIND_CFG) class UnconnectedWrapperDebug extends PureComponent { _renderPageHeader() { const { gitSyncDropdown, handleActivityChange, wrapperProps: { vcs, activeWorkspace, activeWorkspaceMeta, activeProject, syncItems, isLoggedIn, } } = this.props; if (!activeWorkspace) { return null; } const collection = isCollection(activeWorkspace); let insomniaSync: ReactNode = null; if (isLoggedIn && collection && isRemoteProject(activeProject) && vcs) { insomniaSync = ; } const gitSync = isDesign(activeWorkspace) && gitSyncDropdown; const sync = insomniaSync || gitSync; return ( ); } _renderPageSidebar() { const { activeEnvironment, activeWorkspace, environments, handleChangeEnvironment, handleRequestCreate, handleRequestGroupCreate, handleSidebarSort, settings, sidebarChildren, sidebarFilter, } = this.props; const { handleActivateRequest, handleCopyAsCurl, handleCreateRequest, handleCreateRequestGroup, handleDuplicateRequest, handleDuplicateRequestGroup, handleGenerateCode, handleSetRequestGroupCollapsed, handleSetRequestPinned, handleSetSidebarFilter, } = this.props.wrapperProps; if (!activeWorkspace) { return null; } return (
); } _renderRequestPane() { const { activeEnvironment, activeRequest, activeWorkspace, forceRefreshKey, handleForceUpdateRequest, handleForceUpdateRequestHeaders, handleImport, handleSendAndDownloadRequestWithActiveEnvironment, handleSendRequestWithActiveEnvironment, handleUpdateRequestAuthentication, handleUpdateRequestBody, handleUpdateRequestHeaders, handleUpdateRequestMethod, handleUpdateRequestParameters, handleUpdateRequestUrl, handleUpdateSettingsUseBulkHeaderEditor, handleUpdateSettingsUseBulkParametersEditor, responseDownloadPath, settings, } = this.props; const { handleCreateRequestForWorkspace, handleGenerateCodeForActiveRequest, handleUpdateDownloadPath, handleUpdateRequestMimeType, headerEditorKey, } = this.props.wrapperProps; if (!activeWorkspace) { return null; } // 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 ( ); } return ( ); } _renderResponsePane() { const { forceRefreshKey, handleDeleteResponse, handleDeleteResponses, handleSetActiveResponse, handleSetPreviewMode, handleSetResponseFilter, handleShowRequestSettingsModal, activeEnvironment, activeRequest, activeRequestResponses, activeResponse, activeUnitTestResult, loadStartTime, requestVersions, responseFilter, responseFilterHistory, responsePreviewMode, settings, } = this.props; // 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 ( ); } return ( ); } render() { return ( ); } } 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);