Skip to content

Commit 4e820fa

Browse files
committed
Merge branch 'develop' into fix/release-css
2 parents faf3e9e + 3d8aa83 commit 4e820fa

21 files changed

+1436
-34
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": "1.10.6",
3+
"version": "1.10.9",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Common/Hooks/UseRegisterShortcut/types.ts

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

1717
import { IS_PLATFORM_MAC_OS } from '@Common/Constants'
1818

19+
// NOTE: check this link for more info on keyboard keys: https://w3c.github.io/uievents-key/
1920
export const KEYBOARD_KEYS_MAP = {
2021
Control: 'Ctrl',
2122
Shift: '⇧',
@@ -25,8 +26,22 @@ export const KEYBOARD_KEYS_MAP = {
2526
E: 'E',
2627
R: 'R',
2728
K: 'K',
29+
X: 'X',
30+
A: 'A',
2831
Escape: 'Esc',
2932
Enter: '↩',
33+
ArrowLeft: '←',
34+
ArrowRight: '→',
35+
ArrowUp: '↑',
36+
ArrowDown: '↓',
37+
PageUp: 'PgUp',
38+
PageDown: 'PgDn',
39+
Home: 'Home',
40+
End: 'End',
41+
Backspace: '⌫',
42+
Delete: '⌦',
43+
'.': '.',
44+
Space: 'Space',
3045
} as const
3146

3247
export type SupportedKeyboardKeysType = keyof typeof KEYBOARD_KEYS_MAP

src/Common/Hooks/useStateFilters/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface UseStateFiltersReturnType<T>
3131
| 'pageSize'
3232
| 'searchKey'
3333
| 'handleSearch'
34+
| 'isFilterApplied'
3435
> {}
3536

3637
export interface PaginationType<T> extends Pick<UseUrlFiltersReturnType<T>, 'pageSize'> {

src/Common/Hooks/useStateFilters/useStateFilters.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const useStateFilters = <T = string,>({
116116
changePage,
117117
changePageSize,
118118
offset,
119+
isFilterApplied: !!searchKey,
119120
}
120121
}
121122

src/Common/Hooks/useUrlFilters/types.ts

Lines changed: 4 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
*/
@@ -86,4 +86,5 @@ export type UseUrlFiltersReturnType<T, K = unknown> = K & {
8686
* Update the search params with the passed object
8787
*/
8888
updateSearchParams: (paramsToSerialize: Partial<K>, options?: UpdateSearchParamsOptionsType<T, K>) => void
89+
isFilterApplied: boolean
8990
}

src/Common/Hooks/useUrlFilters/useUrlFilters.ts

Lines changed: 4 additions & 2 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,6 +221,7 @@ const useUrlFilters = <T = string, K = unknown>({
220221
clearFilters,
221222
...parsedParams,
222223
updateSearchParams,
224+
isFilterApplied: !!searchKey || areAnyAdditionalFiltersApplied(parsedParams),
223225
}
224226
}
225227

src/Common/Hooks/useUrlFilters/utils.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,28 @@
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]) || typeof parsedParams[key] === 'string') {
36+
return parsedParams[key].length > 0
37+
}
38+
39+
return true
40+
})
41+
}

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/Button/Button.component.tsx

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

17-
import { ButtonHTMLAttributes, MutableRefObject, PropsWithChildren, useEffect, useRef, useState } from 'react'
18-
import { Link, LinkProps } from 'react-router-dom'
17+
import { MutableRefObject, PropsWithChildren, useEffect, useRef, useState } from 'react'
18+
import { Link } from 'react-router-dom'
1919
import { Progressing } from '@Common/Progressing'
2020
import { Tooltip } from '@Common/Tooltip'
2121
import { TooltipProps } from '@Common/Tooltip/types'
@@ -26,6 +26,7 @@ import './button.scss'
2626

2727
const ButtonElement = ({
2828
component = ButtonComponentType.button,
29+
anchorProps,
2930
linkProps,
3031
buttonProps,
3132
onClick,
@@ -53,26 +54,44 @@ const ButtonElement = ({
5354
elementRef: MutableRefObject<HTMLButtonElement | HTMLAnchorElement>
5455
}
5556
>) => {
57+
// Added the specific class to ensure that the link override is applied
58+
const linkOrAnchorClassName = `${props.className} button__link ${props.disabled ? 'dc__disable-click' : ''}`
59+
5660
if (component === ButtonComponentType.link) {
5761
return (
5862
<Link
5963
{...linkProps}
6064
{...props}
61-
// Added the specific class to ensure that the link override is applied
62-
className={`${props.className} button__link ${props.disabled ? 'dc__disable-click' : ''}`}
63-
onClick={onClick as LinkProps['onClick']}
65+
className={linkOrAnchorClassName}
66+
onClick={onClick as ButtonProps<typeof component>['onClick']}
6467
ref={elementRef as MutableRefObject<HTMLAnchorElement>}
6568
/>
6669
)
6770
}
6871

72+
if (component === ButtonComponentType.anchor) {
73+
return (
74+
<a
75+
target="_blank"
76+
rel="noopener noreferrer"
77+
{...anchorProps}
78+
{...props}
79+
className={linkOrAnchorClassName}
80+
onClick={onClick as ButtonProps<typeof component>['onClick']}
81+
ref={elementRef as MutableRefObject<HTMLAnchorElement>}
82+
>
83+
{props.children}
84+
</a>
85+
)
86+
}
87+
6988
return (
7089
<button
7190
{...buttonProps}
7291
{...props}
7392
// eslint-disable-next-line react/button-has-type
7493
type={buttonProps?.type || 'button'}
75-
onClick={onClick as ButtonHTMLAttributes<HTMLButtonElement>['onClick']}
94+
onClick={onClick as ButtonProps<typeof component>['onClick']}
7695
ref={elementRef as MutableRefObject<HTMLButtonElement>}
7796
/>
7897
)

0 commit comments

Comments
 (0)