mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +00:00
[PUI] Adjust stock details page (#8196)
* Adjust stock details page * Remove unused import * Details rendering fix * Cleanup * Handle null / undefined cases * More cleanup
This commit is contained in:
parent
392624cb84
commit
e6470ffdea
@ -11,7 +11,7 @@ import {
|
|||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { getValueAtPath } from 'mantine-datatable';
|
import { getValueAtPath } from 'mantine-datatable';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { ReactNode, useCallback, useMemo } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { api } from '../../App';
|
import { api } from '../../App';
|
||||||
@ -182,37 +182,28 @@ function NameBadge({
|
|||||||
function TableStringValue(props: Readonly<FieldProps>) {
|
function TableStringValue(props: Readonly<FieldProps>) {
|
||||||
let value = props?.field_value;
|
let value = props?.field_value;
|
||||||
|
|
||||||
if (props?.field_data?.value_formatter) {
|
let renderedValue = null;
|
||||||
value = props.field_data.value_formatter();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value === undefined) {
|
|
||||||
return '---';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.field_data?.badge) {
|
if (props.field_data?.badge) {
|
||||||
return <NameBadge pk={value} type={props.field_data.badge} />;
|
return <NameBadge pk={value} type={props.field_data.badge} />;
|
||||||
|
} else if (props?.field_data?.value_formatter) {
|
||||||
|
renderedValue = props.field_data.value_formatter();
|
||||||
|
} else if (value === null || value === undefined) {
|
||||||
|
renderedValue = <Text size="sm">'---'</Text>;
|
||||||
|
} else {
|
||||||
|
renderedValue = <Text size="sm">{value.toString()}</Text>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<Group wrap="nowrap" gap="xs" justify="space-apart">
|
||||||
style={{
|
<Group wrap="nowrap" gap="xs" justify="left">
|
||||||
display: 'flex',
|
{renderedValue}
|
||||||
justifyContent: 'space-between',
|
{props.field_data.unit == true && <Text size="xs">{props.unit}</Text>}
|
||||||
wordBreak: 'break-word',
|
|
||||||
alignItems: 'flex-start'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Group wrap="nowrap" gap="xs" justify="space-apart">
|
|
||||||
<Group wrap="nowrap" gap="xs" justify="left">
|
|
||||||
{value ? value : props.field_data?.unit && '0'}{' '}
|
|
||||||
{props.field_data.unit == true && props.unit}
|
|
||||||
</Group>
|
|
||||||
{props.field_data.user && (
|
|
||||||
<NameBadge pk={props.field_data?.user} type="user" />
|
|
||||||
)}
|
|
||||||
</Group>
|
</Group>
|
||||||
</div>
|
{props.field_data.user && (
|
||||||
|
<NameBadge pk={props.field_data?.user} type="user" />
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +297,7 @@ function TableAnchorValue(props: Readonly<FieldProps>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<>
|
||||||
{make_link ? (
|
{make_link ? (
|
||||||
<Anchor href="#" onClick={handleLinkClick}>
|
<Anchor href="#" onClick={handleLinkClick}>
|
||||||
<Text>{value}</Text>
|
<Text>{value}</Text>
|
||||||
@ -314,7 +305,7 @@ function TableAnchorValue(props: Readonly<FieldProps>) {
|
|||||||
) : (
|
) : (
|
||||||
<Text>{value}</Text>
|
<Text>{value}</Text>
|
||||||
)}
|
)}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,9 +338,6 @@ export function DetailsTableField({
|
|||||||
}>) {
|
}>) {
|
||||||
function getFieldType(type: string) {
|
function getFieldType(type: string) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'text':
|
|
||||||
case 'string':
|
|
||||||
return TableStringValue;
|
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return BooleanValue;
|
return BooleanValue;
|
||||||
case 'link':
|
case 'link':
|
||||||
@ -358,6 +346,8 @@ export function DetailsTableField({
|
|||||||
return ProgressBarValue;
|
return ProgressBarValue;
|
||||||
case 'status':
|
case 'status':
|
||||||
return StatusValue;
|
return StatusValue;
|
||||||
|
case 'text':
|
||||||
|
case 'string':
|
||||||
default:
|
default:
|
||||||
return TableStringValue;
|
return TableStringValue;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
import { Trans } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
|
import { Alert, Text } from '@mantine/core';
|
||||||
|
|
||||||
export function ErrorItem({
|
export function ErrorItem({
|
||||||
id,
|
id,
|
||||||
error
|
error
|
||||||
}: Readonly<{ id: string; error?: any }>) {
|
}: Readonly<{ id: string; error?: any }>) {
|
||||||
const error_message = error?.message || error?.toString() || (
|
const error_message = error?.message || error?.toString() || t`Unknown error`;
|
||||||
<Trans>Unknown error</Trans>
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>
|
<Alert color="red" title={t`An error occurred`}>
|
||||||
<Trans>An error occurred:</Trans>
|
<Text>{error_message}</Text>
|
||||||
</p>
|
</Alert>
|
||||||
{error_message}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ export default function StockDetail() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const detailsPanel = useMemo(() => {
|
const detailsPanel = useMemo(() => {
|
||||||
let data = stockitem;
|
let data = { ...stockitem };
|
||||||
let part = stockitem?.part_detail ?? {};
|
let part = stockitem?.part_detail ?? {};
|
||||||
|
|
||||||
data.available_stock = Math.max(0, data.quantity - data.allocated);
|
data.available_stock = Math.max(0, data.quantity - data.allocated);
|
||||||
@ -164,7 +164,14 @@ export default function StockDetail() {
|
|||||||
type: 'text',
|
type: 'text',
|
||||||
name: 'available_stock',
|
name: 'available_stock',
|
||||||
label: t`Available`,
|
label: t`Available`,
|
||||||
icon: 'quantity'
|
icon: 'stock'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
name: 'allocated',
|
||||||
|
label: t`Allocated to Orders`,
|
||||||
|
icon: 'tick_off',
|
||||||
|
hidden: !stockitem.allocated
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
@ -281,12 +288,12 @@ export default function StockDetail() {
|
|||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={8}>
|
<Grid.Col span={8}>
|
||||||
<DetailsTable fields={tl} item={stockitem} />
|
<DetailsTable fields={tl} item={data} />
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
<DetailsTable fields={tr} item={stockitem} />
|
<DetailsTable fields={tr} item={data} />
|
||||||
<DetailsTable fields={bl} item={stockitem} />
|
<DetailsTable fields={bl} item={data} />
|
||||||
<DetailsTable fields={br} item={stockitem} />
|
<DetailsTable fields={br} item={data} />
|
||||||
</ItemDetailsGrid>
|
</ItemDetailsGrid>
|
||||||
);
|
);
|
||||||
}, [stockitem, instanceQuery]);
|
}, [stockitem, instanceQuery]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user