Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display the settings modal for remote spaces and update the copy for … #3885

Merged
2 changes: 1 addition & 1 deletion packages/insomnia-app/app/models/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const isBaseSpace = (space: Space) => space._id === BASE_SPACE_ID;
export const isNotBaseSpace = (space: Space) => !isBaseSpace(space);
export const isLocalSpace = (space: Space): space is LocalSpace => space.remoteId === null;
export const isRemoteSpace = (space: Space): space is RemoteSpace => !isLocalSpace(space);
export const spaceHasSettings = (space: Space) => isLocalSpace(space) && !isBaseSpace(space);
export const spaceHasSettings = (space: Space) => !isBaseSpace(space);

interface CommonSpace {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { bindActionCreators } from 'redux';
import { AUTOBIND_CFG } from '../../../common/constants';
import { strings } from '../../../common/strings';
import * as models from '../../../models/index';
import { isBaseSpace, isRemoteSpace } from '../../../models/space';
import { isRemoteSpace, spaceHasSettings } from '../../../models/space';
import { RootState } from '../../redux/modules';
import * as spaceActions from '../../redux/modules/space';
import { selectActiveSpace } from '../../redux/selectors';
Expand All @@ -15,6 +15,7 @@ import Modal from '../base/modal';
import ModalBody from '../base/modal-body';
import ModalHeader from '../base/modal-header';
import PromptButton from '../base/prompt-button';
import HelpTooltip from '../help-tooltip';

export type ReduxProps = ReturnType<typeof mapStateToProps> & ReturnType<typeof mapDispatchToProps>;

Expand Down Expand Up @@ -48,10 +49,12 @@ class SpaceSettingsModal extends PureComponent<Props> {

render() {
const { space } = this.props;
if (isBaseSpace(space) || isRemoteSpace(space)) {
if (!spaceHasSettings(space)) {
return null;
}

const isRemote = isRemoteSpace(space);

return (
<Modal ref={this._handleSetModalRef} freshState>
<ModalHeader key={`header::${space._id}`}>
Expand All @@ -62,14 +65,24 @@ class SpaceSettingsModal extends PureComponent<Props> {
<div className="form-control form-control--outlined">
<label>
Name
<DebouncedInput
// @ts-expect-error -- TSCONVERSION props are spread into an input element
type="text"
delay={500}
placeholder="My Space"
defaultValue={space.name}
onChange={this._handleRename}
/>
{isRemote && (
<>
<HelpTooltip className="space-left">
To rename a ${strings.remoteSpace.singular.toLowerCase()} ${strings.space.singular.toLowerCase()} please visit <a href="https://app.insomnia.rest/app/teams">the insomnia website.</a>
</HelpTooltip>
<input disabled readOnly defaultValue={space.name} />
</>
)}
{!isRemote && (
<DebouncedInput
// @ts-expect-error -- TSCONVERSION props are spread into an input element
type="text"
delay={500}
placeholder="My Space"
defaultValue={space.name}
onChange={this._handleRename}
/>
)}
</label>
</div>
<h2>Actions</h2>
Expand Down
8 changes: 6 additions & 2 deletions packages/insomnia-app/app/ui/redux/modules/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ACTIVITY_HOME } from '../../../common/constants';
import { SegmentEvent } from '../../../common/segment-event';
import { strings } from '../../../common/strings';
import * as models from '../../../models';
import { BASE_SPACE_ID, Space } from '../../../models/space';
import { BASE_SPACE_ID, isRemoteSpace, Space } from '../../../models/space';
import { showAlert, showPrompt } from '../../components/modals';
import { setActiveActivity, setActiveSpace } from './global';

Expand All @@ -28,9 +28,13 @@ export const createSpace = () => dispatch => {
};

export const removeSpace = (space: Space) => dispatch => {
const message = isRemoteSpace(space)
? `Deleting a ${strings.remoteSpace.singular.toLowerCase()} ${strings.space.singular.toLowerCase()} will delete all local copies and changes of ${strings.document.plural.toLowerCase()} and ${strings.collection.plural.toLowerCase()} within. All changes that are not synced will be lost. The ${strings.remoteSpace.singular.toLowerCase()} ${strings.space.singular.toLowerCase()} will continue to exist remotely. Deleting this ${strings.space.singular.toLowerCase()} locally cannot be undone. Are you sure you want to delete ${space.name}?`
: `Deleting a space will delete all ${strings.document.plural.toLowerCase()} and ${strings.collection.plural.toLowerCase()} within. This cannot be undone. Are you sure you want to delete ${space.name}?`;

showAlert({
title: `Delete ${strings.space.singular}`,
message: `Deleting a space will delete all ${strings.document.plural.toLowerCase()} and ${strings.collection.plural.toLowerCase()} within. This cannot be undone. Are you sure you want to delete ${space.name}?`,
message,
addCancel: true,
okLabel: 'Delete',
onConfirm: async () => {
Expand Down