Skip to content

Commit

Permalink
✨ Add policy filter to events tab
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Dec 20, 2024
1 parent 0fc2445 commit fd92f82
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
12 changes: 12 additions & 0 deletions components/mod-event/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useState } from 'react'
import { RepoFinder } from '@/repositories/Finder'
import { Dropdown } from '@/common/Dropdown'
import { ChevronDownIcon } from '@heroicons/react/24/solid'
import { ActionPolicySelector } from '@/reports/ModerationForm/ActionPolicySelector'

export const EventFilterPanel = ({
limit,
Expand Down Expand Up @@ -271,6 +272,17 @@ export const EventFilterPanel = ({
</FormLabel>
</div>
</div>
{types.includes(MOD_EVENTS.TAKEDOWN) && (
<div className="flex flex-row gap-2 mt-2">
<FormLabel label="Policy" className="flex-1">
<ActionPolicySelector
onSelect={(policy) => {
changeListFilter({ field: 'policy', value: policy })
}}
/>
</FormLabel>
</div>
)}
{types.includes(MOD_EVENTS.TAG) && (
<div className="flex flex-row gap-2 mt-2">
<FormLabel label="Added Tags" className="flex-1 max-w-sm">
Expand Down
8 changes: 8 additions & 0 deletions components/mod-event/useModEventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const initialListState = {
removedLabels: [],
addedTags: '',
removedTags: '',
policy: '',
showContentPreview: false,
limit: 25,
}
Expand Down Expand Up @@ -157,6 +158,7 @@ type EventListFilterPayload =
| { field: 'removedLabels'; value: string[] }
| { field: 'addedTags'; value: string }
| { field: 'removedTags'; value: string }
| { field: 'policy'; value: string }
| { field: 'limit'; value: number }

type EventListAction =
Expand Down Expand Up @@ -246,6 +248,7 @@ export const useModEventList = (
addedTags,
removedTags,
reportTypes,
policy,
limit,
} = listState
const queryParams: ToolsOzoneModerationQueryEvents.QueryParams = {
Expand Down Expand Up @@ -335,6 +338,10 @@ export const useModEventList = (
})
}

if (filterTypes.includes(MOD_EVENTS.TAKEDOWN) && policy) {
queryParams.policy = policy

Check failure on line 342 in components/mod-event/useModEventList.tsx

View workflow job for this annotation

GitHub Actions / Build

Property 'policy' does not exist on type 'QueryParams'.
}

const { data } = await labelerAgent.tools.ozone.moderation.queryEvents({
...queryParams,
})
Expand Down Expand Up @@ -372,6 +379,7 @@ export const useModEventList = (
listState.createdBy ||
listState.subject ||
listState.oldestFirst ||
listState.policy ||
listState.reportTypes.length > 0 ||
listState.addedLabels.length > 0 ||
listState.removedLabels.length > 0 ||
Expand Down
4 changes: 0 additions & 4 deletions components/reports/ModerationForm/ActionPolicySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export const ActionPolicySelector = ({
const policyList = Object.values(data?.value || {})
const matchingPolicies = policyList
?.filter((tpl) => {
if (selected && tpl.name !== selected) {
return false
}

if (query.length) {
return tpl.name.toLowerCase().includes(query.toLowerCase())
}
Expand Down
8 changes: 6 additions & 2 deletions components/setting/policy/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ export const PolicyEditor = ({
id="name"
name="name"
required
placeholder="Name of the policy. Only alphabets are allowed."
placeholder="Name of the policy. Only alphabetic characters are allowed."
className="block w-full"
pattern="[A-Za-z ]+"
/>
</FormLabel>
<FormLabel label="Name" htmlFor="name" className="flex-1 mb-3">
<FormLabel
label="Description"
htmlFor="description"
className="flex-1 mb-3"
>
<Textarea
required
id="description"
Expand Down

0 comments on commit fd92f82

Please sign in to comment.