added default sorting to tables

This commit is contained in:
Zai Shi 2024-05-16 16:20:07 +02:00
parent 372bd3296a
commit 85d167ed3c
3 changed files with 17 additions and 6 deletions

View File

@ -100,10 +100,19 @@ const columns: ColumnDef<ExtendedApiKeySet>[] = [
];
export function ApiKeyTable(props: { apiKeys: ApiKeySet[] }) {
const extendedApiKeys = useMemo(() => props.apiKeys.map((apiKey) => ({
...apiKey,
status: ({ 'valid': 'valid', 'manually-revoked': 'revoked', 'expired': 'expired' } as const)[apiKey.whyInvalid() || 'valid'],
} satisfies ExtendedApiKeySet)), [props.apiKeys]);
const extendedApiKeys = useMemo(() => {
const keys = props.apiKeys.map((apiKey) => ({
...apiKey,
status: ({ 'valid': 'valid', 'manually-revoked': 'revoked', 'expired': 'expired' } as const)[apiKey.whyInvalid() || 'valid'],
} satisfies ExtendedApiKeySet));
// first soft based on status, then by expiresAt
return keys.sort((a, b) => {
if (a.status === b.status) {
return a.expiresAt < b.expiresAt ? 1 : -1;
}
return a.status === 'valid' ? -1 : 1;
});
}, [props.apiKeys]);
return <DataTable data={extendedApiKeys} columns={columns} toolbarRender={toolbarRender} />;
}

View File

@ -1,5 +1,5 @@
'use client';;
import { useState } from "react";
import { useMemo, useState } from "react";
import * as yup from "yup";
import { ServerTeam } from '@stackframe/stack';
import { ColumnDef, Row, Table } from "@tanstack/react-table";
@ -124,5 +124,7 @@ const columns: ColumnDef<ServerTeam>[] = [
];
export function TeamTable(props: { teams: ServerTeam[] }) {
const teams = useMemo(() => props.teams.sort((a, b) => b.createdAt - a.createdAt), [props.teams]);
return <DataTable data={props.teams} columns={columns} toolbarRender={toolbarRender} />;
}

View File

@ -187,7 +187,7 @@ export function extendUsers(users: ServerUser[]): ExtendedServerUser[] {
...user,
authType: (user.authWithEmail ? "email" : user.oauthProviders[0]) || "",
emailVerified: user.primaryEmailVerified ? "verified" : "unverified",
}));
})).sort((a, b) => b.signedUpAt - a.signedUpAt);
}
export function UserTable(props: { users: ServerUser[] }) {