From 0189485062da94f41fb52f5efc4c98d5c46b1870 Mon Sep 17 00:00:00 2001 From: casperiv0 <53900565+casperiv0@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:43:15 +0200 Subject: [PATCH] fix: only use experimental tables --- .../manage/manage-businesses-controller.ts | 4 ++++ .../manage/manage-citizens-controller.ts | 4 ++++ .../admin/manage/manage-users-controller.ts | 5 +++- .../general/blacklisted-words-tab.tsx | 2 +- .../manage/citizens/all-citizens-tab.tsx | 23 ++++++++++++++++--- .../tabs/callsigns-tab/callsigns-tab.tsx | 2 +- .../admin/manage/users/tabs/all-users-tab.tsx | 10 +++++++- .../citizen/tow/tow-taxi-calls-table.tsx | 2 +- .../pages/admin/manage/businesses/[id].tsx | 2 +- .../pages/admin/manage/businesses/index.tsx | 12 +++++++++- .../src/pages/ems-fd/hospital-services.tsx | 2 +- apps/client/src/pages/officer/impound-lot.tsx | 2 +- .../src/pages/officer/my-record-reports.tsx | 2 +- apps/client/src/pages/pets/index.tsx | 2 +- apps/client/src/pages/tow/logs.tsx | 2 +- 15 files changed, 61 insertions(+), 15 deletions(-) diff --git a/apps/api/src/controllers/admin/manage/manage-businesses-controller.ts b/apps/api/src/controllers/admin/manage/manage-businesses-controller.ts index e49732fe7..9289263ae 100644 --- a/apps/api/src/controllers/admin/manage/manage-businesses-controller.ts +++ b/apps/api/src/controllers/admin/manage/manage-businesses-controller.ts @@ -14,6 +14,7 @@ import { UPDATE_EMPLOYEE_SCHEMA } from "@snailycad/schemas"; import { EmployeeAsEnum } from "@snailycad/types"; import { ExtendedBadRequest } from "src/exceptions/extended-bad-request"; import { AuditLogActionType, createAuditLogEntry } from "@snailycad/audit-logger/server"; +import { getPrismaModelOrderBy } from "~/utils/order-by"; const businessInclude = { user: { @@ -40,6 +41,7 @@ export class AdminManageBusinessesController { @QueryParams("skip", Number) skip = 0, @QueryParams("includeAll", Boolean) includeAll = false, @QueryParams("query", String) query = "", + @QueryParams("sorting") sorting = "", ): Promise { const where = {} as Prisma.BusinessWhereInput; @@ -51,6 +53,7 @@ export class AdminManageBusinessesController { where.status = WhitelistStatus.PENDING; } + const orderBy = getPrismaModelOrderBy(sorting); const [totalCount, businesses] = await prisma.$transaction([ prisma.business.count({ where }), prisma.business.findMany({ @@ -58,6 +61,7 @@ export class AdminManageBusinessesController { skip: includeAll ? undefined : skip, where, include: businessInclude, + orderBy, }), ]); diff --git a/apps/api/src/controllers/admin/manage/manage-citizens-controller.ts b/apps/api/src/controllers/admin/manage/manage-citizens-controller.ts index 5d08b63cb..9e911471a 100644 --- a/apps/api/src/controllers/admin/manage/manage-citizens-controller.ts +++ b/apps/api/src/controllers/admin/manage/manage-citizens-controller.ts @@ -20,6 +20,7 @@ import { isFeatureEnabled } from "lib/upsert-cad"; import { leoProperties, unitProperties } from "utils/leo/includes"; import { recordsInclude } from "~/controllers/leo/search/SearchController"; import { ExtendedBadRequest } from "~/exceptions/extended-bad-request"; +import { getPrismaModelOrderBy } from "~/utils/order-by"; @UseBeforeEach(IsAuth) @Controller("/admin/manage/citizens") @@ -37,6 +38,7 @@ export class AdminManageCitizensController { @QueryParams("userId", String) userId?: string, @QueryParams("includeOfficers", Boolean) includeOfficers = false, @QueryParams("includeDeputies", Boolean) includeDeputies = false, + @QueryParams("sorting") sorting = "", ): Promise { const [name, surname] = query.toString().toLowerCase().split(/ +/g); @@ -58,10 +60,12 @@ export class AdminManageCitizensController { } : undefined; + const orderBy = getPrismaModelOrderBy(sorting); const [totalCount, citizens] = await prisma.$transaction([ prisma.citizen.count({ where }), prisma.citizen.findMany({ where, + orderBy, include: { gender: true, ethnicity: true, diff --git a/apps/api/src/controllers/admin/manage/manage-users-controller.ts b/apps/api/src/controllers/admin/manage/manage-users-controller.ts index 4eeb18491..98a95bced 100644 --- a/apps/api/src/controllers/admin/manage/manage-users-controller.ts +++ b/apps/api/src/controllers/admin/manage/manage-users-controller.ts @@ -35,6 +35,7 @@ import { isDiscordIdInUse } from "lib/discord/utils"; import { getTranslator } from "~/utils/get-translator"; import { sendRawWebhook, sendDiscordWebhook } from "~/lib/discord/webhooks"; import { type APIEmbed } from "discord-api-types/v10"; +import { getPrismaModelOrderBy } from "~/utils/order-by"; const manageUsersSelect = (selectCitizens: boolean) => ({ @@ -69,6 +70,7 @@ export class ManageUsersController { @QueryParams("query", String) query = "", @QueryParams("pendingOnly", Boolean) pendingOnly = false, @QueryParams("includeAll", Boolean) includeAll = false, + @QueryParams("sorting") sorting = "", ): Promise { const where = query || pendingOnly @@ -87,9 +89,10 @@ export class ManageUsersController { } : undefined; + const orderBy = getPrismaModelOrderBy(sorting); const [totalCount, pendingCount] = await prisma.$transaction([ prisma.user.count({ where }), - prisma.user.count({ where: { whitelistStatus: WhitelistStatus.PENDING } }), + prisma.user.count({ orderBy, where: { whitelistStatus: WhitelistStatus.PENDING } }), ]); const shouldIncludeAll = includeAll; diff --git a/apps/client/src/components/admin/manage/cad-settings/general/blacklisted-words-tab.tsx b/apps/client/src/components/admin/manage/cad-settings/general/blacklisted-words-tab.tsx index b9ebce258..7aeeef0de 100644 --- a/apps/client/src/components/admin/manage/cad-settings/general/blacklisted-words-tab.tsx +++ b/apps/client/src/components/admin/manage/cad-settings/general/blacklisted-words-tab.tsx @@ -36,7 +36,7 @@ export function BlacklistedWordsTab() { }, }); const [tempWord, wordState] = useTemporaryItem(asyncTable.items); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); function onRemoveWordClick(word: BlacklistedWord) { wordState.setTempId(word.id); diff --git a/apps/client/src/components/admin/manage/citizens/all-citizens-tab.tsx b/apps/client/src/components/admin/manage/citizens/all-citizens-tab.tsx index 737a5e58b..0ffcfc902 100644 --- a/apps/client/src/components/admin/manage/citizens/all-citizens-tab.tsx +++ b/apps/client/src/components/admin/manage/citizens/all-citizens-tab.tsx @@ -40,6 +40,18 @@ export function AllCitizensTab({ citizens: initialData, totalCount, setCitizens search, initialData, totalCount, + sortingSchema: { + name: "name", + surname: "surname", + dateOfBirth: "dateOfBirth", + gender: "gender.value", + ethnicity: "ethnicity.value", + hairColor: "hairColor", + eyeColor: "eyeColor", + weight: "weight", + height: "height", + user: "user.username", + }, fetchOptions: { path: "/admin/manage/citizens", onResponse: (json: GetManageCitizensData) => ({ @@ -48,7 +60,10 @@ export function AllCitizensTab({ citizens: initialData, totalCount, setCitizens }), }, }); - const tableState = useTableState({ pagination: asyncTable.pagination }); + const tableState = useTableState({ + sorting: asyncTable.sorting, + pagination: asyncTable.pagination, + }); const [tempValue, valueState] = useTemporaryItem(asyncTable.items); const { hasPermissions } = usePermission(); @@ -146,7 +161,8 @@ export function AllCitizensTab({ citizens: initialData, totalCount, setCitizens tableState={tableState} data={asyncTable.items.map((citizen) => ({ id: citizen.id, - name: `${citizen.name} ${citizen.surname}`, + name: citizen.name, + surname: citizen.surname, dateOfBirth: ( {citizen.dateOfBirth} @@ -193,7 +209,8 @@ export function AllCitizensTab({ citizens: initialData, totalCount, setCitizens ), }))} columns={[ - { header: tCitizen("fullName"), accessorKey: "name" }, + { header: tCitizen("name"), accessorKey: "name" }, + { header: tCitizen("surname"), accessorKey: "surname" }, { header: tCitizen("dateOfBirth"), accessorKey: "dateOfBirth" }, { header: tCitizen("gender"), accessorKey: "gender" }, { header: tCitizen("ethnicity"), accessorKey: "ethnicity" }, diff --git a/apps/client/src/components/admin/manage/units/tabs/callsigns-tab/callsigns-tab.tsx b/apps/client/src/components/admin/manage/units/tabs/callsigns-tab/callsigns-tab.tsx index 7fe9b72e8..3da3b1bdd 100644 --- a/apps/client/src/components/admin/manage/units/tabs/callsigns-tab/callsigns-tab.tsx +++ b/apps/client/src/components/admin/manage/units/tabs/callsigns-tab/callsigns-tab.tsx @@ -47,7 +47,7 @@ export function CallsignsTab({ units }: Props) { const common = useTranslations("Common"); const { generateCallsign } = useGenerateCallsign(); const modalState = useModal(); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); const hasViewUsersPermissions = hasPermissions([Permissions.ViewUsers]); const { department } = useValues(); diff --git a/apps/client/src/components/admin/manage/users/tabs/all-users-tab.tsx b/apps/client/src/components/admin/manage/users/tabs/all-users-tab.tsx index 452eee2b0..e67444b18 100644 --- a/apps/client/src/components/admin/manage/users/tabs/all-users-tab.tsx +++ b/apps/client/src/components/admin/manage/users/tabs/all-users-tab.tsx @@ -36,12 +36,20 @@ export function AllUsersTab({ users, totalCount }: GetManageUsersData) { search, initialData: users, totalCount, + sortingSchema: { + username: "username", + rank: "rank", + whitelistStatus: "whitelistStatus", + }, fetchOptions: { path: "/admin/manage/users", onResponse: (json: GetManageUsersData) => ({ totalCount: json.totalCount, data: json.users }), }, }); - const tableState = useTableState({ pagination: asyncTable.pagination }); + const tableState = useTableState({ + sorting: asyncTable.sorting, + pagination: asyncTable.pagination, + }); return ( diff --git a/apps/client/src/components/citizen/tow/tow-taxi-calls-table.tsx b/apps/client/src/components/citizen/tow/tow-taxi-calls-table.tsx index 457a106b9..28db32670 100644 --- a/apps/client/src/components/citizen/tow/tow-taxi-calls-table.tsx +++ b/apps/client/src/components/citizen/tow/tow-taxi-calls-table.tsx @@ -42,7 +42,7 @@ export function TowTaxiCallsTable({ initialData, type, noCallsText }: Props) { }, }, }); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); const [tempCall, callState] = useTemporaryItem(asyncTable.items); const modalState = useModal(); diff --git a/apps/client/src/pages/admin/manage/businesses/[id].tsx b/apps/client/src/pages/admin/manage/businesses/[id].tsx index a7e9923e8..ba25f9c5c 100644 --- a/apps/client/src/pages/admin/manage/businesses/[id].tsx +++ b/apps/client/src/pages/admin/manage/businesses/[id].tsx @@ -62,7 +62,7 @@ export default function ManageBusinesses({ business, businessId }: Props) { totalCount: business.totalCount, initialData: business.employees, }); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); const [tempEmployee, employeeState] = useTemporaryItem(asyncTable.items); const t = useTranslations(); diff --git a/apps/client/src/pages/admin/manage/businesses/index.tsx b/apps/client/src/pages/admin/manage/businesses/index.tsx index 8f33f41da..e671bbebd 100644 --- a/apps/client/src/pages/admin/manage/businesses/index.tsx +++ b/apps/client/src/pages/admin/manage/businesses/index.tsx @@ -40,6 +40,13 @@ export default function ManageBusinesses({ businesses: data }: Props) { search, totalCount: data.totalCount, initialData: data.businesses, + sortingSchema: { + name: "name", + user: "user.username", + whitelisted: "whitelisted", + whitelistStatus: "whitelistStatus", + owners: "employees._count", + }, fetchOptions: { path: "/admin/manage/businesses", onResponse: (json: GetManageBusinessesData) => ({ @@ -48,7 +55,10 @@ export default function ManageBusinesses({ businesses: data }: Props) { }), }, }); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ + pagination: asyncTable.pagination, + sorting: asyncTable.sorting, + }); const [tempValue, valueState] = useTemporaryItem(asyncTable.items); const TABS = [ diff --git a/apps/client/src/pages/ems-fd/hospital-services.tsx b/apps/client/src/pages/ems-fd/hospital-services.tsx index 930d2f8e4..91e7b81ee 100644 --- a/apps/client/src/pages/ems-fd/hospital-services.tsx +++ b/apps/client/src/pages/ems-fd/hospital-services.tsx @@ -66,7 +66,7 @@ export default function EmsFdIncidents({ deadCitizens }: Props) { initialData: deadCitizens.citizens, totalCount: deadCitizens.totalCount, }); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); const [tempCitizen, tempCitizenState] = useTemporaryItem(asyncTable.items); return ( diff --git a/apps/client/src/pages/officer/impound-lot.tsx b/apps/client/src/pages/officer/impound-lot.tsx index 3d046105e..9adc91418 100644 --- a/apps/client/src/pages/officer/impound-lot.tsx +++ b/apps/client/src/pages/officer/impound-lot.tsx @@ -46,7 +46,7 @@ export default function ImpoundLot({ vehicles: data }: Props) { initialData: data.vehicles, totalCount: data.totalCount, }); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); const [tempVehicle, vehicleState] = useTemporaryItem(asyncTable.items); function handleCheckoutClick(item: ImpoundedVehicle) { diff --git a/apps/client/src/pages/officer/my-record-reports.tsx b/apps/client/src/pages/officer/my-record-reports.tsx index 07e504bee..0db0026ca 100644 --- a/apps/client/src/pages/officer/my-record-reports.tsx +++ b/apps/client/src/pages/officer/my-record-reports.tsx @@ -46,7 +46,7 @@ export default function MyOfficersLogs({ reports: data }: Props) { totalCount: data.totalCount, initialData: data.reports, }); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); return ( diff --git a/apps/client/src/pages/pets/index.tsx b/apps/client/src/pages/pets/index.tsx index 2fb3f4c5d..955b96936 100644 --- a/apps/client/src/pages/pets/index.tsx +++ b/apps/client/src/pages/pets/index.tsx @@ -31,7 +31,7 @@ export default function PetsPage(props: PetsPageProps) { initialData: props.pets.pets, totalCount: props.pets.totalCount, }); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); return ( diff --git a/apps/client/src/pages/tow/logs.tsx b/apps/client/src/pages/tow/logs.tsx index c5ab34b4e..569e42fa0 100644 --- a/apps/client/src/pages/tow/logs.tsx +++ b/apps/client/src/pages/tow/logs.tsx @@ -37,7 +37,7 @@ export default function TowLogs(props: Props) { }, }, }); - const tableState = useTableState(asyncTable); + const tableState = useTableState({ pagination: asyncTable.pagination }); function assignedUnit(call: TowCall) { return call.assignedUnit ? (