mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-30 12:45:42 +00:00
Stock form fixes (#10673)
* Improve rendering of SupplierPart in forms - Display pack_quantity * Ensure boolean values have default
This commit is contained in:
@@ -2,7 +2,7 @@ import { isTrue } from '@lib/functions/Conversion';
|
||||
import type { ApiFormFieldType } from '@lib/types/Forms';
|
||||
import { Switch } from '@mantine/core';
|
||||
import { useId } from '@mantine/hooks';
|
||||
import { useMemo } from 'react';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import type { FieldValues, UseControllerReturn } from 'react-hook-form';
|
||||
|
||||
export function BooleanField({
|
||||
@@ -25,6 +25,13 @@ export function BooleanField({
|
||||
|
||||
const { value } = field;
|
||||
|
||||
// Set default value if value is undefined
|
||||
useEffect(() => {
|
||||
if (value === undefined) {
|
||||
onChange(definition.default ?? false);
|
||||
}
|
||||
}, [value, definition]);
|
||||
|
||||
// Coerce the value to a (stringified) boolean value
|
||||
const booleanValue: boolean = useMemo(() => {
|
||||
return isTrue(value);
|
||||
@@ -33,6 +40,7 @@ export function BooleanField({
|
||||
return (
|
||||
<Switch
|
||||
{...definition}
|
||||
defaultValue={definition.default ?? false}
|
||||
checked={booleanValue}
|
||||
id={fieldId}
|
||||
aria-label={`boolean-field-${fieldName}`}
|
||||
|
||||
@@ -79,15 +79,22 @@ export function RenderSupplierPart(
|
||||
const supplier = instance.supplier_detail ?? {};
|
||||
const part = instance.part_detail ?? {};
|
||||
|
||||
const secondary: string = instance.SKU;
|
||||
let suffix: string = part.full_name;
|
||||
|
||||
if (instance.pack_quantity) {
|
||||
suffix += ` (${instance.pack_quantity})`;
|
||||
}
|
||||
|
||||
return (
|
||||
<RenderInlineModel
|
||||
{...props}
|
||||
primary={supplier?.name}
|
||||
secondary={instance.SKU}
|
||||
secondary={secondary}
|
||||
image={
|
||||
part?.thumbnail ?? part?.image ?? supplier?.thumbnail ?? supplier?.image
|
||||
}
|
||||
suffix={part.full_name}
|
||||
suffix={suffix}
|
||||
url={
|
||||
props.link
|
||||
? getDetailUrl(ModelType.supplierpart, instance.pk)
|
||||
|
||||
Reference in New Issue
Block a user