mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +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,43 +8,49 @@ import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
|||||||
import { useFeatureSearch } from 'hooks/api/getters/useFeatureSearch/useFeatureSearch';
|
import { useFeatureSearch } from 'hooks/api/getters/useFeatureSearch/useFeatureSearch';
|
||||||
import { EventSchemaType } from 'openapi';
|
import { EventSchemaType } from 'openapi';
|
||||||
import type { IProjectCard } from 'interfaces/project';
|
import type { IProjectCard } from 'interfaces/project';
|
||||||
|
import { useEventCreators } from 'hooks/api/getters/useEventCreators/useEventCreators';
|
||||||
|
|
||||||
const sharedFilters: IFilterItem[] = [
|
const useSharedFilters = (): IFilterItem[] => {
|
||||||
{
|
const { eventCreators } = useEventCreators();
|
||||||
label: 'Date From',
|
return [
|
||||||
icon: 'today',
|
{
|
||||||
options: [],
|
label: 'Date From',
|
||||||
filterKey: 'from',
|
icon: 'today',
|
||||||
dateOperators: ['IS'],
|
options: [],
|
||||||
},
|
filterKey: 'from',
|
||||||
{
|
dateOperators: ['IS'],
|
||||||
label: 'Date To',
|
},
|
||||||
icon: 'today',
|
{
|
||||||
options: [],
|
label: 'Date To',
|
||||||
filterKey: 'to',
|
icon: 'today',
|
||||||
dateOperators: ['IS'],
|
options: [],
|
||||||
},
|
filterKey: 'to',
|
||||||
{
|
dateOperators: ['IS'],
|
||||||
// todo fill this in with actual values
|
},
|
||||||
label: 'Created by',
|
{
|
||||||
icon: 'person',
|
label: 'Created by',
|
||||||
options: [],
|
icon: 'person',
|
||||||
filterKey: 'createdBy',
|
options: eventCreators.map((creator) => ({
|
||||||
singularOperators: ['IS'],
|
label: creator.name,
|
||||||
pluralOperators: ['IS_ANY_OF'],
|
value: creator.id.toString(),
|
||||||
},
|
})),
|
||||||
{
|
filterKey: 'createdBy',
|
||||||
label: 'Event type',
|
singularOperators: ['IS'],
|
||||||
icon: 'announcement',
|
pluralOperators: ['IS_ANY_OF'],
|
||||||
options: Object.entries(EventSchemaType).map(([key, value]) => ({
|
},
|
||||||
label: key,
|
{
|
||||||
value: value,
|
label: 'Event type',
|
||||||
})),
|
icon: 'announcement',
|
||||||
filterKey: 'type',
|
options: Object.entries(EventSchemaType).map(([key, value]) => ({
|
||||||
singularOperators: ['IS'],
|
label: key,
|
||||||
pluralOperators: ['IS_ANY_OF'],
|
value: value,
|
||||||
},
|
})),
|
||||||
];
|
filterKey: 'type',
|
||||||
|
singularOperators: ['IS'],
|
||||||
|
pluralOperators: ['IS_ANY_OF'],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
type EventLogFiltersProps = {
|
type EventLogFiltersProps = {
|
||||||
logType: 'flag' | 'project' | 'global';
|
logType: 'flag' | 'project' | 'global';
|
||||||
@ -60,6 +66,7 @@ export const EventLogFilters: FC<EventLogFiltersProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { projects } = useProjects();
|
const { projects } = useProjects();
|
||||||
const { features } = useFeatureSearch({});
|
const { features } = useFeatureSearch({});
|
||||||
|
const sharedFilters = useSharedFilters();
|
||||||
|
|
||||||
const [availableFilters, setAvailableFilters] = useState<IFilterItem[]>([]);
|
const [availableFilters, setAvailableFilters] = useState<IFilterItem[]>([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -106,7 +113,11 @@ export const EventLogFilters: FC<EventLogFiltersProps> = ({
|
|||||||
];
|
];
|
||||||
|
|
||||||
setAvailableFilters(availableFilters);
|
setAvailableFilters(availableFilters);
|
||||||
}, [JSON.stringify(features), JSON.stringify(projects)]);
|
}, [
|
||||||
|
JSON.stringify(features),
|
||||||
|
JSON.stringify(projects),
|
||||||
|
JSON.stringify(sharedFilters),
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Filters
|
<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