Skip to content

Commit 423e678

Browse files
committed
feat: Update resource recommender tab handling and retain search params
1 parent 0d279cb commit 423e678

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

src/components/ResourceBrowser/ResourceList/ResourceFilterOptions.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ const ResourceFilterOptions = ({
182182
newSearchParams.set(GVK_FILTER_KIND_QUERY_PARAM_KEY, kind)
183183
}
184184

185+
updateK8sResourceTab({
186+
url: `${location.pathname}?${newSearchParams.toString()}`,
187+
})
188+
185189
replace({
186190
pathname: location.pathname,
187191
search: newSearchParams.toString(),

src/components/ResourceBrowser/ResourceList/ResourceList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ const ResourceList = () => {
545545
},
546546
clusterName: selectedCluster.label,
547547
handleResourceClick,
548-
updateK8sResourceTab: noop,
548+
updateK8sResourceTab: getUpdateTabUrlForId(RESOURCE_RECOMMENDER_TAB_ID),
549549
nodeType: null,
550550
group: K8S_EMPTY_GROUP,
551551
isLoading: isResourceListLoading,

src/components/ResourceBrowser/ResourceList/Sidebar.tsx

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

1717
import React, { Fragment, useEffect, useMemo, useRef, useState } from 'react'
18-
import { useHistory, useLocation, useParams } from 'react-router-dom'
18+
import { useHistory, useParams } from 'react-router-dom'
1919
import ReactSelect, { GroupBase, InputActionMeta } from 'react-select'
2020
import Select, { FormatOptionLabelMeta } from 'react-select/base'
2121
import DOMPurify from 'dompurify'
@@ -49,7 +49,6 @@ const Sidebar = ({
4949
isOpen,
5050
}: SidebarType) => {
5151
const { registerShortcut, unregisterShortcut } = useRegisterShortcut()
52-
const location = useLocation()
5352
const { push } = useHistory()
5453
const { clusterId, namespace, nodeType } = useParams<URLParams>()
5554
const [searchText, setSearchText] = useState('')
@@ -125,8 +124,8 @@ const Sidebar = ({
125124
}
126125
setSelectedResource(_selectedResource)
127126
updateK8sResourceTabLastSyncMoment()
128-
const _url = `${URLS.RESOURCE_BROWSER}/${clusterId}/${namespace}/${_selectedKind}/${_selectedGroup || K8S_EMPTY_GROUP}${location.search}`
129-
updateK8sResourceTab({ url: _url, dynamicTitle: e.currentTarget.dataset.kind })
127+
const _url = `${URLS.RESOURCE_BROWSER}/${clusterId}/${namespace}/${_selectedKind}/${_selectedGroup || K8S_EMPTY_GROUP}`
128+
updateK8sResourceTab({ url: _url, dynamicTitle: e.currentTarget.dataset.kind, retainSearchParams: true })
130129
if (shouldPushUrl) {
131130
push(_url)
132131
}

src/components/ResourceBrowser/Utils.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ import {
2424
ApiResourceGroupType,
2525
DATE_TIME_FORMAT_STRING,
2626
FeatureTitleWithInfo,
27+
getUrlWithSearchParams,
28+
GVK_FILTER_API_VERSION_QUERY_PARAM_KEY,
29+
GVK_FILTER_KIND_QUERY_PARAM_KEY,
2730
GVKType,
2831
InitTabType,
2932
K8sResourceDetailDataType,
3033
K8sResourceDetailType,
34+
Nodes,
3135
ResponseType,
3236
} from '@devtron-labs/devtron-fe-common-lib'
3337

@@ -329,7 +333,13 @@ export const getTabsBasedOnRole = ({
329333
...(canRenderResourceRecommender && getResourceRecommenderTabConfig
330334
? [
331335
getResourceRecommenderTabConfig(
332-
getURLBasedOnSidebarGVK(SIDEBAR_KEYS.resourceRecommenderGVK.Kind, clusterId, namespace),
336+
`${getURLBasedOnSidebarGVK(SIDEBAR_KEYS.resourceRecommenderGVK.Kind, clusterId, namespace)}${getUrlWithSearchParams(
337+
'',
338+
{
339+
[GVK_FILTER_API_VERSION_QUERY_PARAM_KEY]: 'apps/v1',
340+
[GVK_FILTER_KIND_QUERY_PARAM_KEY]: Nodes.Deployment,
341+
},
342+
)}`,
333343
isResourceRecommenderSelected,
334344
RESOURCE_RECOMMENDER_TAB_ID,
335345
),

src/components/common/DynamicTabs/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export interface PopulateTabDataPropsType
9494
| 'hideName'
9595
| 'id'
9696
>,
97-
Required<Pick<DynamicTabType, 'shouldRemainMounted' | 'title' | 'showNameOnSelect'>> {}
97+
Required<Pick<DynamicTabType, 'shouldRemainMounted' | 'title' | 'showNameOnSelect' | 'isAlpha'>> {}
9898

9999
export interface AddTabParamsType
100100
extends Pick<PopulateTabDataPropsType, 'name' | 'url' | 'tippyConfig'>,

src/components/common/DynamicTabs/useTabs.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
7272
tippyConfig,
7373
lastActiveTabId,
7474
shouldRemainMounted,
75+
isAlpha,
7576
}: PopulateTabDataPropsType): DynamicTabType => ({
7677
id,
7778
name,
@@ -88,6 +89,7 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
8889
tippyConfig,
8990
lastActiveTabId,
9091
shouldRemainMounted,
92+
isAlpha: isAlpha || false,
9193
})
9294

9395
const getTabDataFromLocalStorage = () => localStorage.getItem(TAB_DATA_LOCAL_STORAGE_KEY)
@@ -131,10 +133,12 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
131133
* @returns {DynamicTabType} - Tab data for initialization
132134
*/
133135
const populateInitTab = (_initTab: InitTabType): DynamicTabType => {
134-
const title = getTitleFromKindAndName({
135-
kind: _initTab.kind,
136-
name: _initTab.name,
137-
})
136+
const title =
137+
_initTab.title ||
138+
getTitleFromKindAndName({
139+
kind: _initTab.kind,
140+
name: _initTab.name,
141+
})
138142

139143
const _id =
140144
_initTab.id ??
@@ -157,6 +161,7 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
157161
tippyConfig: _initTab.tippyConfig,
158162
lastActiveTabId: null,
159163
shouldRemainMounted: _initTab.shouldRemainMounted,
164+
isAlpha: _initTab.isAlpha,
160165
})
161166
}
162167

@@ -180,6 +185,10 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
180185

181186
try {
182187
parsedTabsData = JSON.parse(persistedTabsData)
188+
const storedResourceRecommenderTab = (parsedTabsData.data[persistenceKey] ?? []).find(
189+
(tab) => tab.id === RESOURCE_RECOMMENDER_TAB_ID,
190+
)
191+
183192
parsedTabsData.data[persistenceKey] = (parsedTabsData.data[persistenceKey] ?? []).filter(
184193
(tab) => tab.id !== RESOURCE_RECOMMENDER_TAB_ID,
185194
)
@@ -199,7 +208,7 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
199208
parsedTabsData.data[persistenceKey].splice(
200209
monitoringTabIndex + 1,
201210
0,
202-
resourceRecommenderInitTab,
211+
storedResourceRecommenderTab || resourceRecommenderInitTab,
203212
)
204213
}
205214
}
@@ -325,6 +334,7 @@ export function useTabs(persistenceKey: string, fallbackTabIndex = FALLBACK_TAB)
325334
tippyConfig,
326335
lastActiveTabId: getLastActiveTabIdFromTabs(prevTabs, _id),
327336
shouldRemainMounted: false,
337+
isAlpha: false,
328338
}),
329339
)
330340
}

0 commit comments

Comments
 (0)