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 tags to custom fields

Brad Barbind69c0dedd311
diff --git a/apps/carbon/app/components/Form/CustomFormFields.tsx b/apps/carbon/app/components/Form/CustomFormFields.tsx
index a4fb037fca..80ceda5513 100644
--- a/apps/carbon/app/components/Form/CustomFormFields.tsx
+++ b/apps/carbon/app/components/Form/CustomFormFields.tsx
@@ -5,9 +5,10 @@ import Employee from "./Employee";
type CustomFormFieldsProps = {
table: string;
+ tags?: string[];
};
-const CustomFormFields = ({ table }: CustomFormFieldsProps) => {
+const CustomFormFields = ({ table, tags = [] }: CustomFormFieldsProps) => {
const customFormSchema = useCustomFieldsSchema();
const tableFields = customFormSchema?.[table];
@@ -17,6 +18,10 @@ const CustomFormFields = ({ table }: CustomFormFieldsProps) => {
<>
{tableFields
.sort((a, b) => a.sortOrder - b.sortOrder)
+ .filter((field) => {
+ if (!field.tags || !Array.isArray(field.tags)) return true;
+ return field.tags.some((tag) => tags.includes(tag));
+ })
.map((field) => {
switch (field.dataTypeId) {
case DataType.Boolean:
diff --git a/apps/carbon/app/components/Form/Tags.tsx b/apps/carbon/app/components/Form/Tags.tsx
new file mode 100644
index 0000000000..64441431da
--- /dev/null
+++ b/apps/carbon/app/components/Form/Tags.tsx
@@ -0,0 +1,54 @@
+import type { CreatableMultiSelectProps } from "@carbon/form";
+import { CreatableMultiSelect } from "@carbon/form";
+import { useMount } from "@carbon/react";
+import { useFetcher } from "@remix-run/react";
+import { useMemo } from "react";
+import type { getTagsList } from "~/modules/shared";
+import type { action } from "~/routes/x+/settings+/tags.new";
+import { path } from "~/utils/path";
+
+type TagsSelectProps = Omit<CreatableMultiSelectProps, "options" | "value"> & {
+ table?: string;
+};
+
+const Tags = ({ table, ...props }: TagsSelectProps) => {
+ const tagsFetcher = useFetcher<Awaited<ReturnType<typeof getTagsList>>>();
+ const newTagFetcher = useFetcher<typeof action>();
+
+ useMount(() => {
+ tagsFetcher.load(path.to.api.tags(table));
+ });
+
+ const options = useMemo(
+ () =>
+ tagsFetcher.data?.data
+ ? tagsFetcher.data?.data.map((c) => ({
+ value: c.id,
+ label: c.name,
+ }))
+ : [],
+ [tagsFetcher.data]
+ );
+ return (
+ <CreatableMultiSelect
+ label={props?.label ?? "Tag"}
+ options={options}
+ {...props}
+ onCreateOption={(option) => {
+ if (!option) return;
+
+ const formData = new FormData();
+ formData.append("name", option);
+ formData.append("table", table ?? "");
+ newTagFetcher.submit(formData, {
+ method: "post",
+ action: path.to.newTag,
+ });
+ }}
+ />
+ );
+};
+
+Tags.displayName = "Tags";
+
+export default Tags;
diff --git a/apps/carbon/app/components/Form/index.ts b/apps/carbon/app/components/Form/index.ts
index 85779cf72a..b518516751 100644
--- a/apps/carbon/app/components/Form/index.ts
+++ b/apps/carbon/app/components/Form/index.ts
@@ -64,6 +64,7 @@ import SupplierProcess from "./SupplierProcess";
import SupplierStatus from "./SupplierStatus";
import SupplierType from "./SupplierType";
import Suppliers from "./Suppliers";
+import Tags from "./Tags";
import UnitHint, { getUnitHint } from "./UnitHint";
import UnitOfMeasure from "./UnitOfMeasure";
import User from "./User";
@@ -133,6 +134,7 @@ export {
Suppliers,
SupplierStatus,
SupplierType,
+ Tags,
TextArea,
TimePicker,
Timezone,
diff --git a/apps/carbon/app/hooks/useCustomFieldsSchema.tsx b/apps/carbon/app/hooks/useCustomFieldsSchema.tsx
index 1ed453df11..4fa4995457 100644
--- a/apps/carbon/app/hooks/useCustomFieldsSchema.tsx
+++ b/apps/carbon/app/hooks/useCustomFieldsSchema.tsx
@@ -34,6 +34,7 @@ const fieldValidator = z
listOptions: z.array(z.string()).nullable(),
name: z.string(),
sortOrder: z.number(),
+ tags: z.array(z.string()).nullable(),
})
)
.nullable();
diff --git a/apps/carbon/app/modules/sales/ui/Opportunity/OpportunityNotes.tsx b/apps/carbon/app/modules/sales/ui/Opportunity/OpportunityNotes.tsx
index 93df974721..157152aed1 100644
--- a/apps/carbon/app/modules/sales/ui/Opportunity/OpportunityNotes.tsx
+++ b/apps/carbon/app/modules/sales/ui/Opportunity/OpportunityNotes.tsx
@@ -4,6 +4,7 @@ import {
Card,
CardAction,
CardContent,
+ CardDescription,
CardHeader,
CardTitle,
Editor,
@@ -98,6 +99,9 @@ const OpportunityNotes = ({
<HStack className="w-full justify-between">
<CardHeader>
<CardTitle>{title}</CardTitle>
+ <CardDescription>
+ {tab === "internal" ? "Internal Notes" : "External Notes"}
+ </CardDescription>
</CardHeader>
<CardAction>
<TabsList>
diff --git a/apps/carbon/app/modules/settings/settings.models.ts b/apps/carbon/app/modules/settings/settings.models.ts
index 3fc5b71e7e..47456b8fc8 100644
--- a/apps/carbon/app/modules/settings/settings.models.ts
+++ b/apps/carbon/app/modules/settings/settings.models.ts
@@ -52,6 +52,7 @@ export const customFieldValidator = z
z.number().min(1, { message: "Data type is required" })
),
listOptions: z.string().min(1).array().optional(),
+ tags: z.array(z.string()).optional(),
})
.refine((input) => {
// allows bar to be optional only when foo is 'foo'
diff --git a/apps/carbon/app/modules/settings/ui/CustomFields/CustomFieldForm.tsx b/apps/carbon/app/modules/settings/ui/CustomFields/CustomFieldForm.tsx
index 41033540bf..2055c34c81 100644
--- a/apps/carbon/app/modules/settings/ui/CustomFields/CustomFieldForm.tsx
+++ b/apps/carbon/app/modules/settings/ui/CustomFields/CustomFieldForm.tsx
@@ -14,11 +14,11 @@ import { ValidatedForm } from "@carbon/form";
import { useParams } from "@remix-run/react";
import { useState } from "react";
import type { z } from "zod";
-import { Array, Hidden, Input, Select, Submit } from "~/components/Form";
+import { Array, Hidden, Input, Select, Submit, Tags } from "~/components/Form";
import { usePermissions } from "~/hooks";
import type { AttributeDataType } from "~/modules/people";
import { customFieldValidator } from "~/modules/settings";
-import { DataType } from "~/modules/shared";
+import { customFieldTablesWithTags, DataType } from "~/modules/shared";
import { path } from "~/utils/path";
type CustomFieldFormProps = {
@@ -101,11 +101,17 @@ const CustomFieldForm = ({
onChange={onChangeCheckForListType}
/>
{isList && <Array name="listOptions" label="List Options" />}
+
+ {customFieldTablesWithTags.includes(table) && (
+ <Tags table={table} name="tags" />
+ )}
</VStack>
</DrawerBody>
<DrawerFooter>
<HStack>
- <Submit isDisabled={isDisabled}>Save</Submit>
+ <Submit withBlocker={false} isDisabled={isDisabled}>
+ Save
+ </Submit>
<Button size="md" variant="solid" onClick={onClose}>
Cancel
</Button>
diff --git a/apps/carbon/app/modules/settings/ui/CustomFields/CustomFieldsTable.tsx b/apps/carbon/app/modules/settings/ui/CustomFields/CustomFieldsTable.tsx
index 04ec6d5b1e..5c98ac5686 100644
--- a/apps/carbon/app/modules/settings/ui/CustomFields/CustomFieldsTable.tsx
+++ b/apps/carbon/app/modules/settings/ui/CustomFields/CustomFieldsTable.tsx
@@ -4,11 +4,12 @@ import type { ColumnDef } from "@tanstack/react-table";
import { memo, useCallback, useMemo } from "react";
import { BiAddToQueue } from "react-icons/bi";
import { BsListUl } from "react-icons/bs";
-import { LuDatabase, LuLayoutGrid, LuList } from "react-icons/lu";
+import { LuDatabase, LuLayoutGrid, LuList, LuTags } from "react-icons/lu";
import { Hyperlink, Table } from "~/components";
import { Enumerable } from "~/components/Enumerable";
import { usePermissions, useUrlParams } from "~/hooks";
import { modulesType, type CustomFieldsTableType } from "~/modules/settings";
+import { customFieldTablesWithTags } from "~/modules/shared";
import { path } from "~/utils/path";
type CustomFieldsTableProps = {
@@ -27,7 +28,12 @@ const CustomFieldsTable = memo(({ data, count }: CustomFieldsTableProps) => {
accessorKey: "name",
header: "Table",
cell: ({ row }) => (
- <Hyperlink to={row.original.table!}>{row.original.name}</Hyperlink>
+ <div className="flex items-center gap-2">
+ <Hyperlink to={row.original.table!}>{row.original.name}</Hyperlink>
+ {customFieldTablesWithTags.includes(row.original.table!) && (
+ <LuTags className="text-red-500" />
+ )}
+ </div>
),
meta: {
icon: <LuDatabase />,
diff --git a/apps/carbon/app/modules/shared/shared.models.ts b/apps/carbon/app/modules/shared/shared.models.ts
index d8cd004447..42e76761d5 100644
--- a/apps/carbon/app/modules/shared/shared.models.ts
+++ b/apps/carbon/app/modules/shared/shared.models.ts
@@ -1,6 +1,15 @@
import { z } from "zod";
import { zfd } from "zod-form-data";
+export const customFieldTablesWithTags = [
+ "consumable",
+ "fixture",
+ "job",
+ "material",
+ "part",
+ "tool",
+];
+
export const methodItemType = [
"Part",
"Material",
diff --git a/apps/carbon/app/modules/shared/shared.service.ts b/apps/carbon/app/modules/shared/shared.service.ts
index 0574de3a9a..481fbeb54c 100644
--- a/apps/carbon/app/modules/shared/shared.service.ts
+++ b/apps/carbon/app/modules/shared/shared.service.ts
@@ -43,6 +43,20 @@ export async function getNotes(
.order("createdAt");
}
+export async function getTagsList(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ table?: string | null
+) {
+ let query = client.from("tag").select("id, name").eq("companyId", companyId);
+
+ if (table) {
+ query = query.eq("table", table);
+ }
+
+ return query;
+}
+
export async function importCsv(
client: SupabaseClient<Database>,
args: {
@@ -71,6 +85,13 @@ export async function insertNote(
return client.from("note").insert([note]).select("*").single();
}
+export async function insertTag(
+ client: SupabaseClient<Database>,
+ tag: Database["public"]["Tables"]["tag"]["Insert"]
+) {
+ return client.from("tag").insert(tag).select("*").single();
+}
+
export async function upsertExternalLink(
client: SupabaseClient<Database>,
externalLink: Database["public"]["Tables"]["externalLink"]["Insert"]
diff --git a/apps/carbon/app/routes/api+/shared.tags.ts b/apps/carbon/app/routes/api+/shared.tags.ts
new file mode 100644
index 0000000000..4b6af48c16
--- /dev/null
+++ b/apps/carbon/app/routes/api+/shared.tags.ts
@@ -0,0 +1,12 @@
+import { requirePermissions } from "@carbon/auth/auth.server";
+import type { LoaderFunctionArgs } from "@vercel/remix";
+import { json } from "@vercel/remix";
+import { getTagsList } from "~/modules/shared";
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ const { client, companyId } = await requirePermissions(request, {});
+ const url = new URL(request.url);
+ const table = url.searchParams.get("table");
+
+ return json(await getTagsList(client, companyId, table as string | null));
+}
diff --git a/apps/carbon/app/routes/x+/settings+/custom-fields.$table.$id.tsx b/apps/carbon/app/routes/x+/settings+/custom-fields.$table.$id.tsx
index 105d14956f..9799b4e731 100644
--- a/apps/carbon/app/routes/x+/settings+/custom-fields.$table.$id.tsx
+++ b/apps/carbon/app/routes/x+/settings+/custom-fields.$table.$id.tsx
@@ -101,6 +101,7 @@ export default function UpdateCustomFieldRoute() {
dataTypeId: (customField.dataTypeId || DataType.Text).toString(),
table: table,
listOptions: customField.listOptions ?? [],
+ tags: customField.tags ?? [],
}}
dataTypes={routeData?.dataTypes ?? []}
onClose={onClose}
diff --git a/apps/carbon/app/routes/x+/settings+/custom-fields.$table.new.tsx b/apps/carbon/app/routes/x+/settings+/custom-fields.$table.new.tsx
index dfa3eddf1e..184a4019d4 100644
--- a/apps/carbon/app/routes/x+/settings+/custom-fields.$table.new.tsx
+++ b/apps/carbon/app/routes/x+/settings+/custom-fields.$table.new.tsx
@@ -63,6 +63,7 @@ export default function NewCustomFieldRoute() {
// @ts-ignore
dataTypeId: DataType.Text.toString(),
table: table,
+ tags: [],
}}
dataTypes={routeData?.dataTypes ?? []}
onClose={onClose}
diff --git a/apps/carbon/app/routes/x+/settings+/tags.new.tsx b/apps/carbon/app/routes/x+/settings+/tags.new.tsx
new file mode 100644
index 0000000000..a47ae738fa
--- /dev/null
+++ b/apps/carbon/app/routes/x+/settings+/tags.new.tsx
@@ -0,0 +1,34 @@
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import { insertTag } from "~/modules/shared";
+
+export async function action({ request }: ActionFunctionArgs) {
+ const { client, companyId, userId } = await requirePermissions(request, {});
+
+ const formData = await request.formData();
+ const name = formData.get("name");
+ const table = formData.get("table");
+
+ if (typeof name !== "string" || typeof table !== "string") {
+ return json(
+ { success: false, message: "Invalid form data" },
+ { status: 400 }
+ );
+ }
+
+ const tag = await insertTag(client, {
+ name,
+ table,
+ companyId,
+ createdBy: userId,
+ });
+
+ if (tag.error) {
+ return json(
+ { success: false, message: tag.error.message },
+ { status: 500 }
+ );
+ }
+
+ return json({ success: true, tag });
+}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 6a769e4bcd..1cd10574dd 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -51,7 +51,6 @@ export const path = {
scrapReasons: `${api}/production/scrap-reasons`,
sequences: (table: string) => `${api}/settings/sequences?table=${table}`,
services: `${api}/items/services`,
-
shifts: (id: string) =>
generatePath(`${api}/people/shifts?location=${id}`),
shelves: (id: string) =>
@@ -64,6 +63,8 @@ export const path = {
generatePath(`${api}/purchasing/supplier-processes?processId=${id}`),
supplierStatuses: `${api}/purchasing/supplier-statuses`,
supplierTypes: `${api}/purchasing/supplier-types`,
+ tags: (table?: string) =>
+ generatePath(`${api}/shared/tags?table=${table}`),
unitOfMeasures: `${api}/items/uoms`,
workCentersByLocation: (id: string) =>
generatePath(`${api}/resources/work-centers?location=${id}`),
@@ -562,6 +563,7 @@ export const path = {
generatePath(`${x}/supplier/${id}/processes/new`),
newSupplierStatus: `${x}/purchasing/supplier-statuses/new`,
newSupplierType: `${x}/purchasing/supplier-types/new`,
+ newTag: `${x}/settings/tags/new`,
newTool: `${x}/tool/new`,
newToolSupplier: (id: string) =>
generatePath(`${x}/tool/${id}/purchasing/new`),
diff --git a/apps/mes/app/components/EndShift.tsx b/apps/mes/app/components/EndShift.tsx
index bab3a3a566..e879054028 100644
--- a/apps/mes/app/components/EndShift.tsx
+++ b/apps/mes/app/components/EndShift.tsx
@@ -19,7 +19,7 @@ import { useEffect, useState } from "react";
import { flushSync } from "react-dom";
import { FaFlagCheckered } from "react-icons/fa6";
import { useUser } from "~/hooks";
-import type { action } from "~/routes/x+/end-shift.tsx";
+import type { action } from "~/routes/x+/end-shift";
import {
getActiveJobOperationsByEmployee,
type Operation,
@@ -46,8 +46,6 @@ export const EndShift = ({ isCollapsed }: { isCollapsed: boolean }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetcher.data?.success]);
- console.log({ fetcher });
-
const openModal = async () => {
flushSync(() => {
setLoading(true);
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 7d9390c52c..022a77a5d8 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -4017,6 +4017,7 @@ export type Database = {
name: string
sortOrder: number
table: string
+ tags: string[] | null
updatedAt: string | null
updatedBy: string | null
}
@@ -4031,6 +4032,7 @@ export type Database = {
name: string
sortOrder?: number
table: string
+ tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -4045,6 +4047,7 @@ export type Database = {
name?: string
sortOrder?: number
table?: string
+ tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -20802,6 +20805,97 @@ export type Database = {
},
]
}
+ tag: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ name: string
+ table: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ id?: string
+ name: string
+ table?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ id?: string
+ name?: string
+ table?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "tag_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "tag_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
terms: {
Row: {
id: string
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 7d9390c52c..022a77a5d8 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -4017,6 +4017,7 @@ export type Database = {
name: string
sortOrder: number
table: string
+ tags: string[] | null
updatedAt: string | null
updatedBy: string | null
}
@@ -4031,6 +4032,7 @@ export type Database = {
name: string
sortOrder?: number
table: string
+ tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -4045,6 +4047,7 @@ export type Database = {
name?: string
sortOrder?: number
table?: string
+ tags?: string[] | null
updatedAt?: string | null
updatedBy?: string | null
}
@@ -20802,6 +20805,97 @@ export type Database = {
},
]
}
+ tag: {
+ Row: {
+ companyId: string
+ createdAt: string
+ createdBy: string
+ id: string
+ name: string
+ table: string | null
+ }
+ Insert: {
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ id?: string
+ name: string
+ table?: string | null
+ }
+ Update: {
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ id?: string
+ name?: string
+ table?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "tag_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "tag_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tag_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
terms: {
Row: {
id: string
diff --git a/packages/database/supabase/migrations/20241119015113_tags.sql b/packages/database/supabase/migrations/20241119015113_tags.sql
new file mode 100644
index 0000000000..ee8ef83ae4
--- /dev/null
+++ b/packages/database/supabase/migrations/20241119015113_tags.sql
@@ -0,0 +1,106 @@
+CREATE TABLE IF NOT EXISTS "tag" (
+ "id" TEXT NOT NULL DEFAULT xid() PRIMARY KEY,
+ "name" TEXT NOT NULL,
+ "table" TEXT NOT NULL,
+ "companyId" TEXT NOT NULL REFERENCES "company"("id") ON DELETE CASCADE,
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
+ "createdBy" TEXT NOT NULL REFERENCES "user"("id") ON DELETE RESTRICT,
+ UNIQUE("companyId", "name", "table")
+);
+
+ALTER TABLE "tag" ENABLE ROW LEVEL SECURITY;
+
+CREATE POLICY "Users can view tags in their company" ON "tag"
+ FOR SELECT
+ USING (
+ auth.uid()::text IN (
+ SELECT "userId" FROM "userToCompany" WHERE "companyId" = "tag"."companyId"
+ )
+ );
+
+CREATE POLICY "Users can insert tags in their company" ON "tag"
+ FOR INSERT
+ WITH CHECK (
+ auth.uid()::text IN (
+ SELECT "userId" FROM "userToCompany" WHERE "companyId" = "tag"."companyId"
+ )
+ );
+
+
+CREATE POLICY "Users can delete tags in their company" ON "tag"
+ FOR DELETE
+ USING (
+ has_role('employee', "companyId") AND
+ has_company_permission('update_settings', "companyId")
+ );
+
+UPDATE "customFieldTable" SET "table" = 'quoteMakeMethod', "name" = 'Quote Make Method' WHERE "table" = 'quoteAssembly';
+UPDATE "customFieldTable" SET "table" = 'salesRfq', "name" = 'Sales RFQ' WHERE "table" = 'rfqSales';
+UPDATE "customFieldTable" SET "table" = 'salesRfqLine', "name" = 'Sales RFQ Line' WHERE "table" = 'rfqLineSales';
+DELETE FROM "customFieldTable" WHERE "table" = 'serviceSupplier';
+ALTER TABLE "account" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "accountCategory" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "accountSubcategory" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "buyMethod" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "consumable" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "contractor" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "currency" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "customer" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "customerContact" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "customerLocation" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "customerStatus" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "customerType" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "department" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "employeeJob" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "fixture" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "holiday" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "itemCost" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "itemInventory" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "itemPlanning" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "itemPostingGroup" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "itemReplenishment" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "itemUnitSalePrice" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "job" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "journal" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "journalLine" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "location" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "makeMethod" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "material" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "materialForm" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "materialSubstance" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "methodMaterial" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "methodOperation" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "part" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "partner" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "paymentTerm" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "process" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "purchaseInvoice" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "purchaseInvoiceLine" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "purchaseOrder" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "purchaseOrderDelivery" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "purchaseOrderLine" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "purchaseOrderPayment" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "quote" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "quoteMakeMethod" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "quoteLine" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "quoteMaterial" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "quoteOperation" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "salesRfq" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "salesRfqLine" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "receipt" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "service" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "shelf" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "shift" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "shippingMethod" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "shippingTerm" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "supplier" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "supplierContact" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "supplierLocation" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "supplierPayment" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "supplierProcess" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "supplierShipping" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "supplierStatus" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "supplierType" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "tool" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "unitOfMeasure" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
+ALTER TABLE "workCenter" ADD COLUMN "tags" TEXT[] DEFAULT ARRAY[]::TEXT[];
diff --git a/packages/database/supabase/migrations/20241119033335_redefine-views.sql b/packages/database/supabase/migrations/20241119033335_redefine-views.sql
new file mode 100644
index 0000000000..ac53e67e5c
--- /dev/null
+++ b/packages/database/supabase/migrations/20241119033335_redefine-views.sql
@@ -0,0 +1,217 @@
+CREATE OR REPLACE VIEW "customFieldTables" WITH(SECURITY_INVOKER=true) AS
+SELECT
+ cft.*,
+ c.id AS "companyId",
+ COALESCE(cf.fields, '[]') as fields
+FROM "customFieldTable" cft
+ CROSS JOIN "company" c
+ LEFT JOIN (
+ SELECT
+ cf."table",
+ cf."companyId",
+ COALESCE(json_agg(
+ json_build_object(
+ 'id', id,
+ 'name', name,
+ 'sortOrder', "sortOrder",
+ 'dataTypeId', "dataTypeId",
+ 'listOptions', "listOptions",
+ 'active', active,
+ 'tags', tags
+ )
+ ), '[]') AS fields
+ FROM "customField" cf
+ GROUP BY cf."table", cf."companyId"
+ ) cf
+ ON cf.table = cft.table AND cf."companyId" = c.id;
+
+
+-- Update parts view
+DROP VIEW IF EXISTS "parts";
+CREATE OR REPLACE VIEW "parts" WITH (SECURITY_INVOKER=true) AS
+SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."unitOfMeasureCode",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ mu.id as "modelId",
+ mu."autodeskUrn",
+ mu."modelPath",
+ mu."name" as "modelName",
+ mu."size" as "modelSize",
+ p.*,
+ ps."supplierIds",
+ uom.name as "unitOfMeasure"
+FROM "part" p
+INNER JOIN "item" i ON i.id = p."itemId"
+LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(ps."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" ps
+ GROUP BY "itemId"
+) ps ON ps."itemId" = p."itemId"
+LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
+
+DROP VIEW IF EXISTS "fixtures";
+CREATE OR REPLACE VIEW "fixtures" WITH (SECURITY_INVOKER=true) AS
+SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."unitOfMeasureCode",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ f.*,
+ mu.id as "modelId",
+ mu."autodeskUrn",
+ mu."modelPath",
+ mu."name" as "modelName",
+ mu."size" as "modelSize",
+ s."supplierIds",
+ c.name as "customer"
+FROM "fixture" f
+INNER JOIN "item" i ON i.id = f."itemId"
+LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(s."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" s
+ GROUP BY "itemId"
+) s ON s."itemId" = f."itemId"
+LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"
+LEFT JOIN "customer" c ON c.id = f."customerId";
+
+DROP VIEW IF EXISTS "materials";
+CREATE OR REPLACE VIEW "materials" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."thumbnailPath",
+ i."unitOfMeasureCode",
+ m.*,
+ mf."name" AS "materialForm",
+ ms."name" AS "materialSubstance",
+ s."supplierIds",
+ uom.name as "unitOfMeasure"
+ FROM "material" m
+ INNER JOIN "item" i ON i.id = m."itemId"
+ LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(s."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" s
+ GROUP BY "itemId"
+ ) s ON s."itemId" = m."itemId"
+ LEFT JOIN "materialForm" mf ON mf.id = m."materialFormId"
+ LEFT JOIN "materialSubstance" ms ON ms.id = m."materialSubstanceId"
+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
+
+
+DROP VIEW IF EXISTS "tools";
+CREATE OR REPLACE VIEW "tools" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."thumbnailPath",
+ i."unitOfMeasureCode",
+ t.*,
+ s."supplierIds",
+ uom.name as "unitOfMeasure"
+ FROM "tool" t
+ INNER JOIN "item" i ON i.id = t."itemId"
+ LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(s."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" s
+ GROUP BY "itemId"
+ ) s ON s."itemId" = t."itemId"
+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
+
+DROP VIEW IF EXISTS "consumables";
+CREATE OR REPLACE VIEW "consumables" WITH(SECURITY_INVOKER=true) AS
+ SELECT
+ i."active",
+ i."assignee",
+ i."defaultMethodType",
+ i."description",
+ i."itemTrackingType",
+ i."name",
+ i."replenishmentSystem",
+ i."thumbnailPath",
+ i."unitOfMeasureCode",
+ c.*,
+ s."supplierIds",
+ uom.name as "unitOfMeasure"
+ FROM "consumable" c
+ INNER JOIN "item" i ON i.id = c."itemId"
+ LEFT JOIN (
+ SELECT
+ "itemId",
+ string_agg(s."supplierPartId", ',') AS "supplierIds"
+ FROM "buyMethod" s
+ GROUP BY "itemId"
+ ) s ON s."itemId" = c."itemId"
+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId";
+
+DROP VIEW IF EXISTS "jobs";
+CREATE OR REPLACE VIEW "jobs" WITH(SECURITY_INVOKER=true) AS
+WITH job_model AS (
+ SELECT
+ j.id AS job_id,
+ COALESCE(j."modelUploadId", i."modelUploadId") AS model_upload_id
+ FROM "job" j
+ INNER JOIN "item" i ON j."itemId" = i."id"
+)
+SELECT
+ j.*,
+ i.name,
+ i."readableId" as "itemReadableId",
+ i.type as "itemType",
+ i.name as "description",
+ i."itemTrackingType",
+ i.active,
+ i."replenishmentSystem",
+ mu.id as "modelId",
+ mu."autodeskUrn",
+ mu."modelPath",
+ CASE
+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"
+ ELSE i."thumbnailPath"
+ END as "thumbnailPath",
+ mu."name" as "modelName",
+ mu."size" as "modelSize",
+ so."salesOrderId" as "salesOrderReadableId",
+ qo."quoteId" as "quoteReadableId"
+FROM "job" j
+INNER JOIN "item" i ON j."itemId" = i."id"
+LEFT JOIN job_model jm ON j.id = jm.job_id
+LEFT JOIN "modelUpload" mu ON mu.id = jm.model_upload_id
+LEFT JOIN "salesOrder" so on j."salesOrderId" = so.id
+LEFT JOIN "quote" qo ON j."quoteId" = qo.id;
diff --git a/packages/react/src/CreateableMultiSelect.tsx b/packages/react/src/CreateableMultiSelect.tsx
index f15c4701a5..5c66a58662 100644
--- a/packages/react/src/CreateableMultiSelect.tsx
+++ b/packages/react/src/CreateableMultiSelect.tsx
@@ -327,7 +327,7 @@ function SelectedOption({
<Badge
key={item}
variant="secondary"
- className="border border-border shadow-sm"
+ className="border border-card shadow-sm"
>
{options.find((option) => option.value === item)?.label}
<BadgeCloseButton
diff --git a/packages/react/src/Editor/Editor.tsx b/packages/react/src/Editor/Editor.tsx
index 084ee91771..c38eeef5aa 100644
--- a/packages/react/src/Editor/Editor.tsx
+++ b/packages/react/src/Editor/Editor.tsx
@@ -24,7 +24,6 @@ import {
import { useMemo, useState } from "react";
import { toast } from "sonner";
import { Separator } from "../Separator";
-import { cn } from "../utils/cn";
import { ColorSelector } from "./components/ColorSelector";
import { LinkSelector } from "./components/LinkSelector";
import { NodeSelector } from "./components/NodeSelector";
@@ -94,7 +93,7 @@ const Editor = ({
return (
<EditorRoot>
<EditorContent
- className={cn("p-4", className)}
+ className={className}
{...(initialValue && { initialContent: initialValue })}
extensions={extensions}
editorProps={{
diff --git a/packages/react/src/MultiSelect.tsx b/packages/react/src/MultiSelect.tsx
index dfb3207aea..a325d5919b 100644
--- a/packages/react/src/MultiSelect.tsx
+++ b/packages/react/src/MultiSelect.tsx
@@ -79,7 +79,11 @@ const MultiSelect = forwardRef<HTMLButtonElement, MultiSelectProps>(
{hasSelections ? (
<div className="flex gap-1 flex-wrap">
{value.map((item) => (
- <Badge key={item} variant="secondary">
+ <Badge
+ key={item}
+ variant="secondary"
+ className="border border-card"
+ >
{options.find((option) => option.value === item)?.label}
<BadgeCloseButton
type="button"