mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Build allocation table updates (#7106)
* Update build line allocation table - Allow display of "tracked" items in main allocation table * Add resolveItem function for finding nested items * Update BuildLineTable * Allow BuildLineList to be ordered by 'trackable' field * Bump API version
This commit is contained in:
@ -19,3 +19,16 @@ export function isTrue(value: any): boolean {
|
||||
|
||||
return ['true', 'yes', '1', 'on', 't', 'y'].includes(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* Resolve a nested item in an object.
|
||||
* Returns the resolved item, if it exists.
|
||||
*
|
||||
* e.g. resolveItem(data, "sub.key.accessor")
|
||||
*
|
||||
* Allows for retrieval of nested items in an object.
|
||||
*/
|
||||
export function resolveItem(obj: any, path: string): any {
|
||||
let properties = path.split('.');
|
||||
return properties.reduce((prev, curr) => prev?.[curr], obj);
|
||||
}
|
||||
|
@ -203,8 +203,7 @@ export default function BuildDetail() {
|
||||
content: build?.pk ? (
|
||||
<BuildLineTable
|
||||
params={{
|
||||
build: id,
|
||||
tracked: false
|
||||
build: id
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
|
@ -3,6 +3,7 @@
|
||||
*/
|
||||
import { t } from '@lingui/macro';
|
||||
import { Anchor } from '@mantine/core';
|
||||
import { access } from 'fs';
|
||||
|
||||
import { YesNoButton } from '../components/buttons/YesNoButton';
|
||||
import { Thumbnail } from '../components/images/Thumbnail';
|
||||
@ -11,6 +12,7 @@ import { TableStatusRenderer } from '../components/render/StatusRenderer';
|
||||
import { RenderOwner } from '../components/render/User';
|
||||
import { formatCurrency, renderDate } from '../defaults/formatters';
|
||||
import { ModelType } from '../enums/ModelType';
|
||||
import { resolveItem } from '../functions/conversion';
|
||||
import { cancelEvent } from '../functions/events';
|
||||
import { TableColumn } from './Column';
|
||||
import { ProjectCodeHoverCard } from './TableHoverCard';
|
||||
@ -29,19 +31,24 @@ export function BooleanColumn({
|
||||
accessor,
|
||||
title,
|
||||
sortable,
|
||||
switchable
|
||||
switchable,
|
||||
ordering
|
||||
}: {
|
||||
accessor: string;
|
||||
title?: string;
|
||||
ordering?: string;
|
||||
sortable?: boolean;
|
||||
switchable?: boolean;
|
||||
}): TableColumn {
|
||||
return {
|
||||
accessor: accessor,
|
||||
title: title,
|
||||
ordering: ordering,
|
||||
sortable: sortable ?? true,
|
||||
switchable: switchable ?? true,
|
||||
render: (record: any) => <YesNoButton value={record[accessor]} />
|
||||
render: (record: any) => (
|
||||
<YesNoButton value={resolveItem(record, accessor)} />
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@ -71,7 +78,7 @@ export function LinkColumn({
|
||||
accessor: accessor,
|
||||
sortable: false,
|
||||
render: (record: any) => {
|
||||
let url = record[accessor];
|
||||
let url = resolveItem(record, accessor);
|
||||
|
||||
if (!url) {
|
||||
return '-';
|
||||
|
@ -28,6 +28,7 @@ import { ActionButton } from '../components/buttons/ActionButton';
|
||||
import { ButtonMenu } from '../components/buttons/ButtonMenu';
|
||||
import { ApiFormFieldSet } from '../components/forms/fields/ApiFormField';
|
||||
import { ModelType } from '../enums/ModelType';
|
||||
import { resolveItem } from '../functions/conversion';
|
||||
import { extractAvailableFields, mapFields } from '../functions/forms';
|
||||
import { getDetailUrl } from '../functions/urls';
|
||||
import { TableState } from '../hooks/UseTable';
|
||||
@ -519,7 +520,8 @@ export function InvenTreeTable<T = any>({
|
||||
// If a custom row click handler is provided, use that
|
||||
props.onRowClick(record, index, event);
|
||||
} else if (tableProps.modelType) {
|
||||
const pk = record?.[tableProps.modelField ?? 'pk'];
|
||||
const accessor = tableProps.modelField ?? 'pk';
|
||||
const pk = resolveItem(record, accessor);
|
||||
|
||||
if (pk) {
|
||||
// If a model type is provided, navigate to the detail view for that model
|
||||
|
@ -6,13 +6,11 @@ import {
|
||||
IconTool
|
||||
} from '@tabler/icons-react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { PartHoverCard } from '../../components/images/Thumbnail';
|
||||
import { ProgressBar } from '../../components/items/ProgressBar';
|
||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||
import { ModelType } from '../../enums/ModelType';
|
||||
import { getDetailUrl } from '../../functions/urls';
|
||||
import { useTable } from '../../hooks/UseTable';
|
||||
import { apiUrl } from '../../states/ApiState';
|
||||
import { useUserState } from '../../states/UserState';
|
||||
@ -25,7 +23,6 @@ import { TableHoverCard } from '../TableHoverCard';
|
||||
export default function BuildLineTable({ params = {} }: { params?: any }) {
|
||||
const table = useTable('buildline');
|
||||
const user = useUserState();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const tableFilters: TableFilter[] = useMemo(() => {
|
||||
return [
|
||||
@ -47,6 +44,11 @@ export default function BuildLineTable({ params = {} }: { params?: any }) {
|
||||
name: 'optional',
|
||||
label: t`Optional`,
|
||||
description: t`Show optional lines`
|
||||
},
|
||||
{
|
||||
name: 'tracked',
|
||||
label: t`Tracked`,
|
||||
description: t`Show tracked lines`
|
||||
}
|
||||
];
|
||||
}, []);
|
||||
@ -122,18 +124,28 @@ export default function BuildLineTable({ params = {} }: { params?: any }) {
|
||||
return [
|
||||
{
|
||||
accessor: 'bom_item',
|
||||
ordering: 'part',
|
||||
sortable: true,
|
||||
switchable: false,
|
||||
render: (record: any) => <PartHoverCard part={record.part_detail} />
|
||||
},
|
||||
{
|
||||
accessor: 'bom_item_detail.reference'
|
||||
accessor: 'bom_item_detail.reference',
|
||||
ordering: 'reference',
|
||||
sortable: true,
|
||||
title: t`Reference`
|
||||
},
|
||||
BooleanColumn({
|
||||
accessor: 'bom_item_detail.consumable'
|
||||
accessor: 'bom_item_detail.consumable',
|
||||
ordering: 'consumable'
|
||||
}),
|
||||
BooleanColumn({
|
||||
accessor: 'bom_item_detail.optional'
|
||||
accessor: 'bom_item_detail.optional',
|
||||
ordering: 'optional'
|
||||
}),
|
||||
BooleanColumn({
|
||||
accessor: 'part_detail.trackable',
|
||||
ordering: 'trackable'
|
||||
}),
|
||||
{
|
||||
accessor: 'bom_item_detail.quantity',
|
||||
@ -198,6 +210,11 @@ export default function BuildLineTable({ params = {} }: { params?: any }) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Tracked items must be allocated to a particular output
|
||||
if (record?.part_detail?.trackable) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
icon: <IconArrowRight />,
|
||||
@ -234,11 +251,8 @@ export default function BuildLineTable({ params = {} }: { params?: any }) {
|
||||
},
|
||||
tableFilters: tableFilters,
|
||||
rowActions: rowActions,
|
||||
onRowClick: (row: any) => {
|
||||
if (row?.part_detail?.pk) {
|
||||
navigate(getDetailUrl(ModelType.part, row.part_detail.pk));
|
||||
}
|
||||
}
|
||||
modelType: ModelType.part,
|
||||
modelField: 'part_detail.pk'
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
Reference in New Issue
Block a user