mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-30 04:35: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 type { ApiFormFieldType } from '@lib/types/Forms';
|
||||||
import { Switch } from '@mantine/core';
|
import { Switch } from '@mantine/core';
|
||||||
import { useId } from '@mantine/hooks';
|
import { useId } from '@mantine/hooks';
|
||||||
import { useMemo } from 'react';
|
import { useEffect, useMemo } from 'react';
|
||||||
import type { FieldValues, UseControllerReturn } from 'react-hook-form';
|
import type { FieldValues, UseControllerReturn } from 'react-hook-form';
|
||||||
|
|
||||||
export function BooleanField({
|
export function BooleanField({
|
||||||
@@ -25,6 +25,13 @@ export function BooleanField({
|
|||||||
|
|
||||||
const { value } = field;
|
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
|
// Coerce the value to a (stringified) boolean value
|
||||||
const booleanValue: boolean = useMemo(() => {
|
const booleanValue: boolean = useMemo(() => {
|
||||||
return isTrue(value);
|
return isTrue(value);
|
||||||
@@ -33,6 +40,7 @@ export function BooleanField({
|
|||||||
return (
|
return (
|
||||||
<Switch
|
<Switch
|
||||||
{...definition}
|
{...definition}
|
||||||
|
defaultValue={definition.default ?? false}
|
||||||
checked={booleanValue}
|
checked={booleanValue}
|
||||||
id={fieldId}
|
id={fieldId}
|
||||||
aria-label={`boolean-field-${fieldName}`}
|
aria-label={`boolean-field-${fieldName}`}
|
||||||
|
|||||||
@@ -79,15 +79,22 @@ export function RenderSupplierPart(
|
|||||||
const supplier = instance.supplier_detail ?? {};
|
const supplier = instance.supplier_detail ?? {};
|
||||||
const part = instance.part_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 (
|
return (
|
||||||
<RenderInlineModel
|
<RenderInlineModel
|
||||||
{...props}
|
{...props}
|
||||||
primary={supplier?.name}
|
primary={supplier?.name}
|
||||||
secondary={instance.SKU}
|
secondary={secondary}
|
||||||
image={
|
image={
|
||||||
part?.thumbnail ?? part?.image ?? supplier?.thumbnail ?? supplier?.image
|
part?.thumbnail ?? part?.image ?? supplier?.thumbnail ?? supplier?.image
|
||||||
}
|
}
|
||||||
suffix={part.full_name}
|
suffix={suffix}
|
||||||
url={
|
url={
|
||||||
props.link
|
props.link
|
||||||
? getDetailUrl(ModelType.supplierpart, instance.pk)
|
? getDetailUrl(ModelType.supplierpart, instance.pk)
|
||||||
|
|||||||
Reference in New Issue
Block a user