@devtron-labs/devtron-fe-common-lib 0.0.56 → 0.0.58-beta-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.eslintignore +96 -0
  2. package/.eslintrc.js +84 -16
  3. package/.github/pull_request_template.md +25 -0
  4. package/.github/workflows/ci.yml +31 -0
  5. package/.github/workflows/release-package.yml +2 -3
  6. package/.husky/pre-commit +5 -0
  7. package/.lintstagedrc +3 -0
  8. package/.nvmrc +1 -0
  9. package/dist/Common/Common.service.d.ts +2 -2
  10. package/dist/Common/Constants.d.ts +0 -8
  11. package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
  12. package/dist/Common/CustomInput/Types.d.ts +0 -1
  13. package/dist/Common/DebouncedSearch/DebouncedSearch.d.ts +2 -0
  14. package/dist/Common/EmptyState/GenericEmptyState.d.ts +1 -1
  15. package/dist/Common/Helper.d.ts +8 -1
  16. package/dist/Common/Pagination/PageSizeSelector.d.ts +4 -0
  17. package/dist/Common/Pagination/Pagination.d.ts +5 -0
  18. package/dist/Common/Pagination/constants.d.ts +5 -0
  19. package/dist/Common/Pagination/index.d.ts +1 -0
  20. package/dist/Common/Pagination/types.d.ts +51 -0
  21. package/dist/Common/Pagination/utils.d.ts +6 -0
  22. package/dist/Common/SearchBar/SearchBar.component.d.ts +39 -0
  23. package/dist/Common/SearchBar/index.d.ts +2 -0
  24. package/dist/Common/SearchBar/types.d.ts +35 -0
  25. package/dist/Common/Types.d.ts +15 -3
  26. package/dist/Common/index.d.ts +2 -0
  27. package/dist/index.js +462 -229
  28. package/package.json +19 -2
  29. package/src/Assets/Icon/ic-search.svg +6 -0
  30. package/src/Common/Constants.ts +0 -9
  31. package/src/Common/CustomInput/CustomInput.tsx +2 -3
  32. package/src/Common/CustomInput/Types.ts +0 -1
  33. package/src/Common/DebouncedSearch/DebouncedSearch.tsx +2 -0
  34. package/src/Common/EmptyState/GenericEmptyState.tsx +13 -45
  35. package/src/Common/Helper.tsx +45 -16
  36. package/src/Common/Pagination/PageSizeSelector.tsx +78 -0
  37. package/src/Common/Pagination/Pagination.tsx +127 -0
  38. package/src/Common/Pagination/constants.ts +6 -0
  39. package/src/Common/Pagination/index.tsx +3 -0
  40. package/src/Common/Pagination/pagination.scss +123 -0
  41. package/src/Common/Pagination/types.ts +55 -0
  42. package/src/Common/Pagination/utils.tsx +24 -0
  43. package/src/Common/SearchBar/SearchBar.component.tsx +120 -0
  44. package/src/Common/SearchBar/index.ts +2 -0
  45. package/src/Common/SearchBar/searchBar.scss +31 -0
  46. package/src/Common/SearchBar/types.ts +36 -0
  47. package/src/Common/Types.ts +15 -3
  48. package/src/Common/index.ts +2 -0
@@ -0,0 +1,24 @@
1
+ import { CreatePageArrType, Page, PageSizeOption } from './types'
2
+ import { FALLBACK_PAGE_SIZE_OPTIONS, VISIBLE_PAGES_LIMIT } from './constants'
3
+
4
+ /**
5
+ * Returns an array of pages numbers and whether they are selected, visible or not
6
+ */
7
+ export const createPageArr = ({ size, pageSize, selectedPageNo }: CreatePageArrType): Page[] => {
8
+ const arr = []
9
+ const numberOfPages = Math.ceil(size / pageSize)
10
+ // we are showing 2 numbers before and after the selected page, so computing the lower and upper bounds
11
+ const lowerBound = selectedPageNo - 2 < 1 ? 1 : selectedPageNo - 2
12
+ const upperBound = selectedPageNo + 2 > numberOfPages ? numberOfPages : selectedPageNo + 2
13
+ for (let i = 1; i <= numberOfPages; i++) {
14
+ arr.push({
15
+ value: i,
16
+ selected: i === selectedPageNo,
17
+ isVisible: upperBound - VISIBLE_PAGES_LIMIT < i && i < lowerBound + VISIBLE_PAGES_LIMIT,
18
+ })
19
+ }
20
+ return arr
21
+ }
22
+
23
+ export const getDefaultPageValueOptions = (pageSizeOptions: PageSizeOption[]): PageSizeOption[] =>
24
+ pageSizeOptions?.length ? pageSizeOptions : FALLBACK_PAGE_SIZE_OPTIONS
@@ -0,0 +1,120 @@
1
+ import { ChangeEvent, useCallback, useRef, useState, KeyboardEvent } from 'react'
2
+ import { ReactComponent as Search } from '../../Assets/Icon/ic-search.svg'
3
+ import { ReactComponent as Clear } from '../../Assets/Icon/ic-error-cross.svg'
4
+ import { SearchBarProps } from './types'
5
+ import './searchBar.scss'
6
+ import { debounce } from '../Helper'
7
+
8
+ /**
9
+ * Generic search input component with support for enter based and debounced search
10
+ * Note: The component is uncontrolled
11
+ *
12
+ * @example Usage with default debounced search
13
+ * ```tsx
14
+ * <SearchBar handleSearchChange={triggerSearchApi} shouldDebounce />
15
+ * ```
16
+ *
17
+ * @example Initial search text
18
+ * ```tsx
19
+ * <SearchBar initialSearchText="Keyword" />
20
+ * ```
21
+ *
22
+ * @example Custom width
23
+ * ```tsx
24
+ * <SearchBar containerClassName="w-300" />
25
+ * ```
26
+ *
27
+ * @example Trigger search on enter key press
28
+ * ```tsx
29
+ * <SearchBar handleEnter={triggerSearchApi} />
30
+ * ```
31
+ *
32
+ * @example Custom timeout for debounced search
33
+ * ```tsx
34
+ * <SearchBar handleSearchChange={triggerSearchApi} shouldDebounce debounceTimeout={500} />
35
+ * ```
36
+ *
37
+ * @example Placeholder for the search
38
+ * ```tsx
39
+ * <SearchBar inputProps={{ placeholder: 'Enter search text' }} />
40
+ * ```
41
+ */
42
+ const SearchBar = ({
43
+ initialSearchText = '',
44
+ handleSearchChange = () => {},
45
+ handleEnter = () => {},
46
+ inputProps = {},
47
+ containerClassName,
48
+ shouldDebounce = false,
49
+ debounceTimeout = 300,
50
+ }: SearchBarProps) => {
51
+ const [showClearButton, setShowClearButton] = useState(!!initialSearchText)
52
+ const inputRef = useRef<HTMLInputElement>()
53
+ const debouncedSearchChange = useCallback(debounce(handleSearchChange, debounceTimeout), [
54
+ handleSearchChange,
55
+ debounceTimeout,
56
+ ])
57
+
58
+ const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
59
+ const { value } = e.target
60
+ setShowClearButton(!!value)
61
+ if (shouldDebounce) {
62
+ debouncedSearchChange(value)
63
+ } else {
64
+ handleSearchChange(value)
65
+ }
66
+ }
67
+
68
+ const _applySearch = (value: string) => {
69
+ handleSearchChange(value)
70
+ handleEnter(value)
71
+ }
72
+
73
+ const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
74
+ const { key } = e
75
+
76
+ if (key === 'Enter') {
77
+ const inputTarget = e.target as HTMLInputElement
78
+ const value = inputTarget.value.trim()
79
+ _applySearch(value)
80
+ }
81
+ }
82
+
83
+ const clearSearch = () => {
84
+ inputRef.current.value = ''
85
+ _applySearch('')
86
+ }
87
+
88
+ return (
89
+ <div className={containerClassName}>
90
+ <div className="search-bar bcn-0 dc__block w-100 min-w-200 dc__position-rel en-2 bw-1 br-4 h-32">
91
+ <Search className="search-bar__icon dc__position-abs icon-color-n6 icon-dim-18" />
92
+ <input
93
+ placeholder="Search"
94
+ data-testid="search-bar"
95
+ type="text"
96
+ {...inputProps}
97
+ defaultValue={initialSearchText}
98
+ className={`search-bar__input bcn-0 dc__position-abs w-100 h-100 br-4 dc__no-border pt-6 pr-10 pb-6 pl-30 fs-13 lh-20 fw-4 cn-9 placeholder-cn5 ${
99
+ showClearButton ? 'pr-30' : 'pr-10'
100
+ }`}
101
+ onChange={handleChange}
102
+ onKeyDown={handleKeyDown}
103
+ ref={inputRef}
104
+ />
105
+ {showClearButton && (
106
+ <button
107
+ className="flex search-bar__clear-button dc__position-abs dc__transparent mt-0 mb-0 mr-5 ml-5"
108
+ type="button"
109
+ onClick={clearSearch}
110
+ aria-label="Clear search"
111
+ >
112
+ <Clear className="icon-dim-18 icon-n4 dc__vertical-align-middle" />
113
+ </button>
114
+ )}
115
+ </div>
116
+ </div>
117
+ )
118
+ }
119
+
120
+ export default SearchBar
@@ -0,0 +1,2 @@
1
+ export { default as SearchBar } from './SearchBar.component'
2
+ export type { SearchBarProps } from './types'
@@ -0,0 +1,31 @@
1
+ .search-bar {
2
+
3
+ &:focus,
4
+ &:focus-within {
5
+ outline: none;
6
+ border: solid 1px var(--B500);
7
+ }
8
+
9
+ &__input {
10
+
11
+ &:focus,
12
+ &:focus-visible {
13
+ border: none;
14
+ outline: none;
15
+ }
16
+ }
17
+
18
+ &__icon {
19
+ z-index: 1;
20
+ top: 50%;
21
+ left: 8px;
22
+ transform: translateY(-50%);
23
+ }
24
+
25
+ &__clear-button {
26
+ right: 0;
27
+ top: 50%;
28
+ transform: translateY(-50%);
29
+ z-index: 1;
30
+ }
31
+ }
@@ -0,0 +1,36 @@
1
+ import { InputHTMLAttributes } from 'react'
2
+
3
+ export interface SearchBarProps {
4
+ /**
5
+ * Initial search text
6
+ *
7
+ * @default ''
8
+ */
9
+ initialSearchText?: string
10
+ /**
11
+ * Search handler for the search input
12
+ */
13
+ handleSearchChange?: (searchText: string) => void
14
+ /**
15
+ * Enter event handler for the search input
16
+ */
17
+ handleEnter?: (searchText: string) => void
18
+ /**
19
+ * Input props for the search input
20
+ */
21
+ inputProps?: InputHTMLAttributes<HTMLInputElement>
22
+ /**
23
+ * Class name for the container; can be used for handling width
24
+ */
25
+ containerClassName?: string
26
+ /**
27
+ * If true, the change handler would be triggered with debounce
28
+ *
29
+ * @default false
30
+ */
31
+ shouldDebounce?: boolean
32
+ /**
33
+ * Timeout for the debounce handler to be triggered
34
+ */
35
+ debounceTimeout?: number
36
+ }
@@ -3,10 +3,23 @@ import { Placement } from 'tippy.js'
3
3
  import { ImageComment, ReleaseTag } from './ImageTags.Types'
4
4
  import { DockerConfigOverrideType, TaskErrorObj } from '.'
5
5
 
6
- export interface ResponseType {
6
+ /**
7
+ * Generic response type object with support for overriding the result type
8
+ *
9
+ * @example Default usage:
10
+ * ```ts
11
+ * interface UserResponse extends ResponseType {}
12
+ * ```
13
+ *
14
+ * @example Override the response type:
15
+ * ```ts
16
+ * interface UserResponse extends ResponseType<Record<string, string>> {}
17
+ * ```
18
+ */
19
+ export interface ResponseType<T = any> {
7
20
  code: number
8
21
  status: string
9
- result?: any
22
+ result?: T
10
23
  errors?: any
11
24
  }
12
25
 
@@ -94,7 +107,6 @@ export interface GenericEmptyStateType {
94
107
  imageClassName?: string
95
108
  children?: ReactNode
96
109
  noImage?: boolean
97
- imageStyles?: CSSProperties
98
110
  /**
99
111
  * @default 'column'
100
112
  */
@@ -26,6 +26,7 @@ export * from './Common.service'
26
26
  export * from './Checkbox'
27
27
  export { default as EmptyState } from './EmptyState/EmptyState'
28
28
  export { default as GenericEmptyState } from './EmptyState/GenericEmptyState'
29
+ export * from './SearchBar'
29
30
  export { default as Toggle } from './Toggle/Toggle'
30
31
  export { default as ScanVulnerabilitiesTable } from './Security/ScanVulnerabilitiesTable'
31
32
  export { default as StyledRadioGroup } from './RadioGroup/RadioGroup'
@@ -46,3 +47,4 @@ export { default as ChartVersionAndTypeSelector } from './ChartVersionAndTypeSel
46
47
  export * from './AddCDButton'
47
48
  export * from './CustomInput'
48
49
  export * from './DraggableWrapper'
50
+ export * from './Pagination'