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: upsert saved view

Brad Barbin6f3bd18adb7e
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsx
index 821df6f554..b92f15f99b 100644
--- a/apps/erp/app/components/Table/Table.tsx
+++ b/apps/erp/app/components/Table/Table.tsx
@@ -72,9 +72,11 @@ interface TableProps<T extends object> {
label: string;
}[];
primaryAction?: ReactNode;
+ table?: string;
title?: string;
withInlineEditing?: boolean;
withPagination?: boolean;
+ withSavedView?: boolean;
withSearch?: boolean;
withSelectableRows?: boolean;
withSimpleSorting?: boolean;
@@ -94,9 +96,11 @@ const Table = <T extends object>({
editableComponents,
importCSV,
primaryAction,
+ table: tableName,
title,
withInlineEditing = false,
withPagination = true,
+ withSavedView = true,
withSearch = true,
withSelectableRows = false,
withSimpleSorting = true,
@@ -600,6 +604,8 @@ const Table = <T extends object>({
<TableHeader
columnAccessors={columnAccessors}
columnOrder={columnOrder}
+ columnPinning={columnPinning}
+ columnVisibility={columnVisibility}
columns={table.getAllLeafColumns()}
compact={compact}
editMode={editMode}
@@ -611,9 +617,11 @@ const Table = <T extends object>({
selectedRows={selectedRows}
setColumnOrder={setColumnOrder}
setEditMode={setEditMode}
+ table={tableName}
title={title}
withInlineEditing={withInlineEditing}
withPagination={withPagination}
+ withSavedView={withSavedView}
withSearch={withSearch}
withSelectableRows={withSelectableRows}
/>
diff --git a/apps/erp/app/components/Table/components/TableHeader.tsx b/apps/erp/app/components/Table/components/TableHeader.tsx
index 24232a7cbe..ffb40cfbf5 100644
--- a/apps/erp/app/components/Table/components/TableHeader.tsx
+++ b/apps/erp/app/components/Table/components/TableHeader.tsx
@@ -1,4 +1,4 @@
-import { Input, ValidatedForm } from "@carbon/form";
+import { Hidden, Input, Submit, ValidatedForm } from "@carbon/form";
import {
Badge,
Button,
@@ -21,16 +21,23 @@ import {
TooltipTrigger,
useDisclosure,
} from "@carbon/react";
-import type { Column, ColumnOrderState } from "@tanstack/react-table";
+import { useFetcher } from "@remix-run/react";
+import type {
+ Column,
+ ColumnOrderState,
+ ColumnPinningState,
+} from "@tanstack/react-table";
import { useState, type ReactNode } from "react";
import { BsThreeDotsVertical } from "react-icons/bs";
import { LuCheck, LuFilePen, LuImport, LuLayers, LuLock } from "react-icons/lu";
-import { z } from "zod";
import { SearchFilter } from "~/components";
import { ImportCSVModal } from "~/components/ImportCSVModal";
import { CollapsibleSidebarTrigger } from "~/components/Layout/Navigation";
import { useUrlParams } from "~/hooks";
import type { fieldMappings } from "~/modules/shared/imports.models";
+import { savedViewValidator } from "~/modules/shared/shared.models";
+import type { action as savedViewAction } from "~/routes/x+/shared+/view";
+import { path } from "~/utils/path";
import Columns from "./Columns";
import { ActiveFilters, Filter } from "./Filter";
import type { ColumnFilter } from "./Filter/types";
@@ -42,6 +49,8 @@ type HeaderProps<T> = {
renderActions?: (selectedRows: T[]) => ReactNode;
columnAccessors: Record<string, string>;
columnOrder: ColumnOrderState;
+ columnPinning: ColumnPinningState;
+ columnVisibility: Record<string, boolean>;
columns: Column<T, unknown>[];
compact?: boolean;
editMode: boolean;
@@ -55,7 +64,9 @@ type HeaderProps<T> = {
selectedRows: T[];
setColumnOrder: (newOrder: ColumnOrderState) => void;
setEditMode: (editMode: boolean) => void;
+ table?: string;
title?: string;
+ withSavedView: boolean;
withInlineEditing: boolean;
withPagination: boolean;
withSearch: boolean;
@@ -66,6 +77,8 @@ const TableHeader = <T extends object>({
compact,
columnAccessors,
columnOrder,
+ columnPinning,
+ columnVisibility,
columns,
editMode,
filters,
@@ -76,9 +89,11 @@ const TableHeader = <T extends object>({
renderActions,
setColumnOrder,
setEditMode,
+ table,
title,
withInlineEditing,
withPagination,
+ withSavedView,
withSearch,
withSelectableRows,
}: HeaderProps<T>) => {
@@ -89,20 +104,30 @@ const TableHeader = <T extends object>({
>(null);
const savedViewDisclosure = useDisclosure();
+ const canSaveView = withSavedView && !!table;
+ const fetcher = useFetcher<typeof savedViewAction>();
return (
<div className={cn("w-full flex flex-col", !compact && "mb-8")}>
- {savedViewDisclosure.isOpen ? (
+ {canSaveView && savedViewDisclosure.isOpen ? (
<ValidatedForm
- onSubmit={() => {}}
- validator={z.object({
- name: z
- .string()
- .min(1, { message: "A name is required to save a view" }),
- })}
+ method="post"
+ action={path.to.saveView}
+ validator={savedViewValidator}
className="w-full px-2 md:px-0"
+ fetcher={fetcher}
>
<Card className="my-4 p-0">
+ <Hidden
+ name="state"
+ value={JSON.stringify({
+ columnOrder,
+ columnPinning,
+ columnVisibility,
+ })}
+ />
+ <Hidden name="table" value={table} />
+ <Hidden name="type" value="Private" />
<CardContent className="flex flex-col gap-0 p-4">
<Input
autoFocus
@@ -122,7 +147,7 @@ const TableHeader = <T extends object>({
<Button variant="secondary" onClick={savedViewDisclosure.onClose}>
Cancel
</Button>
- <Button>Save</Button>
+ <Submit>Save</Submit>
</CardFooter>
</Card>
</ValidatedForm>
@@ -214,19 +239,21 @@ const TableHeader = <T extends object>({
withSelectableRows={withSelectableRows}
/>
- <Tooltip>
- <TooltipTrigger asChild>
- <IconButton
- aria-label="Save View"
- variant={savedViewDisclosure.isOpen ? "active" : "ghost"}
- icon={<LuLayers />}
- onClick={savedViewDisclosure.onToggle}
- />
- </TooltipTrigger>
- <TooltipContent>
- <p>Save View</p>
- </TooltipContent>
- </Tooltip>
+ {canSaveView && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ aria-label="Save View"
+ variant={savedViewDisclosure.isOpen ? "active" : "ghost"}
+ icon={<LuLayers />}
+ onClick={savedViewDisclosure.onToggle}
+ />
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>Save View</p>
+ </TooltipContent>
+ </Tooltip>
+ )}
{withPagination &&
(pagination.canNextPage || pagination.canPreviousPage) && (
diff --git a/apps/erp/app/components/Table/components/Views/useSavedView.tsx b/apps/erp/app/components/Table/components/Views/useSavedView.tsx
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx
index 1866deaaff..47fc169cdc 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuotesTable.tsx
@@ -213,7 +213,6 @@ const QuotesTable = memo(({ data, count }: QuotesTableProps) => {
icon: <LuMap />,
},
},
-
{
id: "createdBy",
header: "Created By",
@@ -313,6 +312,7 @@ const QuotesTable = memo(({ data, count }: QuotesTableProps) => {
)
}
renderContextMenu={renderContextMenu}
+ table="quote"
title="Quotes"
/>
{selectedQuotation && selectedQuotation.id && (
diff --git a/apps/erp/app/modules/shared/shared.models.ts b/apps/erp/app/modules/shared/shared.models.ts
index 0523a5499d..b5710ee1be 100644
--- a/apps/erp/app/modules/shared/shared.models.ts
+++ b/apps/erp/app/modules/shared/shared.models.ts
@@ -91,6 +91,23 @@ export const operationToolValidator = z.object({
),
});
+export const savedViewValidator = z.object({
+ id: zfd.text(z.string().optional()),
+ table: z.string(),
+ name: z.string().min(1, { message: "A name is required to save a view" }),
+ description: z.string().optional(),
+ filter: z.string().optional(),
+ sort: z.string().optional(),
+ state: z.string(),
+ type: z.enum(["Public", "Private"]),
+});
+
+export const savedViewStateValidator = z.object({
+ columnOrder: z.array(z.string()),
+ columnPinning: z.any(),
+ columnVisibility: z.record(z.boolean()),
+});
+
export const standardFactorType = [
"Hours/Piece",
"Hours/100 Pieces",
diff --git a/apps/erp/app/modules/shared/shared.service.ts b/apps/erp/app/modules/shared/shared.service.ts
index 9c3966a40c..258ac3ad9e 100644
--- a/apps/erp/app/modules/shared/shared.service.ts
+++ b/apps/erp/app/modules/shared/shared.service.ts
@@ -195,14 +195,6 @@ export async function upsertExternalLink(
return client.from("externalLink").insert(externalLink).select("id").single();
}
-export async function updateNote(
- client: SupabaseClient<Database>,
- id: string,
- note: string
-) {
- return client.from("note").update({ note }).eq("id", id);
-}
-
export async function updateModelThumbnail(
client: SupabaseClient<Database>,
modelId: string,
@@ -233,3 +225,52 @@ export async function upsertModelUpload(
}
return client.from("modelUpload").update(upload).eq("id", upload.id);
}
+
+export async function updateNote(
+ client: SupabaseClient<Database>,
+ id: string,
+ note: string
+) {
+ return client.from("note").update({ note }).eq("id", id);
+}
+
+export async function upsertSavedView(
+ client: SupabaseClient<Database>,
+ view: {
+ id?: string;
+ name: string;
+ description?: string;
+ table: string;
+ type: "Public" | "Private";
+ filter?: string;
+ sort?: string;
+ columnPinning?: Record<string, boolean>;
+ columnVisibility?: Record<string, boolean>;
+ columnOrder?: string[];
+ userId: string;
+ companyId: string;
+ }
+) {
+ const { userId, ...data } = view;
+ if ("id" in view && view.id) {
+ return client
+ .from("tableView")
+ .update({
+ ...data,
+ updatedBy: userId,
+ })
+ .eq("id", view.id);
+ }
+ const tableModule = await client
+ .from("customFieldTable")
+ .select("module")
+ .eq("table", view.table)
+ .single();
+
+ if (tableModule.error) return tableModule;
+ return client.from("tableView").insert({
+ ...data,
+ module: tableModule.data?.module,
+ createdBy: userId,
+ });
+}
diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.tsx
index a5b2cf67c4..97a07749db 100644
--- a/apps/erp/app/routes/x+/quote+/$quoteId.tsx
+++ b/apps/erp/app/routes/x+/quote+/$quoteId.tsx
@@ -136,7 +136,7 @@ export default function QuoteRoute() {
return (
<PanelProvider>
- <div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full">
+ <div className="flex flex-col h-[calc(100dvh-49px)] overflow-hidden w-full ">
<QuoteHeader />
<div className="flex h-[calc(100dvh-99px)] overflow-hidden w-full">
<div className="flex flex-grow overflow-hidden">
diff --git a/apps/erp/app/routes/x+/shared+/view.tsx b/apps/erp/app/routes/x+/shared+/view.tsx
new file mode 100644
index 0000000000..96b11f4b38
--- /dev/null
+++ b/apps/erp/app/routes/x+/shared+/view.tsx
@@ -0,0 +1,56 @@
+import { assertIsPost } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { validator } from "@carbon/form";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import {
+ savedViewStateValidator,
+ savedViewValidator,
+} from "~/modules/shared/shared.models";
+
+import { upsertSavedView } from "~/modules/shared/shared.service";
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, companyId, userId } = await requirePermissions(request, {});
+
+ const formData = await request.formData();
+ const validation = await validator(savedViewValidator).validate(formData);
+
+ if (validation.error) {
+ return json({
+ success: false,
+ message: "Invalid form data",
+ });
+ }
+
+ const { state, ...data } = validation.data;
+
+ try {
+ const parsedState = JSON.parse(state);
+ const validatedState = savedViewStateValidator.parse(parsedState);
+
+ const result = await upsertSavedView(client, {
+ ...data,
+ ...validatedState,
+ userId,
+ companyId,
+ });
+
+ if (result.error) {
+ return json({
+ success: false,
+ message: result.error.message,
+ });
+ }
+
+ return json({
+ success: true,
+ message: "View saved",
+ });
+ } catch (error) {
+ return json({
+ success: false,
+ message: "Invalid state",
+ });
+ }
+}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index fe580c6b1a..dd469f529e 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -824,6 +824,7 @@ export const path = {
salesRfqStatus: (id: string) => generatePath(`${x}/sales-rfq/${id}/status`),
salesRfqs: `${x}/sales/rfqs`,
salesSettings: `${x}/settings/sales`,
+ saveView: `${x}/shared/view`,
schedule: `${x}/schedule`,
scheduleOperationUpdate: `${x}/schedule/operation/update`,
scrapReason: (id: string) =>
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 652900154b..5b67c2282f 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -573,6 +573,231 @@ export default {
tags: ["supplierAccount"],
},
},
+ "/tableView": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.tableView.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.table",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.description",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.module",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.type",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnPinning",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnVisibility",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.filter",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.sort",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.updatedBy",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/tableView",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["tableView"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.tableView",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["tableView"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.tableView.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.table",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.description",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.module",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.type",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnPinning",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnVisibility",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.filter",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.sort",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.updatedBy",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["tableView"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.tableView.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.name",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.table",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.description",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.module",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.type",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnOrder",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnPinning",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.columnVisibility",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.filter",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.sort",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.createdBy",
+ },
+ {
+ $ref: "#/parameters/rowFilter.tableView.updatedBy",
+ },
+ {
+ $ref: "#/parameters/body.tableView",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["tableView"],
+ },
+ },
"/supplierType": {
get: {
parameters: [
@@ -44637,6 +44862,110 @@ export default {
},
type: "object",
},
+ tableView: {
+ required: [
+ "id",
+ "name",
+ "table",
+ "type",
+ "companyId",
+ "createdAt",
+ "createdBy",
+ ],
+ properties: {
+ id: {
+ default: "public.xid()",
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ name: {
+ format: "text",
+ type: "string",
+ },
+ table: {
+ description:
+ "Note:\nThis is a Foreign Key to `customFieldTable.table`.<fk table='customFieldTable' column='table'/>",
+ format: "text",
+ type: "string",
+ },
+ description: {
+ format: "text",
+ type: "string",
+ },
+ module: {
+ enum: [
+ "Accounting",
+ "Documents",
+ "Invoicing",
+ "Inventory",
+ "Items",
+ "Messaging",
+ "Parts",
+ "People",
+ "Production",
+ "Purchasing",
+ "Resources",
+ "Sales",
+ "Settings",
+ "Users",
+ ],
+ format: "public.module",
+ type: "string",
+ },
+ type: {
+ default: "Private",
+ enum: ["Public", "Private"],
+ format: 'public."tableViewType"',
+ type: "string",
+ },
+ columnOrder: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
+ columnPinning: {
+ format: "jsonb",
+ },
+ columnVisibility: {
+ format: "jsonb",
+ },
+ filter: {
+ format: "text",
+ type: "string",
+ },
+ sort: {
+ format: "text",
+ type: "string",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ createdAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ createdBy: {
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ updatedBy: {
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
supplierType: {
required: [
"id",
@@ -63663,6 +63992,120 @@ export default {
in: "query",
type: "string",
},
+ "body.tableView": {
+ name: "tableView",
+ description: "tableView",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/tableView",
+ },
+ },
+ "rowFilter.tableView.id": {
+ name: "id",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.name": {
+ name: "name",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.table": {
+ name: "table",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.description": {
+ name: "description",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.module": {
+ name: "module",
+ required: false,
+ format: "public.module",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.type": {
+ name: "type",
+ required: false,
+ format: 'public."tableViewType"',
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.columnOrder": {
+ name: "columnOrder",
+ required: false,
+ format: "text[]",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.columnPinning": {
+ name: "columnPinning",
+ required: false,
+ format: "jsonb",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.columnVisibility": {
+ name: "columnVisibility",
+ required: false,
+ format: "jsonb",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.filter": {
+ name: "filter",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.sort": {
+ name: "sort",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.companyId": {
+ name: "companyId",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.createdAt": {
+ name: "createdAt",
+ required: false,
+ format: "timestamp with time zone",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.createdBy": {
+ name: "createdBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.tableView.updatedBy": {
+ name: "updatedBy",
+ required: false,
+ format: "text",
+ in: "query",
+ type: "string",
+ },
"body.supplierType": {
name: "supplierType",
description: "supplierType",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 7c11408250..10ccb31b83 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -24130,6 +24130,173 @@ export type Database = {
},
]
}
+ tableView: {
+ Row: {
+ columnOrder: string[] | null
+ columnPinning: Json | null
+ columnVisibility: Json | null
+ companyId: string
+ createdAt: string
+ createdBy: string
+ description: string | null
+ filter: string | null
+ id: string
+ module: Database["public"]["Enums"]["module"] | null
+ name: string
+ sort: string | null
+ table: string
+ type: Database["public"]["Enums"]["tableViewType"]
+ updatedBy: string | null
+ }
+ Insert: {
+ columnOrder?: string[] | null
+ columnPinning?: Json | null
+ columnVisibility?: Json | null
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ description?: string | null
+ filter?: string | null
+ id?: string
+ module?: Database["public"]["Enums"]["module"] | null
+ name: string
+ sort?: string | null
+ table: string
+ type?: Database["public"]["Enums"]["tableViewType"]
+ updatedBy?: string | null
+ }
+ Update: {
+ columnOrder?: string[] | null
+ columnPinning?: Json | null
+ columnVisibility?: Json | null
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ description?: string | null
+ filter?: string | null
+ id?: string
+ module?: Database["public"]["Enums"]["module"] | null
+ name?: string
+ sort?: string | null
+ table?: string
+ type?: Database["public"]["Enums"]["tableViewType"]
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "tableView_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "tableView_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "tableView_table_fkey"
+ columns: ["table"]
+ isOneToOne: false
+ referencedRelation: "customFieldTable"
+ referencedColumns: ["table"]
+ },
+ {
+ foreignKeyName: "tableView_table_fkey"
+ columns: ["table"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["table"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
tag: {
Row: {
companyId: string
@@ -34251,6 +34418,7 @@ export type Database = {
| "Reminder"
| "Refund"
supplierQuoteStatus: "Active" | "Expired"
+ tableViewType: "Public" | "Private"
trackingSource: "Purchased" | "Manufactured"
}
CompositeTypes: {
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 7c11408250..10ccb31b83 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -24130,6 +24130,173 @@ export type Database = {
},
]
}
+ tableView: {
+ Row: {
+ columnOrder: string[] | null
+ columnPinning: Json | null
+ columnVisibility: Json | null
+ companyId: string
+ createdAt: string
+ createdBy: string
+ description: string | null
+ filter: string | null
+ id: string
+ module: Database["public"]["Enums"]["module"] | null
+ name: string
+ sort: string | null
+ table: string
+ type: Database["public"]["Enums"]["tableViewType"]
+ updatedBy: string | null
+ }
+ Insert: {
+ columnOrder?: string[] | null
+ columnPinning?: Json | null
+ columnVisibility?: Json | null
+ companyId: string
+ createdAt?: string
+ createdBy: string
+ description?: string | null
+ filter?: string | null
+ id?: string
+ module?: Database["public"]["Enums"]["module"] | null
+ name: string
+ sort?: string | null
+ table: string
+ type?: Database["public"]["Enums"]["tableViewType"]
+ updatedBy?: string | null
+ }
+ Update: {
+ columnOrder?: string[] | null
+ columnPinning?: Json | null
+ columnVisibility?: Json | null
+ companyId?: string
+ createdAt?: string
+ createdBy?: string
+ description?: string | null
+ filter?: string | null
+ id?: string
+ module?: Database["public"]["Enums"]["module"] | null
+ name?: string
+ sort?: string | null
+ table?: string
+ type?: Database["public"]["Enums"]["tableViewType"]
+ updatedBy?: string | null
+ }
+ Relationships: [
+ {
+ foreignKeyName: "tableView_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "companies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "company"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "tableView_companyId_fkey"
+ columns: ["companyId"]
+ isOneToOne: false
+ referencedRelation: "integrations"
+ referencedColumns: ["companyId"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_createdBy_fkey"
+ columns: ["createdBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ {
+ foreignKeyName: "tableView_table_fkey"
+ columns: ["table"]
+ isOneToOne: false
+ referencedRelation: "customFieldTable"
+ referencedColumns: ["table"]
+ },
+ {
+ foreignKeyName: "tableView_table_fkey"
+ columns: ["table"]
+ isOneToOne: false
+ referencedRelation: "customFieldTables"
+ referencedColumns: ["table"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employees"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeesAcrossCompanies"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "employeeSummary"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "user"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "tableView_updatedBy_fkey"
+ columns: ["updatedBy"]
+ isOneToOne: false
+ referencedRelation: "userDefaults"
+ referencedColumns: ["userId"]
+ },
+ ]
+ }
tag: {
Row: {
companyId: string
@@ -34251,6 +34418,7 @@ export type Database = {
| "Reminder"
| "Refund"
supplierQuoteStatus: "Active" | "Expired"
+ tableViewType: "Public" | "Private"
trackingSource: "Purchased" | "Manufactured"
}
CompositeTypes: {
diff --git a/packages/database/supabase/migrations/20250204195403_saved-views.sql b/packages/database/supabase/migrations/20250204195403_saved-views.sql
index 675966be63..b9f0e000b3 100644
--- a/packages/database/supabase/migrations/20250204195403_saved-views.sql
+++ b/packages/database/supabase/migrations/20250204195403_saved-views.sql
@@ -1,11 +1,13 @@
-CREATE TYPE "viewType" AS ENUM ('Public', 'Private');
+CREATE TYPE "tableViewType" AS ENUM ('Public', 'Private');
DROP TABLE IF EXISTS "tableView";
CREATE TABLE IF NOT EXISTS "tableView" (
"id" TEXT NOT NULL DEFAULT xid(),
"name" TEXT NOT NULL,
"table" TEXT NOT NULL,
- "type" "viewType" NOT NULL DEFAULT 'Private',
+ "description" TEXT,
+ "module" module,
+ "type" "tableViewType" NOT NULL DEFAULT 'Private',
"columnOrder" TEXT ARRAY,
"columnPinning" JSONB,
"columnVisibility" JSONB,
@@ -22,7 +24,12 @@ CREATE TABLE IF NOT EXISTS "tableView" (
CONSTRAINT "tableView_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE
);
-ALTER TABLE "view" ENABLE ROW LEVEL SECURITY;
+CREATE INDEX "tableView_module_createdBy_idx" ON "tableView" ("module", "createdBy");
+CREATE INDEX "tableView_companyId_idx" ON "tableView" ("companyId");
+
+
+
+ALTER TABLE "tableView" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "SELECT" ON "tableView"
FOR SELECT