-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add server side pagination and filteration #503
Open
G3root
wants to merge
35
commits into
main
Choose a base branch
from
pagination-table
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
6175a7f
feat: add data table hook
G3root 9267b5a
feat: add new data table hook
G3root c8ae1ac
chore: rename hook
G3root a0106f4
feat: add paginated hook
G3root 99ff880
feat: add offset schema
G3root 07f2d55
feat: use offset schema
G3root 5c8a3d3
fix: session
G3root 1238f71
feat: add const
G3root 612238a
chore: fix error handling
G3root 733b70d
chore: make header optional
G3root 36c9a72
feat: add api client
G3root bcede0d
chore: add nuqs
G3root 399b222
feat: use pagination
G3root b207ff0
refactor: hook
G3root fd34967
feat: add sort
G3root e7e7449
feat: add sort
G3root 85116f3
chore: hide select
G3root 4ddcf2a
feat: add search filter
G3root 9851bf3
feat: refactor data
G3root 69a423e
feat: add debounce component
G3root 2409c0d
feat: add debounce input
G3root 3523911
feat: add search
G3root 8810540
fix: query
G3root 5acdd81
feat: update tables
G3root 6c5d5f1
feat: add seed
G3root 2fe228f
Merge branch 'main' into pagination-table
G3root 92d651d
chore: add tax id
G3root e733531
chore: upgrade trpc
G3root fcf2db6
feat: use new trpc
G3root 9ca66a6
feat: add error boundary
G3root 233b004
chore: rename loading
G3root 33ba09b
feat: use useSuspense
G3root b91f92d
fix: data
G3root c477f15
feat: add search param hook
G3root 160cf3d
feat: add search
G3root File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ import colors from "colors"; | |
import inquirer from "inquirer"; | ||
colors.enable(); | ||
|
||
import { Prisma } from "@prisma/client"; | ||
import type { QuestionCollection } from "inquirer"; | ||
import seedCompanies from "./companies"; | ||
import { seedStakeholders } from "./stakeholder"; | ||
import seedTeam from "./team"; | ||
|
||
if (process.env.NODE_ENV === "production") { | ||
|
@@ -23,47 +25,86 @@ const seed = async () => { | |
const answer = inquiry.answer as boolean; | ||
|
||
if (answer) { | ||
await nuke(); | ||
await cleanupDb(); | ||
|
||
console.log("Seeding database".underline.cyan); | ||
return db.$transaction(async () => { | ||
await seedCompanies(); | ||
await seedTeam(); | ||
return db.$transaction(async (tx) => { | ||
const companies = await seedCompanies(tx); | ||
await seedTeam(tx); | ||
|
||
for (const company of companies) { | ||
await seedStakeholders(tx, company.id, company.name, 500); | ||
} | ||
}); | ||
} else { | ||
throw new Error("Seeding aborted"); | ||
} | ||
}; | ||
|
||
const nuke = async () => { | ||
console.log("🚀 Nuking database records".yellow); | ||
return db.$transaction(async (db) => { | ||
await db.user.deleteMany(); | ||
await db.member.deleteMany(); | ||
await db.company.deleteMany(); | ||
await db.shareClass.deleteMany(); | ||
await db.equityPlan.deleteMany(); | ||
await db.document.deleteMany(); | ||
await db.bucket.deleteMany(); | ||
await db.audit.deleteMany(); | ||
await db.session.deleteMany(); | ||
}); | ||
throw new Error("Seeding aborted"); | ||
}; | ||
|
||
await seed() | ||
.then(async () => { | ||
.then(() => { | ||
console.log("✅ Database seeding completed".green); | ||
console.log( | ||
`💌 We have created four admin accounts for you. Please login with one of these emails:\n` | ||
"💌 We have created four admin accounts for you. Please login with one of these emails:\n" | ||
.cyan, | ||
`[email protected]\n`.underline.yellow, | ||
`[email protected]\n`.underline.yellow, | ||
`[email protected]\n`.underline.yellow, | ||
`[email protected]\n`.underline.yellow, | ||
"[email protected]\n".underline.yellow, | ||
"[email protected]\n".underline.yellow, | ||
"[email protected]\n".underline.yellow, | ||
"[email protected]\n".underline.yellow, | ||
); | ||
await db.$disconnect(); | ||
}) | ||
.catch(async (error: Error) => { | ||
.catch((error: Error) => { | ||
console.log(`❌ ${error.message}`.red); | ||
}) | ||
.finally(async () => { | ||
await db.$disconnect(); | ||
}); | ||
|
||
export async function cleanupDb() { | ||
console.log("🚀 Nuking database records".yellow); | ||
|
||
try { | ||
const tables = await db.$queryRaw<{ tablename: string }[]>` | ||
SELECT tablename FROM pg_tables | ||
WHERE schemaname = 'public' AND tablename != '_prisma_migrations' | ||
`; | ||
|
||
// Disable foreign key checks | ||
await db.$executeRaw`SET CONSTRAINTS ALL DEFERRED`; | ||
|
||
for (const { tablename } of tables) { | ||
try { | ||
// Check if the table exists before attempting to truncate | ||
const tableExists = await db.$queryRaw<[{ exists: boolean }]>` | ||
SELECT EXISTS ( | ||
SELECT FROM information_schema.tables | ||
WHERE table_schema = 'public' AND table_name = ${tablename} | ||
) | ||
`; | ||
|
||
if (tableExists[0].exists) { | ||
await db.$executeRaw( | ||
Prisma.sql`TRUNCATE TABLE "${Prisma.raw(tablename)}" CASCADE`, | ||
); | ||
console.log(`Table ${tablename} truncated successfully`.green); | ||
} else { | ||
console.log(`Table ${tablename} doesn't exist, skipping`.yellow); | ||
} | ||
} catch (err) { | ||
if (err instanceof Prisma.PrismaClientKnownRequestError) { | ||
console.error(`Error truncating table ${tablename}:`, err.message); | ||
} else { | ||
console.error(`Unexpected error truncating table ${tablename}:`, err); | ||
} | ||
} | ||
} | ||
|
||
// Re-enable foreign key checks | ||
await db.$executeRaw`SET CONSTRAINTS ALL IMMEDIATE`; | ||
|
||
console.log( | ||
"All tables reset successfully, except _prisma_migrations".yellow, | ||
); | ||
} catch (error) { | ||
console.error("Error resetting tables:", error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { TPrismaOrTransaction } from "@/server/db"; | ||
import { faker } from "@faker-js/faker"; | ||
import colors from "colors"; | ||
import { StakeholderRelationshipEnum, StakeholderTypeEnum } from "../enums"; | ||
colors.enable(); | ||
|
||
export async function seedStakeholders( | ||
tx: TPrismaOrTransaction, | ||
companyId: string, | ||
companyName: string, | ||
count = 100, | ||
) { | ||
const stakeholders = []; | ||
|
||
for (let index = 0; index < count; index++) { | ||
stakeholders.push({ | ||
name: faker.person.fullName(), | ||
email: faker.internet.email(), | ||
institutionName: faker.company.name(), | ||
stakeholderType: faker.helpers.arrayElement( | ||
Object.values(StakeholderTypeEnum), | ||
), | ||
currentRelationship: faker.helpers.arrayElement( | ||
Object.values(StakeholderRelationshipEnum), | ||
), | ||
taxId: faker.finance.accountNumber(), | ||
|
||
streetAddress: faker.location.streetAddress(), | ||
city: faker.location.city(), | ||
state: faker.location.state(), | ||
zipcode: faker.location.zipCode(), | ||
country: faker.location.country(), | ||
companyId, | ||
}); | ||
} | ||
console.log( | ||
`Seeding ${stakeholders.length} stakeholders for ${companyName}`.blue, | ||
); | ||
|
||
const record = await tx.stakeholder.createMany({ data: stakeholders }); | ||
|
||
console.log( | ||
`🎉 Seeded ${record.count} stakeholders for ${companyName}`.green, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upgraded to trpc 11 to useSuspenseQuery from "@tanstack/react-query". useSuspenseQuery is introduced in
"@tanstack/react-query
v5 upgrading only this package breaks trpc