mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-09 21:30:54 +00:00
dumb spotlight down
This commit is contained in:
@@ -2,6 +2,7 @@ import { t } from '@lingui/macro';
|
|||||||
import { Container, Flex, Space } from '@mantine/core';
|
import { Container, Flex, Space } from '@mantine/core';
|
||||||
import { Spotlight, createSpotlight } from '@mantine/spotlight';
|
import { Spotlight, createSpotlight } from '@mantine/spotlight';
|
||||||
import { IconSearch } from '@tabler/icons-react';
|
import { IconSearch } from '@tabler/icons-react';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
import { Navigate, Outlet, useLocation, useNavigate } from 'react-router-dom';
|
import { Navigate, Outlet, useLocation, useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { getActions } from '../../defaults/actions';
|
import { getActions } from '../../defaults/actions';
|
||||||
@@ -28,7 +29,26 @@ export const [firstStore, firstSpotlight] = createSpotlight();
|
|||||||
|
|
||||||
export default function LayoutComponent() {
|
export default function LayoutComponent() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const defaultactions = getActions(navigate);
|
const defaultactions = getActions(navigate);
|
||||||
|
const [actions, setActions] = useState(defaultactions);
|
||||||
|
const [customActions, setCustomActions] = useState<boolean>(false);
|
||||||
|
|
||||||
|
function actionsAreChanging(change: any) {
|
||||||
|
if (change.registeredActions.length > defaultactions.length)
|
||||||
|
setCustomActions(true);
|
||||||
|
setActions(change);
|
||||||
|
}
|
||||||
|
// firstStore.subscribe(actionsAreChanging);
|
||||||
|
|
||||||
|
// clear additional actions on location change
|
||||||
|
useEffect(() => {
|
||||||
|
if (customActions) {
|
||||||
|
setActions(defaultactions);
|
||||||
|
setCustomActions(false);
|
||||||
|
}
|
||||||
|
}, [location]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ProtectedRoute>
|
<ProtectedRoute>
|
||||||
@@ -40,9 +60,8 @@ export default function LayoutComponent() {
|
|||||||
<Space h="xl" />
|
<Space h="xl" />
|
||||||
<Footer />
|
<Footer />
|
||||||
<Spotlight
|
<Spotlight
|
||||||
actions={defaultactions}
|
actions={actions}
|
||||||
store={firstStore}
|
store={firstStore}
|
||||||
//onActionsChange={actionsAreChanging}
|
|
||||||
highlightQuery
|
highlightQuery
|
||||||
searchProps={{
|
searchProps={{
|
||||||
leftSection: <IconSearch size="1.2rem" />,
|
leftSection: <IconSearch size="1.2rem" />,
|
||||||
|
@@ -2,6 +2,7 @@ import { Trans } from '@lingui/macro';
|
|||||||
import { Button, Card, Stack, TextInput } from '@mantine/core';
|
import { Button, Card, Stack, TextInput } from '@mantine/core';
|
||||||
import { Group, Text } from '@mantine/core';
|
import { Group, Text } from '@mantine/core';
|
||||||
import { Accordion } from '@mantine/core';
|
import { Accordion } from '@mantine/core';
|
||||||
|
import { SpotlightActionData } from '@mantine/spotlight';
|
||||||
import { IconAlien } from '@tabler/icons-react';
|
import { IconAlien } from '@tabler/icons-react';
|
||||||
import { ReactNode, useMemo, useState } from 'react';
|
import { ReactNode, useMemo, useState } from 'react';
|
||||||
|
|
||||||
@@ -18,7 +19,6 @@ import {
|
|||||||
useCreateApiFormModal,
|
useCreateApiFormModal,
|
||||||
useEditApiFormModal
|
useEditApiFormModal
|
||||||
} from '../../hooks/UseForm';
|
} from '../../hooks/UseForm';
|
||||||
import { useSpotlightState } from '../../states/SpotlightState';
|
|
||||||
|
|
||||||
// Generate some example forms using the modal API forms interface
|
// Generate some example forms using the modal API forms interface
|
||||||
const fields = partCategoryFields({});
|
const fields = partCategoryFields({});
|
||||||
@@ -176,8 +176,9 @@ function SpotlighPlayground() {
|
|||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const setAdditionalActions =
|
const setAdditionalActions = (value: SpotlightActionData[]) => {
|
||||||
useSpotlightState.getState().setAdditionalActions;
|
console.log('would add', value);
|
||||||
|
};
|
||||||
setAdditionalActions([
|
setAdditionalActions([
|
||||||
{
|
{
|
||||||
id: 'secret-action-1',
|
id: 'secret-action-1',
|
||||||
|
Reference in New Issue
Block a user