2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-09 15:10:54 +00:00

Add setting to show location path as plain text in tables (#9960)

* Add setting to show location path as plain text in tables

* Use the Location Path setting also for Default Location in the PartTable

* Add setting to show PartCategoty as plain text

* Set DefaultLocationColumn defaultVisible to false

* Fix typo

* Simplify settings keys

* Simplify the name attribute

* Fix typo

---------

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
gunstr
2025-07-09 03:19:05 +02:00
committed by GitHub
parent b6c8db56fb
commit 223287b1e1
6 changed files with 111 additions and 27 deletions

View File

@ -24,7 +24,9 @@ The *Display Settings* screen shows general display configuration options:
{{ usersetting("FORMS_CLOSE_USING_ESCAPE") }}
{{ usersetting("PART_SHOW_QUANTITY_IN_FORMS") }}
{{ usersetting("DISPLAY_STOCKTAKE_TAB") }}
{{ usersetting("SHOW_FULL_CATEGORY_IN_TABLES")}}
{{ usersetting("ENABLE_LAST_BREADCRUMB") }}
{{ usersetting("SHOW_FULL_LOCATION_IN_TABLES") }}
### Search Settings

View File

@ -225,6 +225,22 @@ USER_SETTINGS: dict[str, InvenTreeSettingsKeyType] = {
'default': False,
'validator': bool,
},
'SHOW_FULL_LOCATION_IN_TABLES': {
'name': _('Show full stock location in tables'),
'description': _(
'Disabled: The full location path is displayed as a hover tooltip. Enabled: The full location path is displayed as plain text.'
),
'default': False,
'validator': bool,
},
'SHOW_FULL_CATEGORY_IN_TABLES': {
'name': _('Show full part categories in tables'),
'description': _(
'Disabled: The full category path is displayed as a hover tooltip. Enabled: The full category path is displayed as plain text.'
),
'default': False,
'validator': bool,
},
'NOTIFICATION_ERROR_REPORT': {
'name': _('Receive error reports'),
'description': _('Receive notifications for system errors'),

View File

@ -55,7 +55,9 @@ export default function UserSettings() {
'FORMS_CLOSE_USING_ESCAPE',
'PART_SHOW_QUANTITY_IN_FORMS',
'DISPLAY_STOCKTAKE_TAB',
'ENABLE_LAST_BREADCRUMB'
'ENABLE_LAST_BREADCRUMB',
'SHOW_FULL_LOCATION_IN_TABLES',
'SHOW_FULL_CATEGORY_IN_TABLES'
]}
/>
)

View File

@ -19,7 +19,10 @@ import { TableStatusRenderer } from '../components/render/StatusRenderer';
import { RenderOwner, RenderUser } from '../components/render/User';
import { formatCurrency, formatDate } from '../defaults/formatters';
import { resolveItem } from '../functions/conversion';
import { useGlobalSettingsState } from '../states/SettingsStates';
import {
useGlobalSettingsState,
useUserSettingsState
} from '../states/SettingsStates';
import type { TableColumn, TableColumnProps } from './Column';
import { ProjectCodeHoverCard, TableHoverCard } from './TableHoverCard';
@ -114,7 +117,34 @@ export function PathColumn(props: TableColumnProps): TableColumn {
};
}
export function PathColumnPlainText(props: TableColumnProps): TableColumn {
return {
...props,
accessor: props.accessor ?? 'path',
render: (record: any) => {
const instance = resolveItem(record, props.accessor ?? '');
if (!instance || !instance.pathstring) {
return '-';
}
return <Text>{instance.pathstring}</Text>;
}
};
}
export function LocationColumn(props: TableColumnProps): TableColumn {
const userSettings = useUserSettingsState.getState();
const enabled = userSettings.isSet('SHOW_FULL_LOCATION_IN_TABLES', false);
if (enabled) {
return PathColumnPlainText({
accessor: 'location',
title: t`Location`,
sortable: true,
ordering: 'location',
...props
});
} else {
return PathColumn({
accessor: 'location',
title: t`Location`,
@ -123,8 +153,44 @@ export function LocationColumn(props: TableColumnProps): TableColumn {
...props
});
}
}
export function DefaultLocationColumn(props: TableColumnProps): TableColumn {
const userSettings = useUserSettingsState.getState();
const enabled = userSettings.isSet('SHOW_FULL_LOCATION_IN_TABLES', false);
if (enabled) {
return PathColumnPlainText({
accessor: 'default_location',
title: t`Default Location`,
sortable: true,
defaultVisible: false,
ordering: 'default_location',
...props
});
} else {
return PathColumn({
accessor: 'default_location',
title: t`Default Location`,
sortable: true,
defaultVisible: false,
ordering: 'default_location',
...props
});
}
}
export function CategoryColumn(props: TableColumnProps): TableColumn {
const userSettings = useUserSettingsState.getState();
const enabled = userSettings.isSet('SHOW_FULL_CATEGORY_IN_TABLES', false);
if (enabled) {
return PathColumnPlainText({
accessor: 'category',
title: t`Category`,
sortable: true,
ordering: 'category',
...props
});
} else {
return PathColumn({
accessor: 'category',
title: t`Category`,
@ -133,6 +199,7 @@ export function CategoryColumn(props: TableColumnProps): TableColumn {
...props
});
}
}
export function BooleanColumn(props: TableColumn): TableColumn {
return {

View File

@ -24,6 +24,7 @@ import { useUserState } from '../../states/UserState';
import type { TableColumn } from '../Column';
import {
CategoryColumn,
DefaultLocationColumn,
DescriptionColumn,
LinkColumn,
PartColumn
@ -61,12 +62,9 @@ function partTableColumns(): TableColumn[] {
CategoryColumn({
accessor: 'category_detail'
}),
{
accessor: 'default_location',
sortable: true,
render: (record: any) => record.default_location_detail?.pathstring,
defaultVisible: false
},
DefaultLocationColumn({
accessor: 'default_location_detail'
}),
{
accessor: 'total_in_stock',
sortable: true,

View File

@ -25,8 +25,8 @@ import type { TableColumn } from '../Column';
import {
DateColumn,
DescriptionColumn,
LocationColumn,
PartColumn,
PathColumn,
StatusColumn
} from '../ColumnRenderers';
import {
@ -223,10 +223,9 @@ function stockItemTableColumns({
accessor: 'batch',
sortable: true
},
PathColumn({
accessor: 'location_detail',
title: t`Location`,
hidden: !showLocation
LocationColumn({
hidden: !showLocation,
accessor: 'location_detail'
}),
{
accessor: 'purchase_order',