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

Brad Barbindc24da62b75f
diff --git a/apps/carbon/app/modules/users/ui/Groups/GroupsTable.tsx b/apps/carbon/app/modules/users/ui/Groups/GroupsTable.tsx
index 2e8aaa23d1..de065b9817 100644
--- a/apps/carbon/app/modules/users/ui/Groups/GroupsTable.tsx
+++ b/apps/carbon/app/modules/users/ui/Groups/GroupsTable.tsx
@@ -10,8 +10,8 @@ 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 { Avatar, Table } from "~/components";
-import { usePermissions } from "~/hooks";
+import { Avatar, New, TableNew } from "~/components";
+import { usePermissions, useUrlParams } from "~/hooks";
import type { Group } from "~/modules/users";
import { path } from "~/utils/path";
@@ -23,6 +23,7 @@ type GroupsTableProps = {
const GroupsTable = memo(({ data, count }: GroupsTableProps) => {
const navigate = useNavigate();
const permissions = usePermissions();
+ const [params] = useUrlParams();
const rows = data.map((row) => ({
id: row.data.id,
@@ -113,10 +114,15 @@ const GroupsTable = memo(({ data, count }: GroupsTableProps) => {
);
return (
- <Table<(typeof rows)[number]>
+ <TableNew<(typeof rows)[number]>
data={rows}
count={count}
columns={columns}
+ primaryAction={
+ permissions.can("create", "users") && (
+ <New label="Group" to={`new?${params.toString()}`} />
+ )
+ }
renderContextMenu={renderContextMenu}
/>
);
diff --git a/apps/carbon/app/modules/users/ui/Groups/GroupsTableFilters.tsx b/apps/carbon/app/modules/users/ui/Groups/GroupsTableFilters.tsx
deleted file mode 100644
index 6dc3dacc46..0000000000
--- a/apps/carbon/app/modules/users/ui/Groups/GroupsTableFilters.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import { Button, HStack } from "@carbon/react";
-import { Link } from "@remix-run/react";
-import { IoMdAdd } from "react-icons/io";
-import { TableFilters } from "~/components/Layout";
-import { DebouncedInput } from "~/components/Search";
-import { usePermissions, useUrlParams } from "~/hooks";
-
-const GroupsTableFilters = () => {
- const [params] = useUrlParams();
- const permissions = usePermissions();
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="name" size="sm" placeholder="Search" />
- </HStack>
- <HStack>
- {permissions.can("create", "users") && (
- <Button asChild leftIcon={<IoMdAdd />}>
- <Link to={`new?${params.toString()}`}>New Group</Link>
- </Button>
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default GroupsTableFilters;
diff --git a/apps/carbon/app/modules/users/ui/Groups/index.ts b/apps/carbon/app/modules/users/ui/Groups/index.ts
index 90d56a4f65..0d19184082 100644
--- a/apps/carbon/app/modules/users/ui/Groups/index.ts
+++ b/apps/carbon/app/modules/users/ui/Groups/index.ts
@@ -1,5 +1,4 @@
import GroupForm from "./GroupsForm";
import GroupsTable from "./GroupsTable";
-import GroupsTableFilters from "./GroupsTableFilters";
-export { GroupForm, GroupsTable, GroupsTableFilters };
+export { GroupForm, GroupsTable };
diff --git a/apps/carbon/app/modules/users/users.service.ts b/apps/carbon/app/modules/users/users.service.ts
index 691a5361c2..1ef50c0802 100644
--- a/apps/carbon/app/modules/users/users.service.ts
+++ b/apps/carbon/app/modules/users/users.service.ts
@@ -129,13 +129,13 @@ export async function getGroupMembers(
export async function getGroups(
client: SupabaseClient<Database>,
args?: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
uid: string | null;
}
) {
let query = client.rpc("groups_query", {
_uid: args?.uid ?? "",
- _name: args?.name ?? "",
+ _name: args?.search ?? "",
});
if (args) query = setGenericQueryFilters(query, args);
diff --git a/apps/carbon/app/routes/x+/users+/groups.tsx b/apps/carbon/app/routes/x+/users+/groups.tsx
index 7bb5a76e61..2d7449d69c 100644
--- a/apps/carbon/app/routes/x+/users+/groups.tsx
+++ b/apps/carbon/app/routes/x+/users+/groups.tsx
@@ -4,7 +4,7 @@ import { json } from "@remix-run/node";
import { Outlet, useLoaderData } from "@remix-run/react";
import { arrayToTree } from "performant-array-to-tree";
import type { Group } from "~/modules/users";
-import { GroupsTable, GroupsTableFilters, getGroups } from "~/modules/users";
+import { GroupsTable, getGroups } from "~/modules/users";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
import type { Handle } from "~/utils/handle";
@@ -25,11 +25,19 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
- const name = searchParams.get("name");
+ const search = searchParams.get("search");
const uid = searchParams.get("uid");
- const { limit, offset, sorts } = getGenericQueryFilters(searchParams);
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
- const groups = await getGroups(client, { name, uid, limit, offset, sorts });
+ const groups = await getGroups(client, {
+ search,
+ uid,
+ limit,
+ offset,
+ sorts,
+ filters,
+ });
if (groups.error) {
return json(
@@ -50,7 +58,6 @@ export default function GroupsRoute() {
return (
<VStack spacing={0} className="h-full">
- <GroupsTableFilters />
{/* @ts-ignore */}
<GroupsTable data={groups} count={count} />
<Outlet />