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 people table

Brad Barbinfca4f4157fd4
diff --git a/apps/carbon/app/components/Layout/Navigation/DetailSidebar.tsx b/apps/carbon/app/components/Layout/Navigation/DetailSidebar.tsx
index c6f8be8f4e..636a61c996 100644
--- a/apps/carbon/app/components/Layout/Navigation/DetailSidebar.tsx
+++ b/apps/carbon/app/components/Layout/Navigation/DetailSidebar.tsx
@@ -54,7 +54,7 @@ const DetailSidebar = ({ links }: DetailSidebarProps) => {
variant={isActive ? "primary" : "ghost"}
className="w-full justify-start"
>
- <Link to={route.to}>
+ <Link to={route.to} prefetch="intent">
{route.icon && <route.icon className="mr-2" />}
<span>{route.name}</span>
{route.count !== undefined && (
diff --git a/apps/carbon/app/components/Layout/Navigation/GroupedContentSidebar.tsx b/apps/carbon/app/components/Layout/Navigation/GroupedContentSidebar.tsx
index fa682f864d..e91b60e984 100644
--- a/apps/carbon/app/components/Layout/Navigation/GroupedContentSidebar.tsx
+++ b/apps/carbon/app/components/Layout/Navigation/GroupedContentSidebar.tsx
@@ -31,7 +31,10 @@ const GroupedContentSidebar = ({ groups }: { groups: RouteGroup[] }) => {
variant={isActive ? "primary" : "ghost"}
className="w-full justify-start"
>
- <Link to={route.to + (route.q ? `?q=${route.q}` : "")}>
+ <Link
+ to={route.to + (route.q ? `?q=${route.q}` : "")}
+ prefetch="intent"
+ >
{route.name}
</Link>
</Button>
diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.ts
index 4a92830717..2126a852bc 100644
--- a/apps/carbon/app/modules/resources/resources.service.ts
+++ b/apps/carbon/app/modules/resources/resources.service.ts
@@ -569,8 +569,6 @@ export async function getPeople(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
search: string | null;
- type: string | null;
- active: boolean | null;
}
) {
const employees = await getEmployees(client, args);
diff --git a/apps/carbon/app/modules/resources/ui/People/PeopleTable.tsx b/apps/carbon/app/modules/resources/ui/People/PeopleTable.tsx
index 20a5539de1..050cb5c9df 100644
--- a/apps/carbon/app/modules/resources/ui/People/PeopleTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/People/PeopleTable.tsx
@@ -1,4 +1,5 @@
import {
+ Checkbox,
Enumerable,
HStack,
Hyperlink,
@@ -9,26 +10,22 @@ import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import { BsFillPenFill } from "react-icons/bs";
-import { Avatar, Table } from "~/components";
+import { Avatar, New, TableNew } from "~/components";
import { usePermissions, useUrlParams } from "~/hooks";
import type { AttributeCategory, Person } from "~/modules/resources";
import { DataType } from "~/modules/shared";
+import type { EmployeeType } from "~/modules/users";
import { path } from "~/utils/path";
type PeopleTableProps = {
attributeCategories: AttributeCategory[];
data: Person[];
count: number;
- isEditable?: boolean;
+ employeeTypes: Partial<EmployeeType>[];
};
const PeopleTable = memo(
- ({
- attributeCategories,
- data,
- count,
- isEditable = false,
- }: PeopleTableProps) => {
+ ({ attributeCategories, data, count, employeeTypes }: PeopleTableProps) => {
const navigate = useNavigate();
const permissions = usePermissions();
const [params] = useUrlParams();
@@ -140,6 +137,29 @@ const PeopleTable = memo(
accessorKey: "employeeType.name",
header: "Employee Type",
cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: employeeTypes.map((type) => ({
+ value: type.name!,
+ label: type.name!,
+ })),
+ },
+ },
+ },
+ {
+ accessorKey: "user.active",
+ header: "Active",
+ cell: (item) => <Checkbox isChecked={item.getValue<boolean>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: [
+ { value: "true", label: "Active" },
+ { value: "false", label: "Inactive" },
+ ],
+ },
+ },
},
];
@@ -163,7 +183,7 @@ const PeopleTable = memo(
});
return [...defaultColumns, ...additionalColumns];
- }, [attributeCategories, navigate, renderGenericAttribute]);
+ }, [attributeCategories, employeeTypes, navigate, renderGenericAttribute]);
const renderContextMenu = useMemo(() => {
return permissions.can("update", "resources")
@@ -186,7 +206,7 @@ const PeopleTable = memo(
return (
<>
- <Table<(typeof rows)[number]>
+ <TableNew<(typeof rows)[number]>
// actions={actions}
count={count}
columns={columns}
@@ -194,10 +214,16 @@ const PeopleTable = memo(
defaultColumnPinning={{
left: ["Select", "User"],
}}
+ primaryAction={
+ permissions.can("create", "users") && (
+ <New
+ label="Employee"
+ to={`${path.to.newEmployee}?${params.toString()}`}
+ />
+ )
+ }
renderContextMenu={renderContextMenu}
withColumnOrdering
- withFilters
- withPagination
/>
</>
);
diff --git a/apps/carbon/app/modules/users/ui/Employees/CreateEmployeeModal.tsx b/apps/carbon/app/modules/users/ui/Employees/CreateEmployeeModal.tsx
index c27d34de2f..13e85173a3 100644
--- a/apps/carbon/app/modules/users/ui/Employees/CreateEmployeeModal.tsx
+++ b/apps/carbon/app/modules/users/ui/Employees/CreateEmployeeModal.tsx
@@ -38,7 +38,7 @@ const CreateEmployeeModal = () => {
<Modal
open
onOpenChange={(open) => {
- if (!open) navigate(path.to.employeeAccounts);
+ if (!open) navigate(-1);
}}
>
<ModalOverlay />
diff --git a/apps/carbon/app/modules/users/users.service.ts b/apps/carbon/app/modules/users/users.service.ts
index a9c5ca064e..5ffd3d1664 100644
--- a/apps/carbon/app/modules/users/users.service.ts
+++ b/apps/carbon/app/modules/users/users.service.ts
@@ -65,8 +65,6 @@ export async function getEmployees(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
search: string | null;
- type: string | null;
- active: boolean | null;
}
) {
let query = client
@@ -80,14 +78,6 @@ export async function getEmployees(
query = query.ilike("user.fullName", `%${args.search}%`);
}
- if (args.type) {
- query = query.eq("employeeTypeId", args.type);
- }
-
- if (args.active !== null) {
- query = query.eq("user.active", args.active);
- }
-
query = setGenericQueryFilters(query, args, [
{ column: "user(lastName)", ascending: true },
]);
diff --git a/apps/carbon/app/routes/x+/resources+/people.tsx b/apps/carbon/app/routes/x+/resources+/people.tsx
index 86f88ec0ea..8a3a9a7a85 100644
--- a/apps/carbon/app/routes/x+/resources+/people.tsx
+++ b/apps/carbon/app/routes/x+/resources+/people.tsx
@@ -2,10 +2,8 @@ import { VStack } from "@carbon/react";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
-import { usePermissions } from "~/hooks";
import {
PeopleTable,
- PeopleTableFilters,
getAttributeCategories,
getPeople,
} from "~/modules/resources";
@@ -30,9 +28,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
- const name = searchParams.get("name");
- const type = searchParams.get("type");
- const active = searchParams.get("active") !== "false";
+ const search = searchParams.get("name");
const { limit, offset, sorts, filters } =
getGenericQueryFilters(searchParams);
@@ -40,7 +36,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
const [attributeCategories, employeeTypes, people] = await Promise.all([
getAttributeCategories(client),
getEmployeeTypes(client),
- getPeople(client, { name, type, active, limit, offset, sorts, filters }),
+ getPeople(client, { search, limit, offset, sorts, filters }),
]);
if (attributeCategories.error) {
return redirect(
@@ -69,7 +65,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
return json({
attributeCategories: attributeCategories.data,
- employeeTypes: employeeTypes.data,
+ employeeTypes: employeeTypes.data ?? [],
people: people.data,
count: people.count,
});
@@ -78,16 +74,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
export default function ResourcesPeopleRoute() {
const { attributeCategories, count, employeeTypes, people } =
useLoaderData<typeof loader>();
- const permissions = usePermissions();
return (
<VStack spacing={0} className="h-full">
- <PeopleTableFilters employeeTypes={employeeTypes ?? []} />
<PeopleTable
attributeCategories={attributeCategories}
data={people ?? []}
count={count ?? 0}
- isEditable={permissions.can("update", "resources")}
+ employeeTypes={employeeTypes}
/>
<Outlet />
</VStack>