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: add settings to kanban view

Brad Barbine959d102a290
diff --git a/apps/carbon/app/routes/x+/schedule+/index.tsx b/apps/carbon/app/routes/x+/schedule+/index.tsx
index 17a8b1b84a..16fd0bbcb2 100644
--- a/apps/carbon/app/routes/x+/schedule+/index.tsx
+++ b/apps/carbon/app/routes/x+/schedule+/index.tsx
@@ -8,10 +8,16 @@ import {
Button,
ClientOnly,
HStack,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
Spinner,
+ Switch,
toast,
useInterval,
+ useLocalStorage,
useMount,
+ VStack,
} from "@carbon/react";
import {
getLocalTimeZone,
@@ -23,7 +29,7 @@ import { Link, useLoaderData } from "@remix-run/react";
import type { RealtimeChannel } from "@supabase/supabase-js";
import { json, redirect, type LoaderFunctionArgs } from "@vercel/remix";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { LuAlertTriangle, LuPlusCircle } from "react-icons/lu";
+import { LuAlertTriangle, LuPlusCircle, LuSettings2 } from "react-icons/lu";
import { SearchFilter } from "~/components";
import { Enumerable } from "~/components/Enumerable";
import { ActiveFilters, Filter } from "~/components/Table/components/Filter";
@@ -33,11 +39,12 @@ import { useUrlParams, useUser } from "~/hooks";
import { getActiveJobOperationsByLocation } from "~/modules/production";
import type { Column, Item } from "~/modules/production/ui/Schedule";
-import {
- Kanban,
- type Event,
- type Progress,
+import type {
+ DisplaySettings,
+ Event,
+ Progress,
} from "~/modules/production/ui/Schedule/Kanban";
+import { Kanban } from "~/modules/production/ui/Schedule/Kanban";
import {
getLocationsList,
getProcessesList,
@@ -234,7 +241,20 @@ export async function loader({ request }: LoaderFunctionArgs) {
});
}
-export default function ScheduleRoute() {
+const defaultDisplaySettings: DisplaySettings = {
+ showDuration: true,
+ showCustomer: true,
+ showDescription: true,
+ showDueDate: true,
+ showEmployee: true,
+ showProgress: true,
+ showStatus: true,
+ showSalesOrder: true,
+ showThumbnail: true,
+};
+
+const DISPLAY_SETTINGS_KEY = "kanban-schedule-display-settings";
+function KanbanSchedule() {
const {
columns,
items: initialItems,
@@ -243,6 +263,10 @@ export default function ScheduleRoute() {
} = useLoaderData<typeof loader>();
const [items, setItems] = useState<Item[]>(initialItems);
+ const [displaySettings, setDisplaySettings] = useLocalStorage(
+ DISPLAY_SETTINGS_KEY,
+ defaultDisplaySettings
+ );
useEffect(() => {
setItems(initialItems);
@@ -310,9 +334,118 @@ export default function ScheduleRoute() {
<HStack className="px-4 py-2 justify-between bg-card border-b border-border">
<HStack>
<SearchFilter param="search" size="sm" placeholder="Search" />
-
<Filter filters={filters} />
</HStack>
+
+ <Popover>
+ <PopoverTrigger asChild>
+ <Button
+ leftIcon={<LuSettings2 />}
+ variant="secondary"
+ className="border-dashed border-border"
+ >
+ Settings
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="w-48">
+ <VStack>
+ <Switch
+ variant="small"
+ label="Customer"
+ checked={displaySettings.showCustomer}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showCustomer: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Description"
+ checked={displaySettings.showDescription}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showDescription: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Due Date"
+ checked={displaySettings.showDueDate}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showDueDate: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Duration"
+ checked={displaySettings.showDuration}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showDuration: checked,
+ }))
+ }
+ />
+ {/* <Switch
+ variant="small"
+ label="Employee"
+ checked={displaySettings.showEmployee}
+ onCheckedChange={(checked) => setDisplaySettings(prev => ({...prev, showEmployee: checked}))}
+ /> */}
+ <Switch
+ variant="small"
+ label="Progress"
+ checked={displaySettings.showProgress}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showProgress: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Status"
+ checked={displaySettings.showStatus}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showStatus: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Sales Order"
+ checked={displaySettings.showSalesOrder}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showSalesOrder: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Thumbnail"
+ checked={displaySettings.showThumbnail}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showThumbnail: checked,
+ }))
+ }
+ />
+ </VStack>
+ </PopoverContent>
+ </Popover>
</HStack>
{currentFilters.length > 0 && (
<HStack className="px-4 py-1.5 justify-between bg-card border-b border-border w-full">
@@ -324,30 +457,12 @@ export default function ScheduleRoute() {
<div className="flex flex-grow h-full items-stretch overflow-hidden relative">
<div className="flex flex-1 min-h-0 w-full relative">
{columns.length > 0 ? (
- <ClientOnly
- fallback={
- <div className="flex h-full w-full items-center justify-center">
- <Spinner className="h-8 w-8" />
- </div>
- }
- >
- {() => (
- <Kanban
- columns={columns}
- items={items}
- progressByItemId={progressByOperation}
- showCustomer
- showDescription
- showDueDate
- showDuration
- showEmployee
- showProgress
- showStatus
- showSalesOrder
- showThumbnail
- />
- )}
- </ClientOnly>
+ <Kanban
+ columns={columns}
+ items={items}
+ progressByItemId={progressByOperation}
+ {...displaySettings}
+ />
) : hasFilters ? (
<div className="flex flex-col w-full h-full items-center justify-center gap-4">
<div className="flex justify-center items-center h-12 w-12 rounded-full bg-foreground text-background">
@@ -377,6 +492,20 @@ export default function ScheduleRoute() {
);
}
+export default function ScheduleRoute() {
+ return (
+ <ClientOnly
+ fallback={
+ <div className="flex h-full w-full items-center justify-center">
+ <Spinner className="h-8 w-8" />
+ </div>
+ }
+ >
+ {() => <KanbanSchedule />}
+ </ClientOnly>
+ );
+}
+
function useProgressByOperation(
items: Item[],
setItems: React.Dispatch<React.SetStateAction<Item[]>>,
diff --git a/apps/mes/app/components/Kanban/components/ColumnCard.tsx b/apps/mes/app/components/Kanban/components/ColumnCard.tsx
index 4b8ba4e454..873fe5438c 100644
--- a/apps/mes/app/components/Kanban/components/ColumnCard.tsx
+++ b/apps/mes/app/components/Kanban/components/ColumnCard.tsx
@@ -64,7 +64,7 @@ export function ColumnCard({
};
const variants = cva(
- "w-[350px] max-w-full bg-primary-foreground flex flex-col flex-shrink-0 snap-center rounded-none from-card/50 via-card/50",
+ "w-[350px] max-w-full bg-primary-foreground flex flex-col flex-shrink-0 snap-center rounded-none from-card/20 via-card/20",
{
variants: {
dragging: {
diff --git a/apps/mes/app/components/Kanban/components/ItemCard.tsx b/apps/mes/app/components/Kanban/components/ItemCard.tsx
index e3129ff8dd..b892f2bede 100644
--- a/apps/mes/app/components/Kanban/components/ItemCard.tsx
+++ b/apps/mes/app/components/Kanban/components/ItemCard.tsx
@@ -28,7 +28,7 @@ import { InProgressStatusIcon } from "~/assets/icons/InProgressStatusIcon";
import { TodoStatusIcon } from "~/assets/icons/TodoStatusIcon";
import { DeadlineIcon } from "~/components/Icons";
-import { path } from "~/utils/path";
+import { getPrivateUrl, path } from "~/utils/path";
import type { DisplaySettings, Item } from "../types";
type ItemCardProps = {
@@ -143,9 +143,9 @@ export function ItemCard({
{showThumbnail && item.thumbnailPath && (
<div className="flex justify-center">
<img
- src={item.thumbnailPath}
+ src={getPrivateUrl(item.thumbnailPath)}
alt={item.title}
- className="w-full max-w-[200px] h-auto"
+ className="w-full h-auto"
/>
</div>
)}
diff --git a/apps/mes/app/root.tsx b/apps/mes/app/root.tsx
index 699030743b..42107b4205 100644
--- a/apps/mes/app/root.tsx
+++ b/apps/mes/app/root.tsx
@@ -1,4 +1,4 @@
-import { error, getBrowserEnv } from "@carbon/auth";
+import { error, getBrowserEnv, VERCEL_ENV, VERCEL_URL } from "@carbon/auth";
import { getSessionFlash } from "@carbon/auth/session.server";
import { validator } from "@carbon/form";
import { Button, Heading, toast } from "@carbon/react";
@@ -66,6 +66,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
POSTHOG_PROJECT_PUBLIC_KEY,
SUPABASE_API_URL,
SUPABASE_ANON_PUBLIC,
+ VERCEL_ENV,
+ VERCEL_URL,
},
mode: getMode(request),
theme: getTheme(request),
diff --git a/apps/mes/app/routes/x+/operations.tsx b/apps/mes/app/routes/x+/operations.tsx
index f5acaeaea4..aabdf12ec7 100644
--- a/apps/mes/app/routes/x+/operations.tsx
+++ b/apps/mes/app/routes/x+/operations.tsx
@@ -5,17 +5,23 @@ import {
ClientOnly,
Heading,
HStack,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
SidebarTrigger,
Spinner,
+ Switch,
+ useLocalStorage,
+ VStack,
} from "@carbon/react";
import { json, redirect, useLoaderData } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { useMemo } from "react";
-import { LuAlertTriangle } from "react-icons/lu";
+import { LuAlertTriangle, LuSettings2 } from "react-icons/lu";
import type { ColumnFilter } from "~/components/Filter";
import { ActiveFilters, Filter, useFilters } from "~/components/Filter";
-import type { Column, Item } from "~/components/Kanban";
+import type { Column, DisplaySettings, Item } from "~/components/Kanban";
import { Kanban } from "~/components/Kanban";
import SearchFilter from "~/components/SearchFilter";
import { useUrlParams } from "~/hooks";
@@ -200,9 +206,41 @@ export async function loader({ request }: LoaderFunctionArgs) {
);
}
-export default function Operations() {
+export default function ScheduleRoute() {
+ return (
+ <ClientOnly
+ fallback={
+ <div className="flex h-screen w-full items-center justify-center">
+ <Spinner className="h-8 w-8" />
+ </div>
+ }
+ >
+ {() => <KanbanSchedule />}
+ </ClientOnly>
+ );
+}
+
+const defaultDisplaySettings: DisplaySettings = {
+ showDuration: true,
+ showCustomer: true,
+ showDescription: true,
+ showDueDate: true,
+ showEmployee: true,
+ showProgress: true,
+ showStatus: true,
+ showSalesOrder: true,
+ showThumbnail: true,
+};
+
+const DISPLAY_SETTINGS_KEY = "kanban-schedule-display-settings";
+
+function KanbanSchedule() {
const { columns, items, processes, workCenters } =
useLoaderData<typeof loader>();
+ const [displaySettings, setDisplaySettings] = useLocalStorage(
+ DISPLAY_SETTINGS_KEY,
+ defaultDisplaySettings
+ );
const [params] = useUrlParams();
const { hasFilters, clearFilters } = useFilters();
@@ -255,6 +293,115 @@ export default function Operations() {
<Filter filters={filters} />
</HStack>
+ <Popover>
+ <PopoverTrigger asChild>
+ <Button
+ leftIcon={<LuSettings2 />}
+ variant="secondary"
+ className="border-dashed border-border"
+ >
+ Settings
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="w-48">
+ <VStack>
+ <Switch
+ variant="small"
+ label="Customer"
+ checked={displaySettings.showCustomer}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showCustomer: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Description"
+ checked={displaySettings.showDescription}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showDescription: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Due Date"
+ checked={displaySettings.showDueDate}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showDueDate: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Duration"
+ checked={displaySettings.showDuration}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showDuration: checked,
+ }))
+ }
+ />
+ {/* <Switch
+ variant="small"
+ label="Employee"
+ checked={displaySettings.showEmployee}
+ onCheckedChange={(checked) => setDisplaySettings(prev => ({...prev, showEmployee: checked}))}
+ /> */}
+ <Switch
+ variant="small"
+ label="Progress"
+ checked={displaySettings.showProgress}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showProgress: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Status"
+ checked={displaySettings.showStatus}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showStatus: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Sales Order"
+ checked={displaySettings.showSalesOrder}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showSalesOrder: checked,
+ }))
+ }
+ />
+ <Switch
+ variant="small"
+ label="Thumbnail"
+ checked={displaySettings.showThumbnail}
+ onCheckedChange={(checked) =>
+ setDisplaySettings((prev) => ({
+ ...prev,
+ showThumbnail: checked,
+ }))
+ }
+ />
+ </VStack>
+ </PopoverContent>
+ </Popover>
</HStack>
{currentFilters.length > 0 && (
<HStack className="px-4 py-1.5 justify-between bg-card border-b border-border w-full">
@@ -266,29 +413,14 @@ export default function Operations() {
<div className="flex flex-grow h-full items-stretch overflow-hidden relative">
<div className="flex flex-1 min-h-0 w-full relative">
{columns.length > 0 ? (
- <ClientOnly
- fallback={
- <div className="flex w-full h-full items-center justify-center">
- <Spinner className="h-8 w-8" />
- </div>
- }
- >
- {() => (
- <Kanban
- columns={columns}
- items={items}
- showCustomer
- showDescription
- showDueDate
- showDuration
- showEmployee={false}
- showProgress={false}
- showStatus
- showSalesOrder={false}
- showThumbnail
- />
- )}
- </ClientOnly>
+ <Kanban
+ columns={columns}
+ items={items}
+ {...displaySettings}
+ showEmployee={false}
+ showProgress={false}
+ showSalesOrder={false}
+ />
) : hasFilters ? (
<div className="flex flex-col w-full h-full items-center justify-center gap-4">
<div className="flex justify-center items-center h-12 w-12 rounded-full bg-foreground text-background">
diff --git a/packages/auth/src/config/env.ts b/packages/auth/src/config/env.ts
index 4fdd12f5da..45564b4459 100644
--- a/packages/auth/src/config/env.ts
+++ b/packages/auth/src/config/env.ts
@@ -9,6 +9,7 @@ declare global {
POSTHOG_API_HOST: string;
POSTHOG_PROJECT_PUBLIC_KEY: string;
VERCEL_URL: string;
+ VERCEL_ENV: string;
};
}
}
@@ -27,6 +28,7 @@ declare global {
SUPABASE_URL: string;
SUPABASE_SERVICE_ROLE: string;
VERCEL_URL: string;
+ VERCEL_ENV: string;
}
}
}
@@ -93,6 +95,10 @@ export const VERCEL_ENV = getEnv("VERCEL_ENV", {
isSecret: false,
isRequired: false,
});
+export const NODE_ENV = getEnv("NODE_ENV", {
+ isSecret: false,
+ isRequired: false,
+});
export const POSTHOG_API_HOST = getEnv("POSTHOG_API_HOST", {
isSecret: false,
});
@@ -105,14 +111,11 @@ export const SUPABASE_ANON_PUBLIC = getEnv("SUPABASE_ANON_PUBLIC", {
});
export function getAppUrl() {
- if (
- process.env.VERCEL_ENV === "production" ||
- process.env.NODE_ENV === "production"
- ) {
+ if (VERCEL_ENV === "production" || NODE_ENV === "production") {
return "https://app.carbonos.dev";
}
- if (process.env.VERCEL_ENV === "preview") {
+ if (VERCEL_ENV === "preview") {
return `https://${process.env.VERCEL_URL}`;
}
@@ -126,6 +129,9 @@ export function getBrowserEnv() {
POSTHOG_API_HOST,
POSTHOG_PROJECT_PUBLIC_KEY,
NOVU_APPLICATION_ID,
+ VERCEL_ENV,
+ VERCEL_URL,
+ NODE_ENV,
};
}
diff --git a/packages/react/src/hooks/useLocalStorage.ts b/packages/react/src/hooks/useLocalStorage.ts
index ba6e8c55f1..f9f6f26c19 100644
--- a/packages/react/src/hooks/useLocalStorage.ts
+++ b/packages/react/src/hooks/useLocalStorage.ts
@@ -3,7 +3,7 @@ import { useEffect, useState } from "react";
const useLocalStorage = <T>(
key: string,
initialValue: T
-): [T, (value: T) => void] => {
+): [T, (value: T | ((prev: T) => T)) => void] => {
const [storedValue, setStoredValue] = useState(initialValue);
useEffect(() => {
@@ -14,11 +14,12 @@ const useLocalStorage = <T>(
}
}, [key]);
- const setValue = (value: T) => {
+ const setValue = (value: T | ((prev: T) => T)) => {
// Save state
- setStoredValue(value);
+ const newValue = value instanceof Function ? value(storedValue) : value;
+ setStoredValue(newValue);
// Save to localStorage
- window.localStorage.setItem(key, JSON.stringify(value));
+ window.localStorage.setItem(key, JSON.stringify(newValue));
};
return [storedValue, setValue];
};