Skip to content

Commit 7aba048

Browse files
committed
Merge branch 'main' of https://github.com/devtron-labs/dashboard into feat/replace-toggle
2 parents cd70524 + 2e25f83 commit 7aba048

File tree

7 files changed

+54
-50
lines changed

7 files changed

+54
-50
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"homepage": "/dashboard",
66
"dependencies": {
7-
"@devtron-labs/devtron-fe-common-lib": "1.14.2-pre-2",
7+
"@devtron-labs/devtron-fe-common-lib": "1.15.0",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/components/common/Banner/Banner.tsx

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

17-
import { useCallback, useEffect, useRef, useState } from 'react'
17+
import { useEffect, useRef, useState } from 'react'
1818

1919
import {
2020
AnimatePresence,
@@ -83,36 +83,21 @@ export const Banner = () => {
8383
const [showAnnouncementBanner, setShowAnnouncementBanner] = useState(
8484
ANNOUNCEMENT_CONFIG.message ? shouldShowAnnouncementBanner() : false,
8585
)
86-
const hasShownOnlineBanner = useRef(false)
8786
const onlineTimer = useRef<ReturnType<typeof setTimeout>>(null)
8887

89-
const onOnline = useCallback(() => {
90-
// Only show the online banner if we haven't shown it since the last offline state
91-
if (!hasShownOnlineBanner.current) {
92-
setShowOnlineBanner(true)
93-
hasShownOnlineBanner.current = true
94-
95-
// Clear any existing timer before setting a new one
96-
if (onlineTimer.current) {
97-
clearTimeout(onlineTimer.current)
98-
}
99-
100-
onlineTimer.current = setTimeout(() => setShowOnlineBanner(false), ONLINE_BANNER_TIMEOUT)
101-
}
102-
}, [])
103-
104-
const onOffline = () => {
105-
hasShownOnlineBanner.current = false
88+
const onOnline = () => {
89+
clearTimeout(onlineTimer.current)
90+
setShowOnlineBanner(true)
91+
onlineTimer.current = setTimeout(() => setShowOnlineBanner(false), ONLINE_BANNER_TIMEOUT)
10692
}
10793

108-
const isOnline = useOnline({ onOnline, onOffline })
94+
const isOnline = useOnline({ onOnline })
10995

11096
useEffect(
11197
() => () => {
11298
if (onlineTimer.current) {
11399
clearTimeout(onlineTimer.current)
114100
}
115-
hasShownOnlineBanner.current = false
116101
},
117102
[],
118103
)

src/components/common/Description/GenericDescription.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export default function GenericDescription({
346346
>
347347
{isEditDescriptionView ? (
348348
<div className="min-w-500 bg__primary br-4 dc__border-top dc__border-left dc__border-right w-100 dc__border-bottom">
349-
<div className="py-8 px-16 dc__top-radius-4 flex dc__gap-8 bg__secondary dc__border-bottom fs-13">
349+
<div className="py-8 px-16 dc__top-radius-4 flex dc__content-space dc__gap-8 bg__secondary dc__border-bottom fs-13">
350350
<div className="fw-6 lh-20 cn-9">Readme</div>
351351
{descriptionUpdatedBy && descriptionUpdatedOn && (
352352
<Tooltip content={`Last updated by ${descriptionUpdatedBy} on ${descriptionUpdatedOn}`}>

src/components/common/hooks/useOnline/useOnline.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
11
import { useEffect, useRef, useState } from 'react'
22

3-
import { noop, useMainContext } from '@devtron-labs/devtron-fe-common-lib'
3+
import { getIsRequestAborted, noop, useMainContext } from '@devtron-labs/devtron-fe-common-lib'
44

55
import { getInternetConnectivity } from '@Services/service'
66

77
import { INTERNET_CONNECTIVITY_INTERVAL } from '../constants'
88

9-
export const useOnline = ({ onOnline = noop, onOffline = noop }: { onOnline?: () => void; onOffline?: () => void }) => {
9+
export const useOnline = ({ onOnline = noop }: { onOnline?: () => void }) => {
1010
const [online, setOnline] = useState(structuredClone(navigator.onLine))
1111
const abortControllerRef = useRef<AbortController>(new AbortController())
1212
const timeoutRef = useRef<NodeJS.Timeout>(null)
1313
const { isAirgapped } = useMainContext()
1414

15+
const handleClearTimeout = () => {
16+
if (timeoutRef.current) {
17+
clearTimeout(timeoutRef.current)
18+
}
19+
abortControllerRef.current.abort()
20+
}
21+
1522
const checkConnectivity = async () => {
1623
if (isAirgapped) return
17-
// Cancel any pending request
18-
if (abortControllerRef.current) {
19-
abortControllerRef.current.abort()
20-
}
2124

25+
handleClearTimeout()
2226
const controller = new AbortController()
2327
abortControllerRef.current = controller
2428

2529
try {
2630
await getInternetConnectivity(abortControllerRef.current)
27-
setOnline(true)
28-
if (online) {
29-
onOnline()
30-
}
31-
} catch {
32-
setOnline(false)
33-
} finally {
31+
setOnline((prev) => {
32+
if (!prev) {
33+
onOnline()
34+
}
35+
return true
36+
})
3437
timeoutRef.current = setTimeout(checkConnectivity, INTERNET_CONNECTIVITY_INTERVAL)
38+
} catch (error) {
39+
setOnline(false)
40+
if (!getIsRequestAborted(error)) {
41+
timeoutRef.current = setTimeout(checkConnectivity, INTERNET_CONNECTIVITY_INTERVAL)
42+
}
3543
}
3644
}
3745
const handleOffline = () => {
38-
if (timeoutRef.current) {
39-
clearTimeout(timeoutRef.current)
40-
}
41-
abortControllerRef.current.abort()
46+
handleClearTimeout()
4247
setOnline(false)
43-
if (onOffline) {
44-
onOffline()
45-
}
4648
}
4749

4850
const handleOnline = async () => {
4951
// Verify connectivity when browser reports online
5052
await checkConnectivity()
5153
}
5254

55+
useEffect(() => {
56+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
57+
handleOnline()
58+
}, [])
59+
5360
useEffect(() => {
5461
if (isAirgapped) return null
5562
window.addEventListener('online', handleOnline)

src/components/common/navigation/NavigationRoutes.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ export default function NavigationRoutes({ reloadVersionConfig }: Readonly<Navig
154154
const [licenseInfoDialogType, setLicenseInfoDialogType] = useState<LicenseInfoDialogType>(null)
155155
const [intelligenceConfig, setIntelligenceConfig] = useState<IntelligenceConfig>(null)
156156

157-
const [sidePanelConfig, setSidePanelConfig] = useState<SidePanelConfig>({ open: false, docLink: null, reinitialize: false })
157+
const [sidePanelConfig, setSidePanelConfig] = useState<SidePanelConfig>({
158+
open: false,
159+
docLink: null,
160+
reinitialize: false,
161+
})
158162
const asideWidth = useMotionValue(0)
159163

160164
const {
@@ -534,7 +538,7 @@ export default function NavigationRoutes({ reloadVersionConfig }: Readonly<Navig
534538
{serverMode && (
535539
<>
536540
<div
537-
className={`main flexbox-col bg__primary ${appTheme === AppThemeType.light ? 'dc__no-border' : 'border__primary-translucent'} mt-8 mb-8 ml-8 br-6 dc__overflow-hidden`}
541+
className={`main flexbox-col bg__primary ${appTheme === AppThemeType.light ? 'dc__no-border' : 'border__primary-translucent'} br-6 dc__overflow-hidden mt-8 mb-8 ml-8 ${!sidePanelConfig.open ? 'mr-8' : ''}`}
538542
ref={navRouteRef}
539543
>
540544
<Banner />

src/services/service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,15 @@ export const getTemplateOptions = (appId: number, envId: number): Promise<Respon
559559
get(getUrlWithSearchParams(Routes.DEPLOYMENT_OPTIONS, { appId, envId }))
560560

561561
export const getInternetConnectivity = (controller: AbortController): Promise<any> => {
562+
const timeoutId = setTimeout(() => {
563+
controller.abort()
564+
}, 10000)
565+
562566
return fetch(`${window._env_?.CENTRAL_API_ENDPOINT ?? 'https://api.devtron.ai'}/${Routes.HEALTH}`, {
563567
signal: controller.signal,
564-
}).then((res) => res.json())
568+
})
569+
.then((res) => res.json())
570+
.finally(() => {
571+
clearTimeout(timeoutId)
572+
})
565573
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,10 +1124,10 @@
11241124
dependencies:
11251125
"@jridgewell/trace-mapping" "0.3.9"
11261126

1127-
"@devtron-labs/devtron-fe-common-lib@1.14.2-pre-2":
1128-
version "1.14.2-pre-2"
1129-
resolved "https://registry.yarnpkg.com/@devtron-labs/devtron-fe-common-lib/-/devtron-fe-common-lib-1.14.2-pre-2.tgz#2637f88dd08df753eff175aace6977529f0cb5a7"
1130-
integrity sha512-drUHHzbjfJJLL1J5Z92EKQ7B2yVN7JTbQirWTsZ3hwSRzCy+Vf7eZqlZEQjWtVtCP+KJY8OignSW6lOdkA7X/A==
1127+
"@devtron-labs/devtron-fe-common-lib@1.15.0":
1128+
version "1.15.0"
1129+
resolved "https://registry.yarnpkg.com/@devtron-labs/devtron-fe-common-lib/-/devtron-fe-common-lib-1.15.0.tgz#a0895775e32cf29414f0bcea77c3d4b2de00a362"
1130+
integrity sha512-HimvKRILKRKKpNyDwAre+T3a8YFTJXrppm8FZtCJ2JDpvpjcCYtG/Ny+WsUAm89P/6OVQKC9baUt0HEIcGeAMQ==
11311131
dependencies:
11321132
"@codemirror/lang-json" "6.0.1"
11331133
"@codemirror/lang-yaml" "6.1.2"

0 commit comments

Comments
 (0)