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: custom fields for shift form

Brad Barbin0968ada142db
diff --git a/apps/carbon/app/components/Table/components/Pagination/Pagination.tsx b/apps/carbon/app/components/Table/components/Pagination/Pagination.tsx
index d05d76fbfd..09e7fff041 100644
--- a/apps/carbon/app/components/Table/components/Pagination/Pagination.tsx
+++ b/apps/carbon/app/components/Table/components/Pagination/Pagination.tsx
@@ -105,22 +105,36 @@ export const PaginationButtons = ({
return (
<>
{condensed ? (
- <>
- <IconButton
- aria-label="Previous"
- icon={<BsChevronLeft />}
- isDisabled={!canPreviousPage}
- onClick={previousPage}
- variant="secondary"
- />
- <IconButton
- aria-label="Next"
- icon={<BsChevronRight />}
- isDisabled={!canNextPage}
- onClick={nextPage}
- variant="secondary"
- />
- </>
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger>
+ <IconButton
+ aria-label="Previous"
+ icon={<BsChevronLeft />}
+ isDisabled={!canPreviousPage}
+ onClick={previousPage}
+ variant="secondary"
+ />
+ </TooltipTrigger>
+ <TooltipContent>
+ <HStack>F</HStack>
+ </TooltipContent>
+ </Tooltip>
+ <Tooltip>
+ <TooltipTrigger>
+ <IconButton
+ aria-label="Next"
+ icon={<BsChevronRight />}
+ isDisabled={!canNextPage}
+ onClick={nextPage}
+ variant="secondary"
+ />
+ </TooltipTrigger>
+ <TooltipContent>
+ <HStack>J</HStack>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
) : (
<TooltipProvider>
<div className="text-foreground flex text-sm font-medium align-center">
diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.ts
index 660936b00a..51a7faab13 100644
--- a/apps/carbon/app/modules/resources/resources.service.ts
+++ b/apps/carbon/app/modules/resources/resources.service.ts
@@ -15,6 +15,7 @@ import type {
holidayValidator,
locationValidator,
partnerValidator,
+ shiftValidator,
workCellTypeValidator,
} from "./resources.models";
@@ -650,9 +651,7 @@ export async function getShift(
return client
.from("shift")
.select(
- `id, name, startTime, endTime, locationId,
- monday, tuesday, wednesday, thursday, friday, saturday, sunday,
- employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`
+ `*, employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`
)
.eq("id", shiftId)
.eq("active", true)
@@ -666,9 +665,7 @@ export async function getShifts(
let query = client
.from("shift")
.select(
- `id, name, startTime, endTime, locationId,
- monday, tuesday, wednesday, thursday, friday, saturday, sunday,
- employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`,
+ `*, employeeShift(user(id, fullName, avatarUrl)), location(name, timezone)`,
{
count: "exact",
}
@@ -1174,27 +1171,21 @@ export async function upsertPartner(
export async function upsertShift(
client: SupabaseClient<Database>,
- shift: {
- id?: string;
- name: string;
- startTime: string;
- endTime: string;
- locationId: string;
- monday: boolean;
- tuesday: boolean;
- wednesday: boolean;
- thursday: boolean;
- friday: boolean;
- saturday: boolean;
- sunday: boolean;
- }
+ shift:
+ | (Omit<z.infer<typeof shiftValidator>, "id"> & {
+ createdBy: string;
+ customFields?: Json;
+ })
+ | (Omit<z.infer<typeof shiftValidator>, "id"> & {
+ id: string;
+ updatedBy: string;
+ customFields?: Json;
+ })
) {
- const { id, ...update } = shift;
- if (id) {
- return client.from("shift").update(sanitize(update)).eq("id", id);
+ if ("createdBy" in shift) {
+ return client.from("shift").insert([shift]).select("*").single();
}
-
- return client.from("shift").insert([update]).select("*").single();
+ return client.from("shift").update(sanitize(shift)).eq("id", shift.id);
}
export async function upsertWorkCell(
diff --git a/apps/carbon/app/modules/resources/ui/Abilities/AbilitiesTable.tsx b/apps/carbon/app/modules/resources/ui/Abilities/AbilitiesTable.tsx
index 58d48381cf..9792d6ecfe 100644
--- a/apps/carbon/app/modules/resources/ui/Abilities/AbilitiesTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/Abilities/AbilitiesTable.tsx
@@ -2,7 +2,7 @@ import {
AvatarGroup,
AvatarGroupList,
AvatarOverflowIndicator,
- Hyperlink,
+ Enumerable,
MenuIcon,
MenuItem,
} from "@carbon/react";
@@ -68,9 +68,11 @@ const AbilitiesTable = memo(({ data, count }: AbilitiesTableProps) => {
accessorKey: "name",
header: "Ability",
cell: ({ row }) => (
- <Hyperlink onClick={() => navigate(path.to.ability(row.original.id))}>
- {row.original.name}
- </Hyperlink>
+ <Enumerable
+ value={row.original.name}
+ onClick={() => navigate(path.to.ability(row.original.id))}
+ className="cursor-pointer"
+ />
),
},
{
diff --git a/apps/carbon/app/modules/resources/ui/Departments/DepartmentsTable.tsx b/apps/carbon/app/modules/resources/ui/Departments/DepartmentsTable.tsx
index 4ece1c9044..4c4edbf1c0 100644
--- a/apps/carbon/app/modules/resources/ui/Departments/DepartmentsTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/Departments/DepartmentsTable.tsx
@@ -1,4 +1,4 @@
-import { Hyperlink, MenuIcon, MenuItem } from "@carbon/react";
+import { Enumerable, HStack, MenuIcon, MenuItem } from "@carbon/react";
import { useNavigate } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
@@ -33,14 +33,22 @@ const DepartmentsTable = memo(({ data, count }: DepartmentsTableProps) => {
accessorKey: "name",
header: "Department",
cell: ({ row }) => (
- <Hyperlink onClick={() => navigate(row.original.id)}>
- {row.original.name}
- </Hyperlink>
+ <Enumerable
+ value={row.original.name}
+ onClick={() => navigate(row.original.id)}
+ className="cursor-pointer"
+ />
),
},
{
header: "Sub-Departments",
- cell: ({ row }) => row.original.parentDepartment,
+ cell: ({ row }) => (
+ <HStack>
+ {row.original.parentDepartment.split(", ").map((v) => (
+ <Enumerable key={v} value={v} />
+ ))}
+ </HStack>
+ ),
},
];
}, [navigate]);
diff --git a/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTable.tsx b/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTable.tsx
index 10edb45bfb..c2f880d5cf 100644
--- a/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTable.tsx
+++ b/apps/carbon/app/modules/resources/ui/Shifts/ShiftsTable.tsx
@@ -3,6 +3,7 @@ import {
AvatarGroupList,
AvatarOverflowIndicator,
Badge,
+ Enumerable,
Hyperlink,
MenuIcon,
MenuItem,
@@ -136,7 +137,7 @@ const ShiftsTable = memo(({ data, count }: ShiftsTableProps) => {
{
accessorKey: "location.name",
header: "Location",
- cell: (item) => item.getValue(),
+ cell: (item) => <Enumerable value={item.getValue<string>()} />,
},
{
header: "Days",
diff --git a/apps/carbon/app/routes/x+/resources+/shifts.$shiftId.tsx b/apps/carbon/app/routes/x+/resources+/shifts.$shiftId.tsx
index 3024665e96..758d45c410 100644
--- a/apps/carbon/app/routes/x+/resources+/shifts.$shiftId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/shifts.$shiftId.tsx
@@ -10,6 +10,7 @@ import {
} from "~/modules/resources";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
+import { getCustomFields, setCustomFields } from "~/utils/form";
import { assertIsPost, notFound } from "~/utils/http";
import { path } from "~/utils/path";
import { error, success } from "~/utils/result";
@@ -38,20 +39,25 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
- const { client } = await requirePermissions(request, {
+ const { client, userId } = await requirePermissions(request, {
create: "resources",
});
- const validation = await validator(shiftValidator).validate(
- await request.formData()
- );
+ const formData = await request.formData();
+ const validation = await validator(shiftValidator).validate(formData);
if (validation.error) {
return validationError(validation.error);
}
+ const { id, ...data } = validation.data;
+ if (!id) throw new Error("Shift ID is required");
+
const createShift = await upsertShift(client, {
- ...validation.data,
+ id,
+ ...data,
+ updatedBy: userId,
+ customFields: setCustomFields(formData),
});
if (createShift.error) {
@@ -87,6 +93,7 @@ export default function ShiftRoute() {
friday: shift.friday,
saturday: shift.saturday,
sunday: shift.sunday,
+ ...getCustomFields(shift.customFields),
};
return <ShiftForm key={initialValues.id} initialValues={initialValues} />;
diff --git a/apps/carbon/app/routes/x+/resources+/shifts.new.tsx b/apps/carbon/app/routes/x+/resources+/shifts.new.tsx
index eb0f97c169..e597b0f9d8 100644
--- a/apps/carbon/app/routes/x+/resources+/shifts.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/shifts.new.tsx
@@ -4,26 +4,30 @@ import { redirect } from "@remix-run/node";
import { ShiftForm, shiftValidator, upsertShift } from "~/modules/resources";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
+import { setCustomFields } from "~/utils/form";
import { assertIsPost } from "~/utils/http";
import { path } from "~/utils/path";
import { error, success } from "~/utils/result";
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
- const { client } = await requirePermissions(request, {
+ const { client, userId } = await requirePermissions(request, {
create: "resources",
});
- const validation = await validator(shiftValidator).validate(
- await request.formData()
- );
+ const formData = await request.formData();
+ const validation = await validator(shiftValidator).validate(formData);
if (validation.error) {
return validationError(validation.error);
}
+ const { id, ...data } = validation.data;
+
const createShift = await upsertShift(client, {
- ...validation.data,
+ ...data,
+ createdBy: userId,
+ customFields: setCustomFields(formData),
});
if (createShift.error) {
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index f52e00b7ab..7e36de3986 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -9860,6 +9860,8 @@ export type Database = {
shift: {
Row: {
active: boolean
+ createdAt: string
+ createdBy: string
customFields: Json | null
endTime: string
friday: boolean
@@ -9872,10 +9874,14 @@ export type Database = {
sunday: boolean
thursday: boolean
tuesday: boolean
+ updatedAt: string | null
+ updatedBy: string | null
wednesday: boolean
}
Insert: {
active?: boolean
+ createdAt?: string
+ createdBy: string
customFields?: Json | null
endTime: string
friday?: boolean
@@ -9888,10 +9894,14 @@ export type Database = {
sunday?: boolean
thursday?: boolean
tuesday?: boolean
+ updatedAt?: string | null
+ updatedBy?: string | null
wednesday?: boolean
}
Update: {
active?: boolean
+ createdAt?: string
+ createdBy?: string
customFields?: Json | null
endTime?: string
friday?: boolean
@@ -9904,9 +9914,32 @@ export type Database = {
sunday?: boolean
thursday?: boolean
tuesday?: boolean
+ updatedAt?: string | null
+ updatedBy?: string | null
wednesday?: boolean
}
Relationships: [
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "shifts_locationId_fkey"
columns: ["locationId"]
@@ -9928,6 +9961,27 @@ export type Database = {
referencedRelation: "purchaseOrders"
referencedColumns: ["locationId"]
},
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
]
}
shippingMethod: {
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index f52e00b7ab..7e36de3986 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -9860,6 +9860,8 @@ export type Database = {
shift: {
Row: {
active: boolean
+ createdAt: string
+ createdBy: string
customFields: Json | null
endTime: string
friday: boolean
@@ -9872,10 +9874,14 @@ export type Database = {
sunday: boolean
thursday: boolean
tuesday: boolean
+ updatedAt: string | null
+ updatedBy: string | null
wednesday: boolean
}
Insert: {
active?: boolean
+ createdAt?: string
+ createdBy: string
customFields?: Json | null
endTime: string
friday?: boolean
@@ -9888,10 +9894,14 @@ export type Database = {
sunday?: boolean
thursday?: boolean
tuesday?: boolean
+ updatedAt?: string | null
+ updatedBy?: string | null
wednesday?: boolean
}
Update: {
active?: boolean
+ createdAt?: string
+ createdBy?: string
customFields?: Json | null
endTime?: string
friday?: boolean
@@ -9904,9 +9914,32 @@ export type Database = {
sunday?: boolean
thursday?: boolean
tuesday?: boolean
+ updatedAt?: string | null
+ updatedBy?: string | null
wednesday?: boolean
}
Relationships: [
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
{
foreignKeyName: "shifts_locationId_fkey"
columns: ["locationId"]
@@ -9928,6 +9961,27 @@ export type Database = {
referencedRelation: "purchaseOrders"
referencedColumns: ["locationId"]
},
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "shifts_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
]
}
shippingMethod: {
diff --git a/packages/database/supabase/migrations/20230224035103_shifts.sql b/packages/database/supabase/migrations/20230224035103_shifts.sql
index 235e64ec79..e1cb4c20fa 100644
--- a/packages/database/supabase/migrations/20230224035103_shifts.sql
+++ b/packages/database/supabase/migrations/20230224035103_shifts.sql
@@ -63,9 +63,15 @@ CREATE TABLE "shift" (
"friday" BOOLEAN NOT NULL DEFAULT false,
"saturday" BOOLEAN NOT NULL DEFAULT false,
"active" BOOLEAN NOT NULL DEFAULT true,
+ "createdBy" TEXT NOT NULL,
+ "createdAt" TIMESTAMP NOT NULL DEFAULT now(),
+ "updatedBy" TEXT,
+ "updatedAt" TIMESTAMP,
CONSTRAINT "shifts_pkey" PRIMARY KEY ("id"),
- CONSTRAINT "shifts_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location"("id") ON DELETE CASCADE ON UPDATE CASCADE
+ CONSTRAINT "shifts_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "location"("id") ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT "shifts_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "shifts_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
ALTER TABLE "shift" ENABLE ROW LEVEL SECURITY;
diff --git a/packages/database/supabase/seed.sql b/packages/database/supabase/seed.sql
index 35a8aea3dd..82f818c80d 100644
--- a/packages/database/supabase/seed.sql
+++ b/packages/database/supabase/seed.sql
@@ -508,7 +508,7 @@ VALUES
('shelf', 'Shelf', 'Inventory'),
('shift', 'Shift', 'Resources'),
('shippingMethod', 'Shipping Method', 'Inventory'),
--- ('shippingTerm', 'Shipping Term', 'Accounting'),
+('shippingTerm', 'Shipping Term', 'Accounting'),
('supplier', 'Supplier', 'Purchasing'),
('supplierContact', 'Supplier Contact', 'Purchasing'),
('supplierLocation', 'Supplier Location', 'Purchasing'),