Skip to content

Commit 069d954

Browse files
committed
Show only ten users who have used most tokens in the user table
1 parent 0f011aa commit 069d954

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/client/components/Admin/Usage/UserTable.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ type Usage = Omit<ChatInstanceUsage, 'chatInstance'> & {
2525
chatInstance?: ChatInstance
2626
}
2727

28-
const sortUsage = (a: Usage, b: Usage) =>
29-
a.user.username.localeCompare(b.user.username)
28+
const sortUsage = (a: Usage, b: Usage) => b.usageCount - a.usageCount
3029

3130
const handleLoginAs = (user: User) => () => {
3231
localStorage.setItem('adminLoggedInAs', user.id)
@@ -42,24 +41,22 @@ const UserTable = () => {
4241

4342
const [searchedUsages, setSearchedUsages] = useState<Usage[]>([])
4443

45-
const { t } = useTranslation()
44+
const { t, i18n } = useTranslation()
4645

47-
if (isLoading || usersLoading) return null
46+
const { language } = i18n
4847

49-
const filteredUsers = users.filter(({ usage }) => usage !== 0)
48+
if (isLoading || usersLoading) return null
5049

51-
const userUsages: Usage[] = filteredUsers.map((user) => ({
50+
const userUsages: Usage[] = users.map((user) => ({
5251
id: user.id,
5352
user,
5453
usageCount: user.usage,
5554
}))
5655

57-
const filteredUsage = chatInstanceUsage.filter(
58-
({ usageCount }) => usageCount !== 0
59-
)
60-
const sortedUsage = (filteredUsage as Usage[])
56+
const sortedUsage = (chatInstanceUsage as Usage[])
6157
.concat(userUsages)
6258
.sort(sortUsage)
59+
.slice(0, 10)
6360

6461
const onDeleteChatInstanceUsage = (chatInstanceUsageId: string) => {
6562
try {
@@ -108,7 +105,7 @@ const UserTable = () => {
108105
</TableCell>
109106
<TableCell align="right">
110107
<Typography variant="h5">
111-
<b>{t('admin:courseId')}</b>
108+
<b>Kurssin nimi</b>
112109
</Typography>
113110
</TableCell>
114111
</TableRow>
@@ -126,7 +123,7 @@ const UserTable = () => {
126123
</TableCell>
127124
<TableCell align="right">
128125
<Typography variant="overline">
129-
<code>{chatInstance?.courseId ?? ''}</code>
126+
<code>{chatInstance?.name[language] ?? ''}</code>
130127
</Typography>
131128
</TableCell>
132129
<TableCell>
@@ -143,7 +140,7 @@ const UserTable = () => {
143140
</TableCell>
144141
<TableCell>
145142
<Button variant="outlined" onClick={handleLoginAs(user)}>
146-
Kirjaudu käyttäjällä
143+
Kirjaudu käyttäjänä
147144
</Button>
148145
</TableCell>
149146
</TableRow>

0 commit comments

Comments
 (0)