Fix admin pool sorting and OAuth refresh

This commit is contained in:
fawney19
2026-05-13 09:16:52 +08:00
parent 4387a9cdd5
commit 3c2497f019
15 changed files with 498 additions and 195 deletions

View File

@@ -99,6 +99,49 @@ describe('poolManagementState', () => {
})
})
it('supports score sort in storage and query state', () => {
writePoolManagementViewState(
{
providerId: 'provider-g',
search: 'score search',
status: 'cooldown',
page: 3,
pageSize: 25,
sortBy: 'score',
sortOrder: 'desc',
statsMode: 'current_cycle',
},
storage,
)
expect(readPoolManagementViewState({}, storage)).toMatchObject({
providerId: 'provider-g',
search: 'score search',
status: 'cooldown',
page: 3,
pageSize: 25,
sortBy: 'score',
sortOrder: 'desc',
statsMode: 'current_cycle',
})
expect(
buildPoolManagementQueryPatch({
providerId: 'provider-g',
search: 'score search',
status: 'cooldown',
page: 3,
pageSize: 25,
sortBy: 'score',
sortOrder: 'desc',
statsMode: 'current_cycle',
}),
).toMatchObject({
sortBy: 'score',
sortOrder: 'desc',
})
})
it('omits defaults when building query patch', () => {
expect(
buildPoolManagementQueryPatch({
@@ -131,13 +174,13 @@ describe('poolManagementState', () => {
status: 'all',
page: 1,
pageSize: 50,
sortBy: 'last_used_at',
sortOrder: 'asc',
sortBy: 'score',
sortOrder: 'desc',
statsMode: 'account_total',
}),
).toMatchObject({
sortBy: 'last_used_at',
sortOrder: 'asc',
sortBy: 'score',
sortOrder: 'desc',
statsMode: 'account_total',
})
})

View File

@@ -1,5 +1,5 @@
export type PoolManagementStatus = 'all' | 'active' | 'cooldown' | 'inactive'
export type PoolManagementSortBy = 'imported_at' | 'last_used_at'
export type PoolManagementSortBy = 'imported_at' | 'last_used_at' | 'score'
export type PoolManagementSortOrder = 'asc' | 'desc'
export type PoolManagementStatsMode = 'current_cycle' | 'account_total'
@@ -73,7 +73,7 @@ function normalizePositiveInteger(value: unknown, fallback: number): number {
}
function normalizeSortBy(value: unknown): PoolManagementSortBy | null {
if (value === 'imported_at' || value === 'last_used_at') {
if (value === 'imported_at' || value === 'last_used_at' || value === 'score') {
return value
}
return DEFAULT_POOL_MANAGEMENT_VIEW_STATE.sortBy