mirror of
https://github.com/inventree/InvenTree.git
synced 2026-02-13 01:38:03 +00:00
feat(frontend): add warning to SO line calcs (#11296)
This commit is contained in:
@@ -111,6 +111,8 @@ export type ApiFormFieldType = {
|
|||||||
read_only?: boolean;
|
read_only?: boolean;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
placeholderAutofill?: boolean;
|
placeholderAutofill?: boolean;
|
||||||
|
placeholderWarningCompare?: string | number;
|
||||||
|
placeholderWarning?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
preFieldContent?: JSX.Element;
|
preFieldContent?: JSX.Element;
|
||||||
postFieldContent?: JSX.Element;
|
postFieldContent?: JSX.Element;
|
||||||
|
|||||||
@@ -179,6 +179,10 @@ export function ApiFormField({
|
|||||||
fieldName={fieldName}
|
fieldName={fieldName}
|
||||||
definition={reducedDefinition}
|
definition={reducedDefinition}
|
||||||
placeholderAutofill={fieldDefinition.placeholderAutofill ?? false}
|
placeholderAutofill={fieldDefinition.placeholderAutofill ?? false}
|
||||||
|
placeholderWarningCompare={
|
||||||
|
fieldDefinition.placeholderWarningCompare ?? undefined
|
||||||
|
}
|
||||||
|
placeholderWarning={fieldDefinition.placeholderWarning ?? undefined}
|
||||||
onChange={(value: any) => {
|
onChange={(value: any) => {
|
||||||
onChange(value);
|
onChange(value);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { t } from '@lingui/core/macro';
|
import { t } from '@lingui/core/macro';
|
||||||
import { Tooltip } from '@mantine/core';
|
import { Tooltip } from '@mantine/core';
|
||||||
import { IconCopyCheck, IconX } from '@tabler/icons-react';
|
import { IconCopyCheck, IconExclamationMark, IconX } from '@tabler/icons-react';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom "RightSection" component for form fields,
|
* Custom "RightSection" component for form fields,
|
||||||
@@ -55,3 +55,21 @@ export default function AutoFillRightSection({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function AutoFillWarning({
|
||||||
|
fieldName,
|
||||||
|
message
|
||||||
|
}: {
|
||||||
|
fieldName: string;
|
||||||
|
message: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Tooltip label={message} position='top-end'>
|
||||||
|
<IconExclamationMark
|
||||||
|
aria-label={`field-${fieldName}-palceholder-warning`}
|
||||||
|
size='1rem'
|
||||||
|
color='orange'
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { NumberInput } from '@mantine/core';
|
import { NumberInput } from '@mantine/core';
|
||||||
import { useId, useMemo } from 'react';
|
import { useId, useMemo } from 'react';
|
||||||
import type { FieldValues, UseControllerReturn } from 'react-hook-form';
|
import type { FieldValues, UseControllerReturn } from 'react-hook-form';
|
||||||
import AutoFillRightSection from './AutoFillRightSection';
|
import AutoFillRightSection, { AutoFillWarning } from './AutoFillRightSection';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom implementation of the mantine <NumberInput> component,
|
* Custom implementation of the mantine <NumberInput> component,
|
||||||
@@ -12,12 +12,16 @@ export default function NumberField({
|
|||||||
fieldName,
|
fieldName,
|
||||||
definition,
|
definition,
|
||||||
placeholderAutofill,
|
placeholderAutofill,
|
||||||
|
placeholderWarningCompare,
|
||||||
|
placeholderWarning,
|
||||||
onChange
|
onChange
|
||||||
}: Readonly<{
|
}: Readonly<{
|
||||||
controller: UseControllerReturn<FieldValues, any>;
|
controller: UseControllerReturn<FieldValues, any>;
|
||||||
definition: any;
|
definition: any;
|
||||||
fieldName: string;
|
fieldName: string;
|
||||||
placeholderAutofill?: boolean;
|
placeholderAutofill?: boolean;
|
||||||
|
placeholderWarningCompare?: number | string;
|
||||||
|
placeholderWarning?: string;
|
||||||
onChange: (value: any) => void;
|
onChange: (value: any) => void;
|
||||||
}>) {
|
}>) {
|
||||||
const fieldId = useId();
|
const fieldId = useId();
|
||||||
@@ -56,6 +60,43 @@ export default function NumberField({
|
|||||||
return val;
|
return val;
|
||||||
}, [definition.field_type, value]);
|
}, [definition.field_type, value]);
|
||||||
|
|
||||||
|
const rightSection = useMemo(() => {
|
||||||
|
if (
|
||||||
|
definition.placeholder &&
|
||||||
|
placeholderAutofill &&
|
||||||
|
numericalValue == null
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<AutoFillRightSection
|
||||||
|
value={field.value}
|
||||||
|
fieldName={field.name}
|
||||||
|
definition={definition}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else if (placeholderWarning && numericalValue != null) {
|
||||||
|
if (
|
||||||
|
placeholderWarningCompare != null &&
|
||||||
|
numericalValue === placeholderWarningCompare
|
||||||
|
) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<AutoFillWarning fieldName={field.name} message={placeholderWarning} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}, [
|
||||||
|
definition,
|
||||||
|
placeholderAutofill,
|
||||||
|
placeholderWarning,
|
||||||
|
placeholderWarningCompare,
|
||||||
|
numericalValue,
|
||||||
|
field.name,
|
||||||
|
field.value,
|
||||||
|
onChange
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NumberInput
|
<NumberInput
|
||||||
{...definition}
|
{...definition}
|
||||||
@@ -74,18 +115,7 @@ export default function NumberField({
|
|||||||
onChange(value);
|
onChange(value);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
rightSection={
|
rightSection={rightSection}
|
||||||
definition.placeholder &&
|
|
||||||
placeholderAutofill &&
|
|
||||||
numericalValue == null && (
|
|
||||||
<AutoFillRightSection
|
|
||||||
value={field.value}
|
|
||||||
fieldName={field.name}
|
|
||||||
definition={definition}
|
|
||||||
onChange={onChange}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,9 @@ export function useSalesOrderLineItemFields({
|
|||||||
},
|
},
|
||||||
sale_price: {
|
sale_price: {
|
||||||
placeholder: salePrice,
|
placeholder: salePrice,
|
||||||
placeholderAutofill: true
|
placeholderAutofill: true,
|
||||||
|
placeholderWarningCompare: salePrice,
|
||||||
|
placeholderWarning: t`Price based on part and quantity differs${salePrice ? `; suggested: (${salePrice})` : '.'}`
|
||||||
},
|
},
|
||||||
sale_price_currency: {
|
sale_price_currency: {
|
||||||
icon: <IconCoins />,
|
icon: <IconCoins />,
|
||||||
|
|||||||
Reference in New Issue
Block a user