Skip to content

Commit 2bd615b

Browse files
committed
fix: cluster upgrade clear filters
1 parent f0ee5c4 commit 2bd615b

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

src/components/ResourceBrowser/ResourceList/ClusterUpgradeCompatibilityInfo.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
*/
1616

1717
import { useMemo } from 'react'
18-
import { useParams } from 'react-router-dom'
18+
import { useHistory, useLocation, useParams } from 'react-router-dom'
1919

2020
import {
2121
CollapsibleList,
2222
ErrorScreenManager,
2323
FiltersTypeEnum,
2424
GenericEmptyState,
2525
ImageType,
26+
LARGE_PAGE_SIZE_OPTIONS,
2627
PaginationEnum,
2728
Progressing,
2829
Table,
2930
TableColumnType,
31+
TableProps,
3032
useSearchString,
3133
} from '@devtron-labs/devtron-fe-common-lib'
3234

@@ -55,6 +57,8 @@ const ClusterUpgradeCompatibilityInfo = ({
5557
}: ClusterUpgradeCompatibilityInfoProps) => {
5658
const { clusterId } = useParams<ClusterDetailBaseParams>()
5759
const targetK8sVersion = useSearchString().queryParams.get(TARGET_K8S_VERSION_SEARCH_KEY)
60+
const { push } = useHistory()
61+
const location = useLocation()
5862

5963
const {
6064
isLoading,
@@ -136,6 +140,26 @@ const ClusterUpgradeCompatibilityInfo = ({
136140
)
137141
}
138142

143+
const tableFilter: TableProps['filter'] = (row, filterData) =>
144+
!filterData.searchKey ||
145+
Object.entries(row.data).some(
146+
([key, value]) =>
147+
key !== 'id' &&
148+
value !== null &&
149+
value !== undefined &&
150+
String(value).toLowerCase().includes(filterData.searchKey.toLowerCase()),
151+
)
152+
153+
const clearFilters = () => {
154+
const searchParams = new URLSearchParams(location.search)
155+
Array.from(searchParams.keys()).forEach((key) => {
156+
if (key !== TARGET_K8S_VERSION_SEARCH_KEY) {
157+
searchParams.delete(key)
158+
}
159+
})
160+
push({ search: searchParams.toString() })
161+
}
162+
139163
return (
140164
<div className="flexbox h-100 dc__overflow-hidden">
141165
<div className="dc__overflow-auto p-8 w-220 dc__no-shrink">
@@ -156,9 +180,16 @@ const ClusterUpgradeCompatibilityInfo = ({
156180
id="table__cluster-upgrade-compatibility-info"
157181
paginationVariant={PaginationEnum.PAGINATED}
158182
ViewWrapper={ClusterUpgradeCompatibilityInfoTableWrapper}
183+
additionalFilterProps={{
184+
initialSortKey: 'namespace',
185+
defaultPageSize: LARGE_PAGE_SIZE_OPTIONS[0].value,
186+
}}
187+
filter={tableFilter}
159188
additionalProps={{
160189
lowercaseKindToResourceGroupMap,
161190
}}
191+
pageSizeOptions={LARGE_PAGE_SIZE_OPTIONS}
192+
clearFilters={clearFilters}
162193
/>
163194
</div>
164195
)

src/components/ResourceBrowser/ResourceList/ClusterUpgradeCompatibilityInfoTableCellComponent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const ClusterUpgradeCompatibilityInfoTableCellComponent = ({
6767

6868
const openContextMenuCallback = ({ detail: { activeRowData } }) => {
6969
if (activeRowData.id === id) {
70+
contextMenuRef.current?.focus()
7071
contextMenuRef.current?.click()
7172
}
7273
}
@@ -140,7 +141,7 @@ const ClusterUpgradeCompatibilityInfoTableCellComponent = ({
140141
</button>
141142
</Tooltip>
142143
{!shouldHideContextMenu && (
143-
<ClipboardButton content={String(resourceData.name)} rootClassName="p-4 dc__visible-hover--child" />
144+
<ClipboardButton content={String(resourceData.name)} rootClassName="p-2 dc__visible-hover--child" />
144145
)}
145146
</div>
146147

src/components/ResourceBrowser/ResourceList/DynamicTabComponentWrapper.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PropsWithChildren, ReactElement, useEffect } from 'react'
1+
import { cloneElement, ReactElement, useEffect } from 'react'
22
import { useLocation, useParams, useRouteMatch } from 'react-router-dom'
33

44
import { logExceptionToSentry, noop } from '@devtron-labs/devtron-fe-common-lib'
@@ -12,8 +12,9 @@ export const DynamicTabComponentWrapper = ({
1212
markTabActiveById,
1313
getTabId,
1414
addTab,
15+
getTabById,
1516
children,
16-
}: PropsWithChildren<DynamicTabComponentWrapperProps>) => {
17+
}: DynamicTabComponentWrapperProps) => {
1718
const { pathname, search } = useLocation()
1819
const { path } = useRouteMatch()
1920
const params = useParams<Record<string, string>>()
@@ -60,5 +61,5 @@ export const DynamicTabComponentWrapper = ({
6061
updateTabUrl({ id: tabId, url: `${pathname}${search}` })
6162
}, [pathname, search])
6263

63-
return children as ReactElement
64+
return cloneElement(children, { ...children.props, key: getTabById(tabId)?.componentKey }) as ReactElement
6465
}

src/components/ResourceBrowser/ResourceList/ResourceList.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,9 @@ const ResourceList = () => {
248248
() =>
249249
tabs.reduce(
250250
(acc, tab) => {
251-
if (tab.id === ResourceBrowserTabsId.k8s_Resources) {
252-
acc[tab.id] = {
253-
reload: refreshData,
254-
showTimeSinceLastSync: true,
255-
}
251+
acc[tab.id] = {
252+
reload: refreshData,
253+
showTimeSinceLastSync: tab.id === ResourceBrowserTabsId.k8s_Resources,
256254
}
257255

258256
return acc
@@ -330,7 +328,7 @@ const ResourceList = () => {
330328

331329
return (
332330
<div className={!tab?.isSelected ? 'cluster-terminal-hidden' : 'flexbox-col flex-grow-1'}>
333-
<AdminTerminal updateTerminalTabUrl={updateTerminalTabUrl} />
331+
<AdminTerminal updateTerminalTabUrl={updateTerminalTabUrl} key={tab.componentKey} />
334332
</div>
335333
)
336334
}
@@ -377,11 +375,7 @@ const ResourceList = () => {
377375
/>
378376
<Route path={RESOURCE_BROWSER_ROUTES.OVERVIEW} exact>
379377
<DynamicTabComponentWrapper type="fixed" {...DynamicTabComponentWrapperBaseProps}>
380-
<ClusterOverview
381-
selectedCluster={selectedCluster}
382-
addTab={addTab}
383-
key={getTabById(ResourceBrowserTabsId.cluster_overview).componentKey}
384-
/>
378+
<ClusterOverview selectedCluster={selectedCluster} addTab={addTab} />
385379
</DynamicTabComponentWrapper>
386380
</Route>
387381
<Route path={RESOURCE_BROWSER_ROUTES.MONITORING_DASHBOARD} exact>
@@ -462,7 +456,6 @@ const ResourceList = () => {
462456
clusterName={selectedCluster.label}
463457
lowercaseKindToResourceGroupMap={lowercaseKindToResourceGroupMap}
464458
updateTabLastSyncMoment={updateTabLastSyncMoment}
465-
key={getTabById(ResourceBrowserTabsId.k8s_Resources).componentKey}
466459
/>
467460
</DynamicTabComponentWrapper>
468461
</Route>

src/components/ResourceBrowser/ResourceList/Sidebar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import DOMPurify from 'dompurify'
2323
import {
2424
ApiResourceGroupType,
2525
highlightSearchText,
26+
Nodes,
2627
ReactSelectInputAction,
2728
useRegisterShortcut,
2829
} from '@devtron-labs/devtron-fe-common-lib'
@@ -118,6 +119,9 @@ const Sidebar = ({ apiResources, selectedResource, updateK8sResourceTab, updateT
118119
params.delete('pageNumber')
119120
params.delete('sortBy')
120121
params.delete('sortOrder')
122+
if (_selectedKind !== Nodes.Event.toLowerCase()) {
123+
params.delete('eventType')
124+
}
121125
const _url = `${generatePath(RESOURCE_BROWSER_ROUTES.K8S_RESOURCE_LIST, {
122126
clusterId,
123127
kind: _selectedKind,

src/components/ResourceBrowser/ResourceList/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,6 @@ export type DynamicTabComponentWrapperProps = Pick<
101101
UseTabsReturnType,
102102
'updateTabUrl' | 'markTabActiveById' | 'getTabId' | 'getTabById'
103103
> &
104-
({ type: 'fixed'; addTab?: never } | { type: 'dynamic'; addTab: UseTabsReturnType['addTab'] })
104+
({ type: 'fixed'; addTab?: never } | { type: 'dynamic'; addTab: UseTabsReturnType['addTab'] }) & {
105+
children: React.ReactElement
106+
}

0 commit comments

Comments
 (0)