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

Brad Barbin5c73e82ec286
diff --git a/apps/carbon/app/components/Table/components/Sort/Sort.tsx b/apps/carbon/app/components/Table/components/Sort/Sort.tsx
index b13334c117..f52e0a9732 100644
--- a/apps/carbon/app/components/Table/components/Sort/Sort.tsx
+++ b/apps/carbon/app/components/Table/components/Sort/Sort.tsx
@@ -13,6 +13,7 @@ import {
PopoverHeader,
PopoverTrigger,
Switch,
+ cn,
} from "@carbon/react";
import { Reorder } from "framer-motion";
import { BsChevronDown, BsSortUp } from "react-icons/bs";
@@ -40,8 +41,9 @@ const Sort = ({ columnAccessors }: SortProps) => {
<IconButton
aria-label="Sort"
title="Sort"
- variant={hasNoSorts ? "ghost" : "primary"}
+ variant={hasNoSorts ? "ghost" : "secondary"}
icon={<BsSortUp />}
+ className={cn(hasNoSorts && "!border-dashed border-border")}
/>
</PopoverTrigger>
<PopoverContent className="w-[420px]">
diff --git a/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTableFilters.tsx b/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTableFilters.tsx
deleted file mode 100644
index 37eb97e3bb..0000000000
--- a/apps/carbon/app/modules/accounting/ui/Currencies/CurrenciesTableFilters.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 CurrenciesTableFilters = () => {
- const [params] = useUrlParams();
- const permissions = usePermissions();
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="name" size="sm" placeholder="Search" />
- </HStack>
- <HStack>
- {permissions.can("create", "accounting") && (
- <New label="Currency" to={`new?${params.toString()}`} />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default CurrenciesTableFilters;
diff --git a/apps/carbon/app/modules/accounting/ui/Currencies/index.ts b/apps/carbon/app/modules/accounting/ui/Currencies/index.ts
index fc5178a429..eef67117cf 100644
--- a/apps/carbon/app/modules/accounting/ui/Currencies/index.ts
+++ b/apps/carbon/app/modules/accounting/ui/Currencies/index.ts
@@ -1,5 +1,4 @@
-import CurrencyForm from "./CurrencyForm";
import CurrenciesTable from "./CurrenciesTable";
-import CurrenciesTableFilters from "./CurrenciesTableFilters";
+import CurrencyForm from "./CurrencyForm";
-export { CurrencyForm, CurrenciesTable, CurrenciesTableFilters };
+export { CurrenciesTable, CurrencyForm };
diff --git a/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTableFilters.tsx b/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTableFilters.tsx
deleted file mode 100644
index ddaf965b0c..0000000000
--- a/apps/carbon/app/modules/accounting/ui/PaymentTerms/PaymentTermsTableFilters.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 PaymentTermsTableFilters = () => {
- const [params] = useUrlParams();
- const permissions = usePermissions();
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="name" size="sm" placeholder="Search" />
- </HStack>
- <HStack>
- {permissions.can("create", "accounting") && (
- <New label="Payment Term" to={`new?${params.toString()}`} />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default PaymentTermsTableFilters;
diff --git a/apps/carbon/app/modules/accounting/ui/PaymentTerms/index.ts b/apps/carbon/app/modules/accounting/ui/PaymentTerms/index.ts
index 08f3aece14..c139e0fcbe 100644
--- a/apps/carbon/app/modules/accounting/ui/PaymentTerms/index.ts
+++ b/apps/carbon/app/modules/accounting/ui/PaymentTerms/index.ts
@@ -1,5 +1,4 @@
import PaymentTermForm from "./PaymentTermForm";
import PaymentTermsTable from "./PaymentTermsTable";
-import PaymentTermsTableFilters from "./PaymentTermsTableFilters";
-export { PaymentTermForm, PaymentTermsTable, PaymentTermsTableFilters };
+export { PaymentTermForm, PaymentTermsTable };
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTableFilters.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTableFilters.tsx
deleted file mode 100644
index 7950d27506..0000000000
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/PurchaseInvoicesTableFilters.tsx
+++ /dev/null
@@ -1,63 +0,0 @@
-import { HStack } from "@carbon/react";
-import { Combobox, New, Select } from "~/components";
-import { TableFilters } from "~/components/Layout";
-import { DebouncedInput } from "~/components/Search";
-import { usePermissions, useUrlParams } from "~/hooks";
-import { purchaseInvoiceStatusType } from "~/modules/invoicing";
-import { useSuppliers } from "~/stores";
-import { path } from "~/utils/path";
-
-const PurchaseInvoicesTableFilters = () => {
- const [suppliers] = useSuppliers();
- const [params, setParams] = useUrlParams();
- const permissions = usePermissions();
-
- const supplierOptions = suppliers
- .filter((supplier) => supplier.id && supplier.name)
- .map((supplier) => ({
- label: supplier.name,
- value: supplier.id,
- }));
-
- const purchaseInvoiceStatusOptions = purchaseInvoiceStatusType.map(
- (status) => ({
- label: status,
- value: status,
- })
- );
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="search" size="sm" placeholder="Search" />
- <Select
- size="sm"
- value={params.get("status") ?? ""}
- isClearable
- options={purchaseInvoiceStatusOptions}
- onChange={(selected) => {
- setParams({ status: selected });
- }}
- placeholder="Status"
- />
- <Combobox
- size="sm"
- value={params.get("supplierId") ?? ""}
- isClearable
- options={supplierOptions}
- onChange={(selected) => {
- setParams({ supplierId: selected });
- }}
- placeholder="Supplier"
- />
- </HStack>
- <HStack>
- {permissions.can("create", "invoicing") && (
- <New label="Purchase Invoice" to={path.to.newPurchaseInvoice} />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default PurchaseInvoicesTableFilters;
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/index.ts b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/index.ts
index c3849cbbf1..ebb14193e0 100644
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/index.ts
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoices/index.ts
@@ -1,4 +1,3 @@
import PurchaseInvoicesTable from "./PurchaseInvoicesTable";
-import PurchaseInvoicesTableFilters from "./PurchaseInvoicesTableFilters";
-export { PurchaseInvoicesTable, PurchaseInvoicesTableFilters };
+export { PurchaseInvoicesTable };
diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.ts
index 91304fe0f6..6173abef22 100644
--- a/apps/carbon/app/modules/resources/resources.service.ts
+++ b/apps/carbon/app/modules/resources/resources.service.ts
@@ -586,37 +586,40 @@ export async function getPeople(
attributeCategories.data.reduce<PersonAttributes>((acc, category) => {
if (!category.userAttribute || !Array.isArray(category.userAttribute))
return acc;
- category.userAttribute.forEach((attribute) => {
- if (
- attribute.userAttributeValue &&
- Array.isArray(attribute.userAttributeValue) &&
- !Array.isArray(attribute.attributeDataType)
- ) {
- const userAttributeId = attribute.id;
- const userAttributeValue = attribute.userAttributeValue.find(
- (attributeValue) => attributeValue.userId === userId
- );
- const value =
- typeof userAttributeValue?.valueBoolean === "boolean"
- ? userAttributeValue.valueBoolean
- : userAttributeValue?.valueDate ||
- userAttributeValue?.valueNumeric ||
- userAttributeValue?.valueText ||
- userAttributeValue?.valueUser;
-
- if (value && userAttributeValue?.id) {
- acc[userAttributeId] = {
- userAttributeValueId: userAttributeValue.id,
- // @ts-ignore
- dataType: attribute.attributeDataType?.id as DataType,
- value,
- user: !Array.isArray(userAttributeValue.user)
- ? userAttributeValue.user
- : undefined,
- };
+ category.userAttribute.forEach(
+ // @ts-ignore
+ (attribute) => {
+ if (
+ attribute.userAttributeValue &&
+ Array.isArray(attribute.userAttributeValue) &&
+ !Array.isArray(attribute.attributeDataType)
+ ) {
+ const userAttributeId = attribute.id;
+ const userAttributeValue = attribute.userAttributeValue.find(
+ (attributeValue) => attributeValue.userId === userId
+ );
+ const value =
+ typeof userAttributeValue?.valueBoolean === "boolean"
+ ? userAttributeValue.valueBoolean
+ : userAttributeValue?.valueDate ||
+ userAttributeValue?.valueNumeric ||
+ userAttributeValue?.valueText ||
+ userAttributeValue?.valueUser;
+
+ if (value && userAttributeValue?.id) {
+ acc[userAttributeId] = {
+ userAttributeValueId: userAttributeValue.id,
+ // @ts-ignore
+ dataType: attribute.attributeDataType?.id as DataType,
+ value,
+ user: !Array.isArray(userAttributeValue.user)
+ ? userAttributeValue.user
+ : undefined,
+ };
+ }
}
}
- });
+ );
return acc;
}, {});
@@ -638,10 +641,8 @@ export async function getShift(
shiftId: string
) {
return client
- .from("shift")
- .select(
- `*, employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`
- )
+ .from("shifts")
+ .select("*")
.eq("id", shiftId)
.eq("active", true)
.single();
@@ -649,27 +650,19 @@ export async function getShift(
export async function getShifts(
client: SupabaseClient<Database>,
- args: GenericQueryFilters & { search: string | null; location: string | null }
+ args: GenericQueryFilters & { search: string | null }
) {
let query = client
- .from("shift")
- .select(
- `*, employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`,
- {
- count: "exact",
- }
- )
- .eq("active", true)
- .eq("employeeShift.user.active", true);
+ .from("shifts")
+ .select("*", {
+ count: "exact",
+ })
+ .eq("active", true);
if (args?.search) {
query = query.ilike("name", `%${args.search}%`);
}
- if (args.location) {
- query = query.eq("locationId", args.location);
- }
-
query = setGenericQueryFilters(query, args, [
{ column: "locationId", ascending: true },
]);
diff --git a/apps/carbon/app/modules/resources/ui/Departments/DepartmentsTableFilters.tsx b/apps/carbon/app/modules/resources/ui/Departments/DepartmentsTableFilters.tsx
deleted file mode 100644
index e2e036e830..0000000000
--- a/apps/carbon/app/modules/resources/ui/Departments/DepartmentsTableFilters.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 DepartmentsTableFilters = () => {
- const [params] = useUrlParams();
- const permissions = usePermissions();
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="name" size="sm" placeholder="Search" />
- </HStack>
- <HStack>
- {permissions.can("create", "resources") && (
- <New label="Department" to={`new?${params.toString()}`} />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default DepartmentsTableFilters;
diff --git a/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTable.tsx b/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTable.tsx
index c2f880d5cf..f223937b7f 100644
--- a/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTable.tsx
@@ -1,7 +1,4 @@
import {
- AvatarGroup,
- AvatarGroupList,
- AvatarOverflowIndicator,
Badge,
Enumerable,
Hyperlink,
@@ -13,70 +10,23 @@ 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 { New, TableNew } from "~/components";
import { usePermissions, useUrlParams } from "~/hooks";
-import type { Shift } from "~/modules/resources";
+import type { Shift, ShiftLocation } from "~/modules/resources";
import { path } from "~/utils/path";
type ShiftsTableProps = {
data: Shift[];
count: number;
+ locations: Partial<ShiftLocation>[];
};
-const ShiftsTable = memo(({ data, count }: ShiftsTableProps) => {
+const ShiftsTable = memo(({ data, count, locations }: ShiftsTableProps) => {
const navigate = useNavigate();
const permissions = usePermissions();
const [params] = useUrlParams();
- const rows = data.map((row) => ({
- id: row.id,
- name: row.name,
- startTime: row.startTime,
- endTime: row.endTime,
- monday: row.monday,
- tuesday: row.tuesday,
- wednesday: row.wednesday,
- thursday: row.thursday,
- friday: row.friday,
- saturday: row.saturday,
- sunday: row.sunday,
- location: {
- name: Array.isArray(row.location)
- ? row.location[0].name
- : row.location?.name,
- },
- // TODO: move this to a view so the code isn't garbage
- employees: Array.isArray(row.employeeShift)
- ? row.employeeShift.reduce<{ name: string; avatarUrl: string | null }[]>(
- (acc, curr) => {
- if (curr.user) {
- if (Array.isArray(curr.user)) {
- curr.user.forEach((user) => {
- acc.push({
- name: user.fullName ?? "",
- avatarUrl: user.avatarUrl,
- });
- });
- } else {
- acc.push({
- name: curr.user.fullName ?? "",
- avatarUrl: curr.user.avatarUrl,
- });
- }
- }
- return acc;
- },
- []
- )
- : row.employeeShift?.user && Array.isArray(row.employeeShift?.user)
- ? row.employeeShift.user.map((user) => ({
- name: user.fullName ?? "",
- avatarUrl: user.avatarUrl,
- }))
- : [],
- }));
-
- const renderDays = useCallback((row: (typeof rows)[number]) => {
+ const renderDays = useCallback((row: Shift) => {
const days = [
row.monday && "M",
row.tuesday && "Tu",
@@ -94,36 +44,17 @@ const ShiftsTable = memo(({ data, count }: ShiftsTableProps) => {
));
}, []);
- const columns = useMemo<ColumnDef<(typeof rows)[number]>[]>(() => {
+ const columns = useMemo<ColumnDef<Shift>[]>(() => {
return [
{
accessorKey: "name",
header: "Shift",
cell: ({ row }) => (
- <Hyperlink onClick={() => navigate(row.original.id)}>
+ <Hyperlink onClick={() => navigate(row.original.id!)}>
{row.original.name}
</Hyperlink>
),
},
- {
- header: "Employees",
- // accessorKey: undefined, // makes the column unsortable
- cell: ({ row }) => (
- <AvatarGroup limit={5} size="sm">
- <AvatarGroupList>
- {row.original.employees.map((employee, index: number) => (
- <Avatar
- key={index}
- name={employee.name ?? undefined}
- title={employee.name ?? undefined}
- path={employee.avatarUrl}
- />
- ))}
- </AvatarGroupList>
- <AvatarOverflowIndicator />
- </AvatarGroup>
- ),
- },
{
accessorKey: "startTime",
header: "Start Time",
@@ -135,24 +66,35 @@ const ShiftsTable = memo(({ data, count }: ShiftsTableProps) => {
cell: (item) => item.getValue(),
},
{
- accessorKey: "location.name",
+ accessorKey: "locationName",
header: "Location",
cell: (item) => <Enumerable value={item.getValue<string>()} />,
+ meta: {
+ filter: {
+ type: "static",
+ options: locations.map((location) => ({
+ value: location.name!,
+ label: <Enumerable value={location.name!} />,
+ })),
+ },
+ },
},
{
+ id: "days",
header: "Days",
+ // @ts-ignore
cell: ({ row }) => renderDays(row.original),
},
];
- }, [navigate, renderDays]);
+ }, [locations, navigate, renderDays]);
const renderContextMenu = useCallback(
- (row: (typeof rows)[number]) => {
+ (row: Shift) => {
return (
<>
<MenuItem
onClick={() => {
- navigate(`${path.to.shift(row.id)}?${params.toString()}}`);
+ navigate(`${path.to.shift(row.id!)}?${params.toString()}}`);
}}
>
<MenuIcon icon={<BsFillPenFill />} />
@@ -161,7 +103,7 @@ const ShiftsTable = memo(({ data, count }: ShiftsTableProps) => {
<MenuItem
disabled={!permissions.can("delete", "resources")}
onClick={() => {
- navigate(`${path.to.deleteShift(row.id)}?${params.toString()}`);
+ navigate(`${path.to.deleteShift(row.id!)}?${params.toString()}`);
}}
>
<MenuIcon icon={<IoMdTrash />} />
@@ -174,10 +116,15 @@ const ShiftsTable = memo(({ data, count }: ShiftsTableProps) => {
);
return (
- <Table<(typeof rows)[number]>
- data={rows}
+ <TableNew<Shift>
+ data={data}
count={count}
columns={columns}
+ primaryAction={
+ permissions.can("create", "resources") && (
+ <New label="Shift" to={`new?${params.toString()}`} />
+ )
+ }
renderContextMenu={renderContextMenu}
/>
);
diff --git a/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTableFilters.tsx b/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTableFilters.tsx
deleted file mode 100644
index 749882a1ac..0000000000
--- a/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTableFilters.tsx
+++ /dev/null
@@ -1,47 +0,0 @@
-import { HStack } from "@carbon/react";
-import { Combobox, New } from "~/components";
-import { TableFilters } from "~/components/Layout";
-import { DebouncedInput } from "~/components/Search";
-import { usePermissions, useUrlParams } from "~/hooks";
-import type { ShiftLocation } from "~/modules/resources";
-
-type ShiftsTableFiltersProps = {
- locations: Partial<ShiftLocation>[];
-};
-
-const ShiftsTableFilters = ({ locations }: ShiftsTableFiltersProps) => {
- const [params, setParams] = useUrlParams();
- const permissions = usePermissions();
-
- const locationOptions =
- locations?.map<{ value: string; label: string }>((location) => ({
- value: location.id!,
- label: location.name!,
- })) ?? [];
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="name" size="sm" placeholder="Search" />
- <Combobox
- size="sm"
- value={params.get("location") ?? ""}
- isClearable
- options={locationOptions}
- onChange={(selected) => {
- setParams({ location: selected });
- }}
- aria-label="Location"
- placeholder="Location"
- />
- </HStack>
- <HStack>
- {permissions.can("create", "resources") && (
- <New label="Shift" to={`new?${params.toString()}`} />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default ShiftsTableFilters;
diff --git a/apps/carbon/app/modules/resources/ui/Shifts/index.ts b/apps/carbon/app/modules/resources/ui/Shifts/index.ts
index f5af231872..df4e0c79f6 100644
--- a/apps/carbon/app/modules/resources/ui/Shifts/index.ts
+++ b/apps/carbon/app/modules/resources/ui/Shifts/index.ts
@@ -1,5 +1,4 @@
-import ShiftsTable from "./ShiftsTable";
-import ShiftsTableFilters from "./ShiftsTableFilters";
import ShiftForm from "./ShiftForm";
+import ShiftsTable from "./ShiftsTable";
-export { ShiftsTable, ShiftsTableFilters, ShiftForm };
+export { ShiftForm, ShiftsTable };
diff --git a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTableFilters.tsx b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTableFilters.tsx
deleted file mode 100644
index 8d37d4ac34..0000000000
--- a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTableFilters.tsx
+++ /dev/null
@@ -1,82 +0,0 @@
-import { HStack } from "@carbon/react";
-import { Combobox, New, Select } from "~/components";
-import { TableFilters } from "~/components/Layout";
-import { DebouncedInput } from "~/components/Search";
-import { usePermissions, useUrlParams } from "~/hooks";
-import { quoteStatusType } from "~/modules/sales";
-import { useCustomers, useParts } from "~/stores";
-import { path } from "~/utils/path";
-
-const QuotesTableFilters = () => {
- const [customers] = useCustomers();
- const [parts] = useParts();
- const [params, setParams] = useUrlParams();
- const permissions = usePermissions();
-
- const customerOptions = customers
- .filter((customer) => customer.id && customer.name)
- .map((customer) => ({
- label: customer.name,
- value: customer.id,
- }));
-
- const partOptions = parts
- .filter((part) => part.id && part.name)
- .map((part) => ({
- label: part.name,
- value: part.id,
- }));
-
- const quoteStatusOptions = quoteStatusType.map((status) => ({
- label: status,
- value: status,
- }));
-
- return (
- <TableFilters>
- <HStack>
- <DebouncedInput param="search" size="sm" placeholder="Search" />
- <Select
- size="sm"
- value={params.get("status") ?? ""}
- isClearable
- options={quoteStatusOptions}
- onChange={(selected) => {
- setParams({ status: selected });
- }}
- aria-label="Status"
- placeholder="Status"
- />
- <Combobox
- size="sm"
- value={params.get("customerId") ?? ""}
- isClearable
- options={customerOptions}
- onChange={(selected) => {
- setParams({ customerId: selected });
- }}
- aria-label="Customer"
- placeholder="Customer"
- />
- <Combobox
- size="sm"
- value={params.get("partId") ?? ""}
- isClearable
- options={partOptions}
- onChange={(selected) => {
- setParams({ partId: selected });
- }}
- aria-label="Part"
- placeholder="Part"
- />
- </HStack>
- <HStack>
- {permissions.can("create", "sales") && (
- <New to={path.to.newQuote} label="Quote" />
- )}
- </HStack>
- </TableFilters>
- );
-};
-
-export default QuotesTableFilters;
diff --git a/apps/carbon/app/routes/x+/resources+/shifts.tsx b/apps/carbon/app/routes/x+/resources+/shifts.tsx
index d4a2450313..9087abd82f 100644
--- a/apps/carbon/app/routes/x+/resources+/shifts.tsx
+++ b/apps/carbon/app/routes/x+/resources+/shifts.tsx
@@ -2,12 +2,7 @@ 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 {
- ShiftsTable,
- ShiftsTableFilters,
- getLocations,
- getShifts,
-} from "~/modules/resources";
+import { ShiftsTable, getLocations, getShifts } from "~/modules/resources";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
import type { Handle } from "~/utils/handle";
@@ -28,12 +23,12 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
- const name = searchParams.get("name");
- const location = searchParams.get("location");
- const { limit, offset, sorts } = getGenericQueryFilters(searchParams);
+ const search = searchParams.get("search");
+ const { limit, offset, sorts, filters } =
+ getGenericQueryFilters(searchParams);
const [shifts, locations] = await Promise.all([
- getShifts(client, { name, location, limit, offset, sorts }),
+ getShifts(client, { search, limit, offset, sorts, filters }),
getLocations(client),
]);
@@ -56,8 +51,7 @@ export default function ShiftsRoute() {
return (
<VStack spacing={0} className="h-full">
- <ShiftsTableFilters locations={locations} />
- <ShiftsTable data={shifts} count={count} />
+ <ShiftsTable data={shifts} count={count} locations={locations} />
<Outlet />
</VStack>
);
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 9d45929307..90a734fdb2 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -3133,6 +3133,13 @@ export type Database = {
referencedRelation: "shift"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "employeeJob_shiftId_fkey"
+ columns: ["shiftId"]
+ isOneToOne: false
+ referencedRelation: "shifts"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "employeeJob_updatedBy_fkey"
columns: ["updatedBy"]
@@ -3208,6 +3215,13 @@ export type Database = {
referencedRelation: "shift"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "employeeShift_shiftId_fkey"
+ columns: ["shiftId"]
+ isOneToOne: false
+ referencedRelation: "shifts"
+ referencedColumns: ["id"]
+ },
]
}
employeeType: {
@@ -13422,6 +13436,93 @@ export type Database = {
},
]
}
+ shifts: {
+ Row: {
+ active: boolean | null
+ createdAt: string | null
+ createdBy: string | null
+ endTime: string | null
+ friday: boolean | null
+ id: string | null
+ locationId: string | null
+ locationName: string | null
+ monday: boolean | null
+ name: string | null
+ saturday: boolean | null
+ startTime: string | null
+ sunday: boolean | null
+ thursday: boolean | null
+ tuesday: boolean | null
+ updatedAt: string | null
+ updatedBy: string | null
+ wednesday: boolean | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "location"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "partQuantities"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
suppliers: {
Row: {
id: string | null
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 9d45929307..90a734fdb2 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -3133,6 +3133,13 @@ export type Database = {
referencedRelation: "shift"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "employeeJob_shiftId_fkey"
+ columns: ["shiftId"]
+ isOneToOne: false
+ referencedRelation: "shifts"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "employeeJob_updatedBy_fkey"
columns: ["updatedBy"]
@@ -3208,6 +3215,13 @@ export type Database = {
referencedRelation: "shift"
referencedColumns: ["id"]
},
+ {
+ foreignKeyName: "employeeShift_shiftId_fkey"
+ columns: ["shiftId"]
+ isOneToOne: false
+ referencedRelation: "shifts"
+ referencedColumns: ["id"]
+ },
]
}
employeeType: {
@@ -13422,6 +13436,93 @@ export type Database = {
},
]
}
+ shifts: {
+ Row: {
+ active: boolean | null
+ createdAt: string | null
+ createdBy: string | null
+ endTime: string | null
+ friday: boolean | null
+ id: string | null
+ locationId: string | null
+ locationName: string | null
+ monday: boolean | null
+ name: string | null
+ saturday: boolean | null
+ startTime: string | null
+ sunday: boolean | null
+ thursday: boolean | null
+ tuesday: boolean | null
+ updatedAt: string | null
+ updatedBy: string | null
+ wednesday: boolean | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "location"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "partQuantities"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "shifts_locationId_fkey"
+ columns: ["locationId"]
+ isOneToOne: false
+ referencedRelation: "purchaseOrders"
+ referencedColumns: ["locationId"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
suppliers: {
Row: {
id: string | null
diff --git a/packages/database/supabase/migrations/20230224035103_shifts.sql b/packages/database/supabase/migrations/20230224035103_shifts.sql
index 924a540d83..c9c489ca35 100644
--- a/packages/database/supabase/migrations/20230224035103_shifts.sql
+++ b/packages/database/supabase/migrations/20230224035103_shifts.sql
@@ -196,4 +196,10 @@ CREATE POLICY "Employees with resources_delete can delete employee jobs" ON "emp
USING (
coalesce(get_my_claim('resources_delete')::boolean, false) = true
AND (get_my_claim('role'::text)) = '"employee"'::jsonb
- );
\ No newline at end of file
+ );
+
+ CREATE OR REPLACE VIEW "shifts" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ s.*, l."name" as "locationName"
+ FROM "shift" s
+ LEFT JOIN "location" l ON s."locationId" = l."id";
\ No newline at end of file