Show warning for insufficient stock (#7916)

This commit is contained in:
Oliver 2024-08-19 15:11:55 +10:00 committed by GitHub
parent 9fbaeba2ab
commit 0ee06ec13e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import {
IconCornerUpRightDouble, IconCornerUpRightDouble,
IconCurrencyDollar, IconCurrencyDollar,
IconDots, IconDots,
IconExclamationCircle,
IconExternalLink, IconExternalLink,
IconFileUpload, IconFileUpload,
IconFlag, IconFlag,
@ -109,6 +110,7 @@ const icons = {
keywords: IconTag, keywords: IconTag,
status: IconInfoCircle, status: IconInfoCircle,
info: IconInfoCircle, info: IconInfoCircle,
exclamation: IconExclamationCircle,
details: IconInfoCircle, details: IconInfoCircle,
parameters: IconList, parameters: IconList,
list: IconList, list: IconList,

View File

@ -3,6 +3,8 @@ import { Divider, Group, HoverCard, Stack, Text } from '@mantine/core';
import { IconInfoCircle } from '@tabler/icons-react'; import { IconInfoCircle } from '@tabler/icons-react';
import { ReactNode } from 'react'; import { ReactNode } from 'react';
import { InvenTreeIcon, InvenTreeIconType } from '../functions/icons';
/* /*
* A custom hovercard element for displaying extra information in a table cell. * A custom hovercard element for displaying extra information in a table cell.
* If a table cell has extra information available, * If a table cell has extra information available,
@ -11,11 +13,15 @@ import { ReactNode } from 'react';
export function TableHoverCard({ export function TableHoverCard({
value, // The value of the cell value, // The value of the cell
extra, // The extra information to display extra, // The extra information to display
title // The title of the hovercard title, // The title of the hovercard
icon, // The icon to display
iconColor // The icon color
}: { }: {
value: any; value: any;
extra?: ReactNode; extra?: ReactNode;
title?: string; title?: string;
icon?: InvenTreeIconType;
iconColor?: string;
}) { }) {
// If no extra information presented, just return the raw value // If no extra information presented, just return the raw value
if (!extra) { if (!extra) {
@ -31,7 +37,10 @@ export function TableHoverCard({
<HoverCard.Target> <HoverCard.Target>
<Group gap="xs" justify="space-between" wrap="nowrap"> <Group gap="xs" justify="space-between" wrap="nowrap">
{value} {value}
<IconInfoCircle size="16" color="blue" /> <InvenTreeIcon
icon={icon ?? 'info'}
iconProps={{ size: 16, color: iconColor ?? 'blue' }}
/>
</Group> </Group>
</HoverCard.Target> </HoverCard.Target>
<HoverCard.Dropdown> <HoverCard.Dropdown>

View File

@ -126,8 +126,20 @@ export default function BuildLineTable({
); );
} }
const sufficient = available >= record.quantity - record.allocated;
if (!sufficient) {
extra.push(
<Text key="insufficient" c="orange" size="sm">
{t`Insufficient stock`}
</Text>
);
}
return ( return (
<TableHoverCard <TableHoverCard
icon={sufficient ? 'info' : 'exclamation'}
iconColor={sufficient ? 'blue' : 'orange'}
value={ value={
available > 0 ? ( available > 0 ? (
available available