@@ -18,7 +18,14 @@ import Tippy from '@tippyjs/react'
18
18
import { useEffect , useRef } from 'react'
19
19
import { useLocation } from 'react-router-dom'
20
20
import { withShortcut , IWithShortcut } from 'react-keybind'
21
- import { ClipboardButton , GenericEmptyState , Tooltip , extractImage , useSuperAdmin } from '../../../Common'
21
+ import {
22
+ ClipboardButton ,
23
+ GenericEmptyState ,
24
+ Tooltip ,
25
+ extractImage ,
26
+ IS_PLATFORM_MAC_OS ,
27
+ useSuperAdmin ,
28
+ } from '../../../Common'
22
29
import { EMPTY_STATE_STATUS } from '../../constants'
23
30
import { ReactComponent as DropDownIcon } from '../../../Assets/Icon/ic-chevron-down.svg'
24
31
import { GitChangesType , LogResizeButtonType , ScrollerType } from './types'
@@ -29,47 +36,63 @@ import { ReactComponent as ZoomOut } from '../../../Assets/Icon/ic-exit-fullscre
29
36
import './cicdHistory.scss'
30
37
31
38
export const LogResizeButton = withShortcut (
32
- ( { fullScreenView, setFullScreenView, shortcut } : LogResizeButtonType & IWithShortcut ) : JSX . Element => {
39
+ ( {
40
+ shortcutCombo = [ 'F' ] ,
41
+ onlyOnLogs = true ,
42
+ fullScreenView,
43
+ setFullScreenView,
44
+ shortcut,
45
+ } : LogResizeButtonType & IWithShortcut ) : JSX . Element => {
33
46
const { pathname } = useLocation ( )
34
- const zoomButtonRef = useRef < HTMLDivElement > ( null )
47
+ const zoomButtonRef = useRef < HTMLButtonElement > ( null )
35
48
36
- const toggleFullScreen = ( ) : void => {
49
+ const toggleFullScreen = ( ) => {
37
50
// NOTE: need to use ref due to the problem of stale function reference after registering the callback
38
51
setFullScreenView ( ! ( zoomButtonRef . current . dataset . isFullscreenView === 'true' ) )
39
52
}
40
53
54
+ const showButton = pathname . includes ( '/logs' ) || ! onlyOnLogs
55
+ const doesShortcutContainCmdKey = shortcutCombo . some ( ( key ) => key === 'Control' ) && IS_PLATFORM_MAC_OS
56
+
41
57
useEffect ( ( ) => {
42
- shortcut . registerShortcut ( toggleFullScreen , [ 'f' ] , 'ToggleFullscreen' , 'Enter/Exit fullscreen' )
43
- shortcut . registerShortcut (
44
- ( ) => setFullScreenView ( false ) ,
45
- [ 'Escape' ] ,
46
- 'ToggleFullscreen' ,
47
- 'Enter/Exit fullscreen' ,
48
- )
58
+ const combo = shortcutCombo
59
+ . map ( ( key ) => {
60
+ if ( key === 'Control' ) {
61
+ return IS_PLATFORM_MAC_OS ? 'cmd' : 'ctrl'
62
+ }
63
+ return key . toLowerCase ( )
64
+ } )
65
+ . join ( '+' )
66
+
67
+ // FIXME: disabling shortcut for macos since pressing cmd breaks shortcuts through react-keybind
68
+ if ( showButton && shortcutCombo . length && ! doesShortcutContainCmdKey ) {
69
+ shortcut . registerShortcut ( toggleFullScreen , [ combo ] , 'ToggleFullscreen' , 'Enter/Exit fullscreen' )
70
+ }
49
71
50
72
return ( ) => {
51
- shortcut . unregisterShortcut ( [ 'f' ] )
52
- shortcut . unregisterShortcut ( [ 'Escape' ] )
73
+ shortcut . unregisterShortcut ( [ combo ] )
53
74
}
54
- } , [ pathname . includes ( '/logs' ) ] )
75
+ } , [ showButton ] )
55
76
56
77
return (
57
- pathname . includes ( '/logs' ) && (
78
+ showButton && (
58
79
< Tooltip
59
80
placement = "left"
60
81
shortcutKeyCombo = { {
61
82
text : fullScreenView ? 'Exit fullscreen' : 'Enter fullscreen' ,
62
- combo : [ 'F' ] as const ,
83
+ combo : doesShortcutContainCmdKey ? null : shortcutCombo ,
63
84
} }
64
85
>
65
- < div
86
+ < button
87
+ type = "button"
88
+ aria-label = "Enter/Exit fullscreen"
66
89
ref = { zoomButtonRef }
67
90
data-is-fullscreen-view = { fullScreenView }
68
- className = { `zoom ${ fullScreenView ? 'zoom--out' : 'zoom--in' } pointer dc__zi-4 flex` }
91
+ className = { `zoom ${ fullScreenView ? 'zoom--out' : 'zoom--in' } pointer dc__zi-4 flex dc__transparent ` }
69
92
onClick = { toggleFullScreen }
70
93
>
71
94
{ fullScreenView ? < ZoomOut className = "icon-dim-16" /> : < ZoomIn className = "icon-dim-16" /> }
72
- </ div >
95
+ </ button >
73
96
</ Tooltip >
74
97
)
75
98
)
0 commit comments