mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-12 19:31:12 -05:00
🐛 fix(sort): Refactor sorting logic in NodeTable and SubscribeTable components for improved clarity and performance
This commit is contained in:
parent
a604f28fef
commit
331bbea45f
@ -291,20 +291,20 @@ export default function NodeTable() {
|
|||||||
const sourceIndex = items.findIndex((item) => String(item.id) === source);
|
const sourceIndex = items.findIndex((item) => String(item.id) === source);
|
||||||
const targetIndex = items.findIndex((item) => String(item.id) === target);
|
const targetIndex = items.findIndex((item) => String(item.id) === target);
|
||||||
|
|
||||||
const originalSortMap = new Map(items.map((item) => [item.id, item.sort || item.id]));
|
const originalSorts = items.map((item) => item.sort);
|
||||||
|
|
||||||
const [movedItem] = items.splice(sourceIndex, 1);
|
const [movedItem] = items.splice(sourceIndex, 1);
|
||||||
items.splice(targetIndex, 0, movedItem!);
|
items.splice(targetIndex, 0, movedItem!);
|
||||||
|
|
||||||
const updatedItems = items.map((item, index) => {
|
const updatedItems = items.map((item, index) => {
|
||||||
const originalSort = originalSortMap.get(item.id);
|
const originalSort = originalSorts[index];
|
||||||
const newSort = originalSort !== undefined ? originalSort : item.sort;
|
const newSort = originalSort !== undefined ? originalSort : item.sort;
|
||||||
return { ...item, sort: newSort };
|
return { ...item, sort: newSort };
|
||||||
});
|
});
|
||||||
|
|
||||||
const changedItems = updatedItems.filter(
|
const changedItems = updatedItems.filter((item, index) => {
|
||||||
(item) => originalSortMap.get(item.id) !== item.sort,
|
return item.sort !== items[index]?.sort;
|
||||||
);
|
});
|
||||||
|
|
||||||
if (changedItems.length > 0) {
|
if (changedItems.length > 0) {
|
||||||
nodeSort({
|
nodeSort({
|
||||||
|
|||||||
@ -278,20 +278,20 @@ export default function SubscribeTable() {
|
|||||||
const sourceIndex = items.findIndex((item) => String(item.id) === source);
|
const sourceIndex = items.findIndex((item) => String(item.id) === source);
|
||||||
const targetIndex = items.findIndex((item) => String(item.id) === target);
|
const targetIndex = items.findIndex((item) => String(item.id) === target);
|
||||||
|
|
||||||
const originalSortMap = new Map(items.map((item) => [item.id, item.sort || item.id]));
|
const originalSorts = items.map((item) => item.sort);
|
||||||
|
|
||||||
const [movedItem] = items.splice(sourceIndex, 1);
|
const [movedItem] = items.splice(sourceIndex, 1);
|
||||||
items.splice(targetIndex, 0, movedItem!);
|
items.splice(targetIndex, 0, movedItem!);
|
||||||
|
|
||||||
const updatedItems = items.map((item, index) => {
|
const updatedItems = items.map((item, index) => {
|
||||||
const originalSort = originalSortMap.get(item.id);
|
const originalSort = originalSorts[index];
|
||||||
const newSort = originalSort !== undefined ? originalSort : item.sort;
|
const newSort = originalSort !== undefined ? originalSort : item.sort;
|
||||||
return { ...item, sort: newSort };
|
return { ...item, sort: newSort };
|
||||||
});
|
});
|
||||||
|
|
||||||
const changedItems = updatedItems.filter(
|
const changedItems = updatedItems.filter((item, index) => {
|
||||||
(item) => originalSortMap.get(item.id) !== item.sort,
|
return item.sort !== items[index]?.sort;
|
||||||
);
|
});
|
||||||
|
|
||||||
if (changedItems.length > 0) {
|
if (changedItems.length > 0) {
|
||||||
subscribeSort({
|
subscribeSort({
|
||||||
|
|||||||
@ -27,7 +27,7 @@ export function UserNav() {
|
|||||||
<Avatar className='size-8'>
|
<Avatar className='size-8'>
|
||||||
<AvatarImage alt={user?.avatar ?? ''} src={user?.avatar ?? ''} />
|
<AvatarImage alt={user?.avatar ?? ''} src={user?.avatar ?? ''} />
|
||||||
<AvatarFallback className='rounded-none bg-transparent'>
|
<AvatarFallback className='rounded-none bg-transparent'>
|
||||||
{user?.email?.[0]?.toUpperCase()}
|
{user?.auth_methods?.[0]?.auth_identifier.toUpperCase().charAt(0)}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
</Button>
|
</Button>
|
||||||
@ -35,7 +35,9 @@ export function UserNav() {
|
|||||||
<DropdownMenuContent forceMount align='end' className='w-56'>
|
<DropdownMenuContent forceMount align='end' className='w-56'>
|
||||||
<DropdownMenuLabel className='font-normal'>
|
<DropdownMenuLabel className='font-normal'>
|
||||||
<div className='flex flex-col space-y-1'>
|
<div className='flex flex-col space-y-1'>
|
||||||
<p className='text-sm font-medium leading-none'>{user?.email}</p>
|
<p className='text-sm font-medium leading-none'>
|
||||||
|
{user?.auth_methods?.[0]?.auth_identifier}
|
||||||
|
</p>
|
||||||
{/* <p className='text-xs leading-none text-muted-foreground'>ID: {user?.id}</p> */}
|
{/* <p className='text-xs leading-none text-muted-foreground'>ID: {user?.id}</p> */}
|
||||||
</div>
|
</div>
|
||||||
</DropdownMenuLabel>
|
</DropdownMenuLabel>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user