Skip to content

Commit 92f59da

Browse files
committed
refactor: remove upgrade dialog logic and clean up CommandBar component
1 parent d04f788 commit 92f59da

File tree

7 files changed

+17
-43
lines changed

7 files changed

+17
-43
lines changed

src/Pages/Shared/CommandBar/CommandBar.component.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import { useEffect, useState } from 'react'
1+
import { useEffect } from 'react'
22

33
import { handleAnalyticsEvent, useQuery } from '@devtron-labs/devtron-fe-common-lib'
44

55
import CommandBarBackdrop from './CommandBarBackdrop'
6-
import { UPGRADE_DIALOG_LOCAL_STORAGE_KEY } from './constants'
7-
import NavigationUpgradedDialog from './NavigationUpgradedDialog'
86
import { getCommandBarResourceLists } from './service'
97
import { CommandBarBackdropProps, CommandBarProps } from './types'
10-
import { getShowUpgradeDialogFromLocalStorage, hideUpgradeDialogInLocalStorage } from './utils'
118

129
import './CommandBar.scss'
1310

1411
const CommandBar = ({ showCommandBar, setShowCommandBar }: CommandBarProps) => {
15-
const [showUpgradeDialog, setShowUpgradeDialog] = useState(getShowUpgradeDialogFromLocalStorage)
1612
const { isLoading: isResourceListLoading, data: resourceList } = useQuery<
1713
CommandBarBackdropProps['resourceList'],
1814
CommandBarBackdropProps['resourceList'],
@@ -28,22 +24,10 @@ const CommandBar = ({ showCommandBar, setShowCommandBar }: CommandBarProps) => {
2824
setShowCommandBar(false)
2925
}
3026

31-
const handleCloseUpgradeDialog = () => {
32-
setShowUpgradeDialog(false)
33-
hideUpgradeDialogInLocalStorage()
34-
}
35-
3627
useEffect(() => {
37-
const handleStorageEvent = (e: StorageEvent) => {
38-
if (e.key === UPGRADE_DIALOG_LOCAL_STORAGE_KEY && e.newValue === 'true') {
39-
setShowUpgradeDialog(false)
40-
}
41-
}
42-
4328
const handleOpen = (e: KeyboardEvent) => {
4429
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
4530
e.preventDefault()
46-
handleCloseUpgradeDialog()
4731
setShowCommandBar(true)
4832
handleAnalyticsEvent({
4933
category: 'command-bar-shortcut',
@@ -52,15 +36,13 @@ const CommandBar = ({ showCommandBar, setShowCommandBar }: CommandBarProps) => {
5236
}
5337
}
5438
window.addEventListener('keydown', handleOpen)
55-
window.addEventListener('storage', handleStorageEvent)
5639
return () => {
5740
window.removeEventListener('keydown', handleOpen)
58-
window.removeEventListener('storage', handleStorageEvent)
5941
}
6042
}, [])
6143

6244
if (!showCommandBar) {
63-
return <NavigationUpgradedDialog isOpen={showUpgradeDialog} onClose={handleCloseUpgradeDialog} />
45+
return null
6446
}
6547

6648
return (

src/Pages/Shared/CommandBar/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,3 @@ export const NAV_SUB_ITEMS_ICON_MAPPING: Partial<Record<NavigationItemID, IconNa
4040
'application-management-policies': 'ic-gavel',
4141
'global-configuration-authorization': 'ic-key',
4242
}
43-
44-
export const UPGRADE_DIALOG_LOCAL_STORAGE_KEY = 'command-bar-upgrade-dialog-closed'

src/Pages/Shared/CommandBar/utils.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
HELM_APP_LIST_COMMAND_GROUP_ID,
2222
NAV_SUB_ITEMS_ICON_MAPPING,
2323
RECENT_NAVIGATION_ITEM_ID_PREFIX,
24-
UPGRADE_DIALOG_LOCAL_STORAGE_KEY,
2524
} from './constants'
2625
import { CommandBarActionIdType, CommandBarBackdropProps, CommandBarGroupType, CommandBarItemType } from './types'
2726

@@ -386,12 +385,3 @@ export const getAdditionalNavGroups = (
386385
...getTopFiveClusterListGroup(clusterList, searchText),
387386
]
388387
}
389-
390-
export const getShowUpgradeDialogFromLocalStorage = () => {
391-
const hasClosedUpgradeDialog = localStorage.getItem(UPGRADE_DIALOG_LOCAL_STORAGE_KEY)
392-
return hasClosedUpgradeDialog !== 'true'
393-
}
394-
395-
export const hideUpgradeDialogInLocalStorage = () => {
396-
localStorage.setItem(UPGRADE_DIALOG_LOCAL_STORAGE_KEY, 'true')
397-
}

src/components/ResourceBrowser/ResourceList/ResourceList.tsx

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

1717
import { useEffect, useMemo, useState } from 'react'
18-
import { Route, Routes, useLocation, useNavigate, useParams } from 'react-router-dom'
18+
import { generatePath, Route, Routes, useLocation, useNavigate, useParams } from 'react-router-dom'
1919

2020
import {
2121
BASE_ROUTES,
@@ -77,8 +77,7 @@ const CLUSTER_DETAILS_ROUTES = BASE_ROUTES.INFRASTRUCTURE_MANAGEMENT.RESOURCE_BR
7777
const RESOURCE_BROWSER_ROUTES = ROUTER_URLS.RESOURCE_BROWSER.CLUSTER_DETAILS
7878

7979
const ResourceList = ({ selectedCluster, k8SObjectMapRaw }: ResourceListProps) => {
80-
const params = useParams<ClusterDetailBaseParams>()
81-
const { clusterId } = params
80+
const { clusterId } = useParams<ClusterDetailBaseParams>()
8281
const location = useLocation()
8382
const {
8483
tabs,
@@ -92,7 +91,7 @@ const ResourceList = ({ selectedCluster, k8SObjectMapRaw }: ResourceListProps) =
9291
stopTabByIdentifier,
9392
getTabId,
9493
getTabById,
95-
} = useTabs(ROUTER_URLS.RESOURCE_BROWSER.CLUSTER_DETAILS.ROOT)
94+
} = useTabs(generatePath(ROUTER_URLS.RESOURCE_BROWSER.CLUSTER_DETAILS.ROOT, { clusterId }))
9695
const [logSearchTerms, setLogSearchTerms] = useState<Record<string, string>>()
9796
const [isDataStale, setIsDataStale] = useState(false)
9897
const { setIntelligenceConfig, setAIAgentContext, isResourceRecommendationEnabled } = useMainContext()
@@ -131,13 +130,14 @@ const ResourceList = ({ selectedCluster, k8SObjectMapRaw }: ResourceListProps) =
131130
setAIAgentContext(null)
132131
}
133132
}, [])
133+
134134
useEffectAfterMount(() => initTabsBasedOnRole(true), [clusterId])
135135

136136
useEffect(() => {
137137
setAIAgentContext({
138138
path: '',
139139
context: {
140-
...params,
140+
clusterId,
141141
clusterName: selectedCluster.label,
142142
search: location.search,
143143
},

src/components/charts/ChartGroupDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ export default function ChartGroupDetails() {
7878
{
7979
alias: {
8080
...getInfrastructureManagementBreadcrumb(),
81-
'chart-store': {
81+
'chart-store': null,
82+
discover: {
8283
component: <BreadcrumbText heading="Chart Store" />,
8384
linked: true,
8485
},
85-
discover: null,
8686
group: 'Chart groups',
8787
':groupId': {
8888
component: (

src/components/v2/appDetails/k8Resource/K8Resource.component.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
ALL_RESOURCE_KIND_FILTER,
2222
getPodsRootParentNameAndStatus,
2323
Node,
24+
ROUTER_URLS,
2425
StatusFilterButtonComponent,
2526
useSearchString,
2627
} from '@devtron-labs/devtron-fe-common-lib'
@@ -174,8 +175,11 @@ export const K8ResourceComponent = ({
174175
}
175176

176177
export const EmptyK8sResourceComponent = ({ emptyStateMessage }: { emptyStateMessage: string }) => {
177-
const location = useLocation()
178-
const routeMatchUrl = location.pathname
178+
const params = useParams()
179+
const routeMatchUrl = generatePath(ROUTER_URLS.DEVTRON_APP_DETAILS.ENV_DETAILS, {
180+
appId: params.appId,
181+
envId: params.envId,
182+
})
179183
const {
180184
tabs,
181185
initTabs,
@@ -184,6 +188,7 @@ export const EmptyK8sResourceComponent = ({ emptyStateMessage }: { emptyStateMes
184188
stopTabByIdentifier,
185189
// NOTE: fallback to 0th index since that is the k8s_resource tab
186190
} = useTabs(routeMatchUrl, APP_DETAILS_DYNAMIC_TABS_FALLBACK_INDEX)
191+
const location = useLocation()
187192

188193
useEffect(() => {
189194
initTabs(getInitialTabs(location.pathname, routeMatchUrl, false), true)

src/components/workflowEditor/workflowEditor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ class WorkflowEdit extends Component<WorkflowEditProps, WorkflowEditState> {
396396
{
397397
appId: this.props.params.appId,
398398
},
399-
)}
400-
}/${CommonURLS.APP_CONFIG}/${
399+
)}/${CommonURLS.APP_CONFIG}/${
401400
URLS.APP_WORKFLOW_CONFIG
402401
}/${workflowId}/${ciURL}/${URLS.APP_CD_CONFIG}/0/build?parentPipelineType=${parentPipelineType}&addType=${
403402
addType ?? AddPipelineType.PARALLEL

0 commit comments

Comments
 (0)