Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

refactor: standardize name argument as search

Brad Barbin206a7fe5fe30
diff --git a/apps/carbon/app/modules/accounting/accounting.service.ts b/apps/carbon/app/modules/accounting/accounting.service.ts
index 267b5a2e11..13b9bef683 100644
--- a/apps/carbon/app/modules/accounting/accounting.service.ts
+++ b/apps/carbon/app/modules/accounting/accounting.service.ts
@@ -164,7 +164,7 @@ export async function getAccountsList(
export async function getAccountCategories(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
class: string | null;
incomeBalance: string | null;
}
@@ -173,8 +173,8 @@ export async function getAccountCategories(
count: "exact",
});
- if (args.name) {
- query = query.ilike("category", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("category", `%${args.search}%`);
}
if (args.class) {
@@ -216,7 +216,7 @@ export async function getAccountCategory(
export async function getAccountSubcategories(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
}
) {
let query = client
@@ -226,8 +226,8 @@ export async function getAccountSubcategories(
})
.eq("active", true);
- if (args.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
query = setGenericQueryFilters(query, args, [
@@ -389,7 +389,7 @@ export async function getCurrency(
export async function getCurrencies(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
}
) {
let query = client
@@ -399,8 +399,8 @@ export async function getCurrencies(
})
.eq("active", true);
- if (args.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
query = setGenericQueryFilters(query, args, [
@@ -499,7 +499,7 @@ export async function getPaymentTerm(
export async function getPaymentTerms(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
}
) {
let query = client
@@ -509,8 +509,8 @@ export async function getPaymentTerms(
})
.eq("active", true);
- if (args.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
query = setGenericQueryFilters(query, args, [
diff --git a/apps/carbon/app/modules/parts/parts.service.ts b/apps/carbon/app/modules/parts/parts.service.ts
index ff1e471fca..0405f51b31 100644
--- a/apps/carbon/app/modules/parts/parts.service.ts
+++ b/apps/carbon/app/modules/parts/parts.service.ts
@@ -69,23 +69,8 @@ export async function getPartGroups(
return query;
}
-export async function getPartGroupsList(
- client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
-) {
- let query = client.from("partGroup").select("id, name", { count: "exact" });
-
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
- }
-
- if (args) {
- query = setGenericQueryFilters(query, args, [
- { column: "name", ascending: true },
- ]);
- }
-
- return query;
+export async function getPartGroupsList(client: SupabaseClient<Database>) {
+ return client.from("partGroup").select("id, name", { count: "exact" });
}
export async function getPartInventory(
diff --git a/apps/carbon/app/modules/purchasing/purchasing.service.ts b/apps/carbon/app/modules/purchasing/purchasing.service.ts
index ecc07deb71..e6f6d158d3 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.service.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.service.ts
@@ -347,7 +347,7 @@ export async function getSupplierShipping(
export async function getSuppliers(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
type: string | null;
status: string | null;
}
@@ -356,8 +356,8 @@ export async function getSuppliers(
count: "exact",
});
- if (args.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args.type) {
@@ -391,12 +391,12 @@ export async function getSupplierStatus(
export async function getSupplierStatuses(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
+ args?: GenericQueryFilters & { search: string | null }
) {
let query = client.from("supplierStatus").select("*", { count: "exact" });
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
@@ -427,12 +427,12 @@ export async function getSupplierType(
export async function getSupplierTypes(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
+ args?: GenericQueryFilters & { search: string | null }
) {
let query = client.from("supplierType").select("*", { count: "exact" });
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.ts
index 08e85fee5d..4a92830717 100644
--- a/apps/carbon/app/modules/resources/resources.service.ts
+++ b/apps/carbon/app/modules/resources/resources.service.ts
@@ -142,7 +142,7 @@ export async function deleteWorkCellType(
export async function getAbilities(
client: SupabaseClient<Database>,
- args: GenericQueryFilters & { name: string | null }
+ args: GenericQueryFilters & { search: string | null }
) {
let query = client
.from("ability")
@@ -153,8 +153,8 @@ export async function getAbilities(
.eq("employeeAbility.active", true)
.eq("employeeAbility.user.active", true);
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
query = setGenericQueryFilters(query, args, [
@@ -220,7 +220,7 @@ async function getAttributes(
export async function getAttributeCategories(
client: SupabaseClient<Database>,
- args?: { name: string | null } & GenericQueryFilters
+ args?: { search: string | null } & GenericQueryFilters
) {
let query = client
.from("userAttributeCategory")
@@ -230,8 +230,8 @@ export async function getAttributeCategories(
.eq("active", true)
.eq("userAttribute.active", true);
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
@@ -282,12 +282,12 @@ export async function getContractor(
export async function getContractors(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null; ability: string | null }
+ args?: GenericQueryFilters & { search: string | null; ability: string | null }
) {
let query = client.from("contractors").select("*").eq("active", true);
- if (args?.name) {
- query = query.ilike("supplierName", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("supplierName", `%${args.search}%`);
}
if (args?.ability) {
@@ -312,14 +312,14 @@ export async function getDepartment(
export async function getDepartments(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
+ args?: GenericQueryFilters & { search: string | null }
) {
let query = client.from("department").select(`*, department(id, name)`, {
count: "exact",
});
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
@@ -406,7 +406,7 @@ export async function getEquipmentType(
export async function getEquipmentTypes(
client: SupabaseClient<Database>,
- args?: { name: string | null } & GenericQueryFilters
+ args?: { search: string | null } & GenericQueryFilters
) {
let query = client
.from("equipmentType")
@@ -416,8 +416,8 @@ export async function getEquipmentTypes(
.eq("active", true)
.eq("equipment.active", true);
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
@@ -442,14 +442,14 @@ export async function getHoliday(
export async function getHolidays(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null; year: number | null }
+ args?: GenericQueryFilters & { search: string | null; year: number | null }
) {
let query = client.from("holiday").select("*", {
count: "exact",
});
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args?.year) {
@@ -478,12 +478,12 @@ export async function getLocation(
export async function getLocations(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
+ args?: GenericQueryFilters & { search: string | null }
) {
let query = client.from("location").select("*", { count: "exact" });
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
@@ -525,12 +525,12 @@ export async function getPartner(
export async function getPartners(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null; ability: string | null }
+ args?: GenericQueryFilters & { search: string | null; ability: string | null }
) {
let query = client.from("partners").select("*").eq("active", true);
- if (args?.name) {
- query = query.ilike("supplierName", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("supplierName", `%${args.search}%`);
}
if (args?.ability) {
@@ -568,7 +568,7 @@ type Person = Employee & {
export async function getPeople(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
type: string | null;
active: boolean | null;
}
@@ -661,7 +661,7 @@ export async function getShift(
export async function getShifts(
client: SupabaseClient<Database>,
- args: GenericQueryFilters & { name: string | null; location: string | null }
+ args: GenericQueryFilters & { search: string | null; location: string | null }
) {
let query = client
.from("shift")
@@ -674,8 +674,8 @@ export async function getShifts(
.eq("active", true)
.eq("employeeShift.user.active", true);
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args.location) {
@@ -747,7 +747,7 @@ export async function getWorkCellType(
export async function getWorkCellTypes(
client: SupabaseClient<Database>,
- args?: { name: string | null } & GenericQueryFilters
+ args?: { search: string | null } & GenericQueryFilters
) {
let query = client
.from("workCellType")
@@ -757,8 +757,8 @@ export async function getWorkCellTypes(
.eq("active", true)
.eq("workCell.active", true);
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index 534a9f825f..eca1908436 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -215,14 +215,14 @@ export async function getCustomerStatus(
export async function getCustomerStatuses(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
+ args?: GenericQueryFilters & { search: string | null }
) {
let query = client
.from("customerStatus")
.select("id, name", { count: "exact" });
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
@@ -253,12 +253,12 @@ export async function getCustomerType(
export async function getCustomerTypes(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
+ args?: GenericQueryFilters & { search: string | null }
) {
let query = client.from("customerType").select("*", { count: "exact" });
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
@@ -285,31 +285,16 @@ export async function getQuotes(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
search: string | null;
- status: string | null;
- customerId: string | null;
- partId: string | null;
}
) {
let query = client.from("quotes").select("*", { count: "exact" });
if (args.search) {
query = query.or(
- `id.ilike.%${args.search}%,quoteId.ilike.%${args.search}%,name.ilike.%${args.search}%`
+ `quoteId.ilike.%${args.search}%,name.ilike.%${args.search}%`
);
}
- if (args.status) {
- query = query.eq("status", args.status);
- }
-
- if (args.customerId) {
- query = query.eq("customerId", args.customerId);
- }
-
- if (args.partId) {
- query = query.contains("partIds", [args.partId]);
- }
-
query = setGenericQueryFilters(query, args, [
{ column: "favorite", ascending: false },
{ column: "id", ascending: false },
diff --git a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
index f0e982e624..701a7ae86f 100644
--- a/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotations/QuotationsTable.tsx
@@ -10,7 +10,7 @@ import type { ColumnDef } from "@tanstack/react-table";
import { memo, useMemo, useState } from "react";
import { BsFillPenFill, BsPin, BsPinFill } from "react-icons/bs";
import { IoMdTrash } from "react-icons/io";
-import { Avatar, Table } from "~/components";
+import { Avatar, TableNew } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import { type Quotation, type quoteStatusType } from "~/modules/sales";
@@ -181,17 +181,6 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
];
}, [fetcher, navigate]);
- const defaultColumnVisibility = {
- expirationDate: false,
- quoteDate: false,
- customerReference: false,
- locationName: false,
- createdAt: false,
- createdByFullName: false,
- updatedAt: false,
- updatedByFullName: false,
- };
-
const renderContextMenu = useMemo(() => {
// eslint-disable-next-line react/display-name
return (row: Quotation) => (
@@ -216,15 +205,11 @@ const QuotationsTable = memo(({ data, count }: QuotationsTableProps) => {
return (
<>
- <Table<Quotation>
+ <TableNew<Quotation>
count={count}
columns={columns}
data={rows}
- defaultColumnVisibility={defaultColumnVisibility}
withColumnOrdering
- withFilters
- withPagination
- withSimpleSorting
renderContextMenu={renderContextMenu}
/>
{selectedQuotation && selectedQuotation.id && (
diff --git a/apps/carbon/app/modules/settings/settings.service.ts b/apps/carbon/app/modules/settings/settings.service.ts
index 9ca6fb97fa..67b73d2921 100644
--- a/apps/carbon/app/modules/settings/settings.service.ts
+++ b/apps/carbon/app/modules/settings/settings.service.ts
@@ -67,15 +67,15 @@ export async function getCustomFields(
export async function getCustomFieldsTables(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
}
) {
let query = client.from("customFieldTables").select("*", {
count: "exact",
});
- if (args.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
query = setGenericQueryFilters(query, args, [
@@ -146,15 +146,15 @@ export async function getSequence(
export async function getSequences(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
}
) {
let query = client.from("sequence").select("*", {
count: "exact",
});
- if (args.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
query = setGenericQueryFilters(query, args, [
diff --git a/apps/carbon/app/modules/users/users.service.ts b/apps/carbon/app/modules/users/users.service.ts
index 55badd518b..a9c5ca064e 100644
--- a/apps/carbon/app/modules/users/users.service.ts
+++ b/apps/carbon/app/modules/users/users.service.ts
@@ -21,7 +21,7 @@ export async function deleteGroup(
export async function getCustomers(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
type: string | null;
active: boolean | null;
}
@@ -32,8 +32,8 @@ export async function getCustomers(
{ count: "exact" }
);
- if (args.name) {
- query = query.ilike("user.fullName", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("user.fullName", `%${args.search}%`);
}
if (args.type) {
@@ -64,7 +64,7 @@ export async function getEmployee(
export async function getEmployees(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
type: string | null;
active: boolean | null;
}
@@ -76,8 +76,8 @@ export async function getEmployees(
{ count: "exact" }
);
- if (args.name) {
- query = query.ilike("user.fullName", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("user.fullName", `%${args.search}%`);
}
if (args.type) {
@@ -107,12 +107,12 @@ export async function getEmployeeType(
export async function getEmployeeTypes(
client: SupabaseClient<Database>,
- args?: GenericQueryFilters & { name: string | null }
+ args?: GenericQueryFilters & { search: string | null }
) {
let query = client.from("employeeType").select("*", { count: "exact" });
- if (args?.name) {
- query = query.ilike("name", `%${args.name}%`);
+ if (args?.search) {
+ query = query.ilike("name", `%${args.search}%`);
}
if (args) {
@@ -175,7 +175,7 @@ export async function getPermissionsByEmployeeType(
export async function getSuppliers(
client: SupabaseClient<Database>,
args: GenericQueryFilters & {
- name: string | null;
+ search: string | null;
type: string | null;
active: boolean | null;
}
@@ -186,8 +186,8 @@ export async function getSuppliers(
{ count: "exact" }
);
- if (args.name) {
- query = query.ilike("user.fullName", `%${args.name}%`);
+ if (args.search) {
+ query = query.ilike("user.fullName", `%${args.search}%`);
}
if (args.type) {
diff --git a/apps/carbon/app/routes/x+/sales+/quotes.tsx b/apps/carbon/app/routes/x+/sales+/quotes.tsx
index 8a23c7c01d..b1b4358115 100644
--- a/apps/carbon/app/routes/x+/sales+/quotes.tsx
+++ b/apps/carbon/app/routes/x+/sales+/quotes.tsx
@@ -27,9 +27,6 @@ export async function loader({ request }: LoaderFunctionArgs) {
const url = new URL(request.url);
const searchParams = new URLSearchParams(url.search);
const search = searchParams.get("search");
- const status = searchParams.get("status");
- const customerId = searchParams.get("customerId");
- const partId = searchParams.get("partId");
const { limit, offset, sorts, filters } =
getGenericQueryFilters(searchParams);
@@ -37,9 +34,6 @@ export async function loader({ request }: LoaderFunctionArgs) {
const [quotes] = await Promise.all([
getQuotes(client, {
search,
- status,
- partId,
- customerId,
limit,
offset,
sorts,