Skip to content

Commit 7d1ce96

Browse files
committed
Merge branch 'fix/expand-all-logs' of github.com:devtron-labs/devtron-fe-common-lib into feat/fullscreen-terminal
2 parents 4c26877 + eff0bca commit 7d1ce96

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

src/Shared/Components/CICDHistory/History.components.tsx

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

1717
import Tippy from '@tippyjs/react'
18-
import { useEffect, useRef } from 'react'
18+
import { useCallback, useEffect } from 'react'
1919
import { useLocation } from 'react-router-dom'
2020
import { withShortcut, IWithShortcut } from 'react-keybind'
2121
import {
@@ -44,12 +44,11 @@ export const LogResizeButton = withShortcut(
4444
shortcut,
4545
}: LogResizeButtonType & IWithShortcut): JSX.Element => {
4646
const { pathname } = useLocation()
47-
const zoomButtonRef = useRef<HTMLButtonElement>(null)
4847

49-
const toggleFullScreen = () => {
48+
const toggleFullScreen = useCallback((): void => {
5049
// NOTE: need to use ref due to the problem of stale function reference after registering the callback
51-
setFullScreenView(!(zoomButtonRef.current.dataset.isFullscreenView === 'true'))
52-
}
50+
setFullScreenView(!fullScreenView)
51+
}, [fullScreenView])
5352

5453
const showButton = pathname.includes('/logs') || !onlyOnLogs
5554
const doesShortcutContainCmdKey = shortcutCombo.some((key) => key === 'Control') && IS_PLATFORM_MAC_OS
@@ -72,7 +71,7 @@ export const LogResizeButton = withShortcut(
7271
return () => {
7372
shortcut.unregisterShortcut([combo])
7473
}
75-
}, [showButton])
74+
}, [showButton, toggleFullScreen])
7675

7776
return (
7877
showButton && (
@@ -85,13 +84,15 @@ export const LogResizeButton = withShortcut(
8584
>
8685
<button
8786
type="button"
88-
aria-label="Enter/Exit fullscreen"
89-
ref={zoomButtonRef}
90-
data-is-fullscreen-view={fullScreenView}
91-
className={`zoom ${fullScreenView ? 'zoom--out' : 'zoom--in'} pointer dc__zi-4 flex dc__transparent`}
87+
aria-label="Enter/Exit fullscreen view"
88+
className="zoom dc__zi-4 flex dc__transparent log-resize-button"
9289
onClick={toggleFullScreen}
9390
>
94-
{fullScreenView ? <ZoomOut className="icon-dim-16" /> : <ZoomIn className="icon-dim-16" />}
91+
{fullScreenView ? (
92+
<ZoomOut className="icon-dim-16 dc__no-shrink" />
93+
) : (
94+
<ZoomIn className="icon-dim-16 dc__no-shrink" />
95+
)}
9596
</button>
9697
</Tooltip>
9798
)

src/Shared/Components/CICDHistory/LogsRenderer.tsx

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

1717
import { useParams } from 'react-router-dom'
18-
import { useEffect, useMemo, useRef, useState } from 'react'
18+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
1919
import AnsiUp from 'ansi_up'
2020
import DOMPurify from 'dompurify'
2121
import { ANSI_UP_REGEX, ComponentSizeType } from '@Shared/constants'
@@ -189,7 +189,6 @@ const LogsRenderer = ({
189189
// State for logs list in case no stages are available
190190
const [logsList, setLogsList] = useState<string[]>([])
191191
const { searchKey, handleSearch } = useUrlFilters()
192-
const accordionExpansionStateTogglerButtonRef = useRef<HTMLButtonElement>(null)
193192

194193
const areAllStagesExpanded = useMemo(() => stageList.every((item) => item.isOpen), [stageList])
195194

@@ -386,15 +385,14 @@ const LogsRenderer = ({
386385
// And for other cases we would use handleSearchEnter
387386
}, [streamDataList, areEventsProgressing])
388387

389-
const handleToggleOpenAllStages = () => {
388+
const handleToggleOpenAllStages = useCallback(() => {
390389
setStageList((prev) =>
391390
prev.map((stage) => ({
392391
...stage,
393-
// NOTE: need to use ref due to the problem of stale function reference after registering the callback
394-
isOpen: !(accordionExpansionStateTogglerButtonRef.current.dataset.toggleState === 'true'),
392+
isOpen: !areAllStagesExpanded,
395393
})),
396394
)
397-
}
395+
}, [areAllStagesExpanded])
398396

399397
useEffect(() => {
400398
shortcut.registerShortcut(
@@ -407,7 +405,7 @@ const LogsRenderer = ({
407405
return () => {
408406
shortcut.unregisterShortcut(['e'])
409407
}
410-
}, [])
408+
}, [handleToggleOpenAllStages])
411409

412410
const handleSearchEnter = (searchText: string) => {
413411
handleSearch(searchText)
@@ -468,7 +466,6 @@ const LogsRenderer = ({
468466
onClick={handleToggleOpenAllStages}
469467
aria-label="Expand all stages"
470468
data-toggle-state={areAllStagesExpanded}
471-
ref={accordionExpansionStateTogglerButtonRef}
472469
>
473470
{areAllStagesExpanded ? (
474471
<ICCollapseAll className="icon-dim-16 dc__no-shrink dc__transition--transform scn-0" />

src/Shared/Components/CICDHistory/cicdHistory.scss

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@
3737
position: absolute;
3838
bottom: 12px;
3939
right: 12px;
40-
transition: top 0.3s;
41-
padding: 6px;
42-
width: 32px;
43-
height: 32px;
44-
border-radius: 4px;
45-
box-shadow:
46-
0 0 4px 0 rgba(0, 10, 20, 0.5),
47-
0 0 4px 0 rgba(0, 10, 20, 0.5);
48-
background-color: #2c3354;
49-
opacity: 0.8;
50-
51-
&:hover {
52-
opacity: 1;
53-
}
5440
}
5541

5642
.ci-details__history {
@@ -110,10 +96,6 @@
11096
transition: height 0.3s;
11197
}
11298
}
113-
114-
.zoom {
115-
transition: top 0.3s;
116-
}
11799
}
118100
}
119101

@@ -295,3 +277,29 @@
295277
}
296278
}
297279

280+
.log-resize-button {
281+
transition: opacity 0.2s ease-in-out;
282+
padding: 6px;
283+
width: 32px;
284+
height: 32px;
285+
border-radius: 4px;
286+
box-shadow:
287+
0 0 4px 0 rgba(0, 10, 20, 0.5),
288+
0 0 4px 0 rgba(0, 10, 20, 0.5);
289+
background-color: #2c3354;
290+
opacity: 0.8;
291+
z-index: 11;
292+
293+
& > svg {
294+
transition: transform 0.2s ease-in-out;
295+
transform: scale(1);
296+
}
297+
298+
&:hover {
299+
opacity: 1;
300+
301+
& > svg {
302+
transform: scale(1.1);
303+
}
304+
}
305+
}

0 commit comments

Comments
 (0)