Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

Add UI to update long descriptions again (#859)

Gaurav Bhatt760b2c117b45
diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.ts
index 54fb3ae717..9080dd8191 100644
--- a/apps/erp/app/modules/items/items.service.ts
+++ b/apps/erp/app/modules/items/items.service.ts
@@ -2738,6 +2738,7 @@ export async function upsertConsumable(
.insert({
readableId: consumable.id,
name: consumable.name,
+ description: consumable.description,
type: "Consumable",
replenishmentSystem: consumable.replenishmentSystem,
defaultMethodType: consumable.defaultMethodType,
@@ -2879,6 +2880,7 @@ export async function upsertPart(
readableId: part.id,
revision: part.revision ?? "0",
name: part.name,
+ description: part.description,
type: "Part",
replenishmentSystem: part.replenishmentSystem,
defaultMethodType: part.defaultMethodType,
@@ -3510,6 +3512,7 @@ export async function upsertMaterial(
.insert({
readableId: material.id,
name: material.name,
+ description: material.description,
type: "Material",
replenishmentSystem: material.replenishmentSystem,
defaultMethodType: material.defaultMethodType,
@@ -3555,6 +3558,7 @@ export async function upsertMaterial(
.insert({
readableId: material.id,
name: material.name,
+ description: material.description,
type: "Material",
replenishmentSystem: material.replenishmentSystem,
defaultMethodType: material.defaultMethodType,
@@ -4075,6 +4079,7 @@ export async function upsertTool(
readableId: tool.id,
revision: tool.revision ?? "0",
name: tool.name,
+ description: tool.description,
type: "Tool",
replenishmentSystem: tool.replenishmentSystem,
defaultMethodType: tool.defaultMethodType,
diff --git a/apps/erp/app/modules/items/ui/Consumables/ConsumableForm.tsx b/apps/erp/app/modules/items/ui/Consumables/ConsumableForm.tsx
index a11bf94f16..822a1388cf 100644
--- a/apps/erp/app/modules/items/ui/Consumables/ConsumableForm.tsx
+++ b/apps/erp/app/modules/items/ui/Consumables/ConsumableForm.tsx
@@ -147,15 +147,16 @@ const ConsumableForm = ({
/>
)}
- <Input name="name" label={t`Short Description`} />
+ <Input
+ name="name"
+ label={t`Short Description`}
+ characterLimit={40}
+ />
<Select
name="itemTrackingType"
label={t`Tracking Type`}
options={itemTrackingTypeOptions}
/>
- {isEditing && (
- <TextArea name="description" label={t`Long Description`} />
- )}
<DefaultMethodType
name="defaultMethodType"
@@ -196,6 +197,9 @@ const ConsumableForm = ({
tags={initialValues.tags}
/>
</div>
+ <div className="mt-4 w-full">
+ <TextArea name="description" label={t`Long Description`} />
+ </div>
</ModalCardBody>
<ModalCardFooter>
<Submit
diff --git a/apps/erp/app/modules/items/ui/Consumables/ConsumableProperties.tsx b/apps/erp/app/modules/items/ui/Consumables/ConsumableProperties.tsx
index 96cc394ee8..3c017e9995 100644
--- a/apps/erp/app/modules/items/ui/Consumables/ConsumableProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Consumables/ConsumableProperties.tsx
@@ -35,7 +35,7 @@ import type {
PickMethod,
SupplierPart
} from "../../types";
-import { FileBadge } from "../Item";
+import { FileBadge, ItemDescription } from "../Item";
type ConsumablePropertiesProps = {
data?: {
@@ -107,6 +107,7 @@ const ConsumableProperties = ({ data }: ConsumablePropertiesProps) => {
(
field:
| "name"
+ | "description"
| "replenishmentSystem"
| "defaultMethodType"
| "itemTrackingType"
@@ -270,6 +271,7 @@ const ConsumableProperties = ({ data }: ConsumablePropertiesProps) => {
name="name"
inline
size="sm"
+ characterLimit={40}
value={routeData?.consumableSummary?.name ?? ""}
onBlur={(e) => {
onUpdate("name", e.target.value ?? null);
@@ -394,6 +396,11 @@ const ConsumableProperties = ({ data }: ConsumablePropertiesProps) => {
/>
</VStack>
+ <ItemDescription
+ value={routeData?.consumableSummary?.description ?? ""}
+ onChange={(value) => onUpdate("description", value)}
+ />
+
<VStack spacing={2}>
<HStack className="w-full justify-between">
<h3 className="text-xs text-muted-foreground">
diff --git a/apps/erp/app/modules/items/ui/Item/ItemDescription.tsx b/apps/erp/app/modules/items/ui/Item/ItemDescription.tsx
new file mode 100644
index 0000000000..63c3103631
--- /dev/null
+++ b/apps/erp/app/modules/items/ui/Item/ItemDescription.tsx
@@ -0,0 +1,81 @@
+import { TextAreaControlled, ValidatedForm } from "@carbon/form";
+import {
+ HStack,
+ IconButton,
+ TruncatedTooltipText,
+ VStack
+} from "@carbon/react";
+import { useLingui } from "@lingui/react/macro";
+import { useState } from "react";
+import { LuPlus, LuSettings2 } from "react-icons/lu";
+import { z } from "zod";
+
+const descriptionValidator = z.object({
+ description: z.string().optional()
+});
+
+type ItemDescriptionProps = {
+ value: string;
+ onChange: (value: string | null) => void;
+};
+
+/**
+ * Inline long description for item Properties panels. Textarea-based so the
+ * multi-line content reads naturally: while not editing it shows a clamped
+ * preview (line-clamp-3) that reveals the full text on hover via
+ * TruncatedTooltipText; clicking the edit button swaps in a textarea that
+ * persists onBlur through the same bulkUpdateItems path. Controlled `value`
+ * keeps the field in sync (no stale text).
+ */
+const ItemDescription = ({ value, onChange }: ItemDescriptionProps) => {
+ const { t } = useLingui();
+ const [isEditing, setIsEditing] = useState(false);
+
+ if (isEditing) {
+ return (
+ <ValidatedForm
+ defaultValues={{ description: value ?? undefined }}
+ validator={descriptionValidator}
+ className="w-full"
+ >
+ <TextAreaControlled
+ autoFocus
+ label={t`Long Description`}
+ name="description"
+ rows={3}
+ value={value ?? ""}
+ onBlur={(e) => {
+ onChange(e.target.value ?? null);
+ setIsEditing(false);
+ }}
+ className="text-muted-foreground"
+ />
+ </ValidatedForm>
+ );
+ }
+
+ return (
+ <VStack spacing={1} className="w-full">
+ <span className="text-xs text-muted-foreground">{t`Long Description`}</span>
+ <HStack spacing={0} className="w-full justify-between items-start">
+ {value && (
+ <TruncatedTooltipText
+ className="flex-grow text-sm line-clamp-3 text-muted-foreground"
+ tooltip={value}
+ >
+ {value}
+ </TruncatedTooltipText>
+ )}
+ <IconButton
+ icon={value ? <LuSettings2 /> : <LuPlus />}
+ aria-label={value ? "Edit" : "Add"}
+ size="sm"
+ variant="secondary"
+ onClick={() => setIsEditing(true)}
+ />
+ </HStack>
+ </VStack>
+ );
+};
+
+export default ItemDescription;
diff --git a/apps/erp/app/modules/items/ui/Item/ItemForm.tsx b/apps/erp/app/modules/items/ui/Item/ItemForm.tsx
index eca8f7ddc2..4631ed4f31 100644
--- a/apps/erp/app/modules/items/ui/Item/ItemForm.tsx
+++ b/apps/erp/app/modules/items/ui/Item/ItemForm.tsx
@@ -144,15 +144,17 @@ const ItemForm = ({ initialValues, type }: ItemFormProps) => {
label={`${getLabel(type)} ID`}
/>
- <Input name="name" label={t`Short Description`} />
+ <Input
+ name="name"
+ label={t`Short Description`}
+ characterLimit={40}
+ />
<Select
name="itemTrackingType"
label={t`Tracking Type`}
options={itemTrackingTypeOptions}
/>
- <TextArea name="description" label={t`Description`} />
-
<Select
name="replenishmentSystem"
label={t`Replenishment System`}
@@ -182,6 +184,9 @@ const ItemForm = ({ initialValues, type }: ItemFormProps) => {
<Boolean name="active" label={t`Active`} />
</div>
+ <div className="mt-4 w-full">
+ <TextArea name="description" label={t`Long Description`} />
+ </div>
</CardContent>
<CardFooter>
<Submit isDisabled={!permissions.can("update", "parts")}>
diff --git a/apps/erp/app/modules/items/ui/Item/index.ts b/apps/erp/app/modules/items/ui/Item/index.ts
index 34bf7671df..a37b567a07 100644
--- a/apps/erp/app/modules/items/ui/Item/index.ts
+++ b/apps/erp/app/modules/items/ui/Item/index.ts
@@ -3,6 +3,7 @@ import BillOfProcess from "./BillOfProcess";
import BoMExplorer, { BoMActions } from "./BoMExplorer";
import { FileBadge } from "./FileBadge";
import ItemCostingForm from "./ItemCostingForm";
+import ItemDescription from "./ItemDescription";
import ItemDocuments from "./ItemDocuments";
import ItemForm from "./ItemForm";
import ItemNotes from "./ItemNotes";
@@ -23,6 +24,7 @@ export {
BoMExplorer,
FileBadge,
ItemCostingForm,
+ ItemDescription,
ItemDocuments,
ItemForm,
ItemNotes,
diff --git a/apps/erp/app/modules/items/ui/Materials/MaterialForm.tsx b/apps/erp/app/modules/items/ui/Materials/MaterialForm.tsx
index 2a62d53901..f042674787 100644
--- a/apps/erp/app/modules/items/ui/Materials/MaterialForm.tsx
+++ b/apps/erp/app/modules/items/ui/Materials/MaterialForm.tsx
@@ -28,6 +28,7 @@ import {
Number,
Select,
Submit,
+ TextArea,
UnitOfMeasure
} from "~/components/Form";
import MaterialDimension from "~/components/Form/MaterialDimension";
@@ -63,9 +64,9 @@ const MaterialForm = ({
}: MaterialFormProps) => {
const { t } = useLingui();
const [materialId, setMaterialId] = useState(initialValues.id ?? "");
- const [description, setDescription] = useState(
- initialValues.description ?? ""
- );
+ // Holds the auto-generated material short description (persisted to `name`),
+ // composed from the selected substance/grade/shape/dimensions/finish/type.
+ const [generatedName, setGeneratedName] = useState(initialValues.name ?? "");
const [properties, setProperties] = useState<{
substance?: string;
@@ -91,7 +92,7 @@ const MaterialForm = ({
useEffect(() => {
setMaterialId(getMaterialId(properties));
- setDescription(getMaterialDescription(properties));
+ setGeneratedName(getMaterialDescription(properties));
}, [properties]);
useEffect(() => {
@@ -172,7 +173,7 @@ const MaterialForm = ({
{!useCustomId && (
<>
<Hidden name="id" value={materialId} />
- <Hidden name="name" value={description} />
+ <Hidden name="name" value={generatedName} />
</>
)}
<div
@@ -201,9 +202,9 @@ const MaterialForm = ({
<InputControlled
name="name"
label={t`Short Description`}
- value={description}
+ value={generatedName}
onChange={(value) => {
- setDescription(value ?? "");
+ setGeneratedName(value ?? "");
}}
/>
</>
@@ -326,6 +327,9 @@ const MaterialForm = ({
<CustomFormFields table="material" tags={initialValues.tags} />
</div>
+ <div className="mt-4 w-full">
+ <TextArea name="description" label={t`Long Description`} />
+ </div>
</ModalCardBody>
<ModalCardFooter>
<Submit
diff --git a/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx b/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx
index 6f9854abc3..9d0bda218a 100644
--- a/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Materials/MaterialProperties.tsx
@@ -55,7 +55,7 @@ import type {
PickMethod,
SupplierPart
} from "../../types";
-import { FileBadge } from "../Item";
+import { FileBadge, ItemDescription } from "../Item";
type MaterialPropertiesProps = {
data?: {
@@ -145,6 +145,7 @@ const MaterialProperties = ({ data }: MaterialPropertiesProps) => {
(
field:
| "name"
+ | "description"
| "replenishmentSystem"
| "defaultMethodType"
| "itemTrackingType"
@@ -655,6 +656,11 @@ const MaterialProperties = ({ data }: MaterialPropertiesProps) => {
/>
</ValidatedForm>
+ <ItemDescription
+ value={routeData?.materialSummary?.description ?? ""}
+ onChange={(value) => onUpdate("description", value)}
+ />
+
<VStack spacing={2}>
<HStack className="w-full justify-between">
<h3 className="text-xs text-muted-foreground">
diff --git a/apps/erp/app/modules/items/ui/Parts/PartForm.tsx b/apps/erp/app/modules/items/ui/Parts/PartForm.tsx
index d6fa4b7cd0..5e47989e2f 100644
--- a/apps/erp/app/modules/items/ui/Parts/PartForm.tsx
+++ b/apps/erp/app/modules/items/ui/Parts/PartForm.tsx
@@ -40,6 +40,7 @@ import {
Number,
Select,
Submit,
+ TextArea,
UnitOfMeasure
} from "~/components/Form";
import { ReplenishmentSystemIcon } from "~/components/Icons";
@@ -274,7 +275,11 @@ const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {
isReadOnly={isEditing}
/>
- <Input name="name" label={t`Short Description`} />
+ <Input
+ name="name"
+ label={t`Short Description`}
+ characterLimit={40}
+ />
<Select
name="replenishmentSystem"
@@ -335,6 +340,9 @@ const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {
<CustomFormFields table="part" tags={initialValues.tags} />
</div>
+ <div className="mt-4 w-full">
+ <TextArea name="description" label={t`Long Description`} />
+ </div>
<VStack spacing={2} className="mt-4 w-full">
<label
htmlFor="model-upload"
diff --git a/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx b/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
index 3cc4d39acd..28a38f5266 100644
--- a/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Parts/PartProperties.tsx
@@ -51,7 +51,7 @@ import type {
PickMethod,
SupplierPart
} from "../../types";
-import { FileBadge } from "../Item";
+import { FileBadge, ItemDescription } from "../Item";
type PartPropertiesProps = {
data?: {
@@ -117,6 +117,7 @@ const PartProperties = ({ data }: PartPropertiesProps) => {
| "itemPostingGroupId"
| "partId"
| "name"
+ | "description"
| "replenishmentSystem"
| "unitOfMeasureCode"
| "requiresInspection",
@@ -292,6 +293,7 @@ const PartProperties = ({ data }: PartPropertiesProps) => {
name="name"
inline
size="sm"
+ characterLimit={40}
value={routeData?.partSummary?.name ?? ""}
onBlur={(e) => {
onUpdate("name", e.target.value ?? null);
@@ -504,6 +506,11 @@ const PartProperties = ({ data }: PartPropertiesProps) => {
/>
</ValidatedForm>
+ <ItemDescription
+ value={routeData?.partSummary?.description ?? ""}
+ onChange={(value) => onUpdate("description", value)}
+ />
+
<VStack spacing={2}>
<HStack className="w-full justify-between">
<h3 className="text-xs text-muted-foreground">
diff --git a/apps/erp/app/modules/items/ui/Tools/ToolForm.tsx b/apps/erp/app/modules/items/ui/Tools/ToolForm.tsx
index 6b50dea6b8..66ef2f11d8 100644
--- a/apps/erp/app/modules/items/ui/Tools/ToolForm.tsx
+++ b/apps/erp/app/modules/items/ui/Tools/ToolForm.tsx
@@ -39,6 +39,7 @@ import {
Number,
Select,
Submit,
+ TextArea,
UnitOfMeasure
} from "~/components/Form";
import { ReplenishmentSystemIcon, TrackingTypeIcon } from "~/components/Icons";
@@ -267,7 +268,11 @@ const ToolForm = ({ initialValues, type = "card", onClose }: ToolFormProps) => {
isReadOnly={isEditing}
/>
- <Input name="name" label={t`Short Description`} />
+ <Input
+ name="name"
+ label={t`Short Description`}
+ characterLimit={40}
+ />
<Select
name="replenishmentSystem"
@@ -325,6 +330,9 @@ const ToolForm = ({ initialValues, type = "card", onClose }: ToolFormProps) => {
<CustomFormFields table="tool" tags={initialValues.tags} />
</div>
+ <div className="mt-4 w-full">
+ <TextArea name="description" label={t`Long Description`} />
+ </div>
<VStack spacing={2} className="mt-4 w-full">
<label
htmlFor="model-upload"
diff --git a/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx b/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
index 0f9d37eac4..8662bc2423 100644
--- a/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
@@ -40,7 +40,7 @@ import type {
SupplierPart,
Tool
} from "../../types";
-import { FileBadge } from "../Item";
+import { FileBadge, ItemDescription } from "../Item";
type ToolPropertiesProps = {
data?: {
@@ -101,6 +101,7 @@ const ToolProperties = ({ data }: ToolPropertiesProps) => {
(
field:
| "name"
+ | "description"
| "replenishmentSystem"
| "defaultMethodType"
| "itemTrackingType"
@@ -281,6 +282,7 @@ const ToolProperties = ({ data }: ToolPropertiesProps) => {
name="name"
inline
size="sm"
+ characterLimit={40}
value={routeData?.toolSummary?.name ?? ""}
onBlur={(e) => {
onUpdate("name", e.target.value ?? null);
@@ -471,6 +473,11 @@ const ToolProperties = ({ data }: ToolPropertiesProps) => {
)}
</VStack>
+ <ItemDescription
+ value={routeData?.toolSummary?.description ?? ""}
+ onChange={(value) => onUpdate("description", value)}
+ />
+
<VStack spacing={2}>
<HStack className="w-full justify-between">
<h3 className="text-xs text-muted-foreground">
diff --git a/apps/erp/app/routes/x+/items+/update.tsx b/apps/erp/app/routes/x+/items+/update.tsx
index 80851f00e7..6274be19d9 100644
--- a/apps/erp/app/routes/x+/items+/update.tsx
+++ b/apps/erp/app/routes/x+/items+/update.tsx
@@ -57,6 +57,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
case "defaultMethodType":
case "name":
+ case "description":
case "replenishmentSystem":
case "unitOfMeasureCode":
if (field === "replenishmentSystem" && value !== "Buy and Make") {
diff --git a/packages/form/src/components/Input.tsx b/packages/form/src/components/Input.tsx
index 5bb0ae81ae..ca88077ca9 100644
--- a/packages/form/src/components/Input.tsx
+++ b/packages/form/src/components/Input.tsx
@@ -9,8 +9,8 @@ import {
InputLeftAddon,
InputRightAddon
} from "@carbon/react";
-import type { ReactNode } from "react";
-import { forwardRef } from "react";
+import type { ChangeEvent, ReactNode } from "react";
+import { forwardRef, useState } from "react";
import { useField } from "../hooks";
import { useFormStateContext } from "../internal/formStateContext";
import type { ValidationBehaviorOptions } from "../internal/getInputProps";
@@ -22,6 +22,7 @@ type FormInputProps = InputProps & {
isOptional?: boolean;
isRequired?: boolean;
helperText?: string;
+ characterLimit?: number;
prefix?: string;
suffix?: string;
validationBehavior?: ValidationBehaviorOptions;
@@ -37,9 +38,11 @@ const Input = forwardRef<HTMLInputElement, FormInputProps>(
isOptional,
isRequired,
helperText,
+ characterLimit,
prefix,
suffix,
onConfigure,
+ maxLength,
isDisabled: isDisabledProp,
isReadOnly: isReadOnlyProp,
...rest
@@ -49,11 +52,18 @@ const Input = forwardRef<HTMLInputElement, FormInputProps>(
const {
getInputProps,
error,
+ defaultValue,
isOptional: fieldIsOptional
} = useField(name);
const formState = useFormStateContext();
const isDisabled = formState.isDisabled || isDisabledProp;
const isReadOnly = formState.isReadOnly || isReadOnlyProp;
+ const [characterCount, setCharacterCount] = useState(
+ defaultValue?.length ?? 0
+ );
+ const onChange = (e: ChangeEvent<HTMLInputElement>) => {
+ if (characterLimit) setCharacterCount(e.target.value.length);
+ };
const resolvedIsOptional =
isOptional ?? (isRequired ? false : (fieldIsOptional ?? false));
@@ -87,6 +97,8 @@ const Input = forwardRef<HTMLInputElement, FormInputProps>(
id: name,
...rest
})}
+ maxLength={characterLimit ?? maxLength}
+ {...(characterLimit ? { onChange } : {})}
isDisabled={isDisabled}
isReadOnly={isReadOnly}
/>
@@ -99,11 +111,18 @@ const Input = forwardRef<HTMLInputElement, FormInputProps>(
id: name,
...rest
})}
+ maxLength={characterLimit ?? maxLength}
+ {...(characterLimit ? { onChange } : {})}
isDisabled={isDisabled}
isReadOnly={isReadOnly}
/>
)}
+ {characterLimit && (
+ <FormHelperText>
+ {characterCount}/{characterLimit}
+ </FormHelperText>
+ )}
{helperText && <FormHelperText>{helperText}</FormHelperText>}
{error && <FormErrorMessage>{error}</FormErrorMessage>}
</FormControl>
diff --git a/packages/form/src/components/InputControlled.tsx b/packages/form/src/components/InputControlled.tsx
index feb93f281e..74d8ba93c7 100644
--- a/packages/form/src/components/InputControlled.tsx
+++ b/packages/form/src/components/InputControlled.tsx
@@ -27,6 +27,7 @@ type FormInputControlledProps = Omit<InputProps, "value" | "onChange"> & {
isUppercase?: boolean;
isRequired?: boolean;
helperText?: string;
+ characterLimit?: number;
prefix?: string;
suffix?: string;
inline?: boolean;
@@ -44,6 +45,7 @@ const InputControlled = forwardRef<HTMLInputElement, FormInputControlledProps>(
isOptional,
isRequired,
helperText,
+ characterLimit,
prefix,
suffix,
value,
@@ -55,6 +57,7 @@ const InputControlled = forwardRef<HTMLInputElement, FormInputControlledProps>(
isDisabled: isDisabledProp,
onBlur,
onConfigure,
+ maxLength,
...rest
},
ref
@@ -145,6 +148,7 @@ const InputControlled = forwardRef<HTMLInputElement, FormInputControlledProps>(
...rest,
value: controlValue
})}
+ maxLength={characterLimit ?? maxLength}
onChange={handleChange}
value={controlValue}
isReadOnly={isReadOnly}
@@ -176,6 +180,7 @@ const InputControlled = forwardRef<HTMLInputElement, FormInputControlledProps>(
...rest,
value: controlValue
})}
+ maxLength={characterLimit ?? maxLength}
onChange={handleChange}
value={controlValue}
isReadOnly={isReadOnly}
@@ -193,6 +198,11 @@ const InputControlled = forwardRef<HTMLInputElement, FormInputControlledProps>(
}}
/>
)}
+ {characterLimit && (
+ <FormHelperText>
+ {controlValue?.length ?? 0}/{characterLimit}
+ </FormHelperText>
+ )}
{helperText && <FormHelperText>{helperText}</FormHelperText>}
{error && <FormErrorMessage>{error}</FormErrorMessage>}
</FormControl>