Skip to content

Commit 7fd8ddf

Browse files
committed
feat: refactor EditClusterDrawerContent to use getEditClusterDrawerMetadata for metadata fetching
1 parent be03e9e commit 7fd8ddf

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/Pages/GlobalConfigurations/ClustersAndEnvironments/EditClusterDrawerContent.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { APIResponseHandler, ClusterProviderType, noop, useQuery } from '@devtron-labs/devtron-fe-common-lib'
17+
import { APIResponseHandler, noop, useQuery } from '@devtron-labs/devtron-fe-common-lib'
1818

1919
import { importComponentFromFELibrary } from '@Components/common'
2020
import { URLS } from '@Config/routes'
2121

2222
import ClusterForm from './ClusterForm/ClusterForm'
23-
import { getCluster } from './cluster.service'
23+
import { getEditClusterDrawerMetadata } from './cluster.service'
2424
import { EditClusterDrawerContentProps, EditClusterDrawerMetadataType, EditClusterFormProps } from './cluster.type'
2525

2626
const getSSHConfig: (
2727
...props
2828
) => Pick<EditClusterFormProps, 'sshUsername' | 'sshPassword' | 'sshAuthKey' | 'sshServerAddress'> =
2929
importComponentFromFELibrary('getSSHConfig', noop, 'function')
3030

31-
const getCloudProviderForCluster: (clusterId: number) => Promise<ClusterProviderType> = importComponentFromFELibrary(
32-
'getCloudProviderForCluster',
33-
null,
34-
'function',
35-
)
36-
3731
const EditClusterDrawerContent = ({
3832
handleModalClose,
3933
sshTunnelConfig,
@@ -50,26 +44,14 @@ const EditClusterDrawerContent = ({
5044
insecureSkipTlsVerify,
5145
costModuleConfig,
5246
}: EditClusterDrawerContentProps) => {
53-
const getClusterMetadata = async (): Promise<EditClusterDrawerMetadataType> => {
54-
if (!clusterId) {
55-
return { prometheusAuthResult: null, clusterProvider: null }
56-
}
57-
58-
const [prometheusAuthResult, clusterProvider] = await Promise.all([
59-
getCluster(+clusterId),
60-
getCloudProviderForCluster ? getCloudProviderForCluster(+clusterId) : null,
61-
])
62-
return { prometheusAuthResult, clusterProvider }
63-
}
64-
6547
const {
6648
isFetching: isMetadataLoading,
6749
data: metadata,
6850
error: metadataError,
6951
refetch: reloadMetadata,
7052
} = useQuery<EditClusterDrawerMetadataType, EditClusterDrawerMetadataType, [string, number], false>({
7153
queryKey: ['get-cluster-metadata', clusterId],
72-
queryFn: () => getClusterMetadata(),
54+
queryFn: () => getEditClusterDrawerMetadata(clusterId),
7355
enabled: !!clusterId,
7456
})
7557

src/Pages/GlobalConfigurations/ClustersAndEnvironments/cluster.service.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { get, post, put, trash } from '@devtron-labs/devtron-fe-common-lib'
17+
import { ClusterProviderType, get, post, put, trash } from '@devtron-labs/devtron-fe-common-lib'
1818

19+
import { importComponentFromFELibrary } from '@Components/common'
1920
import { Routes } from '@Config/constants'
2021

21-
import { DeleteClusterPayload, Environment, EnvironmentDTO } from './cluster.type'
22+
import { DeleteClusterPayload, EditClusterDrawerMetadataType, Environment, EnvironmentDTO } from './cluster.type'
23+
24+
const getCloudProviderForCluster: (clusterId: number) => Promise<ClusterProviderType> = importComponentFromFELibrary(
25+
'getCloudProviderForCluster',
26+
null,
27+
'function',
28+
)
2229

2330
export const getEnvironmentList = async (): Promise<Environment[]> => {
2431
const { result } = await get<EnvironmentDTO[]>(Routes.ENVIRONMENT)
@@ -86,3 +93,15 @@ export function deleteCluster(payload: DeleteClusterPayload): Promise<any> {
8693
export function deleteEnvironment(request): Promise<any> {
8794
return trash(Routes.ENVIRONMENT, request)
8895
}
96+
97+
export const getEditClusterDrawerMetadata = async (clusterId: number): Promise<EditClusterDrawerMetadataType> => {
98+
if (!clusterId) {
99+
return { prometheusAuthResult: null, clusterProvider: null }
100+
}
101+
102+
const [prometheusAuthResult, clusterProvider] = await Promise.all([
103+
getCluster(+clusterId),
104+
getCloudProviderForCluster ? getCloudProviderForCluster(+clusterId) : null,
105+
])
106+
return { prometheusAuthResult, clusterProvider }
107+
}

0 commit comments

Comments
 (0)