Skip to content

Commit

Permalink
feat: add event creators data to filter (#7822)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomasheartman authored Aug 13, 2024
1 parent bb30032 commit 1b89297
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 37 deletions.
85 changes: 48 additions & 37 deletions frontend/src/component/events/EventLog/EventLogFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,49 @@ 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[] = [
{
label: 'Date From',
icon: 'today',
options: [],
filterKey: 'from',
dateOperators: ['IS'],
},
{
label: 'Date To',
icon: 'today',
options: [],
filterKey: 'to',
dateOperators: ['IS'],
},
{
// todo fill this in with actual values
label: 'Created by',
icon: 'person',
options: [],
filterKey: 'createdBy',
singularOperators: ['IS'],
pluralOperators: ['IS_ANY_OF'],
},
{
label: 'Event type',
icon: 'announcement',
options: Object.entries(EventSchemaType).map(([key, value]) => ({
label: key,
value: value,
})),
filterKey: 'type',
singularOperators: ['IS'],
pluralOperators: ['IS_ANY_OF'],
},
];
const useSharedFilters = (): IFilterItem[] => {
const { eventCreators } = useEventCreators();
return [
{
label: 'Date From',
icon: 'today',
options: [],
filterKey: 'from',
dateOperators: ['IS'],
},
{
label: 'Date To',
icon: 'today',
options: [],
filterKey: 'to',
dateOperators: ['IS'],
},
{
label: 'Created by',
icon: 'person',
options: eventCreators.map((creator) => ({
label: creator.name,
value: creator.id.toString(),
})),
filterKey: 'createdBy',
singularOperators: ['IS'],
pluralOperators: ['IS_ANY_OF'],
},
{
label: 'Event type',
icon: 'announcement',
options: Object.entries(EventSchemaType).map(([key, value]) => ({
label: key,
value: value,
})),
filterKey: 'type',
singularOperators: ['IS'],
pluralOperators: ['IS_ANY_OF'],
},
];
};

type EventLogFiltersProps = {
logType: 'flag' | 'project' | 'global';
Expand All @@ -60,6 +66,7 @@ export const EventLogFilters: FC<EventLogFiltersProps> = ({
}) => {
const { projects } = useProjects();
const { features } = useFeatureSearch({});
const sharedFilters = useSharedFilters();

const [availableFilters, setAvailableFilters] = useState<IFilterItem[]>([]);
useEffect(() => {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 };
};

0 comments on commit 1b89297

Please sign in to comment.