Fix responses not being found if deleted active environment (#2265)

* Fix responses not being found (Closes #2237)

* Fix active envirnoment set

Co-authored-by: Opender Singh <opender94@gmail.com>
This commit is contained in:
Gregory Schier 2020-06-08 15:32:49 -07:00 committed by GitHub
parent c6a5053ae2
commit edf874ce5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 9 deletions

View File

@ -24,6 +24,7 @@ import Tooltip from '../tooltip';
const ROOT_ENVIRONMENT_NAME = 'Base Environment';
type Props = {
handleChangeEnvironment: (id: string | null) => Promise<void>,
activeEnvironmentId: string | null,
editorFontSize: number,
editorIndentSize: number,
@ -208,10 +209,11 @@ class WorkspaceEnvironmentsEditModal extends React.PureComponent<Props, State> {
async _handleDuplicateEnvironment(environment: Environment) {
const { workspace } = this.state;
const newEnvironment = await models.environment.duplicate(environment);
this._load(workspace, newEnvironment);
await this._load(workspace, newEnvironment);
}
async _handleDeleteEnvironment(environment: Environment) {
const { handleChangeEnvironment, activeEnvironmentId } = this.props;
const { rootEnvironment, workspace } = this.state;
// Don't delete the root environment
@ -219,8 +221,14 @@ class WorkspaceEnvironmentsEditModal extends React.PureComponent<Props, State> {
return;
}
// Delete the current one, then activate the root environment
// Unset active environment if it's being deleted
if (activeEnvironmentId === environment._id) {
await handleChangeEnvironment(null);
}
// Delete the current one
await models.environment.remove(environment);
await this._load(workspace, rootEnvironment);
}

View File

@ -106,7 +106,7 @@ export type WrapperProps = {
handleShowExportRequestsModal: Function,
handleShowSettingsModal: Function,
handleExportRequestsToFile: Function,
handleSetActiveWorkspace: (workspaceId: string) => void,
handleSetActiveWorkspace: (workspaceId: string | null) => void,
handleSetActiveEnvironment: Function,
handleMoveDoc: Function,
handleCreateRequest: Function,
@ -462,7 +462,7 @@ class Wrapper extends React.PureComponent<WrapperProps, State> {
handleCreateRequestGroup(activeWorkspace._id);
}
_handleChangeEnvironment(id: string) {
_handleChangeEnvironment(id: string | null) {
const { handleSetActiveEnvironment } = this.props;
handleSetActiveEnvironment(id);
}
@ -727,7 +727,7 @@ class Wrapper extends React.PureComponent<WrapperProps, State> {
<WorkspaceEnvironmentsEditModal
ref={registerModal}
onChange={models.workspace.update}
handleChangeEnvironment={this._handleChangeEnvironment}
lineWrapping={settings.editorLineWrapping}
editorFontSize={settings.editorFontSize}
editorIndentSize={settings.editorIndentSize}

View File

@ -39,6 +39,10 @@ export const selectEntitiesChildrenMap = createSelector(selectEntitiesLists, ent
return parentLookupMap;
});
export const selectSettings = createSelector(selectEntitiesLists, entities => {
return entities.settings[0] || models.settings.init();
});
export const selectActiveWorkspace = createSelector(
state => selectEntitiesLists(state).workspaces,
state => state.entities,
@ -57,6 +61,18 @@ export const selectActiveWorkspaceMeta = createSelector(
},
);
export const selectActiveEnvironment = createSelector(
selectActiveWorkspaceMeta,
selectEntitiesLists,
(meta, entities) => {
if (!meta) {
return null;
}
return entities.environments.find(e => e._id === meta.activeEnvironmentId) || null;
},
);
export const selectActiveWorkspaceClientCertificates = createSelector(
selectEntitiesLists,
selectActiveWorkspace,
@ -271,10 +287,10 @@ export const selectActiveRequestMeta = createSelector(
export const selectActiveRequestResponses = createSelector(
selectActiveRequest,
selectEntitiesLists,
selectActiveWorkspaceMeta,
(activeRequest, entities, meta) => {
selectActiveEnvironment,
selectSettings,
(activeRequest, entities, activeEnvironment, settings) => {
const requestId = activeRequest ? activeRequest._id : 'n/a';
const settings = entities.settings[0];
// Filter responses down if the setting is enabled
return entities.responses
@ -282,7 +298,7 @@ export const selectActiveRequestResponses = createSelector(
const requestMatches = requestId === response.parentId;
if (settings.filterResponsesByEnv) {
const activeEnvironmentId = meta ? meta.activeEnvironmentId : 'n/a';
const activeEnvironmentId = activeEnvironment ? activeEnvironment._id : null;
const environmentMatches = response.environmentId === activeEnvironmentId;
return requestMatches && environmentMatches;
} else {