Skip to content

Commit

Permalink
:rightwards_twisted_arrows: Merge with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Nov 14, 2024
2 parents 325541e + 666ffeb commit 7467579
Show file tree
Hide file tree
Showing 24 changed files with 1,070 additions and 470 deletions.
22 changes: 11 additions & 11 deletions app/events/filters/macros/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ import { ActionButton, LinkButton } from '@/common/buttons'
import { PlusIcon, TrashIcon } from '@heroicons/react/24/solid'
import { ConfirmationModal } from '@/common/modals/confirmation'
import { useState } from 'react'
import { EmptyDataset } from '@/common/feeds/EmptyFeed'

const dateFormatter = new Intl.DateTimeFormat('en-US', {
dateStyle: 'medium',
timeStyle: 'short',
})

export default function EventFiltersMacrosListPage() {
const [isOpen, setIsOpen] = useState(false)
const [removingMacro, setRemovingMacro] = useState('')
const { data: macroList, isFetching, error } = useFilterMacroList()
const {
mutateAsync: removeMacro,
error: removeMacroError,
isLoading: isRemovingMacro,
isLoading: removingMacroMacro,
} = useFilterMacroRemoveMutation()

useTitle('Moderation Filter Macros')
Expand All @@ -36,7 +35,7 @@ export default function EventFiltersMacrosListPage() {
return <Loading />
}

const confirmButtonText = isRemovingMacro ? 'Removing...' : 'Yes, Remove'
const confirmButtonText = removingMacroMacro ? 'Removing...' : 'Yes, Remove'
const listItems = Object.entries(macroList)

return (
Expand Down Expand Up @@ -65,25 +64,26 @@ export default function EventFiltersMacrosListPage() {
appearance="outlined"
size="sm"
type="button"
onClick={() => setIsOpen(true)}
onClick={() => setRemovingMacro(name)}
>
<TrashIcon className="h-3 w-3" />
</ActionButton>

<ConfirmationModal
onConfirm={() => {
removeMacro(name).then(() => setIsOpen(false))
removeMacro(removingMacro).then(() => setRemovingMacro(''))
}}
isOpen={isOpen}
setIsOpen={setIsOpen}
isOpen={removingMacro === name}
setIsOpen={(val) => setRemovingMacro(val ? name : '')}
confirmButtonText={confirmButtonText}
confirmButtonDisabled={isRemovingMacro}
confirmButtonDisabled={removingMacroMacro}
error={removeMacroError?.['message']}
title={`Remove Filter Macro?`}
description={
<>
You can always recreate your macro from the event filter
panel
You{"'"}re about to remove the filter macro{' '}
{`"${removingMacro}"`}. You can always recreate your macro
from the event filter panel.
</>
}
/>
Expand Down
106 changes: 75 additions & 31 deletions app/reports/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ import { ModActionPanelQuick } from '../actions/ModActionPanel/QuickAction'
import { ButtonGroup } from '@/common/buttons'
import { SubjectTable } from 'components/subject/table'
import { useTitle } from 'react-use'
import { LanguagePicker } from '@/common/LanguagePicker'
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 { EmbedTypePickerForModerationQueue } from '@/common/EmbedTypePicker'
import { QUEUE_SEED } from '@/lib/constants'
import { useQueueSetting } from 'components/setting/useQueueSetting'
import QueueFilterPanel from '@/reports/QueueFilter/Panel'

const TABS = [
{
Expand Down Expand Up @@ -106,13 +105,15 @@ const ResolvedFilters = () => {
const appealed = params.get('appealed')

const updateParams = useCallback(
(key: string, newState: boolean) => {
(updates: Record<string, boolean>) => {
const nextParams = new URLSearchParams(params)
if (nextParams.get(key) == `${newState}`) {
nextParams.delete(key)
} else {
nextParams.set(key, `${newState}`)
}
Object.entries(updates).forEach(([key, newState]) => {
if (nextParams.get(key) === `${newState}`) {
nextParams.delete(key)
} else {
nextParams.set(key, `${newState}`)
}
})
router.push((pathname ?? '') + '?' + nextParams.toString())
},
[params, pathname, router],
Expand All @@ -126,20 +127,29 @@ const ResolvedFilters = () => {
{
id: 'takendown',
text: 'Taken Down',
onClick: () => updateParams('takendown', true),
onClick: () => updateParams({ takendown: true }),
isActive: takendown === 'true',
},
{
id: 'includeMuted',
text: 'Show Muted',
onClick: () => updateParams('includeMuted', true),
isActive: includeMuted === 'true',
},
{
id: 'onlyMuted',
text: 'Only Muted',
onClick: () => updateParams('onlyMuted', true),
isActive: onlyMuted === 'true',
id: 'mute',
text:
includeMuted === 'true'
? 'Include Muted'
: onlyMuted === 'true'
? 'Only Muted'
: 'Mutes',
onClick: () => {
// setting a param to it's current value toggles it off
// so we toggle off includeMuted and toggle on onlyMuted
if (includeMuted === 'true') {
updateParams({ includeMuted: true, onlyMuted: true })
} else if (onlyMuted === 'true') {
updateParams({ onlyMuted: true })
} else {
updateParams({ includeMuted: true })
}
},
isActive: includeMuted === 'true' || onlyMuted === 'true',
},
{
id: 'appealed',
Expand All @@ -151,12 +161,12 @@ const ResolvedFilters = () => {
: 'Appeals',
onClick: () => {
if (appealed === 'true') {
updateParams('appealed', false)
updateParams({ appealed: false })
} else if (appealed === 'false') {
// setting the same value toggles the param off
updateParams('appealed', false)
updateParams({ appealed: false })
} else {
updateParams('appealed', true)
updateParams({ appealed: true })
}
},
isActive: appealed === 'true' || appealed === 'false',
Expand Down Expand Up @@ -237,8 +247,7 @@ export const ReportsPageContent = () => {
</SectionHeader>
<div className="md:flex mt-2 mb-2 flex-row justify-between px-4 sm:px-6 lg:px-8">
<div className="flex flex-row items-center gap-2">
<LanguagePicker />
<EmbedTypePickerForModerationQueue />
<QueueFilterPanel />
</div>
<ResolvedFilters />
</div>
Expand Down Expand Up @@ -285,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')
Expand All @@ -294,6 +304,8 @@ function useModerationQueueQuery() {
const tags = params.get('tags')
const excludeTags = params.get('excludeTags')
const queueName = params.get('queueName')
const subjectType = params.get('subjectType')
const collections = params.get('collections')
const { sortField, sortDirection } = getSortParams(params)
const { lastReviewedBy, subject, reporters, includeAllUserRecords } =
useFluentReportSearchParams()
Expand All @@ -316,6 +328,8 @@ function useModerationQueueQuery() {
queueName,
includeMuted,
onlyMuted,
subjectType,
collections,
},
],
queryFn: async ({ pageParam }) => {
Expand All @@ -329,6 +343,17 @@ function useModerationQueueQuery() {

if (subject) {
queryParams.subject = subject
} else {
if (subjectType) {
queryParams.subjectType = subjectType
}

if (subjectType === 'record') {
const collectionNames = collections?.split(',')
if (collectionNames?.length) {
queryParams.collections = collectionNames
}
}
}

if (takendown) {
Expand Down Expand Up @@ -369,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,
})
Expand All @@ -380,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({
Expand All @@ -388,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

Expand All @@ -410,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
}
42 changes: 22 additions & 20 deletions app/repositories/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { RepositoriesTable } from '@/repositories/RepositoriesTable'
import { useSearchParams } from 'next/navigation'
import { useInfiniteQuery } from '@tanstack/react-query'
import { useTitle } from 'react-use'
import { Agent, ToolsOzoneModerationDefs } from '@atproto/api'
import {
Agent,
ToolsOzoneModerationDefs,
ComAtprotoAdminSearchAccounts,
} from '@atproto/api'
import { useLabelerAgent } from '@/shell/ConfigurationContext'
import { ActionButton } from '@/common/buttons'
import { useWorkspaceAddItemsMutation } from '@/workspace/hooks'
Expand All @@ -13,8 +17,8 @@ import { ConfirmationModal } from '@/common/modals/confirmation'
import { WorkspacePanel } from '@/workspace/Panel'
import { useWorkspaceOpener } from '@/common/useWorkspaceOpener'

const isEmailSearch = (q: string) =>
q.startsWith('email:') || q.startsWith('ip:') || q.startsWith('hcap:')
const isEmailSearch = (q: string) => q.startsWith('email:')
const isSignatureSearch = (q: string) => q.startsWith('sig:')

const getRepos =
({ q, labelerAgent }: { q: string; labelerAgent: Agent }) =>
Expand All @@ -30,7 +34,7 @@ const getRepos =
) => {
const limit = 25

if (!isEmailSearch(q)) {
if (!isEmailSearch(q) && !isSignatureSearch(q)) {
const { data } = await labelerAgent.tools.ozone.moderation.searchRepos(
{
q,
Expand All @@ -43,24 +47,22 @@ const getRepos =
return data
}

const email = q
.replace('email:', '')
.replace('ip:', '')
.replace('hcap:', '')
.trim()

if (!email) {
return { repos: [], cursor: undefined }
}

const { data } = await labelerAgent.com.atproto.admin.searchAccounts(
{
let data: ComAtprotoAdminSearchAccounts.OutputSchema
if (isSignatureSearch(q)) {
const value = q.replace('sig:', '').trim()
const res = await labelerAgent.tools.ozone.signature.searchAccounts({
values: [value],
})
data = res.data
} else {
const email = q.replace('email:', '').trim()
const res = await labelerAgent.com.atproto.admin.searchAccounts({
email,
limit,
cursor: pageParam,
},
options,
)
}, options)
data = res.data
}

if (!data.accounts.length) {
return { repos: [], cursor: data.cursor }
Expand Down Expand Up @@ -244,7 +246,7 @@ export default function RepositoriesListPage() {

<RepositoriesTable
repos={repos}
showEmail={isEmailSearch(q)}
showEmail={isEmailSearch(q) || isSignatureSearch(q)}
onLoadMore={fetchNextPage}
showLoadMore={!!hasNextPage}
showEmptySearch={!q?.length && !repos.length}
Expand Down
Loading

0 comments on commit 7467579

Please sign in to comment.