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.

refactor: new table/filter components for shipping methods table

Brad Barbin90cfd5b4a2e4
diff --git a/apps/carbon/app/modules/inventory/inventory.models.ts b/apps/carbon/app/modules/inventory/inventory.models.ts
index 6eec629e64..617bdd8570 100644
--- a/apps/carbon/app/modules/inventory/inventory.models.ts
+++ b/apps/carbon/app/modules/inventory/inventory.models.ts
@@ -29,6 +29,14 @@ export const receiptValidator = z.object({
supplierId: zfd.text(z.string().optional()),
});
+export const shippingCarrierType = [
+ "UPS",
+ "FedEx",
+ "USPS",
+ "DHL",
+ "Other",
+] as const;
+
export const shippingMethodValidator = z.object({
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }),
diff --git a/apps/carbon/app/modules/inventory/inventory.service.ts b/apps/carbon/app/modules/inventory/inventory.service.ts
index 0f629d8b5e..ef1c6c5fd3 100644
--- a/apps/carbon/app/modules/inventory/inventory.service.ts
+++ b/apps/carbon/app/modules/inventory/inventory.service.ts
@@ -79,7 +79,7 @@ export async function getShippingMethod(
export async function getShippingMethods(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
}
) {
let query = client
@@ -89,8 +89,10 @@ export async function getShippingMethods(
})
.eq("active", true);
- if (args.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args.search) {
+ query = query.or(
+ `name.ilike.%${args.search}%,carrier.ilike.%${args.search}%`
+ );
}
query = setGenericQueryFilters(query, args, [
diff --git a/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodForm.tsx b/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodForm.tsx
index dcb0fca0d6..767fa4cef8 100644
--- a/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodForm.tsx
+++ b/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodForm.tsx
@@ -22,7 +22,10 @@ import {
Submit,
} from "~/components/Form";
import { usePermissions } from "~/hooks";
-import { shippingMethodValidator } from "~/modules/inventory";
+import {
+ shippingCarrierType,
+ shippingMethodValidator,
+} from "~/modules/inventory";
import { path } from "~/utils/path";
type ShippingMethodFormProps = {
@@ -39,12 +42,10 @@ const ShippingMethodForm = ({ initialValues }: ShippingMethodFormProps) => {
? !permissions.can("update", "inventory")
: !permissions.can("create", "inventory");
- const shippingCarrierOptions = ["UPS", "FedEx", "USPS", "DHL", "Other"].map(
- (v) => ({
- label: v,
- value: v,
- })
- );
+ const shippingCarrierOptions = shippingCarrierType.map((v) => ({
+ label: v,
+ value: v,
+ }));
return (
<Drawer
diff --git a/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTable.tsx b/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTable.tsx
index e3a2c2898e..61e4ba5ed0 100644
--- a/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTable.tsx
+++ b/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTable.tsx
@@ -4,9 +4,9 @@ import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import { BsFillPenFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
-import { Table } from "~/components";
+import { TableNew } from "~/components";
import { usePermissions, useUrlParams } from "~/hooks";
-import type { ShippingMethod } from "~/modules/inventory";
+import { shippingCarrierType, type ShippingMethod } from "~/modules/inventory";
import { path } from "~/utils/path";
type ShippingMethodsTableProps = {
@@ -39,6 +39,15 @@ const ShippingMethodsTable = memo(
accessorKey: "carrier",
header: "Carrier",
cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: shippingCarrierType.map((v) => ({
+ label: v,
+ value: v,
+ })),
+ },
+ },
},
{
accessorKey: "trackingUrl",
@@ -92,10 +101,13 @@ const ShippingMethodsTable = memo(
);
return (
- <Table<(typeof data)[number]>
+ <TableNew<(typeof data)[number]>
data={data}
columns={columns}
count={count}
+ label="Shipping Method"
+ newPath={path.to.newShippingMethod}
+ newPermission={permissions.can("create", "inventory")}
renderContextMenu={renderContextMenu}
/>
);
diff --git a/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTableFilters.tsx b/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTableFilters.tsx
deleted file mode 100644
index e78fc778f6..0000000000
--- a/apps/carbon/app/modules/inventory/ui/ShippingMethods/ShippingMethodsTableFilters.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import { HStack } from "@carbon/react";
-import { New } from "~/components";
-import { TableFilters } from "~/components/Layout";
-import { DebouncedInput } from "~/components/Search";
-import { usePermissions, useUrlParams } from "~/hooks";
-
-const ShippingMethodsTableFilters = () => {
- const [params] = useUrlParams();
- const permissions = usePermissions();
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="name" size="sm" placeholder="Search" />
- </HStack>
- <HStack>
- {permissions.can("create", "inventory") && (
- <New label="Shipping Method" to={`new?${params.toString()}`} />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default ShippingMethodsTableFilters;
diff --git a/apps/carbon/app/modules/inventory/ui/ShippingMethods/index.ts b/apps/carbon/app/modules/inventory/ui/ShippingMethods/index.ts
index 85db132cde..5affe7b824 100644
--- a/apps/carbon/app/modules/inventory/ui/ShippingMethods/index.ts
+++ b/apps/carbon/app/modules/inventory/ui/ShippingMethods/index.ts
@@ -1,9 +1,4 @@
import ShippingMethodForm from "./ShippingMethodForm";
import ShippingMethodsTable from "./ShippingMethodsTable";
-import ShippingMethodsTableFilters from "./ShippingMethodsTableFilters";
-export {
- ShippingMethodForm,
- ShippingMethodsTable,
- ShippingMethodsTableFilters,
-};
+export { ShippingMethodForm, ShippingMethodsTable };
diff --git a/apps/carbon/app/routes/x+/inventory+/shipping-methods.tsx b/apps/carbon/app/routes/x+/inventory+/shipping-methods.tsx
index 53c9664ad4..8be115ad28 100644
--- a/apps/carbon/app/routes/x+/inventory+/shipping-methods.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/shipping-methods.tsx
@@ -3,11 +3,7 @@ import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
import { getAccountsList } from "~/modules/accounting";
-import {
- ShippingMethodsTable,
- ShippingMethodsTableFilters,
- getShippingMethods,
-} from "~/modules/inventory";
+import { ShippingMethodsTable, getShippingMethods } from "~/modules/inventory";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
import type { Handle } from "~/utils/handle";
@@ -28,15 +24,17 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
- const name = searchParams.get("name");
- const { limit, offset, sorts } = getGenericQueryFilters(searchParams);
+ const search = searchParams.get("search");
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
const [shippingMethods] = await Promise.all([
getShippingMethods(client, {
- name,
+ search,
limit,
offset,
sorts,
+ filters,
}),
getAccountsList(client),
]);
@@ -59,7 +57,6 @@ export default function ShippingMethodsRoute() {
return (
<VStack spacing={0} className="h-full">
- <ShippingMethodsTableFilters />
<ShippingMethodsTable data={shippingMethods ?? []} count={count ?? 0} />
<Outlet />
</VStack>
diff --git a/apps/carbon/app/routes/x+/parts+/groups.tsx b/apps/carbon/app/routes/x+/parts+/groups.tsx
index 032f99ef70..15f42903e2 100644
--- a/apps/carbon/app/routes/x+/parts+/groups.tsx
+++ b/apps/carbon/app/routes/x+/parts+/groups.tsx
@@ -25,7 +25,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
const search = searchParams.get("search");
- const { limit, offset, sorts } = getGenericQueryFilters(searchParams);
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
const [partGroups, accounts] = await Promise.all([
getPartGroups(client, {
@@ -33,6 +34,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
offset,
sorts,
search,
+ filters,
}),
getAccountsList(client),
]);
diff --git a/apps/carbon/app/routes/x+/parts+/uom.tsx b/apps/carbon/app/routes/x+/parts+/uom.tsx
index 1b3cf54dfe..bc96a3604b 100644
--- a/apps/carbon/app/routes/x+/parts+/uom.tsx
+++ b/apps/carbon/app/routes/x+/parts+/uom.tsx
@@ -22,10 +22,11 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
const search = searchParams.get("search");
- const { limit, offset, sorts } = getGenericQueryFilters(searchParams);
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
return json(
- await getUnitOfMeasures(client, { search, limit, offset, sorts })
+ await getUnitOfMeasures(client, { search, limit, offset, sorts, filters })
);
}