diff --git a/app/reports/page-content.tsx b/app/reports/page-content.tsx index ed6e7b59..ff77036e 100644 --- a/app/reports/page-content.tsx +++ b/app/reports/page-content.tsx @@ -22,14 +22,14 @@ import { ModActionPanelQuick } from '../actions/ModActionPanel/QuickAction' import { ButtonGroup } from '@/common/buttons' import { SubjectTable } from 'components/subject/table' import { useTitle } from 'react-use' -import { QueueSelector, QUEUE_NAMES } from '@/reports/QueueSelector' +import { QueueSelector } from '@/reports/QueueSelector' import { simpleHash, unique } from '@/lib/util' import { useEmitEvent } from '@/mod-event/helpers/emitEvent' import { useFluentReportSearchParams } from '@/reports/useFluentReportSearch' import { useLabelerAgent } from '@/shell/ConfigurationContext' import { WorkspacePanel } from 'components/workspace/Panel' import { useWorkspaceOpener } from '@/common/useWorkspaceOpener' -import { QUEUE_SEED } from '@/lib/constants' +import { useQueueSetting } from 'components/setting/useQueueSetting' import QueueFilterPanel from '@/reports/QueueFilter/Panel' const TABS = [ @@ -294,6 +294,7 @@ function getTabFromParams({ reviewState }: { reviewState?: string | null }) { function useModerationQueueQuery() { const labelerAgent = useLabelerAgent() const params = useSearchParams() + const { setting: queueSetting } = useQueueSetting() const takendown = !!params.get('takendown') const includeMuted = !!params.get('includeMuted') @@ -393,7 +394,18 @@ function useModerationQueueQuery() { } }) - return getQueueItems(labelerAgent, queryParams, queueName) + return getQueueItems( + labelerAgent, + queryParams, + queueName, + 0, + queueSetting.data + ? { + queueNames: queueSetting.data.queueNames, + queueSeed: queueSetting.data.queueSeed.setting, + } + : undefined, + ) }, getNextPageParam: (lastPage) => lastPage.cursor, }) @@ -404,6 +416,7 @@ const getQueueItems = async ( queryParams: ToolsOzoneModerationQueryStatuses.QueryParams, queueName: string | null, attempt = 0, + queueSetting?: { queueNames: string[]; queueSeed: string }, ) => { const pageSize = 100 const { data } = await labelerAgent.tools.ozone.moderation.queryStatuses({ @@ -412,13 +425,19 @@ const getQueueItems = async ( ...queryParams, }) - const queueIndex = QUEUE_NAMES.indexOf(queueName ?? '') + const queueIndex = queueSetting?.queueNames.indexOf(queueName ?? '') const statusesInQueue = queueName ? data.subjectStatuses.filter((status) => { const subjectDid = ComAtprotoAdminDefs.isRepoRef(status.subject) ? status.subject.did : new AtUri(`${status.subject.uri}`).host - return getQueueIndex(subjectDid) === queueIndex + return ( + getQueueIndex( + subjectDid, + queueSetting?.queueNames || [], + queueSetting?.queueSeed || '', + ) === queueIndex + ) }) : data.subjectStatuses @@ -434,12 +453,13 @@ const getQueueItems = async ( }, queueName, ++attempt, + queueSetting, ) } return { cursor: data.cursor, subjectStatuses: statusesInQueue } } -function getQueueIndex(did: string) { - return simpleHash(did + QUEUE_SEED) % QUEUE_NAMES.length +function getQueueIndex(did: string, queueNames: string[], queueSeed: string) { + return simpleHash(`${queueSeed}:${did}`) % queueNames.length } diff --git a/components/config/Labeler.tsx b/components/config/Labeler.tsx index c24bffb6..b5ead45f 100644 --- a/components/config/Labeler.tsx +++ b/components/config/Labeler.tsx @@ -14,6 +14,7 @@ import { ServerConfig } from './server-config' import { useConfigurationContext } from '@/shell/ConfigurationContext' import { usePdsAgent } from '@/shell/AuthContext' import { LocalPreferences } from './LocalPreferences' +import { QueueSetting } from 'components/setting/Queue' const BrowserReactJsonView = dynamic(() => import('react-json-view'), { ssr: false, @@ -41,6 +42,7 @@ export function LabelerConfig() { + ) diff --git a/components/reports/QueueSelector.tsx b/components/reports/QueueSelector.tsx index 288a8812..1502f15f 100644 --- a/components/reports/QueueSelector.tsx +++ b/components/reports/QueueSelector.tsx @@ -1,27 +1,14 @@ import { Dropdown } from '@/common/Dropdown' -import { QUEUE_CONFIG } from '@/lib/constants' import { ChevronDownIcon } from '@heroicons/react/20/solid' +import { useQueueSetting } from 'components/setting/useQueueSetting' import { usePathname, useRouter, useSearchParams } from 'next/navigation' -type QueueConfig = Record - -const getQueueConfig = () => { - const config = QUEUE_CONFIG - try { - return JSON.parse(config) as QueueConfig - } catch (err) { - return {} - } -} - -export const QUEUES = getQueueConfig() -export const QUEUE_NAMES = Object.keys(QUEUES) - export const QueueSelector = () => { const searchParams = useSearchParams() const router = useRouter() const pathname = usePathname() const queueName = searchParams.get('queueName') + const { setting: queueSetting } = useQueueSetting() const selectQueue = (queue: string) => () => { const nextParams = new URLSearchParams(searchParams) @@ -34,7 +21,11 @@ export const QueueSelector = () => { } // If no queues are configured, just use a static title - if (!QUEUE_NAMES.length) { + if ( + queueSetting.isLoading || + !queueSetting.data || + !queueSetting.data?.queueNames.length + ) { return (

Queue @@ -42,6 +33,8 @@ export const QueueSelector = () => { ) } + const { queueNames, queueList } = queueSetting.data + return ( { text: 'All', onClick: selectQueue(''), }, - ...QUEUE_NAMES.map((q) => ({ - text: QUEUES[q].name, + ...queueNames.map((q) => ({ + text: queueList[q].name, onClick: selectQueue(q), })), ]} >

- {queueName ? `${QUEUES[queueName].name} Queue` : 'Queue'} + {queueName ? `${queueList[queueName].name} Queue` : 'Queue'}