-
Notifications
You must be signed in to change notification settings - Fork 17
feat(part-info): add part info page #491
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
Conversation
Reviewer's Guide by SourceryThis pull request introduces a new 'Part Info' page that provides insights into table partitions and levels. It includes database and table selectors, displays partition and level counts in tables, and integrates with the existing menu and tables overview page. No diagrams generated as the changes look simple and do not need a visual representation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Hey @duyet - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a loading state for the database and table selectors in
app/[host]/part-info/layout.tsx
. - The revalidate time is set to 300 seconds, but the query cache is enabled; consider if both are needed.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Review instructions: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 2 issues found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
const handleSelect = (newDatabase: string) => { | ||
redirect(`/${host}/part-info/${newDatabase}`) |
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.
suggestion: Revisit use of redirect in a client component.
Since this component is marked with 'use client', consider using Next.js' useRouter hook and its push() method for client-side navigation instead of calling redirect from next/navigation, which is typically used in server components.
Suggested implementation:
+ import { useRouter } from 'next/navigation'
const currentDatabase = params.database as string
const router = useRouter()
const handleSelect = (newDatabase: string) => {
router.push(`/${host}/part-info/${newDatabase}`)
}
@@ -0,0 +1,77 @@ | |||
'use client' |
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.
issue (complexity): Consider creating a custom hook to handle URL parameters to avoid code duplication in the DatabaseSelector and TableSelector components, which simplifies the filter logic by using a conditional check instead of a redundant one, and improves code maintainability and readability by centralizing the parameter extraction logic..
Consider abstracting URL parameter handling into a custom hook to eliminate duplication. For example, you could create:
// hooks/usePartInfoParams.ts
import { useParams } from 'next/navigation';
export function usePartInfoParams() {
const params = useParams();
return {
database: params.database as string,
table: params.table as string,
};
}
Then update your selectors as follows:
// DatabaseSelector.tsx
import { redirect } from 'next/navigation';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { usePartInfoParams } from '@/hooks/usePartInfoParams';
export function DatabaseSelector({ host, databases }: { host: string; databases: string[] }) {
const { database: currentDatabase } = usePartInfoParams();
const handleSelect = (newDatabase: string) => {
redirect(`/${host}/part-info/${newDatabase}`);
};
return (
<Select value={currentDatabase} onValueChange={handleSelect}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select Database" />
</SelectTrigger>
<SelectContent>
{databases.map((db) => (
<SelectItem key={db} value={db}>
{db}
</SelectItem>
))}
</SelectContent>
</Select>
);
}
// TableSelector.tsx
import { redirect } from 'next/navigation';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { usePartInfoParams } from '@/hooks/usePartInfoParams';
export function TableSelector({ host, databaseTables }: { host: string; databaseTables: { database: string; table: string }[] }) {
const { database: currentDatabase, table: currentTable } = usePartInfoParams();
const handleSelect = (newTable: string) => {
redirect(`/${host}/part-info/${currentDatabase}/${newTable}`);
};
return (
<Select value={currentTable} onValueChange={handleSelect}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select Table" />
</SelectTrigger>
<SelectContent>
{databaseTables
.filter((item) => currentDatabase ? item.database === currentDatabase : true)
.map((tbl) => (
<SelectItem key={tbl.table} value={tbl.table}>
{tbl.table}
</SelectItem>
))}
</SelectContent>
</Select>
);
}
This approach reduces duplication and simplifies the filter logic by replacing the redundant check with a clear conditional.
return tables?.[0] || '' | ||
} | ||
|
||
export const getDatabases = async (host: string): Promise<string[]> => { |
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.
issue (complexity): Consider using a Set to improve the efficiency and readability of the getDatabases function by simplifying the process of collecting unique database names.
Try replacing the `map` and `reduce` combination in `getDatabases` with a `Set` to simplify uniqueness handling. For example:
```ts
export const getDatabases = async (host: string): Promise<string[]> => {
const items = await getDatabaseTables(host)
return Array.from(new Set(items.map(item => item.database)))
}
This change reduces complexity while keeping the functionality intact.
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #491 +/- ##
=======================================
Coverage 76.82% 76.82%
=======================================
Files 5 5
Lines 164 164
Branches 59 60 +1
=======================================
Hits 126 126
+ Misses 38 35 -3
- Partials 0 3 +3 ☔ View full report in Codecov by Sentry. |
Summary by Sourcery
Add a new Part Info page to provide detailed information about active table parts and levels
New Features:
Enhancements: