mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	feat: add event creators data to filter (#7822)
Adds event creator data to the event creator filter. It uses a new useEventCreators hook to fetch event creators from the new API, and uses that to populate the event creators filter.
This commit is contained in:
		
							parent
							
								
									bb30032f2e
								
							
						
					
					
						commit
						1b892979d3
					
				| @ -8,8 +8,11 @@ import useProjects from 'hooks/api/getters/useProjects/useProjects'; | ||||
| import { useFeatureSearch } from 'hooks/api/getters/useFeatureSearch/useFeatureSearch'; | ||||
| import { EventSchemaType } from 'openapi'; | ||||
| import type { IProjectCard } from 'interfaces/project'; | ||||
| import { useEventCreators } from 'hooks/api/getters/useEventCreators/useEventCreators'; | ||||
| 
 | ||||
| const sharedFilters: IFilterItem[] = [ | ||||
| const useSharedFilters = (): IFilterItem[] => { | ||||
|     const { eventCreators } = useEventCreators(); | ||||
|     return [ | ||||
|         { | ||||
|             label: 'Date From', | ||||
|             icon: 'today', | ||||
| @ -25,10 +28,12 @@ const sharedFilters: IFilterItem[] = [ | ||||
|             dateOperators: ['IS'], | ||||
|         }, | ||||
|         { | ||||
|         // todo fill this in with actual values
 | ||||
|             label: 'Created by', | ||||
|             icon: 'person', | ||||
|         options: [], | ||||
|             options: eventCreators.map((creator) => ({ | ||||
|                 label: creator.name, | ||||
|                 value: creator.id.toString(), | ||||
|             })), | ||||
|             filterKey: 'createdBy', | ||||
|             singularOperators: ['IS'], | ||||
|             pluralOperators: ['IS_ANY_OF'], | ||||
| @ -45,6 +50,7 @@ const sharedFilters: IFilterItem[] = [ | ||||
|             pluralOperators: ['IS_ANY_OF'], | ||||
|         }, | ||||
|     ]; | ||||
| }; | ||||
| 
 | ||||
| type EventLogFiltersProps = { | ||||
|     logType: 'flag' | 'project' | 'global'; | ||||
| @ -60,6 +66,7 @@ export const EventLogFilters: FC<EventLogFiltersProps> = ({ | ||||
| }) => { | ||||
|     const { projects } = useProjects(); | ||||
|     const { features } = useFeatureSearch({}); | ||||
|     const sharedFilters = useSharedFilters(); | ||||
| 
 | ||||
|     const [availableFilters, setAvailableFilters] = useState<IFilterItem[]>([]); | ||||
|     useEffect(() => { | ||||
| @ -106,7 +113,11 @@ export const EventLogFilters: FC<EventLogFiltersProps> = ({ | ||||
|         ]; | ||||
| 
 | ||||
|         setAvailableFilters(availableFilters); | ||||
|     }, [JSON.stringify(features), JSON.stringify(projects)]); | ||||
|     }, [ | ||||
|         JSON.stringify(features), | ||||
|         JSON.stringify(projects), | ||||
|         JSON.stringify(sharedFilters), | ||||
|     ]); | ||||
| 
 | ||||
|     return ( | ||||
|         <Filters | ||||
|  | ||||
| @ -0,0 +1,13 @@ | ||||
| import { fetcher, useApiGetter } from '../useApiGetter/useApiGetter'; | ||||
| import { formatApiPath } from 'utils/formatPath'; | ||||
| import type { EventCreatorsSchema } from '../../../../openapi'; | ||||
| 
 | ||||
| export const useEventCreators = () => { | ||||
|     const PATH = `api/admin/event-creators`; | ||||
|     const { data, refetch, loading, error } = useApiGetter<EventCreatorsSchema>( | ||||
|         formatApiPath(PATH), | ||||
|         () => fetcher(formatApiPath(PATH), 'Event creators'), | ||||
|     ); | ||||
| 
 | ||||
|     return { eventCreators: data || [], refetch, error, loading }; | ||||
| }; | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user