Skip to content

Commit 34bff8d

Browse files
committed
Merge branch 'main' into chore/vite-update
2 parents 2a0d4a8 + f208ab0 commit 34bff8d

11 files changed

Lines changed: 87 additions & 30 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "4.0.4-pre-0",
3+
"version": "4.0.8",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
Lines changed: 3 additions & 0 deletions
Loading

src/Common/Hooks/useUrlFilters/useUrlFilters.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useMemo, useRef } from 'react'
17+
import { useEffect, useMemo, useRef } from 'react'
1818
import { useLocation, useNavigate } from 'react-router-dom'
1919

2020
import { getUrlWithSearchParams } from '@Common/Helper'
@@ -56,6 +56,10 @@ const useUrlFilters = <T = string, K = {}>({
5656

5757
const isAlreadyReadFromLocalStorage = useRef<boolean>(false)
5858

59+
// Holds the search string to restore from local storage. The actual navigation
60+
// is deferred to an effect since react-router v6 disallows navigate() during render.
61+
const pendingLocalStorageSearch = useRef<string | null>(null)
62+
5963
const getSearchParams = () => {
6064
const locationSearchParams = new URLSearchParams(location.search)
6165
if (!isAlreadyReadFromLocalStorage.current && localStorageKey) {
@@ -67,8 +71,9 @@ const useUrlFilters = <T = string, K = {}>({
6771
const localSearchString = getUrlWithSearchParams('', JSON.parse(localStorageValue))
6872
const localSearchParams = new URLSearchParams(localSearchString.split('?')[1] ?? '')
6973

70-
// This would remain replace since the initial value is being set from local storage
71-
navigate({ search: localSearchParams.toString() }, { replace: true })
74+
// Defer the navigation to an effect (see below). react-router v6 ignores
75+
// navigate() called during render. Returning the params here keeps the first render correct.
76+
pendingLocalStorageSearch.current = localSearchParams.toString()
7277
return localSearchParams
7378
} catch {
7479
localStorage.removeItem(localStorageKey)
@@ -87,6 +92,17 @@ const useUrlFilters = <T = string, K = {}>({
8792

8893
const searchParams = getSearchParams()
8994

95+
// Apply the restored-from-local-storage search params to the URL after the initial render.
96+
// The value is only ever set during the first render, so this runs once on mount.
97+
useEffect(() => {
98+
if (pendingLocalStorageSearch.current !== null) {
99+
const search = pendingLocalStorageSearch.current
100+
pendingLocalStorageSearch.current = null
101+
// This remains replace since the initial value is being set from local storage
102+
navigate({ search }, { replace: true })
103+
}
104+
}, [])
105+
90106
const getParsedSearchParams: UseUrlFiltersProps<T, K>['parseSearchParams'] = (searchParamsToParse) => {
91107
if (parseSearchParams) {
92108
return parseSearchParams(searchParamsToParse)

src/Pages-Devtron-2.0/Navigation/types.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export type NavigationRootItemID =
7878
| 'automation-and-enablement'
7979
| 'data-protection-management'
8080
| 'global-configuration'
81+
| 'audit-logs'
8182

8283
export type CommonNavigationItemType = {
8384
title: string
@@ -107,11 +108,19 @@ export type NavigationItemType = Pick<
107108
})
108109
)
109110

110-
export interface NavigationGroupType extends Pick<
111+
export type NavigationGroupType = Pick<
111112
CommonNavigationItemType,
112113
'title' | 'icon' | 'hideNav' | 'forceHideEnvKey' | 'isAvailableInEA'
113-
> {
114+
> & {
114115
id: NavigationRootItemID
115-
items: NavigationItemType[]
116116
disabled?: boolean
117-
}
117+
} & (
118+
| {
119+
items: NavigationItemType[]
120+
href?: never
121+
}
122+
| {
123+
items?: never
124+
href: string
125+
}
126+
)

src/Pages-Devtron-2.0/Shared/Routes/routes.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { generatePath } from 'react-router-dom'
22

33
import { InfrastructureManagementAppListType } from '@Common/Types'
4-
import { CostBreakdownItemViewParamsType, CostBreakdownViewType } from '@PagesDevtron2.0/index'
4+
import { CostBreakdownItemViewParamsType, CostBreakdownViewType } from '@PagesDevtron2.0/CostVisibility/Shared/types'
55

66
const OVERVIEW = 'overview'
77

@@ -279,6 +279,9 @@ export const BASE_ROUTES = {
279279
DETAIL: ':locationId',
280280
},
281281
},
282+
AUDIT_LOGS: {
283+
ROOT: 'audit-logs',
284+
},
282285
GLOBAL_CONFIG: {
283286
ROOT: 'global-configuration',
284287
HOST_URL: 'host-url',
@@ -288,6 +291,11 @@ export const BASE_ROUTES = {
288291
ROOT: 'cluster-env',
289292
MANAGE_CATEGORIES: 'manage-categories',
290293
},
294+
NODE_AUTOSCALER: {
295+
ROOT: 'node-autoscaler',
296+
CREATE_PROFILE: 'create-profile',
297+
EDIT_PROFILE: 'edit/:profileId',
298+
},
291299
DOCKER: 'docker',
292300
PROJECTS: 'projects',
293301
AUTH: {
@@ -410,6 +418,7 @@ const JOBS_ROOT =
410418
const JOB_DETAIL_ROOT = `${JOBS_ROOT}/${BASE_ROUTES.AUTOMATION_AND_ENABLEMENT.JOBS.DETAIL.ROOT}` as const
411419

412420
const DATA_PROTECTION_MANAGEMENT_ROOT = `/${BASE_ROUTES.DATA_PROTECTION_MANAGEMENT.ROOT}` as const
421+
const AUDIT_LOGS_ROOT = `/${BASE_ROUTES.AUDIT_LOGS.ROOT}` as const
413422
const GLOBAL_CONFIG_ROOT = `/${BASE_ROUTES.GLOBAL_CONFIG.ROOT}` as const
414423
const GLOBAL_CONFIG_AUTH_ROOT = `${GLOBAL_CONFIG_ROOT}/${BASE_ROUTES.GLOBAL_CONFIG.AUTH.ROOT}` as const
415424
const NETWORK_STATUS_INTERFACE_ROOT = `/${BASE_ROUTES.NETWORK_STATUS_INTERFACE.ROOT}` as const
@@ -670,7 +679,9 @@ export const ROUTER_URLS = {
670679
DATA_PROTECTION_MANAGEMENT_BACKUP_LOCATIONS: `${DATA_PROTECTION_MANAGEMENT_ROOT}/${BASE_ROUTES.DATA_PROTECTION_MANAGEMENT.BACKUP_LOCATIONS.ROOT}`,
671680
DATA_PROTECTION_MANAGEMENT_BACKUP_LOCATIONS_DETAIL: `${DATA_PROTECTION_MANAGEMENT_ROOT}/${BASE_ROUTES.DATA_PROTECTION_MANAGEMENT.BACKUP_LOCATIONS.ROOT}/${BASE_ROUTES.DATA_PROTECTION_MANAGEMENT.BACKUP_LOCATIONS.DETAIL}`,
672681

673-
// Global Config
682+
// Audit Logs
683+
AUDIT_LOGS: AUDIT_LOGS_ROOT,
684+
674685
GLOBAL_CONFIG_HOST_URL: `${GLOBAL_CONFIG_ROOT}/${BASE_ROUTES.GLOBAL_CONFIG.HOST_URL}`,
675686
GLOBAL_CONFIG_EXTERNAL_LINKS: `${GLOBAL_CONFIG_ROOT}/${BASE_ROUTES.GLOBAL_CONFIG.EXTERNAL_LINKS}`,
676687
GLOBAL_CONFIG_CHART_REPOSITORIES: `${GLOBAL_CONFIG_ROOT}/${BASE_ROUTES.GLOBAL_CONFIG.CHART_REPOSITORIES}`,

src/Shared/Components/DatePicker/DateTimePicker.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ const DateTimePicker = ({
104104
onChange(updateTime(dateObject, option.value).value)
105105
}
106106

107-
const handleDateRangeChange = (range: DateRange) => {
107+
const handleDateRangeChange = (range: DateRange | undefined) => {
108+
if (!range) {
109+
return
110+
}
108111
if (isDateUpdateRange(isRangePicker, onChange)) {
109112
const fromDate = range.from ? range.from : new Date()
110113
const toDate = range.to ? range.to : undefined

src/Shared/Components/ExportToCsv/ExportToCsv.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ const ExportToCsv = <HeaderItemType extends string>({
2424
downloadRequestId,
2525
}: ExportToCsvProps<HeaderItemType>) => {
2626
const csvRef = useRef(null)
27-
const abortControllerRef = useRef<AbortController>(new AbortController())
27+
const abortControllerRef = useRef<AbortController>(null)
2828

2929
const [dataToExport, setDataToExport] = useState<Awaited<ReturnType<typeof apiPromise>>>([])
3030
const [confirmationModalType, setConfirmationModalType] = useState<'default' | 'custom' | null>(null)
3131
const [isLoading, setIsLoading] = useState(false)
3232
const [dataFetchError, setDataFetchError] = useState<ServerErrors>(null)
33+
const [pendingDownload, setPendingDownload] = useState(false)
3334

3435
const handleInitiateDownload = async () => {
3536
if (disabled) {
@@ -41,8 +42,7 @@ const ExportToCsv = <HeaderItemType extends string>({
4142
setDataFetchError(null)
4243
const data = await apiPromise({ signal: abortControllerRef.current.signal })
4344
setDataToExport(data)
44-
45-
csvRef.current?.link?.click()
45+
setPendingDownload(true)
4646
} catch (error) {
4747
if (!getIsRequestAborted(error)) {
4848
showError(error)
@@ -64,12 +64,12 @@ const ExportToCsv = <HeaderItemType extends string>({
6464
}
6565
}
6666

67-
useEffect(
68-
() => () => {
69-
abortControllerRef.current.abort()
70-
},
71-
[],
72-
)
67+
useEffect(() => {
68+
abortControllerRef.current = new AbortController()
69+
return () => {
70+
abortControllerRef.current?.abort()
71+
}
72+
}, [])
7373

7474
useEffect(() => {
7575
if (!isNullOrUndefined(downloadRequestId)) {
@@ -78,6 +78,13 @@ const ExportToCsv = <HeaderItemType extends string>({
7878
}
7979
}, [downloadRequestId])
8080

81+
useEffect(() => {
82+
if (pendingDownload) {
83+
csvRef.current?.link?.click()
84+
setPendingDownload(false)
85+
}
86+
}, [pendingDownload])
87+
8188
const handleCancelRequest = () => {
8289
abortControllerRef.current.abort()
8390
abortControllerRef.current = new AbortController()

src/Shared/Components/Icon/Icon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ import ICFileCode from '@IconsV2/ic-file-code.svg?react'
149149
import ICFileDownload from '@IconsV2/ic-file-download.svg?react'
150150
import ICFileEdit from '@IconsV2/ic-file-edit.svg?react'
151151
import ICFileKey from '@IconsV2/ic-file-key.svg?react'
152+
import ICFileLogSearch from '@IconsV2/ic-file-log-search.svg?react'
152153
import ICFiles from '@IconsV2/ic-files.svg?react'
153154
import ICFilesChanged from '@IconsV2/ic-files-changed.svg?react'
154155
import ICFilter from '@IconsV2/ic-filter.svg?react'
@@ -492,6 +493,7 @@ export const iconMap = {
492493
'ic-file-download': ICFileDownload,
493494
'ic-file-edit': ICFileEdit,
494495
'ic-file-key': ICFileKey,
496+
'ic-file-log-search': ICFileLogSearch,
495497
'ic-file': ICFile,
496498
'ic-files-changed': ICFilesChanged,
497499
'ic-files': ICFiles,

src/Shared/Hooks/useUserPreferences/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { USER_PREFERENCES_ATTRIBUTE_KEY } from '@Shared/Hooks/useUserPreferences/constants'
1818
import { AppThemeType, ThemeConfigType, ThemePreferenceType } from '@Shared/Providers/ThemeProvider/types'
1919
import { ResourceKindType } from '@Shared/types'
20-
import { NavigationItemID, NavigationSubMenuItemID } from '@PagesDevtron2.0/Navigation'
20+
import { NavigationItemID, NavigationRootItemID, NavigationSubMenuItemID } from '@PagesDevtron2.0/Navigation'
2121

2222
export interface GetUserPreferencesQueryParamsType {
2323
key: typeof USER_PREFERENCES_ATTRIBUTE_KEY
@@ -78,7 +78,9 @@ export interface GetUserPreferencesParsedDTO {
7878
*/
7979
resources?: UserPreferenceResourceType
8080
commandBar: {
81-
recentNavigationActions: { id: NavigationItemID | NavigationSubMenuItemID | CommandBarAdditionalItemsId }[]
81+
recentNavigationActions: {
82+
id: NavigationItemID | NavigationRootItemID | NavigationSubMenuItemID | CommandBarAdditionalItemsId
83+
}[]
8284
}
8385
}
8486
export interface UserPreferencesPayloadValueType extends GetUserPreferencesParsedDTO {}

0 commit comments

Comments
 (0)