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.

feat: delete material with fetcher and styled material title

Brad Barbin690034557802
diff --git a/apps/carbon/app/components/SortableList.tsx b/apps/carbon/app/components/SortableList.tsx
index e32b95ac39..7cc9e5dca6 100644
--- a/apps/carbon/app/components/SortableList.tsx
+++ b/apps/carbon/app/components/SortableList.tsx
@@ -16,7 +16,7 @@ import { LuTrash } from "react-icons/lu";
export interface Item {
id: string;
- text: string;
+ title: ReactNode;
checked: boolean;
details?: ReactNode;
order?: "With Previous" | "After Previous";
@@ -120,7 +120,7 @@ function SortableListItem<T>({
<div ref={ref} className={cn(isExpanded ? "w-full" : "", "z-20 ")}>
<motion.div
layout="position"
- className="grid items-center justify-between grid-cols-[1fr_auto] w-full gap-2"
+ className="grid items-center justify-between grid-cols-[1fr_auto] w-full gap-2 py-1"
>
<AnimatePresence>
{!isExpanded ? (
@@ -137,7 +137,7 @@ function SortableListItem<T>({
id={`checkbox-${item.id}`}
aria-label="Mark to delete"
onCheckedChange={() => onToggleItem(item.id)}
- className="ml-3 h-5 w-5 rounded-md border-foreground/20 bg-background/30 data-[state=checked]:bg-background data-[state=checked]:text-red-200 flex flex-shrink-0 "
+ className="ml-3 border-foreground/20 bg-background/30 data-[state=checked]:bg-background data-[state=checked]:text-red-200 flex flex-shrink-0 "
/>
{/* List Order */}
<p className="font-mono text-xs pl-1 text-foreground/50 flex flex-shrink-0">
@@ -160,16 +160,23 @@ function SortableListItem<T>({
}}
>
<HStack className="w-full justify-between">
- <h4
- className={cn(
- "flex tracking-tighter text-base md:text-lg truncate",
- item.checked
- ? "text-red-400"
- : "text-foreground dark:text-foreground/70"
- )}
- >
- {item.text}
- </h4>
+ {typeof item.title === "string" ? (
+ <h4
+ className={cn(
+ "flex tracking-tighter text-base md:text-lg truncate",
+ item.checked
+ ? "text-red-400"
+ : "text-foreground dark:text-foreground/70"
+ )}
+ >
+ {item.title}
+ </h4>
+ ) : (
+ <div className={item.checked ? "text-red-400" : ""}>
+ {item.title}
+ </div>
+ )}
+
{item.details && (
<div className="flex flex-shrink-0">
{item.details}
diff --git a/apps/carbon/app/components/TreeView/TreeView.tsx b/apps/carbon/app/components/TreeView/TreeView.tsx
index f41bb19527..b283dda6c5 100644
--- a/apps/carbon/app/components/TreeView/TreeView.tsx
+++ b/apps/carbon/app/components/TreeView/TreeView.tsx
@@ -149,6 +149,7 @@ type TreeStateHookProps<TData, TFilterValue> = {
}) => number;
parentRef: RefObject<any>;
filter?: Filter<TData, TFilterValue>;
+ isEager?: boolean;
};
//this is so Framer Motion can be used to render the components
@@ -192,6 +193,7 @@ export function useTree<TData, TFilterValue>({
parentRef,
estimatedRowHeight,
filter,
+ isEager,
}: TreeStateHookProps<TData, TFilterValue>): UseTreeStateOutput {
const previousNodeCount = useRef(tree.length);
const previousSelectedId = useRef<string | undefined>(selectedId);
@@ -210,13 +212,12 @@ export function useTree<TData, TFilterValue>({
}
}, [state.changes.selectedId]);
- //update tree when the number of nodes changes
+ //update tree when the data changes or the tree length changes
useEffect(() => {
- if (tree.length !== previousNodeCount.current) {
- previousNodeCount.current = tree.length;
+ if (isEager || tree.length !== previousNodeCount.current) {
dispatch({ type: "UPDATE_TREE", payload: { tree } });
}
- }, [previousNodeCount.current, tree.length]);
+ }, [previousNodeCount.current, tree]);
//update the filter, if it's changed
const previousFilter = useRef(filter);
@@ -241,7 +242,7 @@ export function useTree<TData, TFilterValue>({
estimateSize: (index: number) => {
return estimatedRowHeight({
node: tree[index],
- state: state.nodes[tree[index].id],
+ state: state.nodes[tree[index]?.id],
index,
});
},
diff --git a/apps/carbon/app/modules/items/items.service.ts b/apps/carbon/app/modules/items/items.service.ts
index 06084ee4d8..e896c0f9bc 100644
--- a/apps/carbon/app/modules/items/items.service.ts
+++ b/apps/carbon/app/modules/items/items.service.ts
@@ -49,6 +49,13 @@ export async function deleteMaterialSubstance(
return client.from("materialSubstance").delete().eq("id", id);
}
+export async function deleteMethodMaterial(
+ client: SupabaseClient<Database>,
+ id: string
+) {
+ return client.from("methodMaterial").delete().eq("id", id);
+}
+
export async function deleteUnitOfMeasure(
client: SupabaseClient<Database>,
id: string
@@ -482,7 +489,8 @@ export async function getMethodMaterials(
return client
.from("methodMaterial")
.select("*")
- .eq("makeMethodId", makeMethodId);
+ .eq("makeMethodId", makeMethodId)
+ .order("order", { ascending: true });
}
export async function getMethodOperations(
diff --git a/apps/carbon/app/modules/items/ui/Fixtures/FixturesTable.tsx b/apps/carbon/app/modules/items/ui/Fixtures/FixturesTable.tsx
index 9c3ad54659..436d43cdb2 100644
--- a/apps/carbon/app/modules/items/ui/Fixtures/FixturesTable.tsx
+++ b/apps/carbon/app/modules/items/ui/Fixtures/FixturesTable.tsx
@@ -88,20 +88,7 @@ const FixturesTable = memo(
},
},
},
- {
- accessorKey: "replenishmentSystem",
- header: "Replenishment",
- cell: (item) => <Enumerable value={item.getValue<string>()} />,
- meta: {
- filter: {
- type: "static",
- options: itemReplenishmentSystems.map((type) => ({
- value: type,
- label: <Enumerable value={type} />,
- })),
- },
- },
- },
+
{
accessorKey: "defaultMethodType",
header: "Default Method",
@@ -126,6 +113,20 @@ const FixturesTable = memo(
},
},
},
+ {
+ accessorKey: "replenishmentSystem",
+ header: "Replenishment",
+ cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: itemReplenishmentSystems.map((type) => ({
+ value: type,
+ label: <Enumerable value={type} />,
+ })),
+ },
+ },
+ },
{
accessorKey: "customerId",
header: "Customer",
diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx
index bb746b9e30..7368ab965f 100644
--- a/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx
@@ -61,7 +61,16 @@ function makeItems(materials: Material[]): ItemWithData[] {
function makeItem(material: Material): ItemWithData {
return {
id: material.id!,
- text: material.description ?? "",
+ title: (
+ <VStack spacing={0}>
+ <h4 className="font-mono">{material.itemReadableId}</h4>
+ {material?.description && (
+ <span className="text-xs text-muted-foreground">
+ {material.description}{" "}
+ </span>
+ )}
+ </VStack>
+ ),
checked: false,
details: (
<HStack spacing={2}>
@@ -90,8 +99,7 @@ const initialMethodMaterial: Omit<Material, "makeMethodId" | "order"> = {
};
const BillOfMaterial = ({ makeMethodId, materials }: BillOfMaterialProps) => {
- const { supabase } = useSupabase();
- const sortOrderFetcher = useFetcher();
+ const fetcher = useFetcher();
const [items, setItems] = useState<ItemWithData[]>(
makeItems(materials ?? [])
@@ -119,7 +127,7 @@ const BillOfMaterial = ({ makeMethodId, materials }: BillOfMaterialProps) => {
return [
...prevItems,
{
- text: "",
+ title: "",
checked: false,
id: temporaryId,
data: {
@@ -139,18 +147,10 @@ const BillOfMaterial = ({ makeMethodId, materials }: BillOfMaterialProps) => {
setItems((prevItems) => prevItems.filter((item) => item.id !== id));
- const response = await supabase
- ?.from("methodMaterial")
- .delete()
- .eq("id", id);
- if (response?.error) {
- // add the item back to the list if there was an error
- setItems((prevItems) => {
- const updatedItems = [...prevItems];
- updatedItems.splice(itemIndex, 0, item);
- return updatedItems;
- });
- }
+ fetcher.submit(new FormData(), {
+ method: "post",
+ action: path.to.deleteMethodMaterial(makeMethodId, item.id),
+ });
};
const onReorder = (items: ItemWithData[]) => {
@@ -175,7 +175,7 @@ const BillOfMaterial = ({ makeMethodId, materials }: BillOfMaterialProps) => {
const updateSortOrder = useDebounce((updates: Record<string, number>) => {
let formData = new FormData();
formData.append("updates", JSON.stringify(updates));
- sortOrderFetcher.submit(formData, {
+ fetcher.submit(formData, {
method: "post",
action: path.to.methodMaterialsOrder(makeMethodId),
});
diff --git a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
index 605aa6f3ab..76dffb8145 100644
--- a/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
+++ b/apps/carbon/app/modules/items/ui/Item/BillOfProcess.tsx
@@ -67,7 +67,7 @@ function makeItems(operations: Operation[]): ItemWithData[] {
function makeItem(operation: Operation): ItemWithData {
return {
id: operation.id!,
- text: operation.description ?? "",
+ title: operation.description ?? "",
checked: false,
order: operation.operationOrder,
details: <Badge variant="secondary">{operation.operationOrder}</Badge>,
@@ -122,7 +122,7 @@ const BillOfProcess = ({ makeMethodId, operations }: BillOfProcessProps) => {
return [
...prevItems,
{
- text: "",
+ title: "",
checked: false,
id: temporaryId,
data: {
diff --git a/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx b/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx
index 548220df9a..1d9bea5ea2 100644
--- a/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx
+++ b/apps/carbon/app/modules/items/ui/Parts/PartManufacturingForm.tsx
@@ -6,16 +6,20 @@ import {
CardTitle,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
+import { useParams } from "@remix-run/react";
import type { z } from "zod";
import {
Boolean,
CustomFormFields,
Hidden,
+ InputControlled,
Number,
Submit,
} from "~/components/Form";
-import { usePermissions } from "~/hooks";
+import { usePermissions, useRouteData } from "~/hooks";
+import type { PartSummary } from "~/modules/items";
import { partManufacturingValidator } from "~/modules/items";
+import { path } from "~/utils/path";
type PartManufacturingFormProps = {
initialValues: z.infer<typeof partManufacturingValidator>;
@@ -25,6 +29,12 @@ const PartManufacturingForm = ({
initialValues,
}: PartManufacturingFormProps) => {
const permissions = usePermissions();
+ const { itemId } = useParams();
+ if (!itemId) throw new Error("Could not find itemId");
+
+ const routeData = useRouteData<{ partSummary: PartSummary }>(
+ path.to.part(itemId)
+ );
return (
<Card>
@@ -39,8 +49,19 @@ const PartManufacturingForm = ({
<CardContent>
<Hidden name="itemId" />
<div className="grid grid-cols-1 lg:grid-cols-3 gap-x-8 gap-y-4 w-full">
+ <InputControlled
+ isReadOnly
+ name="id"
+ label="Part ID"
+ value={routeData?.partSummary?.id ?? ""}
+ />
+ <InputControlled
+ isReadOnly
+ name="name"
+ label="Name"
+ value={routeData?.partSummary?.name ?? ""}
+ />
<Number name="lotSize" label="Lot Size" />
-
<Boolean
name="manufacturingBlocked"
label="Manufacturing Blocked"
diff --git a/apps/carbon/app/modules/items/ui/Parts/PartsTable.tsx b/apps/carbon/app/modules/items/ui/Parts/PartsTable.tsx
index c521db1859..e690fc8983 100644
--- a/apps/carbon/app/modules/items/ui/Parts/PartsTable.tsx
+++ b/apps/carbon/app/modules/items/ui/Parts/PartsTable.tsx
@@ -81,20 +81,7 @@ const PartsTable = memo(
},
},
},
- {
- accessorKey: "replenishmentSystem",
- header: "Replenishment",
- cell: (item) => <Enumerable value={item.getValue<string>()} />,
- meta: {
- filter: {
- type: "static",
- options: itemReplenishmentSystems.map((type) => ({
- value: type,
- label: <Enumerable value={type} />,
- })),
- },
- },
- },
+
{
accessorKey: "defaultMethodType",
header: "Default Method",
@@ -119,6 +106,20 @@ const PartsTable = memo(
},
},
},
+ {
+ accessorKey: "replenishmentSystem",
+ header: "Replenishment",
+ cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: itemReplenishmentSystems.map((type) => ({
+ value: type,
+ label: <Enumerable value={type} />,
+ })),
+ },
+ },
+ },
{
accessorKey: "active",
header: "Active",
diff --git a/apps/carbon/app/modules/settings/ui/Theme/ThemeForm.tsx b/apps/carbon/app/modules/settings/ui/Theme/ThemeForm.tsx
index a97a6f1a40..2c6ead6171 100644
--- a/apps/carbon/app/modules/settings/ui/Theme/ThemeForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/Theme/ThemeForm.tsx
@@ -44,6 +44,7 @@ const ThemeForm = ({ theme: defaultValues }: ThemeFormProps) => {
if (t) {
onThemeChange(t);
}
+
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mode]);
diff --git a/apps/carbon/app/routes/x+/items+/method b/apps/carbon/app/routes/x+/items+/method
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/apps/carbon/app/routes/x+/items+/methods.$makeMethodId.material.delete.$id.tsx b/apps/carbon/app/routes/x+/items+/methods.$makeMethodId.material.delete.$id.tsx
new file mode 100644
index 0000000000..bfe8afe575
--- /dev/null
+++ b/apps/carbon/app/routes/x+/items+/methods.$makeMethodId.material.delete.$id.tsx
@@ -0,0 +1,36 @@
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import { deleteMethodMaterial } from "~/modules/items";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { assertIsPost } from "~/utils/http";
+import { error } from "~/utils/result";
+
+export async function action({ request, params }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client } = await requirePermissions(request, {
+ delete: "parts",
+ });
+
+ const { makeMethodId, id } = params;
+ if (!makeMethodId) {
+ throw new Error("makeMethodId not found");
+ }
+ if (!id) {
+ throw new Error("id not found");
+ }
+
+ const deleteMaterial = await deleteMethodMaterial(client, id);
+ if (deleteMaterial.error) {
+ return json(
+ {
+ id: null,
+ },
+ await flash(
+ request,
+ error(deleteMaterial.error, "Failed to delete method material")
+ )
+ );
+ }
+
+ return json({});
+}
diff --git a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.tsx b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.tsx
index 2b4758eb2a..15cb5def3b 100644
--- a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.tsx
+++ b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.tsx
@@ -114,6 +114,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export default function PartManufacturing() {
const { methods } = useLoaderData<typeof loader>();
+
const { itemId } = useParams();
if (!itemId) throw new Error("Could not find itemId");
@@ -197,6 +198,7 @@ function BoMExplorer({
return false;
},
},
+ isEager: true,
});
return (
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 70a2c497f9..89c0844d4b 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -212,6 +212,8 @@ export const path = {
generatePath(`${x}/items/forms/delete/${id}`),
deleteMaterialSubstance: (id: string) =>
generatePath(`${x}/items/substances/delete/${id}`),
+ deleteMethodMaterial: (makeMethodId: string, id: string) =>
+ generatePath(`${x}/items/methods/${makeMethodId}/material/delete/${id}`),
deletePartner: (id: string) =>
generatePath(`${x}/resources/partners/delete/${id}`),
deletePaymentTerm: (id: string) =>