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,
IconCurrencyDollar,
IconDots,
IconExclamationCircle,
IconExternalLink,
IconFileUpload,
IconFlag,
@ -109,6 +110,7 @@ const icons = {
keywords: IconTag,
status: IconInfoCircle,
info: IconInfoCircle,
exclamation: IconExclamationCircle,
details: IconInfoCircle,
parameters: 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 { ReactNode } from 'react';
import { InvenTreeIcon, InvenTreeIconType } from '../functions/icons';
/*
* A custom hovercard element for displaying extra information in a table cell.
* If a table cell has extra information available,
@ -11,11 +13,15 @@ import { ReactNode } from 'react';
export function TableHoverCard({
value, // The value of the cell
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;
extra?: ReactNode;
title?: string;
icon?: InvenTreeIconType;
iconColor?: string;
}) {
// If no extra information presented, just return the raw value
if (!extra) {
@ -31,7 +37,10 @@ export function TableHoverCard({
<HoverCard.Target>
<Group gap="xs" justify="space-between" wrap="nowrap">
{value}
<IconInfoCircle size="16" color="blue" />
<InvenTreeIcon
icon={icon ?? 'info'}
iconProps={{ size: 16, color: iconColor ?? 'blue' }}
/>
</Group>
</HoverCard.Target>
<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 (
<TableHoverCard
icon={sufficient ? 'info' : 'exclamation'}
iconColor={sufficient ? 'blue' : 'orange'}
value={
available > 0 ? (
available