Skip to content

Commit e71b0b6

Browse files
committed
fix: review comments
1 parent 2d75909 commit e71b0b6

18 files changed

+391
-374
lines changed

src/Common/Hooks/UseRegisterShortcut/UseRegisterShortcutProvider.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ const DEFAULT_TIMEOUT = 300
2626
const UseRegisterShortcutProvider = ({
2727
ignoreTags,
2828
preventDefault = false,
29+
stopPropagation = false,
2930
shortcutTimeout,
3031
children,
32+
eventListenerTargetRef,
3133
}: UseRegisterShortcutProviderType) => {
3234
const disableShortcutsRef = useRef<boolean>(false)
3335
const shortcutsRef = useRef<Record<string, ShortcutType>>({})
@@ -120,6 +122,10 @@ const UseRegisterShortcutProvider = ({
120122
event.preventDefault()
121123
}
122124

125+
if (stopPropagation) {
126+
event.stopPropagation()
127+
}
128+
123129
if (
124130
ignoredTags.map((tag) => tag.toUpperCase()).indexOf((event.target as HTMLElement).tagName.toUpperCase()) >
125131
-1 ||
@@ -156,14 +162,16 @@ const UseRegisterShortcutProvider = ({
156162
}, [])
157163

158164
useEffect(() => {
159-
window.addEventListener('keydown', handleKeydownEvent)
160-
window.addEventListener('keyup', handleKeyupEvent)
161-
window.addEventListener('blur', handleBlur)
165+
const target = eventListenerTargetRef?.current ?? window
166+
167+
target.addEventListener('keydown', handleKeydownEvent)
168+
target.addEventListener('keyup', handleKeyupEvent)
169+
target.addEventListener('blur', handleBlur)
162170

163171
return () => {
164-
window.removeEventListener('keydown', handleKeydownEvent)
165-
window.removeEventListener('keyup', handleKeyupEvent)
166-
window.removeEventListener('blur', handleBlur)
172+
target.removeEventListener('keydown', handleKeydownEvent)
173+
target.removeEventListener('keyup', handleKeyupEvent)
174+
target.removeEventListener('blur', handleBlur)
167175

168176
if (keyDownTimeoutRef.current > -1) {
169177
clearTimeout(keyDownTimeoutRef.current)

src/Common/Hooks/UseRegisterShortcut/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,13 @@ export interface UseRegisterShortcutProviderType {
9393
* If true, call preventDefault on the event
9494
*/
9595
preventDefault?: boolean
96+
/**
97+
* If true, call stopPropagation on the event
98+
*/
99+
stopPropagation?: boolean
100+
/**
101+
* The target to which the event listener is attached
102+
* If not provided, the event listener will be attached to window
103+
*/
104+
eventListenerTargetRef?: React.RefObject<HTMLElement>
96105
}

src/Common/Hooks/useUrlFilters/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { SortingOrder } from '../../Constants'
1818

19-
export interface UseUrlFiltersProps<T, K> {
19+
export interface UseUrlFiltersProps<T, K extends {}> {
2020
/**
2121
* The key on which the sorting should be applied
2222
*/
@@ -37,9 +37,9 @@ export interface UseUrlFiltersProps<T, K> {
3737
redirectionMethod?: 'replace' | 'push'
3838
}
3939

40-
export type UpdateSearchParamsOptionsType<T, K = unknown> = Partial<Pick<UseUrlFiltersProps<T, K>, 'redirectionMethod'>>
40+
export type UpdateSearchParamsOptionsType<T, K = {}> = Partial<Pick<UseUrlFiltersProps<T, K>, 'redirectionMethod'>>
4141

42-
export type UseUrlFiltersReturnType<T, K = unknown> = K & {
42+
export type UseUrlFiltersReturnType<T, K = {}> = K & {
4343
/**
4444
* Currently applied page size
4545
*/

src/Common/Hooks/useUrlFilters/useUrlFilters.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { getUrlWithSearchParams } from '@Common/Helper'
2020
import { DEFAULT_BASE_PAGE_SIZE, EXCLUDED_FALSY_VALUES, SortingOrder } from '../../Constants'
2121
import { DEFAULT_PAGE_NUMBER, URL_FILTER_KEYS } from './constants'
2222
import { UpdateSearchParamsOptionsType, UseUrlFiltersProps, UseUrlFiltersReturnType } from './types'
23-
import { setItemInLocalStorageIfKeyExists } from './utils'
23+
import { areAnyAdditionalFiltersApplied, setItemInLocalStorageIfKeyExists } from './utils'
2424

2525
const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_KEYS
2626

@@ -41,7 +41,8 @@ const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_K
4141
* ```
4242
*
4343
*/
44-
const useUrlFilters = <T = string, K = unknown>({
44+
45+
const useUrlFilters = <T = string, K = {}>({
4546
initialSortKey,
4647
parseSearchParams,
4748
localStorageKey,
@@ -220,7 +221,7 @@ const useUrlFilters = <T = string, K = unknown>({
220221
clearFilters,
221222
...parsedParams,
222223
updateSearchParams,
223-
isFilterApplied: !!Object.keys(parsedParams).length || !!searchKey,
224+
isFilterApplied: !!searchKey || areAnyAdditionalFiltersApplied(parsedParams),
224225
}
225226
}
226227

src/Common/Hooks/useUrlFilters/utils.tsx

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

17+
import { isNullOrUndefined } from '@Shared/Helpers'
18+
1719
export const setItemInLocalStorageIfKeyExists = (localStorageKey: string, value: string) => {
1820
if (localStorageKey) {
1921
localStorage.setItem(localStorageKey, value)
2022
}
2123
}
24+
25+
export const areAnyAdditionalFiltersApplied = (parsedParams: Record<string | number, any>) => {
26+
if (!parsedParams || !Object.keys(parsedParams).length) {
27+
return false
28+
}
29+
30+
return Object.keys(parsedParams).some((key) => {
31+
if (isNullOrUndefined(parsedParams[key])) {
32+
return false
33+
}
34+
35+
if (Array.isArray(parsedParams[key])) {
36+
return parsedParams[key].length > 0
37+
}
38+
39+
if (typeof parsedParams[key] === 'string') {
40+
return parsedParams[key].length > 0
41+
}
42+
43+
return true
44+
})
45+
}

src/Common/Tooltip/ShortcutKeyComboTooltipContent.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ const ShortcutKeyComboTooltipContent = ({ text, combo }: TooltipProps['shortcutK
2323
{!!combo?.length && (
2424
<div className="flexbox dc__gap-4 dc__align-items-center flex-wrap">
2525
{combo.map((key) => (
26-
<span key={key} className="shortcut-keys__chip dc__capitalize lh-16 fs-11 fw-5 flex">
26+
// TODO: check styling for this since span was replaced by kbd
27+
<kbd key={key} className="shortcut-keys__chip dc__capitalize lh-16 fs-11 fw-5 flex">
2728
{KEYBOARD_KEYS_MAP[key]}
28-
</span>
29+
</kbd>
2930
))}
3031
</div>
3132
)}

src/Shared/Components/Table/BulkSelectionActionWidget.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useRegisterShortcut } from '@Common/Hooks'
99
import { useEffect } from 'react'
1010
import { BulkSelectionActionWidgetProps } from './types'
1111
import { Button, ButtonComponentType, ButtonStyleType, ButtonVariantType } from '../Button'
12+
import { DRAG_SELECTOR_IDENTIFIER } from './constants'
1213

1314
const BulkSelectionActionWidget = ({
1415
count,
@@ -28,17 +29,17 @@ const BulkSelectionActionWidget = ({
2829

2930
return (
3031
<DraggableWrapper
31-
dragSelector=".drag-selector"
32+
dragSelector={`.${DRAG_SELECTOR_IDENTIFIER}`}
3233
positionVariant={DraggablePositionVariant.PARENT_BOTTOM_CENTER}
3334
zIndex="calc(var(--modal-index) - 1)"
3435
parentRef={parentRef}
3536
>
36-
<div className="dc__separated-flexbox dc__separated-flexbox--gap-8 pt-12 pb-12 pr-12 pl-12 bulk-selection-widget br-8">
37+
<div className="dc__separated-flexbox dc__separated-flexbox--gap-8 p-12 bulk-selection-widget br-8">
3738
<div className="flexbox dc__gap-8">
38-
<DraggableButton dragClassName="drag-selector" />
39+
<DraggableButton dragClassName={DRAG_SELECTOR_IDENTIFIER} />
3940

4041
<div className="fs-13 lh-20 fw-6 flex dc__gap-12">
41-
<span className="flex dc__gap-2 bcb-5 cn-0 br-4 pr-6 pl-6">{count}</span>
42+
<span className="flex dc__gap-2 bcb-5 text__white br-4 px-6">{count}</span>
4243
<span className="cn-9">Selected</span>
4344
</div>
4445
</div>
@@ -54,7 +55,7 @@ const BulkSelectionActionWidget = ({
5455
ariaLabel="Clear selection(s)"
5556
size={ComponentSizeType.small}
5657
onClick={handleClearBulkSelection}
57-
showAriaLabelInTippy
58+
showAriaLabelInTippy={false}
5859
/>
5960
</div>
6061
</DraggableWrapper>

0 commit comments

Comments
 (0)