2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +00:00
* PartCategoryTree - add "subcategories" field

* Fix rendering of PartCategoryTree

* Implement similar fixes for StockLocationTree

* Bump API version
This commit is contained in:
Oliver
2024-02-27 12:00:11 +11:00
committed by GitHub
parent 8db769968f
commit de23023277
9 changed files with 113 additions and 7 deletions

View File

@ -8,7 +8,11 @@ import {
useMantineTheme
} from '@mantine/core';
import { ReactTree, ThemeSettings } from '@naisutech/react-tree';
import { IconSitemap } from '@tabler/icons-react';
import {
IconChevronDown,
IconChevronRight,
IconSitemap
} from '@tabler/icons-react';
import { useQuery } from '@tanstack/react-query';
import { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
@ -40,7 +44,8 @@ export function PartCategoryTree({
return {
id: category.pk,
label: category.name,
parentId: category.parent
parentId: category.parent,
children: category.subcategories
};
})
)
@ -67,6 +72,14 @@ export function PartCategoryTree({
);
}
function renderIcon({ node, open }: { node: any; open?: boolean }) {
if (node.children == 0) {
return undefined;
}
return open ? <IconChevronDown /> : <IconChevronRight />;
}
const mantineTheme = useMantineTheme();
const themes: ThemeSettings = useMemo(() => {
@ -146,6 +159,7 @@ export function PartCategoryTree({
<ReactTree
nodes={treeQuery.data ?? []}
RenderNode={renderNode}
RenderIcon={renderIcon}
defaultSelectedNodes={selectedCategory ? [selectedCategory] : []}
showEmptyItems={false}
theme={mantineTheme.colorScheme}

View File

@ -1,7 +1,11 @@
import { t } from '@lingui/macro';
import { Drawer, Group, LoadingOverlay, Stack, Text } from '@mantine/core';
import { ReactTree } from '@naisutech/react-tree';
import { IconSitemap } from '@tabler/icons-react';
import {
IconChevronDown,
IconChevronRight,
IconSitemap
} from '@tabler/icons-react';
import { useQuery } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';
@ -32,7 +36,8 @@ export function StockLocationTree({
return {
id: location.pk,
label: location.name,
parentId: location.parent
parentId: location.parent,
children: location.sublocations
};
})
)
@ -59,6 +64,14 @@ export function StockLocationTree({
);
}
function renderIcon({ node, open }: { node: any; open?: boolean }) {
if (node.children == 0) {
return undefined;
}
return open ? <IconChevronDown /> : <IconChevronRight />;
}
return (
<Drawer
opened={opened}
@ -87,6 +100,7 @@ export function StockLocationTree({
nodes={treeQuery.data ?? []}
showEmptyItems={false}
RenderNode={renderNode}
RenderIcon={renderIcon}
defaultSelectedNodes={selectedLocation ? [selectedLocation] : []}
/>
</Stack>