Skip to content

Commit 0f04c31

Browse files
[UI] Search shortcut (#10181)
* Add search shortcut - Use '/' to open search drawer * Add user setting for spotlight * Hide spotlight if disabled * Updated playwright tests
1 parent 4cadc43 commit 0f04c31

File tree

6 files changed

+52
-15
lines changed

6 files changed

+52
-15
lines changed

docs/docs/settings/user.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The *Display Settings* screen shows general display configuration options:
2121
{{ usersetting("ICONS_IN_NAVBAR") }}
2222
{{ usersetting("STICKY_HEADER") }}
2323
{{ usersetting("STICKY_TABLE_HEADER") }}
24+
{{ usersetting("SHOW_SPOTLIGHT") }}
2425
{{ usersetting("DATE_DISPLAY_FORMAT") }}
2526
{{ usersetting("FORMS_CLOSE_USING_ESCAPE") }}
2627
{{ usersetting("DISPLAY_STOCKTAKE_TAB") }}

src/backend/InvenTree/common/setting/user.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ def label_printer_options():
191191
'default': False,
192192
'validator': bool,
193193
},
194+
'SHOW_SPOTLIGHT': {
195+
'name': _('Show Spotlight'),
196+
'description': _('Enable spotlight navigation functionality'),
197+
'default': True,
198+
'validator': bool,
199+
},
194200
'ICONS_IN_NAVBAR': {
195201
'name': _('Navigation Icons'),
196202
'description': _('Display icons in the navigation bar'),

src/frontend/src/components/nav/Header.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
Tooltip,
99
UnstyledButton
1010
} from '@mantine/core';
11-
import { useDisclosure, useDocumentVisibility } from '@mantine/hooks';
11+
import {
12+
useDisclosure,
13+
useDocumentVisibility,
14+
useHotkeys
15+
} from '@mantine/hooks';
1216
import { IconBell, IconSearch } from '@tabler/icons-react';
1317
import { useQuery } from '@tanstack/react-query';
1418
import { type ReactNode, useEffect, useMemo, useState } from 'react';
@@ -49,11 +53,27 @@ export function Header() {
4953
const [server] = useServerApiState(useShallow((state) => [state.server]));
5054
const [navDrawerOpened, { open: openNavDrawer, close: closeNavDrawer }] =
5155
useDisclosure(navigationOpen);
56+
5257
const [
5358
searchDrawerOpened,
5459
{ open: openSearchDrawer, close: closeSearchDrawer }
5560
] = useDisclosure(false);
5661

62+
useHotkeys([
63+
[
64+
'/',
65+
() => {
66+
openSearchDrawer();
67+
}
68+
],
69+
[
70+
'mod+/',
71+
() => {
72+
openSearchDrawer();
73+
}
74+
]
75+
]);
76+
5777
const [
5878
notificationDrawerOpened,
5979
{ open: openNotificationDrawer, close: closeNotificationDrawer }
@@ -154,7 +174,7 @@ export function Header() {
154174
<IconSearch />
155175
</ActionIcon>
156176
</Tooltip>
157-
<SpotlightButton />
177+
{userSettings.isSet('SHOW_SPOTLIGHT') && <SpotlightButton />}
158178
{globalSettings.isSet('BARCODE_ENABLE') && <ScanButton />}
159179
<Indicator
160180
radius='lg'

src/frontend/src/components/nav/Layout.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Navigate, Outlet, useLocation, useNavigate } from 'react-router-dom';
77

88
import { getActions } from '../../defaults/actions';
99
import * as classes from '../../main.css';
10+
import { useUserSettingsState } from '../../states/SettingsStates';
1011
import { useUserState } from '../../states/UserState';
1112
import { Boundary } from '../Boundary';
1213
import { Footer } from './Footer';
@@ -37,6 +38,7 @@ export const [firstStore, firstSpotlight] = createSpotlight();
3738
export default function LayoutComponent() {
3839
const navigate = useNavigate();
3940
const location = useLocation();
41+
const userSettings = useUserSettingsState();
4042

4143
const defaultActions = getActions(navigate);
4244
const [actions, setActions] = useState(defaultActions);
@@ -68,17 +70,19 @@ export default function LayoutComponent() {
6870
</Container>
6971
<Space h='xl' />
7072
<Footer />
71-
<Spotlight
72-
actions={actions}
73-
store={firstStore}
74-
highlightQuery
75-
searchProps={{
76-
leftSection: <IconSearch size='1.2rem' />,
77-
placeholder: t`Search...`
78-
}}
79-
shortcut={['mod + K', '/']}
80-
nothingFound={t`Nothing found...`}
81-
/>
73+
{userSettings.isSet('SHOW_SPOTLIGHT') && (
74+
<Spotlight
75+
actions={actions}
76+
store={firstStore}
77+
highlightQuery
78+
searchProps={{
79+
leftSection: <IconSearch size='1.2rem' />,
80+
placeholder: t`Search...`
81+
}}
82+
shortcut={['mod + K']}
83+
nothingFound={t`Nothing found...`}
84+
/>
85+
)}
8286
</Flex>
8387
</ProtectedRoute>
8488
);

src/frontend/src/pages/Index/Settings/UserSettings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default function UserSettings() {
5858
'ICONS_IN_NAVBAR',
5959
'STICKY_HEADER',
6060
'STICKY_TABLE_HEADER',
61+
'SHOW_SPOTLIGHT',
6162
'DATE_DISPLAY_FORMAT',
6263
'FORMS_CLOSE_USING_ESCAPE',
6364
'DISPLAY_STOCKTAKE_TAB',

src/frontend/tests/pui_general.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { doCachedLogin } from './login.js';
55
/**
66
* Test for integration of django admin button
77
*/
8-
test('Admin Button', async ({ browser }) => {
8+
test('General - Admin Button', async ({ browser }) => {
99
const page = await doCachedLogin(browser, {
1010
username: 'admin',
1111
password: 'inventree',
@@ -21,12 +21,17 @@ test('Admin Button', async ({ browser }) => {
2121
});
2222

2323
// Tests for the global search functionality
24-
test('Search', async ({ browser }) => {
24+
test('General - Search', async ({ browser }) => {
2525
const page = await doCachedLogin(browser, {
2626
username: 'steven',
2727
password: 'wizardstaff'
2828
});
2929

30+
// Open the search drawer with a shortcut
31+
await page.keyboard.press('Control+/');
32+
await page.getByRole('textbox', { name: 'global-search-input' }).waitFor();
33+
await page.keyboard.press('Escape');
34+
3035
await globalSearch(page, 'another customer');
3136

3237
// Check for expected results

0 commit comments

Comments
 (0)