1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 22:39:41 +02:00

feat(helm): helm actions [r8s-259] (#715)

Co-authored-by: James Player <james.player@portainer.io>
Co-authored-by: Cara Ryan <cara.ryan@portainer.io>
Co-authored-by: stevensbkang <skan070@gmail.com>
This commit is contained in:
Ali 2025-05-13 22:15:04 +12:00 committed by GitHub
parent dfa32b6755
commit 4ee349bd6b
117 changed files with 4161 additions and 696 deletions

View file

@ -1,4 +1,4 @@
import { EventList } from 'kubernetes-types/core/v1';
import { EventList, Event } from 'kubernetes-types/core/v1';
import { useQuery } from '@tanstack/react-query';
import { EnvironmentId } from '@/react/portainer/environments/types';
@ -41,7 +41,7 @@ const queryKeys = {
async function getEvents(
environmentId: EnvironmentId,
options?: RequestOptions
) {
): Promise<Event[]> {
const { namespace, params } = options ?? {};
try {
const { data } = await axios.get<EventList>(
@ -56,15 +56,16 @@ async function getEvents(
}
}
type QueryOptions = {
type QueryOptions<T> = {
queryOptions?: {
autoRefreshRate?: number;
select?: (data: Event[]) => T;
};
} & RequestOptions;
export function useEvents(
export function useEvents<T = Event[]>(
environmentId: EnvironmentId,
options?: QueryOptions
options?: QueryOptions<T>
) {
const { queryOptions, params, namespace } = options ?? {};
return useQuery(
@ -75,6 +76,7 @@ export function useEvents(
refetchInterval() {
return queryOptions?.autoRefreshRate ?? false;
},
select: queryOptions?.select,
}
);
}
@ -83,11 +85,13 @@ export function useEventWarningsCount(
environmentId: EnvironmentId,
namespace?: string
) {
const resourceEventsQuery = useEvents(environmentId, {
const resourceEventsQuery = useEvents<number>(environmentId, {
namespace,
queryOptions: {
select: (data) => data.filter((e) => e.type === 'Warning').length,
},
});
const events = resourceEventsQuery.data || [];
return events.filter((e) => e.type === 'Warning').length;
return resourceEventsQuery.data || 0;
}
function buildUrl(environmentId: EnvironmentId, namespace?: string) {