|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import { useEffect, useMemo, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
import { useTags } from '@/portainer/tags/queries';
|
|
|
|
|
import { useEdgeGroups } from '@/react/edge/edge-groups/queries/useEdgeGroups';
|
|
|
|
@ -10,20 +11,33 @@ import { WaitingRoomEnvironment } from '../types';
|
|
|
|
|
|
|
|
|
|
import { useFilterStore } from './filter-store';
|
|
|
|
|
|
|
|
|
|
export function useEnvironments() {
|
|
|
|
|
export function useEnvironments({
|
|
|
|
|
pageLimit = 10,
|
|
|
|
|
search,
|
|
|
|
|
}: {
|
|
|
|
|
pageLimit: number;
|
|
|
|
|
search: string;
|
|
|
|
|
}) {
|
|
|
|
|
const [page, setPage] = useState(0);
|
|
|
|
|
const filterStore = useFilterStore();
|
|
|
|
|
const edgeGroupsQuery = useEdgeGroups();
|
|
|
|
|
|
|
|
|
|
const filterByEnvironmentsIds = filterStore.edgeGroups.length
|
|
|
|
|
const filterByEnvironmentsIds = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
filterStore.edgeGroups.length
|
|
|
|
|
? _.compact(
|
|
|
|
|
filterStore.edgeGroups.flatMap(
|
|
|
|
|
(groupId) =>
|
|
|
|
|
edgeGroupsQuery.data?.find((g) => g.Id === groupId)?.Endpoints
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
: undefined;
|
|
|
|
|
: undefined,
|
|
|
|
|
[edgeGroupsQuery.data, filterStore.edgeGroups]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const environmentsQuery = useEnvironmentList({
|
|
|
|
|
const query = useMemo(
|
|
|
|
|
() => ({
|
|
|
|
|
pageLimit,
|
|
|
|
|
edgeDeviceUntrusted: true,
|
|
|
|
|
excludeSnapshots: true,
|
|
|
|
|
types: EdgeTypes,
|
|
|
|
@ -31,6 +45,25 @@ export function useEnvironments() {
|
|
|
|
|
groupIds: filterStore.groups.length ? filterStore.groups : undefined,
|
|
|
|
|
endpointIds: filterByEnvironmentsIds,
|
|
|
|
|
edgeCheckInPassedSeconds: filterStore.checkIn,
|
|
|
|
|
search,
|
|
|
|
|
}),
|
|
|
|
|
[
|
|
|
|
|
filterByEnvironmentsIds,
|
|
|
|
|
filterStore.checkIn,
|
|
|
|
|
filterStore.groups,
|
|
|
|
|
filterStore.tags,
|
|
|
|
|
pageLimit,
|
|
|
|
|
search,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setPage(0);
|
|
|
|
|
}, [query]);
|
|
|
|
|
|
|
|
|
|
const environmentsQuery = useEnvironmentList({
|
|
|
|
|
page: page + 1,
|
|
|
|
|
...query,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const groupsQuery = useGroups({
|
|
|
|
@ -52,7 +85,8 @@ export function useEnvironments() {
|
|
|
|
|
Object.fromEntries(tags.map((tag) => [tag.ID, tag.Name] as const)),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const envs: Array<WaitingRoomEnvironment> =
|
|
|
|
|
const envs: Array<WaitingRoomEnvironment> = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
environmentsQuery.environments.map((env) => ({
|
|
|
|
|
...env,
|
|
|
|
|
Group: (env.GroupId !== 1 && groupsQuery.data?.[env.GroupId]) || '',
|
|
|
|
@ -61,9 +95,17 @@ export function useEnvironments() {
|
|
|
|
|
[],
|
|
|
|
|
Tags:
|
|
|
|
|
_.compact(env.TagIds?.map((tagId) => tagsQuery.data?.[tagId])) || [],
|
|
|
|
|
}));
|
|
|
|
|
})),
|
|
|
|
|
[
|
|
|
|
|
environmentEdgeGroupsQuery.data,
|
|
|
|
|
environmentsQuery.environments,
|
|
|
|
|
groupsQuery.data,
|
|
|
|
|
tagsQuery.data,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
return useMemo(
|
|
|
|
|
() => ({
|
|
|
|
|
data: envs,
|
|
|
|
|
isLoading:
|
|
|
|
|
environmentsQuery.isLoading ||
|
|
|
|
@ -71,5 +113,17 @@ export function useEnvironments() {
|
|
|
|
|
environmentEdgeGroupsQuery.isLoading ||
|
|
|
|
|
tagsQuery.isLoading,
|
|
|
|
|
totalCount: environmentsQuery.totalCount,
|
|
|
|
|
};
|
|
|
|
|
page,
|
|
|
|
|
setPage,
|
|
|
|
|
}),
|
|
|
|
|
[
|
|
|
|
|
environmentEdgeGroupsQuery.isLoading,
|
|
|
|
|
environmentsQuery.isLoading,
|
|
|
|
|
environmentsQuery.totalCount,
|
|
|
|
|
envs,
|
|
|
|
|
groupsQuery.isLoading,
|
|
|
|
|
page,
|
|
|
|
|
tagsQuery.isLoading,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|