@devtron-labs/devtron-fe-common-lib 0.0.55 → 0.0.56

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/.eslintrc.js +16 -84
  2. package/.github/workflows/release-package.yml +3 -2
  3. package/dist/Common/Common.service.d.ts +2 -2
  4. package/dist/Common/Constants.d.ts +8 -0
  5. package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
  6. package/dist/Common/CustomInput/Types.d.ts +1 -0
  7. package/dist/Common/DebouncedSearch/DebouncedSearch.d.ts +0 -2
  8. package/dist/Common/EmptyState/GenericEmptyState.d.ts +1 -1
  9. package/dist/Common/Helper.d.ts +0 -4
  10. package/dist/Common/Types.d.ts +3 -15
  11. package/dist/Common/index.d.ts +0 -2
  12. package/dist/index.js +214 -430
  13. package/package.json +2 -19
  14. package/src/Common/Constants.ts +9 -0
  15. package/src/Common/CustomInput/CustomInput.tsx +3 -2
  16. package/src/Common/CustomInput/Types.ts +1 -0
  17. package/src/Common/DebouncedSearch/DebouncedSearch.tsx +0 -2
  18. package/src/Common/EmptyState/GenericEmptyState.tsx +45 -13
  19. package/src/Common/Helper.tsx +0 -15
  20. package/src/Common/Types.ts +3 -15
  21. package/src/Common/index.ts +0 -2
  22. package/.eslintignore +0 -96
  23. package/.github/pull_request_template.md +0 -25
  24. package/.github/workflows/ci.yml +0 -31
  25. package/.husky/pre-commit +0 -5
  26. package/.lintstagedrc +0 -3
  27. package/.nvmrc +0 -1
  28. package/dist/Common/Pagination/PageSizeSelector.d.ts +0 -4
  29. package/dist/Common/Pagination/Pagination.d.ts +0 -5
  30. package/dist/Common/Pagination/constants.d.ts +0 -5
  31. package/dist/Common/Pagination/index.d.ts +0 -1
  32. package/dist/Common/Pagination/types.d.ts +0 -51
  33. package/dist/Common/Pagination/utils.d.ts +0 -6
  34. package/dist/Common/SearchBar/SearchBar.component.d.ts +0 -39
  35. package/dist/Common/SearchBar/index.d.ts +0 -2
  36. package/dist/Common/SearchBar/types.d.ts +0 -35
  37. package/src/Assets/Icon/ic-search.svg +0 -6
  38. package/src/Common/Pagination/PageSizeSelector.tsx +0 -78
  39. package/src/Common/Pagination/Pagination.tsx +0 -127
  40. package/src/Common/Pagination/constants.ts +0 -6
  41. package/src/Common/Pagination/index.tsx +0 -3
  42. package/src/Common/Pagination/pagination.scss +0 -123
  43. package/src/Common/Pagination/types.ts +0 -55
  44. package/src/Common/Pagination/utils.tsx +0 -24
  45. package/src/Common/SearchBar/SearchBar.component.tsx +0 -120
  46. package/src/Common/SearchBar/index.ts +0 -2
  47. package/src/Common/SearchBar/searchBar.scss +0 -31
  48. package/src/Common/SearchBar/types.ts +0 -36
@@ -1,127 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
- import PageSizeSelector from './PageSizeSelector'
3
- import { Page, PageValueItemProps, PaginationProps } from './types'
4
- import { createPageArr } from './utils'
5
- import './pagination.scss'
6
-
7
- const PageValueItem = ({ value, isSelected, selectPage }: PageValueItemProps) => {
8
- const classes = isSelected ? 'page__button page__button--selected' : 'page__button'
9
- const handlePageSelection = () => {
10
- selectPage(value)
11
- }
12
-
13
- return (
14
- <li className="page">
15
- <button className={classes} onClick={handlePageSelection} type="button">
16
- {value}
17
- </button>
18
- </li>
19
- )
20
- }
21
-
22
- // NOTE: This component will heavily benefit from data normalization
23
- const Pagination = ({
24
- size,
25
- pageSize,
26
- offset,
27
- changePage,
28
- changePageSize,
29
- isPageSizeFix,
30
- pageSizeOptions,
31
- rootClassName,
32
- }: PaginationProps) => {
33
- const [pages, setPages] = useState<Page[]>([])
34
-
35
- useEffect(() => {
36
- const _pages = createPageArr({ size, pageSize, selectedPageNo: 1 })
37
- setPages(_pages)
38
- }, [size, pageSize])
39
-
40
- useEffect(() => {
41
- const selectedPageNo = 1 + Math.floor(offset / pageSize)
42
- const _pages = createPageArr({ size, pageSize, selectedPageNo })
43
- setPages(_pages)
44
- }, [offset])
45
-
46
- const selectPage = (selectedPageNo: number): void => {
47
- const _pages = createPageArr({ size, pageSize, selectedPageNo })
48
- setPages(_pages)
49
- changePage(selectedPageNo)
50
- }
51
-
52
- const selectPreviousPage = (): void => {
53
- const currPage = pages.find((page) => page.selected)
54
- const selectedPageNo = currPage.value - 1
55
- selectPage(selectedPageNo)
56
- }
57
-
58
- const selectNextPage = (): void => {
59
- const currPage = pages.find((page) => page.selected)
60
- const selectedPageNo = currPage.value + 1
61
- selectPage(selectedPageNo)
62
- }
63
-
64
- const lastPageNo = offset + pageSize < size ? offset + pageSize : size
65
- const pageNoIndex = pages.findIndex((page) => page.selected)
66
- const visiblePages = pages.filter((page) => page.isVisible)
67
- return (
68
- // TODO: Remove pagination-wrapper from dashboard
69
- <div className={rootClassName || ''}>
70
- <div className="page-number">
71
- {offset + 1} - {lastPageNo} of {size}
72
- </div>
73
-
74
- <ul className="pagination">
75
- <li className="page">
76
- <button
77
- className="page__button page__button--icon"
78
- disabled={!pageNoIndex}
79
- onClick={selectPreviousPage}
80
- type="button"
81
- aria-label="Previous page"
82
- >
83
- <span className="left-icon">
84
- <i className="fa fa-chevron-left" />
85
- </span>
86
- </button>
87
- </li>
88
-
89
- {visiblePages.map((page) => (
90
- <PageValueItem
91
- value={page.value}
92
- isSelected={page.selected}
93
- key={page.value}
94
- selectPage={selectPage}
95
- />
96
- ))}
97
-
98
- <li className="page">
99
- <button
100
- className="page__button page__button--icon"
101
- disabled={pageNoIndex === pages.length - 1}
102
- onClick={selectNextPage}
103
- type="button"
104
- aria-label="Next page"
105
- >
106
- <span className="left-icon">
107
- <i className="fa fa-chevron-right" />
108
- </span>
109
- </button>
110
- </li>
111
- </ul>
112
-
113
- {!isPageSizeFix && (
114
- <div className="select">
115
- <span className="select__placeholder">Rows per page</span>
116
- <PageSizeSelector
117
- pageSizeOptions={pageSizeOptions}
118
- pageSize={pageSize}
119
- changePageSize={changePageSize}
120
- />
121
- </div>
122
- )}
123
- </div>
124
- )
125
- }
126
-
127
- export default Pagination
@@ -1,6 +0,0 @@
1
- export const VISIBLE_PAGES_LIMIT = 5
2
- export const FALLBACK_PAGE_SIZE_OPTIONS = [
3
- { value: 20, selected: true },
4
- { value: 40, selected: false },
5
- { value: 50, selected: false },
6
- ]
@@ -1,3 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
- // Disabling since might need to export types as well
3
- export { default as Pagination } from './Pagination'
@@ -1,123 +0,0 @@
1
- .pagination-wrapper {
2
- display: flex;
3
- align-items: center;
4
- padding: 0px 24px;
5
- justify-content: space-between;
6
- margin: 0px;
7
- background-color: var(--white);
8
- }
9
-
10
- .pagination {
11
- margin-top: 16px;
12
- margin-bottom: 16px;
13
- padding: 0px;
14
- }
15
-
16
- .select {
17
- display: flex;
18
- align-items: center;
19
- position: relative;
20
- }
21
-
22
- .select__placeholder {
23
- font-size: 12px;
24
- font-weight: normal;
25
- font-style: normal;
26
- font-stretch: normal;
27
- line-height: 1.5;
28
- letter-spacing: normal;
29
- color: var(--N700);
30
- margin-right: 8px;
31
- }
32
-
33
- .pagination__select-menu {
34
- padding: 0px;
35
- list-style: none;
36
- overflow: hidden;
37
- border: solid 1px var(--N200);
38
- border-radius: 4px;
39
- width: 64px;
40
- position: absolute;
41
- bottom: 31px;
42
- background-color: var(--white);;
43
- }
44
-
45
- .select__button {
46
- width: 64px;
47
- background-color: transparent;
48
- border-radius: 4px;
49
- border: solid 1px var(--N200);
50
- padding: 5px 10px;
51
- text-align: left;
52
- }
53
-
54
- .select__item {
55
- padding: 5px 10px;
56
- cursor: pointer;
57
- }
58
-
59
- .select__icon {
60
- margin-left: 18px;
61
- }
62
-
63
- .page {
64
- margin: 0px 8px;
65
- display: inline-block;
66
- }
67
-
68
- .page-number {
69
- font-size: 12px;
70
- font-weight: normal;
71
- font-style: normal;
72
- font-stretch: normal;
73
- line-height: 1.5;
74
- letter-spacing: normal;
75
- color: var(--N700);
76
- }
77
-
78
- .page__button {
79
- width: 24px;
80
- height: 24px;
81
- border-radius: 8px;
82
- color: var(--B500);
83
- background-color: var(--white);
84
- padding: 0px;
85
- user-select: none;
86
- }
87
-
88
- .page__button--icon {
89
- background-color: var(--white);
90
- color: var(--B500);
91
- }
92
-
93
- /* MODIFIERS */
94
-
95
- .page__button--selected {
96
- color: var(--white);
97
- background-color: var(--B500);
98
- }
99
-
100
- /* States and Selectorys */
101
-
102
- .page__button:disabled {
103
- opacity: 0.5;
104
- }
105
-
106
- .select__item:hover {
107
- background-color: var(--N50);
108
- }
109
-
110
- .page__button:hover ~ :disabled {
111
- background-color: var(--B100);
112
- }
113
-
114
- .page__button--selected:hover {
115
- color: var(--white);
116
- background-color: var(--B500);
117
- }
118
-
119
- @media (min-width: 1024px) {
120
- .pagination {
121
- margin: 16px auto;
122
- }
123
- }
@@ -1,55 +0,0 @@
1
- export interface PageSizeOption {
2
- value: number
3
- selected: boolean
4
- }
5
- export interface PaginationProps {
6
- /**
7
- * number of items
8
- */
9
- size: number
10
- /**
11
- * pageSize
12
- */
13
- pageSize: number
14
- offset: number
15
- changePage: (pageNo: number) => void
16
- changePageSize?: (pageSize: number) => void
17
- /**
18
- * If true will not show page size selector
19
- */
20
- isPageSizeFix?: boolean
21
- /**
22
- * If given would show these options in page size selector else [20,40,50] with 20 as selected
23
- */
24
- pageSizeOptions?: PageSizeOption[]
25
- /**
26
- * class for wrapper
27
- */
28
- rootClassName?: string
29
- }
30
-
31
- export interface Page {
32
- value: number
33
- selected: boolean
34
- isVisible: boolean
35
- }
36
-
37
- export interface CreatePageArrType extends Pick<PaginationProps, 'size' | 'pageSize'> {
38
- selectedPageNo: number
39
- }
40
-
41
- export interface PageSizeSelectorProps
42
- extends Pick<PaginationProps, 'pageSizeOptions' | 'pageSize' | 'changePageSize'> {}
43
-
44
- export interface PageSizeItemsProps extends Pick<PageSizeSelectorProps, 'changePageSize'> {
45
- optionValue: PageSizeOption['value']
46
- options: PageSizeOption[]
47
- setOptions: React.Dispatch<React.SetStateAction<PageSizeOption[]>>
48
- handleCloseDropdown: () => void
49
- }
50
-
51
- export interface PageValueItemProps {
52
- value: PageSizeOption['value']
53
- isSelected: PageSizeOption['selected']
54
- selectPage: (selectedPageNo: number) => void
55
- }
@@ -1,24 +0,0 @@
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
@@ -1,120 +0,0 @@
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
@@ -1,2 +0,0 @@
1
- export { default as SearchBar } from './SearchBar.component'
2
- export type { SearchBarProps } from './types'
@@ -1,31 +0,0 @@
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
- }
@@ -1,36 +0,0 @@
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
- }