Skip to content

Commit 0988ee6

Browse files
Merge pull request #1497 from devtron-labs/feat/cm-based-default-cluster-show
feat: cm based show/hide default_cluster
2 parents bd24067 + fc6f148 commit 0988ee6

File tree

5 files changed

+30
-25
lines changed

5 files changed

+30
-25
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ DEFAULT_CI_TRIGGER_TYPE_MANUAL=false
3737
ANNOUNCEMENT_BANNER_MSG=
3838
LOGIN_PAGE_IMAGE=
3939
LOGIN_PAGE_IMAGE_BG=
40+
HIDE_DEFAULT_CLUSTER=false

src/components/ClusterNodes/ClusterSelectionList.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import { ClusterSelectionType } from '../ResourceBrowser/Types'
1414
import { AppDetailsTabs } from '../v2/appDetails/appDetails.store'
1515
import { K8S_EMPTY_GROUP } from '../ResourceBrowser/Constants'
1616
import './clusterNodes.scss'
17+
import { DEFAULT_CLUSTER_ID } from '../cluster/cluster.type'
1718

1819
export default function ClusterSelectionList({
1920
clusterOptions,
2021
onChangeCluster,
2122
isSuperAdmin,
2223
clusterListLoader,
2324
refreshData,
24-
initTabsBasedOnRole
25+
initTabsBasedOnRole,
2526
}: ClusterSelectionType) {
2627
const location = useLocation()
2728
const history = useHistory()
@@ -35,11 +36,15 @@ export default function ClusterSelectionList({
3536
const [searchApplied, setSearchApplied] = useState(false)
3637

3738
useEffect(() => {
39+
let filteredClusterOptions = clusterOptions
40+
if (window._env_.HIDE_DEFAULT_CLUSTER) {
41+
filteredClusterOptions = clusterOptions.filter((item) => item.id !== DEFAULT_CLUSTER_ID)
42+
}
3843
setClusterList([])
3944
setFilteredClusterList([])
4045
setLastDataSync(!lastDataSync)
41-
setClusterList(clusterOptions)
42-
setFilteredClusterList(clusterOptions)
46+
setClusterList(filteredClusterOptions)
47+
setFilteredClusterList(filteredClusterOptions)
4348
setMinLoader(false)
4449
}, [clusterOptions])
4550

src/components/ResourceBrowser/ResourceList/ClusterSelector.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
SIDEBAR_KEYS,
1111
} from '../Constants'
1212
import { ClusterOptionType } from '../Types'
13+
import { DEFAULT_CLUSTER_ID } from '../../cluster/cluster.type'
1314

1415
interface ClusterSelectorType {
1516
onChange: ({ label, value }) => void
@@ -18,12 +19,16 @@ interface ClusterSelectorType {
1819
}
1920

2021
export default function ClusterSelector({ onChange, clusterList, clusterId }: ClusterSelectorType) {
21-
const defaultOption = clusterList.find((item) => item.value == clusterId)
22+
let filteredClusterList = clusterList
23+
if (window._env_.HIDE_DEFAULT_CLUSTER) {
24+
filteredClusterList = clusterList.filter((item) => Number(item.value) !== DEFAULT_CLUSTER_ID)
25+
}
26+
const defaultOption = filteredClusterList.find((item) => item.value == clusterId)
2227

2328
return (
2429
<ReactSelect
2530
classNamePrefix="cluster-select-header"
26-
options={clusterList}
31+
options={filteredClusterList}
2732
onChange={onChange}
2833
components={{
2934
IndicatorSeparator: null,

src/components/ResourceBrowser/ResourceList/ResourceList.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,9 @@ import {
6363
sortEventListData,
6464
} from '../Utils'
6565
import '../ResourceBrowser.scss'
66-
import {
67-
ClusterCapacityType,
68-
ClusterDetail,
69-
ClusterErrorType,
70-
ClusterImageList,
71-
ERROR_TYPE,
72-
} from '../../ClusterNodes/types'
66+
import { ClusterCapacityType, ClusterDetail, ClusterImageList } from '../../ClusterNodes/types'
7367
import { getHostURLConfiguration } from '../../../services/service'
74-
import {
75-
clusterNamespaceList,
76-
getClusterCapacity,
77-
getClusterList,
78-
getClusterListMin,
79-
} from '../../ClusterNodes/clusterNodes.service'
68+
import { clusterNamespaceList, getClusterList, getClusterListMin } from '../../ClusterNodes/clusterNodes.service'
8069
import ClusterSelectionList from '../../ClusterNodes/ClusterSelectionList'
8170
import ClusterSelector from './ClusterSelector'
8271
import ClusterOverview from '../../ClusterNodes/ClusterOverview'
@@ -85,6 +74,7 @@ import ClusterTerminal from '../../ClusterNodes/ClusterTerminal'
8574
import { createTaintsList } from '../../cluster/cluster.util'
8675
import NodeDetailsList from '../../ClusterNodes/NodeDetailsList'
8776
import NodeDetails from '../../ClusterNodes/NodeDetails'
77+
import { DEFAULT_CLUSTER_ID } from '../../cluster/cluster.type'
8878

8979
export default function ResourceList() {
9080
const { clusterId, namespace, nodeType, node, group } = useParams<{
@@ -699,6 +689,12 @@ export default function ResourceList() {
699689
setSelectedCluster(selected)
700690
getNamespaceList(selected.value)
701691

692+
if (selected.value === DEFAULT_CLUSTER_ID && window._env_.HIDE_DEFAULT_CLUSTER) {
693+
replace({
694+
pathname: URLS.RESOURCE_BROWSER,
695+
})
696+
return
697+
}
702698
if (!skipRedirection) {
703699
const path = `${URLS.RESOURCE_BROWSER}/${selected.value}/${
704700
ALL_NAMESPACE_OPTION.value

src/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface customEnv {
4747
ANNOUNCEMENT_BANNER_MSG?: string
4848
LOGIN_PAGE_IMAGE?: string
4949
LOGIN_PAGE_IMAGE_BG?: string
50+
HIDE_DEFAULT_CLUSTER?: boolean
5051
}
5152
declare global {
5253
interface Window {
@@ -58,11 +59,7 @@ declare global {
5859
}
5960

6061
const root = document.getElementById('root')
61-
if (
62-
process.env.NODE_ENV === 'production' &&
63-
window._env_ &&
64-
(window._env_.SENTRY_ERROR_ENABLED)
65-
) {
62+
if (process.env.NODE_ENV === 'production' && window._env_ && window._env_.SENTRY_ERROR_ENABLED) {
6663
const integrationArr = []
6764
integrationArr.push(new CaptureConsole({ levels: ['error'] }))
6865
if (window._env_.SENTRY_PERFORMANCE_ENABLED) {
@@ -145,13 +142,14 @@ if (!window || !window._env_) {
145142
ENABLE_CHART_SEARCH_IN_HELM_DEPLOY: false,
146143
HIDE_EXCLUDE_INCLUDE_GIT_COMMITS: true,
147144
ENABLE_BUILD_CONTEXT: false,
148-
CLAIR_TOOL_VERSION:'V4',
145+
CLAIR_TOOL_VERSION: 'V4',
149146
ENABLE_RESTART_WORKLOAD: false,
150147
ENABLE_SCOPED_VARIABLES: false,
151148
DEFAULT_CI_TRIGGER_TYPE_MANUAL: false,
152149
ANNOUNCEMENT_BANNER_MSG: '',
153150
LOGIN_PAGE_IMAGE: '',
154-
LOGIN_PAGE_IMAGE_BG: ''
151+
LOGIN_PAGE_IMAGE_BG: '',
152+
HIDE_DEFAULT_CLUSTER: false,
155153
}
156154
}
157155

0 commit comments

Comments
 (0)