Skip to content

Commit a5a7ab7

Browse files
authored
Merge pull request #309 from devtron-labs/feat/fullscreen-terminal
feat: add support to go fullscreen for all terminals
2 parents ad58692 + d786a80 commit a5a7ab7

File tree

7 files changed

+55
-29
lines changed

7 files changed

+55
-29
lines changed

package-lock.json

Lines changed: 2 additions & 2 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": "0.3.6-beta-5",
3+
"version": "0.3.6-beta-7",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,6 @@ export const VULNERABILITIES_SORT_PRIORITY = {
548548
low: 4,
549549
unknown: 5,
550550
}
551+
552+
// TODO: might not work need to verify
553+
export const IS_PLATFORM_MAC_OS = window.navigator.userAgent.toUpperCase().includes('MAC')

src/Common/Tooltip/ShortcutKeyComboTooltipContent.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { KEYBOARD_KEYS_MAP, TooltipProps } from './types'
33
const ShortcutKeyComboTooltipContent = ({ text, combo }: TooltipProps['shortcutKeyCombo']) => (
44
<div className="flexbox dc__gap-8 px-8 py-4 flex-wrap">
55
<span className="lh-18 fs-12 fw-4 cn-0">{text}</span>
6-
<div className="flexbox dc__gap-4 dc__align-items-center flex-wrap">
7-
{combo.map((key) => (
8-
<span key={key} className="shortcut-keys__chip dc__capitalize lh-16 fs-11 fw-5 flex">
9-
{KEYBOARD_KEYS_MAP[key]}
10-
</span>
11-
))}
12-
</div>
6+
{!!combo?.length && (
7+
<div className="flexbox dc__gap-4 dc__align-items-center flex-wrap">
8+
{combo.map((key) => (
9+
<span key={key} className="shortcut-keys__chip dc__capitalize lh-16 fs-11 fw-5 flex">
10+
{KEYBOARD_KEYS_MAP[key]}
11+
</span>
12+
))}
13+
</div>
14+
)}
1315
</div>
1416
)
1517

src/Common/Tooltip/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import { IS_PLATFORM_MAC_OS } from '@Common/Constants'
12
import { TippyProps } from '@tippyjs/react'
23

3-
const isMacOS = navigator.userAgent.toUpperCase().includes('MAC')
4-
54
export const KEYBOARD_KEYS_MAP = {
6-
Control: isMacOS ? '⌘' : 'Ctrl',
5+
Control: IS_PLATFORM_MAC_OS ? '⌘' : 'Ctrl',
76
Shift: '⇧',
87
F: 'F',
98
E: 'E',

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

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ import Tippy from '@tippyjs/react'
1818
import { useCallback, useEffect } from 'react'
1919
import { useLocation } from 'react-router-dom'
2020
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'
2229
import { EMPTY_STATE_STATUS } from '../../constants'
2330
import { ReactComponent as DropDownIcon } from '../../../Assets/Icon/ic-chevron-down.svg'
2431
import { GitChangesType, LogResizeButtonType, ScrollerType } from './types'
@@ -29,44 +36,56 @@ import { ReactComponent as ZoomOut } from '../../../Assets/Icon/ic-exit-fullscre
2936
import './cicdHistory.scss'
3037

3138
export const LogResizeButton = withShortcut(
32-
({ fullScreenView, setFullScreenView, shortcut }: LogResizeButtonType & IWithShortcut): JSX.Element => {
39+
({
40+
shortcutCombo = ['F'],
41+
showOnlyWhenPathIncludesLogs = true,
42+
fullScreenView,
43+
setFullScreenView,
44+
shortcut,
45+
}: LogResizeButtonType & IWithShortcut): JSX.Element => {
3346
const { pathname } = useLocation()
3447

3548
const toggleFullScreen = useCallback((): void => {
3649
// NOTE: need to use ref due to the problem of stale function reference after registering the callback
3750
setFullScreenView(!fullScreenView)
3851
}, [fullScreenView])
3952

53+
const showButton = !showOnlyWhenPathIncludesLogs || pathname.includes('/logs')
54+
const doesShortcutContainCmdKey = shortcutCombo.some((key) => key === 'Control') && IS_PLATFORM_MAC_OS
55+
4056
useEffect(() => {
41-
if (pathname.includes('/logs')) {
42-
shortcut.registerShortcut(toggleFullScreen, ['f'], 'ToggleFullscreen', 'Enter/Exit fullscreen')
43-
shortcut.registerShortcut(
44-
() => setFullScreenView(false),
45-
['Escape'],
46-
'ToggleFullscreen',
47-
'Enter/Exit fullscreen',
48-
)
57+
const combo = shortcutCombo
58+
.map((key) => {
59+
if (key === 'Control') {
60+
return IS_PLATFORM_MAC_OS ? 'cmd' : 'ctrl'
61+
}
62+
return key.toLowerCase()
63+
})
64+
.join('+')
65+
66+
// FIXME: disabling shortcut for macos since pressing cmd breaks shortcuts through react-keybind
67+
if (showButton && shortcutCombo.length && !doesShortcutContainCmdKey) {
68+
shortcut.registerShortcut(toggleFullScreen, [combo], 'ToggleFullscreen', 'Enter/Exit fullscreen')
4969
}
5070

5171
return () => {
52-
shortcut.unregisterShortcut(['f'])
53-
shortcut.unregisterShortcut(['Escape'])
72+
shortcut.unregisterShortcut([combo])
5473
}
55-
}, [pathname, toggleFullScreen])
74+
}, [showButton, toggleFullScreen])
5675

5776
return (
58-
pathname.includes('/logs') && (
77+
showButton && (
5978
<Tooltip
6079
placement="left"
6180
shortcutKeyCombo={{
6281
text: fullScreenView ? 'Exit fullscreen' : 'Enter fullscreen',
63-
combo: ['F'] as const,
82+
combo: doesShortcutContainCmdKey ? null : shortcutCombo,
6483
}}
6584
>
6685
<button
6786
type="button"
6887
aria-label="Enter/Exit fullscreen view"
69-
className="zoom dc__zi-4 flex dc__transparent log-resize-button"
88+
className="zoom dc__zi-4 flex dc__no-border log-resize-button"
7089
onClick={toggleFullScreen}
7190
>
7291
{fullScreenView ? (

src/Shared/Components/CICDHistory/types.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
PaginationProps,
2828
useScrollable,
2929
SortingOrder,
30+
SupportedKeyboardKeysType,
3031
} from '../../../Common'
3132
import { DeploymentStageType } from '../../constants'
3233
import { AggregationKeys, GitTriggers, Node, NodeType, ResourceKindType, ResourceVersionType } from '../../types'
@@ -46,6 +47,8 @@ export enum FetchIdDataStatus {
4647
}
4748

4849
export interface LogResizeButtonType {
50+
shortcutCombo?: SupportedKeyboardKeysType[]
51+
showOnlyWhenPathIncludesLogs?: boolean
4952
fullScreenView: boolean
5053
setFullScreenView: React.Dispatch<React.SetStateAction<boolean>>
5154
}

0 commit comments

Comments
 (0)