mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-09-06 17:46:23 +00:00
fix(web): refine mobile user cards
This commit is contained in:
@@ -16,13 +16,27 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
For commercial licensing, please contact support@quantumnous.com
|
For commercial licensing, please contact support@quantumnous.com
|
||||||
*/
|
*/
|
||||||
import type { Row } from '@tanstack/react-table'
|
import type { Cell, Row } from '@tanstack/react-table'
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
|
|
||||||
import { StatusBadgeTypeContext } from '@/components/status-badge'
|
import { StatusBadgeTypeContext } from '@/components/status-badge'
|
||||||
|
|
||||||
import { getCellLabel, renderCellContent } from './card-cell-utils'
|
import { getCellLabel, renderCellContent } from './card-cell-utils'
|
||||||
|
|
||||||
|
function orderCardCells<TData>(
|
||||||
|
cells: Cell<TData, unknown>[]
|
||||||
|
): Cell<TData, unknown>[] {
|
||||||
|
return [...cells].sort((a, b) => {
|
||||||
|
const aOrder = a.column.columnDef.meta?.mobileOrder
|
||||||
|
const bOrder = b.column.columnDef.meta?.mobileOrder
|
||||||
|
|
||||||
|
if (aOrder == null && bOrder == null) return 0
|
||||||
|
if (aOrder == null) return 1
|
||||||
|
if (bOrder == null) return -1
|
||||||
|
return aOrder - bOrder
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared, column-meta-driven card content rendering for TanStack rows.
|
* Shared, column-meta-driven card content rendering for TanStack rows.
|
||||||
*
|
*
|
||||||
@@ -62,12 +76,14 @@ function CompactContent<TData>({ row }: { row: Row<TData> }) {
|
|||||||
const titleCell = allCells.find((_, i) => cellMetas[i]?.mobileTitle)
|
const titleCell = allCells.find((_, i) => cellMetas[i]?.mobileTitle)
|
||||||
const badgeCell = allCells.find((_, i) => cellMetas[i]?.mobileBadge)
|
const badgeCell = allCells.find((_, i) => cellMetas[i]?.mobileBadge)
|
||||||
const actionsCell = allCells.find((c) => c.column.id === 'actions')
|
const actionsCell = allCells.find((c) => c.column.id === 'actions')
|
||||||
const fieldCells = allCells.filter(
|
const fieldCells = orderCardCells(
|
||||||
(c, i) =>
|
allCells.filter(
|
||||||
c !== titleCell &&
|
(c, i) =>
|
||||||
c !== badgeCell &&
|
c !== titleCell &&
|
||||||
c !== actionsCell &&
|
c !== badgeCell &&
|
||||||
!cellMetas[i]?.mobileHidden
|
c !== actionsCell &&
|
||||||
|
!cellMetas[i]?.mobileHidden
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -135,8 +151,10 @@ function FallbackContent<TData>({ row }: { row: Row<TData> }) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const actionsCell = allCells.find((c) => c.column.id === 'actions')
|
const actionsCell = allCells.find((c) => c.column.id === 'actions')
|
||||||
const contentCells = allCells.filter(
|
const contentCells = orderCardCells(
|
||||||
(c, i) => c.column.id !== 'actions' && !cellMetas[i]?.mobileHidden
|
allCells.filter(
|
||||||
|
(c, i) => c.column.id !== 'actions' && !cellMetas[i]?.mobileHidden
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+10
-4
@@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
For commercial licensing, please contact support@quantumnous.com
|
For commercial licensing, please contact support@quantumnous.com
|
||||||
*/
|
*/
|
||||||
import { type ColumnDef } from '@tanstack/react-table'
|
import type { ColumnDef } from '@tanstack/react-table'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import { BadgeCell } from '@/components/data-table'
|
import { BadgeCell } from '@/components/data-table'
|
||||||
@@ -40,7 +40,7 @@ import {
|
|||||||
USER_ROLES,
|
USER_ROLES,
|
||||||
isUserDeleted,
|
isUserDeleted,
|
||||||
} from '../constants'
|
} from '../constants'
|
||||||
import { type User } from '../types'
|
import type { User } from '../types'
|
||||||
import { DataTableRowActions } from './data-table-row-actions'
|
import { DataTableRowActions } from './data-table-row-actions'
|
||||||
|
|
||||||
function getQuotaProgressColor(percentage: number): string {
|
function getQuotaProgressColor(percentage: number): string {
|
||||||
@@ -80,11 +80,14 @@ export function useUsersColumns(): ColumnDef<User>[] {
|
|||||||
header: t('ID'),
|
header: t('ID'),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
return (
|
return (
|
||||||
<TableId value={row.getValue('id') as number} className='w-[60px]' />
|
<TableId
|
||||||
|
value={row.getValue('id') as number}
|
||||||
|
className='w-[60px] text-sm'
|
||||||
|
/>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
size: 80,
|
size: 80,
|
||||||
meta: { mobileHidden: true },
|
meta: { mobileOrder: 10 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'username',
|
accessorKey: 'username',
|
||||||
@@ -224,6 +227,7 @@ export function useUsersColumns(): ColumnDef<User>[] {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
size: 170,
|
size: 170,
|
||||||
|
meta: { mobileOrder: 40 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'group',
|
accessorKey: 'group',
|
||||||
@@ -242,6 +246,7 @@ export function useUsersColumns(): ColumnDef<User>[] {
|
|||||||
return group.includes(searchValue)
|
return group.includes(searchValue)
|
||||||
},
|
},
|
||||||
size: 140,
|
size: 140,
|
||||||
|
meta: { mobileOrder: 30 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'role',
|
accessorKey: 'role',
|
||||||
@@ -268,6 +273,7 @@ export function useUsersColumns(): ColumnDef<User>[] {
|
|||||||
},
|
},
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
size: 120,
|
size: 120,
|
||||||
|
meta: { mobileOrder: 20 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'invite_info',
|
id: 'invite_info',
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3718,7 +3718,7 @@
|
|||||||
"Right to Left": "De droite à gauche",
|
"Right to Left": "De droite à gauche",
|
||||||
"Role": "Rôle",
|
"Role": "Rôle",
|
||||||
"Roleplay": "Roleplay",
|
"Roleplay": "Roleplay",
|
||||||
"Root": "Racine",
|
"Root": "Root",
|
||||||
"Rose Garden": "Jardin de roses",
|
"Rose Garden": "Jardin de roses",
|
||||||
"Route": "Route",
|
"Route": "Route",
|
||||||
"Route active": "Route active",
|
"Route active": "Route active",
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3718,7 +3718,7 @@
|
|||||||
"Right to Left": "右から左",
|
"Right to Left": "右から左",
|
||||||
"Role": "ロール",
|
"Role": "ロール",
|
||||||
"Roleplay": "ロールプレイ",
|
"Roleplay": "ロールプレイ",
|
||||||
"Root": "ルート",
|
"Root": "Root",
|
||||||
"Rose Garden": "ローズガーデン",
|
"Rose Garden": "ローズガーデン",
|
||||||
"Route": "ルート",
|
"Route": "ルート",
|
||||||
"Route active": "ルート有効",
|
"Route active": "ルート有効",
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3718,7 +3718,7 @@
|
|||||||
"Right to Left": "Справа налево",
|
"Right to Left": "Справа налево",
|
||||||
"Role": "Роль",
|
"Role": "Роль",
|
||||||
"Roleplay": "Ролевые игры",
|
"Roleplay": "Ролевые игры",
|
||||||
"Root": "Корень",
|
"Root": "Root",
|
||||||
"Rose Garden": "Розовый сад",
|
"Rose Garden": "Розовый сад",
|
||||||
"Route": "Маршрут",
|
"Route": "Маршрут",
|
||||||
"Route active": "Маршрут активен",
|
"Route active": "Маршрут активен",
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3718,7 +3718,7 @@
|
|||||||
"Right to Left": "Phải sang trái",
|
"Right to Left": "Phải sang trái",
|
||||||
"Role": "Vai trò",
|
"Role": "Vai trò",
|
||||||
"Roleplay": "Nhập vai",
|
"Roleplay": "Nhập vai",
|
||||||
"Root": "Gốc",
|
"Root": "Root",
|
||||||
"Rose Garden": "Vườn hoa hồng",
|
"Rose Garden": "Vườn hoa hồng",
|
||||||
"Route": "Tuyến đường",
|
"Route": "Tuyến đường",
|
||||||
"Route active": "Tuyến đang hoạt động",
|
"Route active": "Tuyến đang hoạt động",
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3718,7 +3718,7 @@
|
|||||||
"Right to Left": "从右到左",
|
"Right to Left": "从右到左",
|
||||||
"Role": "角色",
|
"Role": "角色",
|
||||||
"Roleplay": "角色扮演",
|
"Roleplay": "角色扮演",
|
||||||
"Root": "根",
|
"Root": "Root",
|
||||||
"Rose Garden": "玫瑰花园",
|
"Rose Garden": "玫瑰花园",
|
||||||
"Route": "路由",
|
"Route": "路由",
|
||||||
"Route active": "路由已启用",
|
"Route active": "路由已启用",
|
||||||
|
|||||||
Vendored
+1
@@ -28,5 +28,6 @@ declare module '@tanstack/react-table' {
|
|||||||
mobileTitle?: boolean // card title area (left, larger text)
|
mobileTitle?: boolean // card title area (left, larger text)
|
||||||
mobileBadge?: boolean // status badge alongside title (right)
|
mobileBadge?: boolean // status badge alongside title (right)
|
||||||
mobileHidden?: boolean // hide this column on mobile entirely
|
mobileHidden?: boolean // hide this column on mobile entirely
|
||||||
|
mobileOrder?: number // lower values appear first in card field area
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user