diff --git a/components/mod-event/EventList.tsx b/components/mod-event/EventList.tsx index 1678e937..8790e765 100644 --- a/components/mod-event/EventList.tsx +++ b/components/mod-event/EventList.tsx @@ -1,4 +1,5 @@ import { + EventListState, FIRST_EVENT_TIMESTAMP, ModEventListQueryOptions, useModEventList, @@ -88,7 +89,7 @@ export const ModEventList = ( const noEvents = modEvents.length === 0 && !isInitialLoadingModEvents const isShowingEventsByCreator = !!props.createdBy return ( -
+
{!isEntireHistoryView ? (
Moderation event stream )} - setShowFiltersPanel((current) => !current)} - > - {hasFilter ? ( - - ) : ( - - )} - Configure - + setShowFiltersPanel((current) => !current)} + > + {hasFilter ? ( + + ) : ( + + )} + Configure +
{showFiltersPanel && ( -
-
-
- - changeListFilter({ field: 'types', value }) - } - /> -
-
-
Comment/Note
- -
- toggleCommentFilter()} - className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" - onKeyDown={(e) => { - if (e.key === 'Enter') { - e.preventDefault() // make sure we don't submit the form - e.currentTarget.click() // simulate a click on the input - } - }} - /> - -
- {commentFilter?.enabled && ( - - setCommentFilterKeyword(ev.target.value)} - autoComplete="off" - /> - - )} - - - - changeListFilter({ - field: 'createdBy', - value: ev.target.value, - }) - } - autoComplete="off" - /> - - - - - changeListFilter({ - field: 'subject', - value: ev.target.value, - }) - } - autoComplete="off" - /> - - - - - changeListFilter({ - field: 'createdAfter', - value: ev.target.value, - }) - } - autoComplete="off" - min={FIRST_EVENT_TIMESTAMP} - max={new Date().toISOString().split('.')[0]} - /> - - - - - changeListFilter({ - field: 'createdBefore', - value: ev.target.value, - }) - } - autoComplete="off" - min={FIRST_EVENT_TIMESTAMP} - max={new Date().toISOString().split('.')[0]} - /> - -
-
-
-
Sort Direction
- - - changeListFilter({ field: 'oldestFirst', value: !oldestFirst }) - } - label="Show oldest events first (default: newest first)" - /> -
-
+ )}
{noEvents ? ( @@ -327,83 +178,247 @@ export const ModEventList = ( ) } -// This is component which renders a list of checkboxes by iterating over MOD_EVENT_TITLES list for filtering by type -// same as the TypeFilter component but instead of dropdown, use checkboxes -// on each checkbox click, it will call the `setSelectedTypes` function and toggle the checkox's type -const TypeFilterCheckbox = ({ - selectedTypes, - setSelectedTypes, -}: { - selectedTypes: string[] - setSelectedTypes: (type: string[]) => void -}) => { +const EventFilterPanel = ({ + types, + commentFilter, + createdBy, + subject, + oldestFirst, + createdAfter, + createdBefore, + toggleCommentFilter, + setCommentFilterKeyword, + changeListFilter, +}: Omit & + Pick< + ReturnType, + | 'changeListFilter' + | 'commentFilter' + | 'toggleCommentFilter' + | 'setCommentFilterKeyword' + >) => { const allTypes = Object.entries(MOD_EVENT_TITLES) const toggleType = (type) => { if (type === 'all') { - if (selectedTypes.length === allTypes.length) { - setSelectedTypes([]) + if (types.length === allTypes.length) { + changeListFilter({ field: 'types', value: [] }) } else { - setSelectedTypes(allTypes.map(([type]) => type)) + changeListFilter({ + field: 'types', + value: allTypes.map(([type]) => type), + }) } return } - const newTypes = selectedTypes.includes(type) - ? selectedTypes.filter((t) => t !== type) - : [...selectedTypes, type] - setSelectedTypes(newTypes) + const newTypes = types.includes(type) + ? types.filter((t) => t !== type) + : [...types, type] + changeListFilter({ field: 'types', value: newTypes }) } return ( -
-
Event Type
-
- toggleType('all')} - className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" - onKeyDown={(e) => { - if (e.key === 'Enter') { - e.preventDefault() // make sure we don't submit the form - e.currentTarget.click() // simulate a click on the input - } - }} - /> - -
- {allTypes.map(([type, title]) => ( -
- toggleType(type)} - className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" - onKeyDown={(e) => { - if (e.key === 'Enter') { - e.preventDefault() // make sure we don't submit the form - e.currentTarget.click() // simulate a click on the input +
+
+
+
+
Event Type
+
+ toggleType('all')} + className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" + onKeyDown={(e) => { + if (e.key === 'Enter') { + e.preventDefault() // make sure we don't submit the form + e.currentTarget.click() // simulate a click on the input + } + }} + /> + +
+ {allTypes.map(([type, title]) => ( +
+ toggleType(type)} + className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" + onKeyDown={(e) => { + if (e.key === 'Enter') { + e.preventDefault() // make sure we don't submit the form + e.currentTarget.click() // simulate a click on the input + } + }} + /> + +
+ ))} +
+
+
+
Comment/Note
+ +
+ toggleCommentFilter()} + className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" + onKeyDown={(e) => { + if (e.key === 'Enter') { + e.preventDefault() // make sure we don't submit the form + e.currentTarget.click() // simulate a click on the input + } + }} + /> + +
+ {commentFilter?.enabled && ( + + setCommentFilterKeyword(ev.target.value)} + autoComplete="off" + /> + + )} + + + + changeListFilter({ + field: 'createdBy', + value: ev.target.value, + }) } - }} - /> - + + + + changeListFilter({ + field: 'subject', + value: ev.target.value, + }) + } + autoComplete="off" + /> + + + - {title} - + + changeListFilter({ + field: 'createdAfter', + value: ev.target.value, + }) + } + autoComplete="off" + min={FIRST_EVENT_TIMESTAMP} + max={new Date().toISOString().split('.')[0]} + /> + + + + + changeListFilter({ + field: 'createdBefore', + value: ev.target.value, + }) + } + autoComplete="off" + min={FIRST_EVENT_TIMESTAMP} + max={new Date().toISOString().split('.')[0]} + /> +
- ))} +
+
+
Sort Direction
+ + + changeListFilter({ field: 'oldestFirst', value: !oldestFirst }) + } + label="Show oldest events first (default: newest first)" + /> +
) } diff --git a/components/mod-event/useModEventList.tsx b/components/mod-event/useModEventList.tsx index a086effd..9fe390ec 100644 --- a/components/mod-event/useModEventList.tsx +++ b/components/mod-event/useModEventList.tsx @@ -30,7 +30,7 @@ const initialListState = { } // The 2 fields need overriding because in the initialState, they are set as undefined so the alternative string type is not accepted without override -type EventListState = Omit & { +export type EventListState = Omit & { subject?: string createdBy?: string }