Skip to content

Commit 8fc2863

Browse files
authored
Merge pull request #2839 from devtron-labs/fix/cluster-terminal-main
fix(main): cluster terminal size
2 parents 772f9b7 + 1ea7298 commit 8fc2863

File tree

5 files changed

+14
-50
lines changed

5 files changed

+14
-50
lines changed

src/components/ClusterNodes/ClusterTerminal.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { useEffect, useRef, useState } from 'react'
18-
import { generatePath, useHistory, useLocation, useParams } from 'react-router-dom'
18+
import { generatePath, useHistory, useLocation } from 'react-router-dom'
1919

2020
import {
2121
Checkbox,
@@ -37,12 +37,10 @@ import {
3737
} from '@devtron-labs/devtron-fe-common-lib'
3838

3939
import { ResourceBrowserTabsId } from '@Components/ResourceBrowser/Constants'
40-
import { K8sResourceListURLParams } from '@Components/ResourceBrowser/ResourceList/types'
4140
import { getClusterTerminalParamsData } from '@Pages/GlobalConfigurations/ClustersAndEnvironments/cluster.util'
4241

4342
import { BUSYBOX_LINK, DEFAULT_CONTAINER_NAME, NETSHOOT_LINK, shellTypes } from '../../config/constants'
4443
import { clusterImageDescription, convertToOptionsList } from '../common'
45-
import { AppDetailsTabs } from '../v2/appDetails/appDetails.store'
4644
import {
4745
EditModeType,
4846
TERMINAL_STATUS,
@@ -88,9 +86,13 @@ const ClusterTerminal = ({
8886
taints,
8987
updateTabUrl,
9088
}: ClusterTerminalType) => {
91-
const { kind } = useParams<K8sResourceListURLParams>()
9289
const { replace } = useHistory()
9390
const location = useLocation()
91+
const isAdminTerminalVisible =
92+
location.pathname ===
93+
generatePath(RESOURCE_BROWSER_ROUTES.TERMINAL, {
94+
clusterId,
95+
})
9496
const queryParams = new URLSearchParams(location.search)
9597
const terminalAccessIdRef = useRef()
9698
const clusterShellTypes = shellTypes.filter((types) => types.label === 'sh' || types.label === 'bash')
@@ -159,7 +161,7 @@ const ClusterTerminal = ({
159161
}
160162

161163
useEffect(() => {
162-
if (kind !== 'terminal' || queryParamsData.selectedNode.value === selectedNodeName.value || !update) {
164+
if (!isAdminTerminalVisible || queryParamsData.selectedNode.value === selectedNodeName.value || !update) {
163165
return
164166
}
165167
/* NOTE: update selectedNodeName */
@@ -188,7 +190,7 @@ const ClusterTerminal = ({
188190
id: ResourceBrowserTabsId.terminal,
189191
url: `${generatePath(RESOURCE_BROWSER_ROUTES.TERMINAL, { clusterId })}?${queryParams.toString()}`,
190192
})
191-
if (kind === AppDetailsTabs.terminal) {
193+
if (isAdminTerminalVisible) {
192194
replace({ search: queryParams.toString() })
193195
}
194196
}, [selectedNodeName.value, selectedNamespace.value, selectedImage.value, selectedTerminalType.value])
@@ -1036,7 +1038,7 @@ const ClusterTerminal = ({
10361038
renderConnectionStrip: renderStripMessage(),
10371039
setSocketConnection,
10381040
socketConnection,
1039-
isTerminalTab: selectedTabIndex === 0 && kind === 'terminal',
1041+
isTerminalTab: selectedTabIndex === 0 && isAdminTerminalVisible,
10401042
sessionId,
10411043
registerLinkMatcher: renderRegisterLinkMatcher,
10421044
},

src/components/ResourceBrowser/ResourceList/AdminTerminalDummy.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/components/ResourceBrowser/ResourceList/DynamicTabComponentWrapper.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ export const DynamicTabComponentWrapper = ({
6161
updateTabUrl({ id: tabId, url: `${pathname}${search}` })
6262
}, [pathname, search])
6363

64-
return cloneElement(children, { ...children.props, key: getTabById(tabId)?.componentKey }) as ReactElement
64+
return children
65+
? (cloneElement(children, { ...children.props, key: getTabById(tabId)?.componentKey }) as ReactElement)
66+
: null
6567
}

src/components/ResourceBrowser/ResourceList/ResourceList.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import { getClusterListing } from '../ResourceBrowser.service'
5555
import { ClusterDetailBaseParams, ClusterOptionType, K8SResourceListType } from '../Types'
5656
import { getClusterChangeRedirectionUrl, getTabsBasedOnRole } from '../Utils'
5757
import AdminTerminal from './AdminTerminal'
58-
import AdminTerminalDummy from './AdminTerminalDummy'
5958
import ClusterSelector from './ClusterSelector'
6059
import ClusterUpgradeCompatibilityInfo from './ClusterUpgradeCompatibilityInfo'
6160
import { DynamicTabComponentWrapper } from './DynamicTabComponentWrapper'
@@ -231,14 +230,7 @@ const ResourceList = ({ selectedCluster, k8SObjectMapRaw }: ResourceListProps) =
231230
</Route>
232231
)}
233232
<Route path={RESOURCE_BROWSER_ROUTES.TERMINAL} exact>
234-
<DynamicTabComponentWrapper type="fixed" {...DynamicTabComponentWrapperBaseProps}>
235-
<AdminTerminalDummy
236-
markTabActiveById={markTabActiveById}
237-
clusterName={selectedCluster.label}
238-
getTabById={getTabById}
239-
updateTabUrl={updateTabUrl}
240-
/>
241-
</DynamicTabComponentWrapper>
233+
<DynamicTabComponentWrapper type="fixed" {...DynamicTabComponentWrapperBaseProps} />
242234
</Route>
243235
{ResourceRecommender && (
244236
<Route path={RESOURCE_BROWSER_ROUTES.RESOURCE_RECOMMENDER} exact>

src/components/ResourceBrowser/ResourceList/types.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ export interface K8sResourceListTableCellComponentProps
9090
reloadResourceListData: () => void
9191
}
9292

93-
export interface AdminTerminalDummyProps
94-
extends Pick<UseTabsReturnType, 'markTabActiveById' | 'updateTabUrl' | 'getTabById'> {
95-
clusterName: string
96-
}
97-
9893
export interface ResourcePageHeaderProps {
9994
breadcrumbs: ReturnType<typeof useBreadcrumb>['breadcrumbs']
10095
renderPageHeaderActionButtons?: () => JSX.Element
@@ -111,7 +106,7 @@ export type DynamicTabComponentWrapperProps = Pick<
111106
'updateTabUrl' | 'markTabActiveById' | 'getTabId' | 'getTabById'
112107
> &
113108
({ type: 'fixed'; addTab?: never } | { type: 'dynamic'; addTab: UseTabsReturnType['addTab'] }) & {
114-
children: React.ReactElement
109+
children?: React.ReactElement
115110
}
116111

117112
export interface ResourceRecommenderTableViewWrapperProps extends ResourceFilterOptionsProps, TableViewWrapperProps {

0 commit comments

Comments
 (0)