-
Notifications
You must be signed in to change notification settings - Fork 9
feat: implement admin tags dashboard #202
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
Open
snomiao
wants to merge
29
commits into
main
Choose a base branch
from
57-feat-req-admin-category-dashboard-admincategory
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 4 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
31c8855
fix(57-feat-req-admin-category-dashboard-admincategory): draft
snomiao c82d135
feat: implement admin category dashboard
snomiao 7539fd0
feat: rename category.tsx to categories.tsx and implement server-side…
snomiao 71e18cd
format: Apply prettier --fix changes
snomiao f9f8b79
refactor: use usePage hook for admin categories pagination
snomiao eda5382
feat: migrate from categories to tags system
snomiao 4db877a
fix: resolve ESLint warning in claim-my-node useEffect dependencies
snomiao 2b44027
Merge main branch into category dashboard feature branch
snomiao ec3ba4f
format: Apply prettier --fix changes
snomiao b1ada46
fix: Show nodes with tags in table instead of uncategorized badge
snomiao 547ee68
format: Apply prettier --fix changes
snomiao 5401b7e
feat: Add tag editing functionality to admin tags page
snomiao af0d5c2
format: Apply prettier --fix changes
snomiao f112b5d
fix: remove href from current page breadcrumb items
snomiao 7466472
Merge remote-tracking branch 'origin/main' into 57-feat-req-admin-cat…
snomiao 172d8b8
format: Apply prettier --fix changes
snomiao 8d78ef3
Merge branch 'main' into 57-feat-req-admin-category-dashboard-adminca…
snomiao b03776c
feat: use admin endpoint for editing admin_tags
snomiao a993612
format: Apply prettier --fix changes
snomiao 1588a27
Merge branch 'main' into 57-feat-req-admin-category-dashboard-adminca…
snomiao 517306e
format: Apply prettier --fix changes
snomiao 5bb25aa
feat: enable publishers to edit node tags
snomiao d8171e0
format: Apply prettier --fix changes
snomiao 526a260
fix: admin tags page now always uses admin endpoint
snomiao ffbfa35
format: Apply prettier --fix changes
snomiao be5a759
fix: rename CategoriesPage to TagsPage for consistency
snomiao 8425cd3
format: Apply prettier --fix changes
snomiao 6290d24
format: Apply prettier and biome formatting fixes
snomiao a0d8af0
Merge branch 'main' into feature/admin-tags
snomiao 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,135 @@ | ||
| import withAdmin from '@/components/common/HOC/authAdmin' | ||
| import AdminTreeNavigation from '@/components/admin/AdminTreeNavigation' | ||
| import { CustomPagination } from '@/components/common/CustomPagination' | ||
| import { useListAllNodes } from '@/src/api/generated' | ||
| import { useNextTranslation } from '@/src/hooks/i18n' | ||
| import { Breadcrumb, Card, Badge } from 'flowbite-react' | ||
| import { HiHome, HiOutlineCollection } from 'react-icons/hi' | ||
| import { useRouter } from 'next/router' | ||
| import React, { useMemo, useState } from 'react' | ||
|
|
||
| export default withAdmin(CategoriesPage) | ||
| function CategoriesPage() { | ||
| const { t } = useNextTranslation() | ||
| const router = useRouter() | ||
| const [page, setPage] = useState<number>(1) | ||
| const [limit] = useState<number>(20) | ||
|
|
||
| // Handle page from URL | ||
| React.useEffect(() => { | ||
| if (router.query.page) { | ||
| setPage(parseInt(router.query.page as string)) | ||
| } | ||
| }, [router.query.page]) | ||
|
|
||
| const { data: nodesData } = useListAllNodes({ | ||
| page: page, | ||
| limit: limit, | ||
| sort: ['category'], | ||
| }) | ||
|
|
||
| const categoriesData = useMemo(() => { | ||
| if (!nodesData?.nodes) return [] | ||
|
|
||
| const categoryMap = new Map<string, number>() | ||
| nodesData.nodes.forEach((node) => { | ||
| const category = node.category || 'Uncategorized' | ||
| categoryMap.set(category, (categoryMap.get(category) || 0) + 1) | ||
| }) | ||
|
|
||
| return Array.from(categoryMap.entries()) | ||
| .map(([category, count]) => ({ category, count })) | ||
| .sort((a, b) => b.count - a.count) | ||
| }, [nodesData?.nodes]) | ||
|
|
||
| const totalPages = Math.ceil((nodesData?.total || 0) / limit) | ||
|
|
||
| const handlePageChange = (newPage: number) => { | ||
| setPage(newPage) | ||
| router.push( | ||
| { | ||
| pathname: router.pathname, | ||
| query: { ...router.query, page: newPage }, | ||
| }, | ||
| undefined, | ||
| { shallow: true } | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <div className="p-4"> | ||
| <Breadcrumb className="py-4"> | ||
| <Breadcrumb.Item href="/" icon={HiHome} className="dark"> | ||
| {t('Home')} | ||
| </Breadcrumb.Item> | ||
| <Breadcrumb.Item href="/admin" className="dark"> | ||
| {t('Admin Dashboard')} | ||
| </Breadcrumb.Item> | ||
| <Breadcrumb.Item href="#" className="dark"> | ||
| {t('Category Management')} | ||
| </Breadcrumb.Item> | ||
| </Breadcrumb> | ||
|
|
||
| <h1 className="text-2xl font-bold text-gray-200 mb-6"> | ||
| {t('Category Management')} | ||
| </h1> | ||
|
|
||
| <div className="grid grid-cols-1 lg:grid-cols-4 gap-6"> | ||
| <div className="lg:col-span-1"> | ||
| <AdminTreeNavigation /> | ||
| </div> | ||
|
|
||
| <div className="lg:col-span-3"> | ||
| <Card className="bg-gray-800 border-gray-700"> | ||
| <div className="flex items-center justify-between mb-4"> | ||
| <h2 className="text-xl font-semibold text-gray-200"> | ||
| {t('Node Categories Overview')} | ||
| </h2> | ||
| <Badge color="info" icon={HiOutlineCollection}> | ||
| {categoriesData.length} {t('categories')} | ||
| </Badge> | ||
| </div> | ||
|
|
||
| <div className="space-y-4"> | ||
| {categoriesData.map(({ category, count }) => ( | ||
| <div | ||
| key={category} | ||
| className="flex items-center justify-between p-4 bg-gray-700 rounded-lg hover:bg-gray-600 transition-colors" | ||
| > | ||
| <div className="flex items-center space-x-3"> | ||
| <HiOutlineCollection className="h-5 w-5 text-blue-400" /> | ||
| <span className="text-lg font-medium text-gray-200"> | ||
| {category} | ||
| </span> | ||
| </div> | ||
| <Badge color="purple" size="sm"> | ||
| {count} {t('nodes')} | ||
| </Badge> | ||
| </div> | ||
| ))} | ||
| </div> | ||
|
|
||
| {categoriesData.length === 0 && ( | ||
| <div className="text-center py-8"> | ||
| <HiOutlineCollection className="h-12 w-12 text-gray-400 mx-auto mb-4" /> | ||
| <p className="text-gray-400"> | ||
| {t('No categories found')} | ||
| </p> | ||
| </div> | ||
| )} | ||
|
|
||
| {totalPages > 1 && ( | ||
| <div className="py-8"> | ||
| <CustomPagination | ||
| currentPage={page} | ||
| totalPages={totalPages} | ||
| onPageChange={handlePageChange} | ||
| /> | ||
| </div> | ||
| )} | ||
| </Card> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.