Skip to content

Commit cd4c4c2

Browse files
authored
Merge pull request #425 from devtron-labs/fix/node-permissions
fix: node permissions
2 parents 25aefa0 + 1e22d35 commit cd4c4c2

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

package-lock.json

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -79,7 +79,6 @@
7979
"@rjsf/validator-ajv8": "^5.13.3",
8080
"@typeform/embed-react": "2.20.0",
8181
"dompurify": "^3.0.2",
82-
"marked": "^13.0.3",
8382
"react": "^17.0.2",
8483
"react-dom": "^17.0.2",
8584
"react-draggable": "^4.4.5",
@@ -92,6 +91,7 @@
9291
},
9392
"dependencies": {
9493
"@types/react-dates": "^21.8.6",
94+
"marked": "^13.0.3",
9595
"ansi_up": "^5.2.1",
9696
"dayjs": "^1.11.13",
9797
"fast-json-patch": "^3.1.1",

src/Common/Hooks/useUrlFilters/useUrlFilters.ts

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect, useMemo } from 'react'
17+
import { useMemo, useRef } from 'react'
1818
import { useHistory, useLocation } from 'react-router-dom'
19+
import { getUrlWithSearchParams } from '@Common/Helper'
1920
import { DEFAULT_BASE_PAGE_SIZE, EXCLUDED_FALSY_VALUES, SortingOrder } from '../../Constants'
2021
import { DEFAULT_PAGE_NUMBER, URL_FILTER_KEYS } from './constants'
2122
import { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types'
@@ -47,7 +48,38 @@ const useUrlFilters = <T = string, K = unknown>({
4748
}: UseUrlFiltersProps<T, K> = {}): UseUrlFiltersReturnType<T, K> => {
4849
const location = useLocation()
4950
const history = useHistory()
50-
const searchParams = new URLSearchParams(location.search)
51+
52+
const isAlreadyReadFromLocalStorage = useRef<boolean>(false)
53+
54+
const getSearchParams = () => {
55+
const locationSearchParams = new URLSearchParams(location.search)
56+
if (!isAlreadyReadFromLocalStorage.current && localStorageKey) {
57+
if (!location.search) {
58+
isAlreadyReadFromLocalStorage.current = true
59+
const localStorageValue = localStorage.getItem(localStorageKey)
60+
if (localStorageValue) {
61+
try {
62+
const localSearchString = getUrlWithSearchParams('', JSON.parse(localStorageValue))
63+
const localSearchParams = new URLSearchParams(localSearchString.split('?')[1] ?? '')
64+
65+
history.replace({ search: localSearchParams.toString() })
66+
return localSearchParams
67+
} catch {
68+
localStorage.removeItem(localStorageKey)
69+
}
70+
}
71+
} else {
72+
setItemInLocalStorageIfKeyExists(
73+
localStorageKey,
74+
JSON.stringify(parseSearchParams(locationSearchParams)),
75+
)
76+
}
77+
}
78+
79+
return locationSearchParams
80+
}
81+
82+
const searchParams = getSearchParams()
5183

5284
const getParsedSearchParams: UseUrlFiltersProps<T, K>['parseSearchParams'] = (searchParamsToParse) => {
5385
if (parseSearchParams) {
@@ -136,7 +168,9 @@ const useUrlFilters = <T = string, K = unknown>({
136168

137169
const clearFilters = () => {
138170
history.replace({ search: '' })
139-
setItemInLocalStorageIfKeyExists(localStorageKey, '')
171+
if (localStorageKey) {
172+
localStorage.removeItem(localStorageKey)
173+
}
140174
}
141175

142176
const updateSearchParams = (paramsToSerialize: Partial<K>) => {
@@ -160,21 +194,6 @@ const useUrlFilters = <T = string, K = unknown>({
160194
_resetPageNumber()
161195
}
162196

163-
useEffect(() => {
164-
if (!localStorageKey) {
165-
return
166-
}
167-
// if we have search string, set secondary params in local storage accordingly
168-
if (location.search) {
169-
setItemInLocalStorageIfKeyExists(localStorageKey, JSON.stringify(parsedParams))
170-
return
171-
}
172-
const localStorageValue = localStorage.getItem(localStorageKey)
173-
if (localStorageValue) {
174-
updateSearchParams(JSON.parse(localStorageValue))
175-
}
176-
}, [])
177-
178197
return {
179198
pageSize,
180199
changePage,

src/Shared/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export enum Nodes {
118118
PodDisruptionBudget = 'PodDisruptionBudget',
119119
Event = 'Event',
120120
Namespace = 'Namespace',
121+
Node = 'Node',
121122
Overview = 'Overview',
122123
MonitoringDashboard = 'MonitoringDashboard',
123124
UpgradeCluster = 'UpgradeCluster',
@@ -527,6 +528,7 @@ export enum AggregationKeys {
527528
'Other Resources' = 'Other Resources',
528529
Events = 'Events',
529530
Namespaces = 'Namespaces',
531+
'Nodes' = 'Nodes',
530532
}
531533

532534
export type AggregationKeysType = keyof typeof AggregationKeys

0 commit comments

Comments
 (0)