From 7397370f4be1bf422c8a225bd285a29513432c3f Mon Sep 17 00:00:00 2001 From: Opender Singh Date: Thu, 29 Jul 2021 16:55:31 +1200 Subject: [PATCH] Use activateWorkspace action to activate a workspace (#3856) Co-authored-by: Dimitri Mitropoulos --- .../app/__jest__/redux-state-for-test.ts | 4 +- .../components/modals/proto-files-modal.tsx | 37 ++++++---- .../modals/request-switcher-modal.tsx | 67 ++++++++++++------- .../app/ui/components/page-layout.tsx | 2 - .../app/ui/components/sidebar/sidebar.tsx | 1 - .../app/ui/components/wrapper-home.tsx | 26 ++----- .../app/ui/components/wrapper.tsx | 14 ---- .../insomnia-app/app/ui/containers/app.tsx | 4 -- .../redux/__tests__/proto-selectors.test.ts | 15 +++-- .../ui/redux/modules/__tests__/git.test.tsx | 7 +- .../redux/modules/__tests__/workspace.test.ts | 43 +++--------- .../app/ui/redux/modules/workspace.ts | 5 +- .../insomnia-app/app/ui/redux/selectors.ts | 5 ++ .../src/button/async-button.tsx | 2 +- 14 files changed, 103 insertions(+), 129 deletions(-) diff --git a/packages/insomnia-app/app/__jest__/redux-state-for-test.ts b/packages/insomnia-app/app/__jest__/redux-state-for-test.ts index 93232cbf9..fe89f1022 100644 --- a/packages/insomnia-app/app/__jest__/redux-state-for-test.ts +++ b/packages/insomnia-app/app/__jest__/redux-state-for-test.ts @@ -1,4 +1,4 @@ -import { ACTIVITY_DEBUG } from '../common/constants'; +import { ACTIVITY_HOME } from '../common/constants'; import { BASE_SPACE_ID } from '../models/space'; import { RootState } from '../ui/redux/modules'; import * as entities from '../ui/redux/modules/entities'; @@ -8,7 +8,7 @@ export const reduxStateForTest = async (global: Partial = {}): Prom entities: entities.reducer(entities.initialEntitiesState, entities.initializeWith(await entities.allDocs())), global: { activeWorkspaceId: null, - activeActivity: ACTIVITY_DEBUG, + activeActivity: ACTIVITY_HOME, activeSpaceId: BASE_SPACE_ID, isLoading: false, isLoggedIn: false, diff --git a/packages/insomnia-app/app/ui/components/modals/proto-files-modal.tsx b/packages/insomnia-app/app/ui/components/modals/proto-files-modal.tsx index 25e5b2b15..e680e6949 100644 --- a/packages/insomnia-app/app/ui/components/modals/proto-files-modal.tsx +++ b/packages/insomnia-app/app/ui/components/modals/proto-files-modal.tsx @@ -7,22 +7,22 @@ import { AUTOBIND_CFG } from '../../../common/constants'; import { GrpcRequestEventEnum } from '../../../common/grpc-events'; import type { ProtoDirectory } from '../../../models/proto-directory'; import type { ProtoFile } from '../../../models/proto-file'; -import type { Workspace } from '../../../models/workspace'; import * as protoManager from '../../../network/grpc/proto-manager'; import type { GrpcDispatch } from '../../context/grpc'; import { grpcActions, sendGrpcIpcMultiple } from '../../context/grpc'; -import type { ExpandedProtoDirectory } from '../../redux/proto-selectors'; +import { RootState } from '../../redux/modules'; import { selectExpandedActiveProtoDirectories } from '../../redux/proto-selectors'; +import { selectActiveWorkspace } from '../../redux/selectors'; import Modal from '../base/modal'; import ModalBody from '../base/modal-body'; import ModalFooter from '../base/modal-footer'; import ModalHeader from '../base/modal-header'; import ProtoFileList from '../proto-file/proto-file-list'; -interface Props { +type ReduxProps = ReturnType; + +interface Props extends ReduxProps { grpcDispatch: GrpcDispatch; - workspace: Workspace; - protoDirectories: ExpandedProtoDirectory[]; } interface State { @@ -105,7 +105,13 @@ class ProtoFilesModal extends PureComponent { } _handleAdd() { - return protoManager.addFile(this.props.workspace._id, createdId => { + const { workspace } = this.props; + + if (!workspace) { + return; + } + + return protoManager.addFile(workspace._id, createdId => { this.setState({ selectedProtoFileId: createdId, }); @@ -122,7 +128,13 @@ class ProtoFilesModal extends PureComponent { } _handleAddDirectory() { - return protoManager.addDirectory(this.props.workspace._id); + const { workspace } = this.props; + + if (!workspace) { + return; + } + + return protoManager.addDirectory(workspace._id); } _handleRename(protoFile: ProtoFile, name: string) { @@ -172,13 +184,10 @@ class ProtoFilesModal extends PureComponent { } } -const mapStateToProps = (state, props) => { - // @ts-expect-error -- TSCONVERSION - const protoDirectories = selectExpandedActiveProtoDirectories(state, props); - return { - protoDirectories, - }; -}; +const mapStateToProps = (state: RootState) => ({ + protoDirectories: selectExpandedActiveProtoDirectories(state), + workspace: selectActiveWorkspace(state), +}); export default connect(mapStateToProps, null, null, { forwardRef: true, diff --git a/packages/insomnia-app/app/ui/components/modals/request-switcher-modal.tsx b/packages/insomnia-app/app/ui/components/modals/request-switcher-modal.tsx index 067ec82d3..6eced6b13 100644 --- a/packages/insomnia-app/app/ui/components/modals/request-switcher-modal.tsx +++ b/packages/insomnia-app/app/ui/components/modals/request-switcher-modal.tsx @@ -2,8 +2,10 @@ import { autoBindMethodsForReact } from 'class-autobind-decorator'; import classnames from 'classnames'; import { buildQueryStringFromParams, joinUrlAndQueryString } from 'insomnia-url'; import React, { Fragment, PureComponent } from 'react'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; -import { ACTIVITY_DEBUG, ACTIVITY_SPEC, AUTOBIND_CFG, GlobalActivity, isWorkspaceActivity } from '../../../common/constants'; +import { AUTOBIND_CFG } from '../../../common/constants'; import { hotKeyRefs } from '../../../common/hotkeys'; import { executeHotKey } from '../../../common/hotkeys-listener'; import { keyboardKeys } from '../../../common/keyboard-keys'; @@ -11,10 +13,11 @@ import { fuzzyMatchAll } from '../../../common/misc'; import type { BaseModel } from '../../../models'; import * as models from '../../../models'; import { isRequest, Request } from '../../../models/request'; -import { isRequestGroup, RequestGroup } from '../../../models/request-group'; -import type { RequestMeta } from '../../../models/request-meta'; -import { isDesign, Workspace } from '../../../models/workspace'; -import { setActiveActivity, setActiveWorkspace } from '../../redux/modules/global'; +import { isRequestGroup } from '../../../models/request-group'; +import { Workspace } from '../../../models/workspace'; +import { RootState } from '../../redux/modules'; +import { activateWorkspace } from '../../redux/modules/workspace'; +import { selectActiveRequest, selectActiveWorkspace, selectRequestMetas, selectWorkspaceRequestsAndRequestGroups, selectWorkspacesForActiveSpace } from '../../redux/selectors'; import Button from '../base/button'; import Highlight from '../base/highlight'; import Modal from '../base/modal'; @@ -23,15 +26,31 @@ import ModalHeader from '../base/modal-header'; import KeydownBinder from '../keydown-binder'; import MethodTag from '../tags/method-tag'; -interface Props { - handleSetActiveWorkspace: typeof setActiveWorkspace; - handleSetActiveActivity: typeof setActiveActivity; +type ReduxProps = ReturnType & ReturnType; + +const mapStateToProps = (state: RootState) => { + const activeRequest = selectActiveRequest(state); + // the request switcher modal does not know about grpc requests yet + const normalizedRequest = activeRequest && isRequest(activeRequest) ? activeRequest : undefined; + + return { + activeRequest: normalizedRequest, + workspace: selectActiveWorkspace(state), + workspaces: selectWorkspacesForActiveSpace(state), + requestMetas: selectRequestMetas(state), + workspaceChildren: selectWorkspaceRequestsAndRequestGroups(state), + }; +}; + +const mapDispatchToProps = (dispatch) => { + const bound = bindActionCreators({ activateWorkspace }, dispatch); + return { + handleActivateWorkspace: bound.activateWorkspace, + }; +}; + +interface Props extends ReduxProps { activateRequest: (id: string) => void; - activeRequest?: Request; - workspaceChildren: (Request | RequestGroup)[]; - workspace?: Workspace; - workspaces: Workspace[]; - requestMetas: RequestMeta[]; } interface State { @@ -155,18 +174,7 @@ class RequestSwitcherModal extends PureComponent { } async _activateWorkspace(workspace: Workspace) { - const { activeActivity } = await models.workspaceMeta.getOrCreateByParentId(workspace._id); - - let goToActivity: GlobalActivity; - - if (activeActivity && isWorkspaceActivity(activeActivity)) { - goToActivity = activeActivity; - } else { - goToActivity = isDesign(workspace) ? ACTIVITY_SPEC : ACTIVITY_DEBUG; - } - - this.props.handleSetActiveActivity(goToActivity); - this.props.handleSetActiveWorkspace(workspace._id); + await this.props.handleActivateWorkspace(workspace); this.modal && this.modal.hide(); } @@ -509,4 +517,11 @@ class RequestSwitcherModal extends PureComponent { } } -export default RequestSwitcherModal; +export default connect( + mapStateToProps, + mapDispatchToProps, + null, + { forwardRef: true } +)(RequestSwitcherModal); + + diff --git a/packages/insomnia-app/app/ui/components/page-layout.tsx b/packages/insomnia-app/app/ui/components/page-layout.tsx index 919c07f87..ff75ffaa9 100644 --- a/packages/insomnia-app/app/ui/components/page-layout.tsx +++ b/packages/insomnia-app/app/ui/components/page-layout.tsx @@ -41,7 +41,6 @@ class PageLayout extends PureComponent { handleInitializeEntities, handleResetDragSidebar, handleSetActiveEnvironment, - handleSetActiveWorkspace, handleSetSidebarRef, handleSetRequestPaneRef, handleSetResponsePaneRef, @@ -114,7 +113,6 @@ class PageLayout extends PureComponent { environmentHighlightColorStyle={settings.environmentHighlightColorStyle} handleInitializeEntities={handleInitializeEntities} handleSetActiveEnvironment={handleSetActiveEnvironment} - handleSetActiveWorkspace={handleSetActiveWorkspace} hidden={sidebarHidden || false} hotKeyRegistry={settings.hotKeyRegistry} isLoading={isLoading} diff --git a/packages/insomnia-app/app/ui/components/sidebar/sidebar.tsx b/packages/insomnia-app/app/ui/components/sidebar/sidebar.tsx index f2eaf2bb7..fabaace59 100644 --- a/packages/insomnia-app/app/ui/components/sidebar/sidebar.tsx +++ b/packages/insomnia-app/app/ui/components/sidebar/sidebar.tsx @@ -16,7 +16,6 @@ interface Props { children: ReactNode; environmentHighlightColorStyle: string; handleSetActiveEnvironment: (...args: any[]) => any; - handleSetActiveWorkspace: (...args: any[]) => any; hidden: boolean; hotKeyRegistry: HotKeyRegistry; isLoading: boolean; diff --git a/packages/insomnia-app/app/ui/components/wrapper-home.tsx b/packages/insomnia-app/app/ui/components/wrapper-home.tsx index 6f95ff9e7..fca193233 100644 --- a/packages/insomnia-app/app/ui/components/wrapper-home.tsx +++ b/packages/insomnia-app/app/ui/components/wrapper-home.tsx @@ -17,18 +17,13 @@ import { bindActionCreators } from 'redux'; import { parseApiSpec, ParsedApiSpec } from '../../common/api-specs'; import { - ACTIVITY_DEBUG, - ACTIVITY_SPEC, AUTOBIND_CFG, - GlobalActivity, - isWorkspaceActivity, } from '../../common/constants'; import { hotKeyRefs } from '../../common/hotkeys'; import { executeHotKey } from '../../common/hotkeys-listener'; import { fuzzyMatchAll, isNotNullOrUndefined } from '../../common/misc'; import { descendingNumberSort } from '../../common/sorting'; import { strings } from '../../common/strings'; -import * as models from '../../models'; import { isRemoteSpace } from '../../models/space'; import { isDesign, Workspace, WorkspaceScopeKeys } from '../../models/workspace'; import { MemClient } from '../../sync/git/mem-client'; @@ -37,7 +32,7 @@ import coreLogo from '../images/insomnia-core-logo.png'; import { cloneGitRepository } from '../redux/modules/git'; import { ForceToWorkspace } from '../redux/modules/helpers'; import { importClipBoard, importFile, importUri } from '../redux/modules/import'; -import { createWorkspace } from '../redux/modules/workspace'; +import { activateWorkspace, createWorkspace } from '../redux/modules/workspace'; import Highlight from './base/highlight'; import SettingsButton from './buttons/settings-button'; import AccountDropdown from './dropdowns/account-dropdown'; @@ -144,19 +139,6 @@ class WrapperHome extends PureComponent { }); } - async _handleClickCard(id: string, defaultActivity: GlobalActivity) { - const { handleSetActiveWorkspace, handleSetActiveActivity } = this.props.wrapperProps; - const { activeActivity } = await models.workspaceMeta.getOrCreateByParentId(id); - - if (!activeActivity || !isWorkspaceActivity(activeActivity)) { - handleSetActiveActivity(defaultActivity); - } else { - handleSetActiveActivity(activeActivity); - } - - handleSetActiveWorkspace(id); - } - renderCard(workspace: Workspace) { const { activeSpace, @@ -237,7 +219,6 @@ class WrapperHome extends PureComponent { let label: string = strings.collection.singular; let format = ''; let labelIcon = ; - let defaultActivity = ACTIVITY_DEBUG; let title = workspace.name; if (isDesign(workspace)) { @@ -251,7 +232,6 @@ class WrapperHome extends PureComponent { format = `OpenAPI ${specFormatVersion}`; } - defaultActivity = ACTIVITY_SPEC; title = apiSpec.fileName || title; } @@ -283,7 +263,7 @@ class WrapperHome extends PureComponent { docLog={log} docMenu={docMenu} docFormat={format} - onClick={() => this._handleClickCard(workspace._id, defaultActivity)} + onClick={() => this.props.handleActivateWorkspace(workspace)} /> ); const renderedCard: RenderedCard = { @@ -419,6 +399,7 @@ const mapDispatchToProps = (dispatch) => { importFile, importClipBoard, importUri, + activateWorkspace, }, dispatch); return ({ @@ -427,6 +408,7 @@ const mapDispatchToProps = (dispatch) => { handleImportFile: bound.importFile, handleImportUri: bound.importUri, handleImportClipboard: bound.importClipBoard, + handleActivateWorkspace: bound.activateWorkspace, }); }; diff --git a/packages/insomnia-app/app/ui/components/wrapper.tsx b/packages/insomnia-app/app/ui/components/wrapper.tsx index 06e97ccf5..3868792fd 100644 --- a/packages/insomnia-app/app/ui/components/wrapper.tsx +++ b/packages/insomnia-app/app/ui/components/wrapper.tsx @@ -471,7 +471,6 @@ class Wrapper extends PureComponent { activeCookieJar, activeEnvironment, activeGitRepository, - activeRequest, activeWorkspace, activeSpace, activeApiSpec, @@ -483,16 +482,12 @@ class Wrapper extends PureComponent { handleGetRenderContext, handleInitializeEntities, handleRender, - handleSetActiveWorkspace, - handleSetActiveActivity, handleSidebarSort, isVariableUncovered, - requestMetas, settings, sidebarChildren, syncItems, vcs, - workspaceChildren, workspaces, } = this.props; @@ -641,15 +636,7 @@ class Wrapper extends PureComponent { { )} diff --git a/packages/insomnia-app/app/ui/containers/app.tsx b/packages/insomnia-app/app/ui/containers/app.tsx index 1af120616..05f069ace 100644 --- a/packages/insomnia-app/app/ui/containers/app.tsx +++ b/packages/insomnia-app/app/ui/containers/app.tsx @@ -95,7 +95,6 @@ import { loadRequestStop, newCommand, setActiveActivity, - setActiveWorkspace, } from '../redux/modules/global'; import { importUri } from '../redux/modules/import'; import { @@ -1783,7 +1782,6 @@ const mapDispatchToProps = (dispatch: Dispatch>) => { importUri: handleImportUri, loadRequestStart: handleStartLoading, loadRequestStop: handleStopLoading, - setActiveWorkspace: handleSetActiveWorkspace, newCommand: handleCommand, setActiveActivity: handleSetActiveActivity, goToNextActivity: handleGoToNextActivity, @@ -1794,7 +1792,6 @@ const mapDispatchToProps = (dispatch: Dispatch>) => { loadRequestStart, loadRequestStop, newCommand, - setActiveWorkspace, setActiveActivity, goToNextActivity, exportRequestsToFile, @@ -1803,7 +1800,6 @@ const mapDispatchToProps = (dispatch: Dispatch>) => { return { handleCommand, handleImportUri, - handleSetActiveWorkspace, handleSetActiveActivity, handleStartLoading, handleStopLoading, diff --git a/packages/insomnia-app/app/ui/redux/__tests__/proto-selectors.test.ts b/packages/insomnia-app/app/ui/redux/__tests__/proto-selectors.test.ts index b2997ddcc..9f80ae1e3 100644 --- a/packages/insomnia-app/app/ui/redux/__tests__/proto-selectors.test.ts +++ b/packages/insomnia-app/app/ui/redux/__tests__/proto-selectors.test.ts @@ -1,5 +1,6 @@ import { globalBeforeEach } from '../../../__jest__/before-each'; import { reduxStateForTest } from '../../../__jest__/redux-state-for-test'; +import { ACTIVITY_DEBUG } from '../../../common/constants'; import * as models from '../../../models'; import { selectExpandedActiveProtoDirectories } from '../proto-selectors'; @@ -10,7 +11,7 @@ describe('selectExpandedActiveProtoDirectories', () => { // Arrange const w = await models.workspace.create(); // Act - const state = await reduxStateForTest({ activeWorkspaceId: w._id }); + const state = await reduxStateForTest({ activeWorkspaceId: w._id, activeActivity: ACTIVITY_DEBUG }); const expandedDirs = selectExpandedActiveProtoDirectories(state); // Assert expect(expandedDirs).toHaveLength(0); @@ -36,7 +37,7 @@ describe('selectExpandedActiveProtoDirectories', () => { }); const w2 = await models.workspace.create(); // Act - const state = await reduxStateForTest({ activeWorkspaceId: w2._id }); + const state = await reduxStateForTest({ activeWorkspaceId: w2._id, activeActivity: ACTIVITY_DEBUG }); const expandedDirs = selectExpandedActiveProtoDirectories(state); // Assert expect(expandedDirs).toHaveLength(0); @@ -52,7 +53,7 @@ describe('selectExpandedActiveProtoDirectories', () => { parentId: pd1._id, }); // Act - const state = await reduxStateForTest({ activeWorkspaceId: w._id }); + const state = await reduxStateForTest({ activeWorkspaceId: w._id, activeActivity: ACTIVITY_DEBUG }); const expandedDirs = selectExpandedActiveProtoDirectories(state); // Assert expect(expandedDirs).toHaveLength(1); @@ -81,7 +82,7 @@ describe('selectExpandedActiveProtoDirectories', () => { parentId: w._id, }); // Act - const state = await reduxStateForTest({ activeWorkspaceId: w._id }); + const state = await reduxStateForTest({ activeWorkspaceId: w._id, activeActivity: ACTIVITY_DEBUG }); const expandedDirs = selectExpandedActiveProtoDirectories(state); // Assert expect(expandedDirs).toHaveLength(1); @@ -110,7 +111,7 @@ describe('selectExpandedActiveProtoDirectories', () => { parentId: pd2._id, }); // Act - const state = await reduxStateForTest({ activeWorkspaceId: w._id }); + const state = await reduxStateForTest({ activeWorkspaceId: w._id, activeActivity: ACTIVITY_DEBUG }); const expandedDirs = selectExpandedActiveProtoDirectories(state); // Assert expect(expandedDirs).toHaveLength(2); @@ -146,7 +147,7 @@ describe('selectExpandedActiveProtoDirectories', () => { parentId: pd2._id, }); // Act - const state = await reduxStateForTest({ activeWorkspaceId: w._id }); + const state = await reduxStateForTest({ activeWorkspaceId: w._id, activeActivity: ACTIVITY_DEBUG }); const expandedDirs = selectExpandedActiveProtoDirectories(state); // Assert expect(expandedDirs).toHaveLength(1); @@ -184,7 +185,7 @@ describe('selectExpandedActiveProtoDirectories', () => { parentId: w._id, }); // Act - const state = await reduxStateForTest({ activeWorkspaceId: w._id }); + const state = await reduxStateForTest({ activeWorkspaceId: w._id, activeActivity: ACTIVITY_DEBUG }); const expandedDirs = selectExpandedActiveProtoDirectories(state); // Assert expect(expandedDirs).toHaveLength(2); diff --git a/packages/insomnia-app/app/ui/redux/modules/__tests__/git.test.tsx b/packages/insomnia-app/app/ui/redux/modules/__tests__/git.test.tsx index 82bdb9869..ef8522d0f 100644 --- a/packages/insomnia-app/app/ui/redux/modules/__tests__/git.test.tsx +++ b/packages/insomnia-app/app/ui/redux/modules/__tests__/git.test.tsx @@ -12,6 +12,7 @@ import { trackEvent, trackSegmentEvent } from '../../../../common/analytics'; import { ACTIVITY_SPEC } from '../../../../common/constants'; import * as models from '../../../../models'; import { gitRepositorySchema } from '../../../../models/__schemas__/model-schemas'; +import { BASE_SPACE_ID } from '../../../../models/space'; import { Workspace, WorkspaceScopeKeys } from '../../../../models/workspace'; import { GIT_INSOMNIA_DIR } from '../../../../sync/git/git-vcs'; import { MemClient } from '../../../../sync/git/mem-client'; @@ -23,7 +24,7 @@ import { getAndClearShowPromptMockArgs, } from '../../../../test-utils'; import { cloneGitRepository, setupGitRepository } from '../git'; -import { LOAD_START, LOAD_STOP, SET_ACTIVE_ACTIVITY, SET_ACTIVE_WORKSPACE } from '../global'; +import { LOAD_START, LOAD_STOP, SET_ACTIVE_ACTIVITY, SET_ACTIVE_SPACE, SET_ACTIVE_WORKSPACE } from '../global'; jest.mock('../../../components/modals'); jest.mock('../../../../sync/git/shallow-clone'); @@ -119,6 +120,10 @@ describe('git', () => { { type: LOAD_STOP, }, + { + type: SET_ACTIVE_SPACE, + spaceId: BASE_SPACE_ID, + }, { type: SET_ACTIVE_WORKSPACE, workspaceId: workspace._id, diff --git a/packages/insomnia-app/app/ui/redux/modules/__tests__/workspace.test.ts b/packages/insomnia-app/app/ui/redux/modules/__tests__/workspace.test.ts index fe3c34215..f48569686 100644 --- a/packages/insomnia-app/app/ui/redux/modules/__tests__/workspace.test.ts +++ b/packages/insomnia-app/app/ui/redux/modules/__tests__/workspace.test.ts @@ -4,7 +4,7 @@ import thunk from 'redux-thunk'; import { globalBeforeEach } from '../../../../__jest__/before-each'; import { reduxStateForTest } from '../../../../__jest__/redux-state-for-test'; import { trackEvent, trackSegmentEvent } from '../../../../common/analytics'; -import { ACTIVITY_DEBUG, ACTIVITY_HOME, ACTIVITY_SPEC, ACTIVITY_UNIT_TEST } from '../../../../common/constants'; +import { ACTIVITY_DEBUG, ACTIVITY_SPEC, ACTIVITY_UNIT_TEST } from '../../../../common/constants'; import { database } from '../../../../common/database'; import * as models from '../../../../models'; import { ApiSpec } from '../../../../models/api-spec'; @@ -64,6 +64,10 @@ describe('workspace', () => { expect(trackSegmentEvent).toHaveBeenCalledWith('Document Created'); expect(trackEvent).toHaveBeenCalledWith('Workspace', 'Create'); expect(store.getActions()).toEqual([ + { + type: SET_ACTIVE_SPACE, + spaceId: BASE_SPACE_ID, + }, { type: SET_ACTIVE_WORKSPACE, workspaceId: workspaceId, @@ -95,34 +99,9 @@ describe('workspace', () => { expect(trackEvent).toHaveBeenCalledWith('Workspace', 'Create'); expect(store.getActions()).toEqual([ { - type: SET_ACTIVE_WORKSPACE, - workspaceId: workspaceId, + type: SET_ACTIVE_SPACE, + spaceId: BASE_SPACE_ID, }, - { - type: SET_ACTIVE_ACTIVITY, - activity: ACTIVITY_DEBUG, - }, - ]); - }); - - it('should create with no space', async () => { - const store = mockStore(await reduxStateForTest()); - - // @ts-expect-error redux-thunk types - store.dispatch(createWorkspace({ scope: WorkspaceScopeKeys.collection })); - - const { title, submitName, defaultValue, onComplete } = getAndClearShowPromptMockArgs(); - expect(title).toBe('Create New Request Collection'); - expect(submitName).toBe('Create'); - expect(defaultValue).toBe('My Collection'); - const workspaceName = 'name'; - await onComplete?.(workspaceName); - - const workspaceId = await expectedModelsCreated(workspaceName, WorkspaceScopeKeys.collection, BASE_SPACE_ID); - - expect(trackSegmentEvent).toHaveBeenCalledWith('Collection Created'); - expect(trackEvent).toHaveBeenCalledWith('Workspace', 'Create'); - expect(store.getActions()).toEqual([ { type: SET_ACTIVE_WORKSPACE, workspaceId: workspaceId, @@ -139,7 +118,7 @@ describe('workspace', () => { it('should activate space and workspace and activity from home', async () => { const space = await models.space.create(); const workspace = await models.workspace.create({ scope: 'design', parentId: space._id }); - const store = mockStore(await reduxStateForTest({ activeSpaceId: 'abc', activeWorkspaceId: 'def', activeActivity: ACTIVITY_HOME })); + const store = mockStore(await reduxStateForTest({ activeSpaceId: 'abc', activeWorkspaceId: 'def' })); await store.dispatch(activateWorkspace(workspace)); @@ -162,7 +141,7 @@ describe('workspace', () => { it('should switch to the default design activity', async () => { const space = await models.space.create(); const workspace = await models.workspace.create({ scope: 'design', parentId: space._id }); - const store = mockStore(await reduxStateForTest({ activeSpaceId: space._id, activeWorkspaceId: workspace._id, activeActivity: ACTIVITY_HOME })); + const store = mockStore(await reduxStateForTest({ activeSpaceId: space._id, activeWorkspaceId: workspace._id })); await store.dispatch(activateWorkspace(workspace)); @@ -223,7 +202,7 @@ describe('workspace', () => { it('should switch to the default collection activity', async () => { const space = await models.space.create(); const workspace = await models.workspace.create({ scope: 'collection', parentId: space._id }); - const store = mockStore(await reduxStateForTest({ activeSpaceId: space._id, activeWorkspaceId: workspace._id, activeActivity: ACTIVITY_HOME })); + const store = mockStore(await reduxStateForTest({ activeSpaceId: space._id, activeWorkspaceId: workspace._id })); await store.dispatch(activateWorkspace(workspace)); @@ -248,7 +227,7 @@ describe('workspace', () => { const workspace = await models.workspace.create({ scope: 'design', parentId: space._id }); await models.workspace.ensureChildren(workspace); await models.workspaceMeta.updateByParentId(workspace._id, { activeActivity: ACTIVITY_UNIT_TEST }); - const store = mockStore(await reduxStateForTest({ activeSpaceId: space._id, activeWorkspaceId: workspace._id, activeActivity: ACTIVITY_HOME })); + const store = mockStore(await reduxStateForTest({ activeSpaceId: space._id, activeWorkspaceId: workspace._id })); await store.dispatch(activateWorkspace(workspace)); diff --git a/packages/insomnia-app/app/ui/redux/modules/workspace.ts b/packages/insomnia-app/app/ui/redux/modules/workspace.ts index 3e032ca62..aecbcbcb8 100644 --- a/packages/insomnia-app/app/ui/redux/modules/workspace.ts +++ b/packages/insomnia-app/app/ui/redux/modules/workspace.ts @@ -23,7 +23,7 @@ const createWorkspaceAndChildren = async (patch: Partial) => { }; const actuallyCreate = (patch: Partial, onCreate?: OnWorkspaceCreateCallback) => { - return async (dispatch: Dispatch) => { + return async (dispatch) => { const workspace = await createWorkspaceAndChildren(patch); if (onCreate) { @@ -31,8 +31,7 @@ const actuallyCreate = (patch: Partial, onCreate?: OnWorkspaceCreateC } trackEvent('Workspace', 'Create'); - dispatch(setActiveWorkspace(workspace._id)); - dispatch(setActiveActivity(isDesign(workspace) ? ACTIVITY_SPEC : ACTIVITY_DEBUG)); + await dispatch(activateWorkspace(workspace)); }; }; diff --git a/packages/insomnia-app/app/ui/redux/selectors.ts b/packages/insomnia-app/app/ui/redux/selectors.ts index aaf6a8e3e..eab0cee2a 100644 --- a/packages/insomnia-app/app/ui/redux/selectors.ts +++ b/packages/insomnia-app/app/ui/redux/selectors.ts @@ -66,6 +66,11 @@ export const selectSettings = createSelector( selectEntitiesLists, entities => entities.settings[0] || models.settings.init()); +export const selectRequestMetas = createSelector( + selectEntitiesLists, + entities => entities.requestMetas, +); + export const selectSpaces = createSelector( selectEntitiesLists, entities => entities.spaces, diff --git a/packages/insomnia-components/src/button/async-button.tsx b/packages/insomnia-components/src/button/async-button.tsx index abfc17ae0..f3658b1c2 100644 --- a/packages/insomnia-components/src/button/async-button.tsx +++ b/packages/insomnia-components/src/button/async-button.tsx @@ -14,7 +14,7 @@ function isPromise(obj: unknown) { } export interface AsyncButtonProps extends ButtonProps { - onClick: (e: React.MouseEvent) => Promise; + onClick: (e: React.MouseEvent) => Promise | undefined; loadingNode?: ReactNode; }