add rename options to request context options (#5256)

* add rename folder and request context options

* Add rename dropdown option for WS requests

Co-authored-by: Filipe Freire <livrofubia@gmail.com>
This commit is contained in:
Jack Kavanagh 2022-10-11 10:27:06 +02:00 committed by GitHub
parent 54d995ec34
commit 7ef73dfb2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 1 deletions

View File

@ -25,7 +25,7 @@ import { DropdownDivider } from '../base/dropdown/dropdown-divider';
import { DropdownHint } from '../base/dropdown/dropdown-hint';
import { DropdownItem } from '../base/dropdown/dropdown-item';
import { PromptButton } from '../base/prompt-button';
import { showError, showModal } from '../modals';
import { showError, showModal, showPrompt } from '../modals';
import { GenerateCodeModal } from '../modals/generate-code-modal';
interface Props extends Pick<DropdownProps, 'right'> {
@ -104,6 +104,19 @@ export const RequestActionsDropdown = forwardRef<DropdownHandle, Props>(({
}
}, [activeEnvironment, request._id]);
const handleRename = useCallback(() => {
showPrompt({
title: 'Rename Request',
defaultValue: request.name,
submitName: 'Rename',
selectText: true,
label: 'Name',
onComplete: name => {
requestOperations.update(request, { name });
},
});
}, [request]);
const togglePin = useCallback(() => {
updateRequestMetaByParentId(request._id, { pinned: !isPinned });
}, [isPinned, request]);
@ -146,6 +159,13 @@ export const RequestActionsDropdown = forwardRef<DropdownHandle, Props>(({
</DropdownItem>
)}
<DropdownItem
onClick={handleRename}
addIcon
>
<i className="fa fa-edit" /> Rename
</DropdownItem>
<DropdownItem
buttonClass={PromptButton}
onClick={deleteRequest}

View File

@ -4,6 +4,7 @@ import { useSelector } from 'react-redux';
import { RENDER_PURPOSE_NO_RENDER } from '../../../common/render';
import * as models from '../../../models';
import * as requestOperations from '../../../models/helpers/request-operations';
import type { RequestGroup } from '../../../models/request-group';
import type { RequestGroupAction } from '../../../plugins';
import { getRequestGroupActions } from '../../../plugins';
@ -84,6 +85,19 @@ export const RequestGroupActionsDropdown = forwardRef<RequestGroupActionsDropdow
createRequestGroup(requestGroup._id);
}, [requestGroup._id]);
const handleRename = useCallback(() => {
showPrompt({
title: 'Rename Folder',
defaultValue: requestGroup.name,
submitName: 'Rename',
selectText: true,
label: 'Name',
onComplete: name => {
requestOperations.update(requestGroup, { name });
},
});
}, [requestGroup]);
const handleDeleteFolder = useCallback(async () => {
await models.stats.incrementDeletedRequestsForDescendents(requestGroup);
models.requestGroup.remove(requestGroup);
@ -164,6 +178,10 @@ export const RequestGroupActionsDropdown = forwardRef<RequestGroupActionsDropdow
<i className="fa fa-code" /> Environment
</DropdownItem>
<DropdownItem onClick={handleRename}>
<i className="fa fa-edit" /> Rename
</DropdownItem>
<DropdownItem buttonClass={PromptButton} addIcon onClick={handleDeleteFolder}>
<i className="fa fa-trash-o" /> Delete
</DropdownItem>

View File

@ -12,6 +12,7 @@ import { DropdownDivider } from '../base/dropdown/dropdown-divider';
import { DropdownHint } from '../base/dropdown/dropdown-hint';
import { DropdownItem } from '../base/dropdown/dropdown-item';
import { PromptButton } from '../base/prompt-button';
import { showPrompt } from '../modals';
interface Props extends Pick<DropdownProps, 'right'> {
handleDuplicateRequest: Function;
@ -33,6 +34,19 @@ export const WebSocketRequestActionsDropdown = forwardRef<DropdownHandle, Props>
handleDuplicateRequest(request);
}, [handleDuplicateRequest, request]);
const handleRename = useCallback(() => {
showPrompt({
title: 'Rename Request',
defaultValue: request.name,
submitName: 'Rename',
selectText: true,
label: 'Name',
onComplete: name => {
requestOperations.update(request, { name });
},
});
}, [request]);
const togglePin = useCallback(() => {
updateRequestMetaByParentId(request._id, { pinned: !isPinned });
}, [isPinned, request]);
@ -58,6 +72,13 @@ export const WebSocketRequestActionsDropdown = forwardRef<DropdownHandle, Props>
<DropdownHint keyBindings={hotKeyRegistry.request_togglePin} />
</DropdownItem>
<DropdownItem
onClick={handleRename}
addIcon
>
<i className="fa fa-edit" /> Rename
</DropdownItem>
<DropdownItem
buttonClass={PromptButton}
onClick={deleteRequest}