fix(app): avoid duplicate env requests [EE-6727] (#11193)

Co-authored-by: testa113 <testa113>
pull/11207/head
Ali 2024-02-16 14:02:02 +13:00 committed by GitHub
parent a374157d6f
commit a46fa3b2c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 17 deletions

View File

@ -5,6 +5,7 @@ import { ContainerStatus, Pod } from 'kubernetes-types/core/v1';
import { IndexOptional } from '@/react/kubernetes/configs/types'; import { IndexOptional } from '@/react/kubernetes/configs/types';
import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store'; import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store';
import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
import { useEnvironment } from '@/react/portainer/environments/queries'; import { useEnvironment } from '@/react/portainer/environments/queries';
import { Datatable } from '@@/datatables'; import { Datatable } from '@@/datatables';
@ -19,42 +20,41 @@ const storageKey = 'k8sContainersDatatable';
const settingsStore = createStore(storageKey); const settingsStore = createStore(storageKey);
export function ApplicationContainersDatatable() { export function ApplicationContainersDatatable() {
const environmentId = useEnvironmentId();
const useServerMetricsQuery = useEnvironment(
environmentId,
(env) => !!env?.Kubernetes?.Configuration.UseServerMetrics
);
const tableState = useTableState(settingsStore, storageKey); const tableState = useTableState(settingsStore, storageKey);
const { const {
params: { params: { name, namespace, 'resource-type': resourceType },
endpointId: environmentId,
name,
namespace,
'resource-type': resourceType,
},
} = useCurrentStateAndParams(); } = useCurrentStateAndParams();
// get the containers from the aapplication pods // get the containers from the aapplication pods
const { data: application, ...applicationQuery } = useApplication( const applicationQuery = useApplication(
environmentId, environmentId,
namespace, namespace,
name, name,
resourceType resourceType
); );
const { data: pods, ...podsQuery } = useApplicationPods( const podsQuery = useApplicationPods(
environmentId, environmentId,
namespace, namespace,
name, name,
application applicationQuery.data
);
const appContainers = useContainersRowData(pods);
const { data: isServerMetricsEnabled } = useEnvironment(
environmentId,
(environment) => !!environment?.Kubernetes?.Configuration.UseServerMetrics
); );
const appContainers = useContainersRowData(podsQuery.data);
return ( return (
<Datatable<IndexOptional<ContainerRowData>> <Datatable<IndexOptional<ContainerRowData>>
dataset={appContainers} dataset={appContainers}
columns={getColumns(!!isServerMetricsEnabled)} columns={getColumns(!!useServerMetricsQuery.data)}
settingsManager={tableState} settingsManager={tableState}
isLoading={applicationQuery.isLoading || podsQuery.isLoading} isLoading={
applicationQuery.isLoading ||
podsQuery.isLoading ||
useServerMetricsQuery.isLoading
}
emptyContentLabel="No containers found" emptyContentLabel="No containers found"
title="Application containers" title="Application containers"
titleIcon={Server} titleIcon={Server}