Skip to content

Commit d1c2928

Browse files
authored
feat(command-palette): add button to open the command palette (#7064)
* add button for quick search * update button styles in project * make it look good with gh stars
1 parent 43edf39 commit d1c2928

5 files changed

Lines changed: 32 additions & 16 deletions

File tree

packages/insomnia/src/common/hotkeys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const keyboardShortcutDescriptions: Record<KeyboardShortcut, string> = {
1212
'request_showSettings': 'Show Request Settings',
1313
'preferences_showKeyboardShortcuts': 'Show Keyboard Shortcuts',
1414
'preferences_showGeneral': 'Show App Preferences',
15-
'request_quickSwitch': 'Switch Requests',
15+
'request_quickSwitch': 'Quick search',
1616
'request_showRecent': 'Show Recent Requests',
1717
'request_showRecentPrevious': 'Show Recent Requests (Previous)',
1818
'plugin_reload': 'Reload Plugins',

packages/insomnia/src/ui/components/command-palette.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import React from 'react';
22
import { useState } from 'react';
3-
import { Collection, ComboBox, Dialog, Header, Input, Label, ListBox, ListBoxItem, Modal, ModalOverlay, Section, Text } from 'react-aria-components';
3+
import { Button, Collection, ComboBox, Dialog, DialogTrigger, Header, Input, Keyboard, Label, ListBox, ListBoxItem, Modal, ModalOverlay, Section, Text } from 'react-aria-components';
44
import { useNavigate, useParams, useRouteLoaderData } from 'react-router-dom';
55

6+
import { constructKeyCombinationDisplay, getPlatformKeyCombinations } from '../../common/hotkeys';
67
import { fuzzyMatch } from '../../common/misc';
78
import { isGrpcRequest } from '../../models/grpc-request';
89
import { isRequest } from '../../models/request';
910
import { isRequestGroup } from '../../models/request-group';
1011
import { isWebSocketRequest } from '../../models/websocket-request';
1112
import { Workspace } from '../../models/workspace';
1213
import { ProjectLoaderData } from '../routes/project';
14+
import { RootLoaderData } from '../routes/root';
1315
import { Collection as WorkspaceCollection, WorkspaceLoaderData } from '../routes/workspace';
1416
import { Icon } from './icon';
1517
import { useDocBodyKeyboardShortcuts } from './keydown-binder';
@@ -25,7 +27,7 @@ export const CommandPalette = () => {
2527
} = useParams();
2628
const workspaceData = useRouteLoaderData(':workspaceId') as WorkspaceLoaderData | undefined;
2729
const projectData = useRouteLoaderData('/project/:projectId') as ProjectLoaderData | undefined;
28-
30+
const { settings } = useRouteLoaderData('root') as RootLoaderData;
2931
let collection: WorkspaceCollection = [];
3032
let workspaces: Workspace[] = [];
3133
if (workspaceData) {
@@ -42,8 +44,18 @@ export const CommandPalette = () => {
4244
},
4345
});
4446

47+
const requestSwitchKeyCombination = getPlatformKeyCombinations(settings.hotKeyRegistry.request_quickSwitch)[0];
48+
4549
return (
46-
<ModalOverlay isOpen={isOpen} onOpenChange={setIsOpen} isDismissable className="w-full h-[--visual-viewport-height] fixed z-10 top-0 left-0 flex pt-20 justify-center bg-black/30">
50+
<DialogTrigger onOpenChange={setIsOpen} isOpen={isOpen}>
51+
<Button data-testid='quick-search' className="px-4 py-1 h-[30.5px] flex-shrink-0 flex items-center justify-center gap-2 bg-[--hl-xs] aria-pressed:bg-[--hl-sm] data-[pressed]:bg-[--hl-sm] rounded-md text-[--color-font] hover:bg-[--hl-xs] ring-inset ring-transparent ring-1 focus:ring-[--hl-md] transition-all text-sm">
52+
<Icon icon="search" />
53+
Search..
54+
{requestSwitchKeyCombination && <Keyboard className='space-x-0.5 items-center font-sans font-normal text-center text-sm shadow-sm bg-[--hl-xs] text-[--hl] rounded-md py-0.5 px-2 inline-block'>
55+
{constructKeyCombinationDisplay(requestSwitchKeyCombination, false)}
56+
</Keyboard>}
57+
</Button>
58+
<ModalOverlay isDismissable className="w-full h-[--visual-viewport-height] fixed z-10 top-0 left-0 flex pt-20 justify-center bg-black/30">
4759
<Modal className="max-w-2xl h-max w-full rounded-md flex flex-col overflow-hidden border border-solid border-[--hl-sm] max-h-[80vh] bg-[--color-bg] text-[--color-font]">
4860
<Dialog className="outline-none h-max overflow-hidden flex flex-col">
4961
{({ close }) => (
@@ -159,5 +171,6 @@ export const CommandPalette = () => {
159171
</Dialog>
160172
</Modal>
161173
</ModalOverlay>
174+
</DialogTrigger>
162175
);
163176
};

packages/insomnia/src/ui/components/dropdowns/remote-workspaces-dropdown.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RemoteProject } from '../../../models/project';
88
import { RemoteCollectionsLoaderData } from '../../routes/remote-collections';
99
import { Dropdown, DropdownButton, DropdownItem, DropdownSection, ItemContent } from '../base/dropdown';
1010
import { HelpTooltip } from '../help-tooltip';
11+
import { Icon } from '../icon';
1112
import { Tooltip } from '../tooltip';
1213

1314
interface Props {
@@ -52,11 +53,13 @@ export const RemoteWorkspacesDropdown: FC<Props> = ({ project: { remoteId } }) =
5253
onOpen={() => load(`/organization/${organizationId}/project/${projectId}/remote-collections`)}
5354
triggerButton={
5455
<StyledDropdownButton
56+
className="flex !border-none !ml-0 items-center justify-center !px-4 gap-2 h-full !bg-[--hl-xxs] aria-pressed:!bg-[--hl-sm] rounded-sm text-[--color-font] hover:!bg-[--hl-xs] focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm"
5557
variant='outlined'
5658
removePaddings={false}
5759
disableHoverBehavior={false}
5860
>
59-
Pull <i className="fa fa-caret-down pad-left-sm" />
61+
<Icon icon='cloud-download' />
62+
Pull
6063
</StyledDropdownButton>
6164
}
6265
>

packages/insomnia/src/ui/routes/organization.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,11 @@ const OrganizationRoute = () => {
434434
<div className="w-full h-full">
435435
<div className={`w-full h-full divide-x divide-solid divide-y divide-[--hl-md] ${isScratchPadBannerVisible ? 'grid-template-app-layout-with-banner' : 'grid-template-app-layout'} grid relative bg-[--color-bg]`}>
436436
<header className="[grid-area:Header] grid grid-cols-3 items-center">
437-
<div className="flex items-center">
438-
<div className="flex w-[50px] py-2">
437+
<div className="flex items-center gap-2">
438+
<div className="flex shrink-0 w-[50px] py-2">
439439
<InsomniaAILogo />
440440
</div>
441+
<CommandPalette />
441442
{!user ? <GitHubStarsButton /> : null}
442443
</div>
443444
<div className="flex place-content-stretch gap-2 flex-nowrap items-center justify-center">
@@ -471,18 +472,18 @@ const OrganizationRoute = () => {
471472
<PresentUsers />
472473
<Button
473474
aria-label="Invite collaborators"
474-
className="px-4 text-[--color-font-surprise] bg-opacity-100 bg-[rgba(var(--color-surprise-rgb),var(--tw-bg-opacity))] py-1 font-semibold border border-solid border-[--hl-md] flex items-center justify-center gap-2 aria-pressed:opacity-80 rounded-sm hover:bg-opacity-80 focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm"
475+
className="px-4 text-[--color-font-surprise] bg-opacity-100 bg-[rgba(var(--color-surprise-rgb),var(--tw-bg-opacity))] py-2 h-full font-semibold border border-solid border-[--hl-md] flex items-center justify-center gap-2 aria-pressed:opacity-80 rounded-md hover:bg-opacity-80 focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm"
475476
onPress={() => {
476477
window.main.openInBrowser(`${getAppWebsiteBaseURL()}/app/dashboard/organizations/${organizationId}/collaborators`);
477478
}}
478479
>
479480
<Icon icon="user-plus" />
480481
<span className="truncate">
481-
Share
482+
Invite
482483
</span>
483484
</Button>
484485
<MenuTrigger>
485-
<Button data-testid='user-dropdown' className="px-1 py-1 flex-shrink-0 flex items-center justify-center gap-2 aria-pressed:bg-[--hl-sm] data-[pressed]:bg-[--hl-sm] rounded-full text-[--color-font] hover:bg-[--hl-xs] focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm">
486+
<Button data-testid='user-dropdown' className="px-1 py-1 flex-shrink-0 flex items-center justify-center gap-2 aria-pressed:bg-[--hl-sm] data-[pressed]:bg-[--hl-sm] rounded-md text-[--color-font] hover:bg-[--hl-xs] focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm">
486487
<Avatar
487488
src={user.picture}
488489
alt={user.name}
@@ -770,7 +771,6 @@ const OrganizationRoute = () => {
770771
</div>
771772
<Toast />
772773
</div>
773-
{<CommandPalette />}
774774
</InsomniaEventStreamProvider>
775775
);
776776
};

packages/insomnia/src/ui/routes/project.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ const ProjectRoute: FC = () => {
10291029
)}
10301030
</div>
10311031
</div>}
1032-
<div className="flex justify-between w-full gap-1 p-[--padding-md]">
1032+
<div className="flex justify-between w-full gap-2 p-[--padding-md]">
10331033
<SearchField
10341034
aria-label="Workspaces filter"
10351035
className="group relative flex-1"
@@ -1064,7 +1064,7 @@ const ProjectRoute: FC = () => {
10641064
>
10651065
<Button
10661066
aria-label="Select sort order"
1067-
className="flex flex-shrink-0 items-center justify-center aspect-square h-full aria-pressed:bg-[--hl-sm] rounded-sm text-[--color-font] hover:bg-[--hl-xs] focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm"
1067+
className="flex flex-shrink-0 items-center justify-center aspect-square h-full bg-[--hl-xxs] aria-pressed:bg-[--hl-sm] rounded-sm text-[--color-font] hover:bg-[--hl-xs] focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm"
10681068
>
10691069
<Icon icon="sort" />
10701070
</Button>
@@ -1107,9 +1107,9 @@ const ProjectRoute: FC = () => {
11071107
<MenuTrigger>
11081108
<Button
11091109
aria-label="Create in project"
1110-
className="flex items-center justify-center h-full aspect-square aria-pressed:bg-[--hl-sm] rounded-sm text-[--color-font] hover:bg-[--hl-xs] focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm"
1110+
className="flex items-center justify-center px-4 gap-2 h-full bg-[--hl-xxs] aria-pressed:bg-[--hl-sm] rounded-sm text-[--color-font] hover:bg-[--hl-xs] focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all text-sm"
11111111
>
1112-
<Icon icon="plus-circle" />
1112+
<Icon icon="plus-circle" /> Create
11131113
</Button>
11141114
<Popover className="min-w-max">
11151115
<Menu
@@ -1185,7 +1185,7 @@ const ProjectRoute: FC = () => {
11851185
key={item._id}
11861186
id={item._id}
11871187
textValue={item.name}
1188-
className="flex-1 overflow-hidden flex-col outline-none p-[--padding-md] flex select-none w-full rounded-sm hover:shadow-md aspect-square ring-1 ring-[--hl-md] hover:ring-[--hl-sm] focus:ring-[--hl-lg] hover:bg-[--hl-xs] focus:bg-[--hl-sm] transition-all"
1188+
className="flex-1 overflow-hidden flex-col outline-none p-[--padding-md] flex select-none w-full rounded-md hover:shadow-md aspect-square ring-1 ring-[--hl-md] hover:ring-[--hl-sm] focus:ring-[--hl-lg] hover:bg-[--hl-xs] focus:bg-[--hl-sm] transition-all"
11891189
>
11901190
<div className="flex gap-2 h-[20px]">
11911191
<div className="flex pr-2 h-full flex-shrink-0 items-center rounded-sm gap-2 bg-[--hl-xs] text-[--color-font] text-sm">

0 commit comments

Comments
 (0)