Skip to content

Commit bd6ecae

Browse files
authored
Merge pull request #406 from devtron-labs/feat/confirmation-modal
feat: add new confirmation modal
2 parents cd4c4c2 + 8b16b07 commit bd6ecae

File tree

19 files changed

+550
-66
lines changed

19 files changed

+550
-66
lines changed

package-lock.json

Lines changed: 142 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: 2 additions & 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": "1.1.5",
3+
"version": "1.1.6",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
@@ -95,6 +95,7 @@
9595
"ansi_up": "^5.2.1",
9696
"dayjs": "^1.11.13",
9797
"fast-json-patch": "^3.1.1",
98+
"framer-motion": "^6.5.1",
9899
"jsonpath-plus": "^10.0.0",
99100
"react-dates": "^21.8.0",
100101
"react-diff-viewer-continued": "^3.4.0",

src/Assets/Icon/ic-medium-info.svg

Lines changed: 5 additions & 0 deletions
Loading

src/Common/Hooks/UseRegisterShortcut/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ export const KEYBOARD_KEYS_MAP = {
2121
Shift: '⇧',
2222
Meta: IS_PLATFORM_MAC_OS ? '⌘' : 'Win',
2323
Alt: IS_PLATFORM_MAC_OS ? '⌥' : 'Alt',
24-
Escape: 'Escape',
2524
F: 'F',
2625
E: 'E',
2726
R: 'R',
2827
K: 'K',
28+
Escape: 'Escape',
29+
Enter: 'Enter',
2930
} as const
3031

3132
export type SupportedKeyboardKeysType = keyof typeof KEYBOARD_KEYS_MAP

src/Common/TippyCustomized.tsx

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

17-
import React, { useRef, useState } from 'react'
17+
import { useRef, useState } from 'react'
1818
import Tippy from '@tippyjs/react'
1919
import { ReactComponent as CloseIcon } from '../Assets/Icon/ic-cross.svg'
2020
import { ReactComponent as Help } from '../Assets/Icon/ic-help.svg'
@@ -31,6 +31,12 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {
3131
const [showHeadingInfo, setShowHeadingInfo] = useState(false)
3232
const isWhiteTheme = props.theme === TippyTheme.white
3333

34+
const closeOnEsc = (e) => {
35+
if (e.keyCode === 27) {
36+
closeTippy(e)
37+
}
38+
}
39+
3440
const onTippyMount = (tippyInstance) => {
3541
tippyRef.current = tippyInstance
3642
document.addEventListener('keydown', closeOnEsc)
@@ -47,12 +53,7 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {
4753
}
4854
}
4955
setShowHeadingInfo(false)
50-
}
51-
52-
const closeOnEsc = (e) => {
53-
if (e.keyCode === 27) {
54-
closeTippy(e)
55-
}
56+
document.removeEventListener('keydown', closeOnEsc)
5657
}
5758

5859
const toggleHeadingInfo = (e) => {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { useEffect } from 'react'
2+
import { createPortal } from 'react-dom'
3+
import { motion } from 'framer-motion'
4+
import { useRegisterShortcut } from '@Common/Hooks'
5+
import { preventBodyScroll, preventOutsideFocus } from '@Shared/Helpers'
6+
import { DEVTRON_BASE_MAIN_ID } from '@Shared/constants'
7+
import { BackdropProps } from './types'
8+
9+
const Backdrop = ({ children, onEscape }: BackdropProps) => {
10+
const { registerShortcut, unregisterShortcut } = useRegisterShortcut()
11+
12+
// useEffect on onEscape since onEscape might change based on conditions
13+
useEffect(() => {
14+
registerShortcut({ keys: ['Escape'], callback: onEscape })
15+
16+
return () => {
17+
unregisterShortcut(['Escape'])
18+
}
19+
}, [onEscape])
20+
21+
useEffect(() => {
22+
preventBodyScroll(true)
23+
// Setting main as inert to that focus is trapped inside the new portal
24+
preventOutsideFocus({ identifier: DEVTRON_BASE_MAIN_ID, preventFocus: true })
25+
26+
return () => {
27+
preventBodyScroll(false)
28+
preventOutsideFocus({ identifier: DEVTRON_BASE_MAIN_ID, preventFocus: false })
29+
}
30+
}, [])
31+
32+
return createPortal(
33+
<motion.div
34+
initial={{ opacity: 0 }}
35+
animate={{ opacity: 1 }}
36+
exit={{ opacity: 0, transition: { duration: 0.35 } }}
37+
className="backdrop dc__position-fixed dc__top-0 dc__left-0 full-height-width flexbox dc__content-center dc__align-items-center dc__overflow-hidden"
38+
>
39+
{children}
40+
</motion.div>,
41+
document.getElementById('animated-dialog-backdrop'),
42+
)
43+
}
44+
45+
export default Backdrop
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Backdrop } from './Backdrop'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ReactNode } from 'react'
2+
3+
export interface BackdropProps {
4+
children: ReactNode
5+
/**
6+
* @param onEscape: please wrap in a useCallback, with respective dependencies or []
7+
*/
8+
onEscape: () => void
9+
}

src/Shared/Components/CICDHistory/Sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ const HistorySummaryCard = React.memo(
240240
<span className="dc__bullet dc__bullet--d2 ml-4 mr-4" />
241241
</>
242242
)}
243-
<div className="cn-7 fs-12 dc__ellipsis-right">
243+
<div className="cn-7 fs-12 dc__truncate">
244244
{triggeredBy === 1 ? 'auto trigger' : triggeredByEmail}
245245
</div>
246246
</div>

0 commit comments

Comments
 (0)