@devtron-labs/devtron-fe-common-lib 0.0.61-beta-9 → 0.0.61-beta-10

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 (97) hide show
  1. package/dist/Common/Constants.d.ts +1 -14
  2. package/dist/Common/DraggableWrapper/types.d.ts +1 -4
  3. package/dist/Common/Helper.d.ts +4 -1
  4. package/dist/Common/Hooks/index.d.ts +0 -1
  5. package/dist/Common/Types.d.ts +1 -13
  6. package/dist/Common/index.d.ts +0 -1
  7. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.d.ts +4 -0
  8. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.d.ts +4 -0
  9. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.d.ts +7 -0
  10. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.d.ts +4 -0
  11. package/dist/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.d.ts +4 -0
  12. package/dist/Pages/GlobalConfigurations/BuildInfra/Descriptor.d.ts +4 -0
  13. package/dist/Pages/GlobalConfigurations/BuildInfra/Footer.d.ts +4 -0
  14. package/dist/Pages/GlobalConfigurations/BuildInfra/constants.d.ts +50 -0
  15. package/dist/Pages/GlobalConfigurations/BuildInfra/index.d.ts +7 -0
  16. package/dist/Pages/GlobalConfigurations/BuildInfra/services.d.ts +6 -0
  17. package/dist/Pages/GlobalConfigurations/BuildInfra/types.d.ts +286 -0
  18. package/dist/Pages/GlobalConfigurations/BuildInfra/utils.d.ts +12 -0
  19. package/dist/Pages/GlobalConfigurations/index.d.ts +1 -1
  20. package/dist/Shared/Components/APIResponseHandler/APIResponseHandler.d.ts +4 -0
  21. package/dist/Shared/Components/APIResponseHandler/constants.d.ts +4 -0
  22. package/dist/Shared/Components/APIResponseHandler/index.d.ts +2 -0
  23. package/dist/Shared/Components/APIResponseHandler/types.d.ts +37 -0
  24. package/dist/Shared/Components/BulkSelection/constants.d.ts +1 -0
  25. package/dist/Shared/Components/BulkSelection/types.d.ts +0 -2
  26. package/dist/Shared/Components/ReactSelect/index.d.ts +1 -0
  27. package/dist/Shared/Components/ReactSelect/utils.d.ts +12 -0
  28. package/dist/Shared/Components/index.d.ts +2 -0
  29. package/dist/Shared/Helpers.d.ts +16 -0
  30. package/dist/Shared/index.d.ts +2 -0
  31. package/dist/Shared/validations.d.ts +8 -0
  32. package/dist/index.js +1193 -386
  33. package/package.json +1 -1
  34. package/src/Assets/Icon/ic-cpu.svg +4 -0
  35. package/src/Assets/Icon/ic-memory.svg +3 -0
  36. package/src/Assets/Icon/ic-timer.svg +3 -0
  37. package/src/Common/BreadCrumb/Types.ts +0 -1
  38. package/src/Common/Checkbox.tsx +1 -0
  39. package/src/Common/Constants.ts +3 -18
  40. package/src/Common/CustomInput/CustomInput.tsx +2 -1
  41. package/src/Common/DraggableWrapper/DraggableWrapper.tsx +3 -1
  42. package/src/Common/DraggableWrapper/types.ts +1 -4
  43. package/src/Common/Helper.tsx +31 -24
  44. package/src/Common/Hooks/index.ts +0 -1
  45. package/src/Common/RJSF/utils.ts +2 -0
  46. package/src/Common/SearchBar/searchBar.scss +1 -1
  47. package/src/Common/Types.ts +1 -13
  48. package/src/Common/index.ts +0 -1
  49. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraConfigForm.tsx +128 -0
  50. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraDescriptionField.tsx +44 -0
  51. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormAction.tsx +106 -0
  52. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraFormItem.tsx +55 -0
  53. package/src/Pages/GlobalConfigurations/BuildInfra/BuildInfraProfileNameField.tsx +32 -0
  54. package/src/Pages/GlobalConfigurations/BuildInfra/Descriptor.tsx +45 -0
  55. package/src/Pages/GlobalConfigurations/BuildInfra/Footer.tsx +56 -0
  56. package/src/Pages/GlobalConfigurations/BuildInfra/Readme.md +4 -0
  57. package/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx +139 -0
  58. package/src/Pages/GlobalConfigurations/BuildInfra/index.ts +7 -0
  59. package/src/Pages/GlobalConfigurations/BuildInfra/services.tsx +167 -0
  60. package/src/Pages/GlobalConfigurations/BuildInfra/types.tsx +339 -0
  61. package/src/Pages/GlobalConfigurations/BuildInfra/utils.tsx +507 -0
  62. package/src/Pages/GlobalConfigurations/index.ts +1 -1
  63. package/src/Shared/Components/APIResponseHandler/APIResponseHandler.tsx +41 -0
  64. package/src/Shared/Components/APIResponseHandler/constants.tsx +5 -0
  65. package/src/Shared/Components/APIResponseHandler/index.ts +2 -0
  66. package/src/Shared/Components/APIResponseHandler/types.tsx +39 -0
  67. package/src/Shared/Components/BulkSelection/BulkSelection.tsx +2 -2
  68. package/src/Shared/Components/BulkSelection/BulkSelectionDropdownItems.tsx +3 -1
  69. package/src/Shared/Components/BulkSelection/BulkSelectionProvider.tsx +17 -17
  70. package/src/Shared/Components/BulkSelection/constants.tsx +1 -0
  71. package/src/Shared/Components/BulkSelection/types.tsx +0 -2
  72. package/src/Shared/Components/ReactSelect/index.ts +1 -0
  73. package/src/Shared/Components/ReactSelect/utils.tsx +97 -0
  74. package/src/Shared/Components/index.ts +2 -0
  75. package/src/Shared/Helpers.tsx +29 -0
  76. package/src/Shared/index.ts +2 -0
  77. package/src/Shared/validations.tsx +130 -0
  78. package/dist/Common/Hooks/useUrlFilters/constants.d.ts +0 -8
  79. package/dist/Common/Hooks/useUrlFilters/index.d.ts +0 -2
  80. package/dist/Common/Hooks/useUrlFilters/types.d.ts +0 -19
  81. package/dist/Common/Hooks/useUrlFilters/useUrlFilters.d.ts +0 -20
  82. package/dist/Common/SortableTableHeaderCell/SortableTableHeaderCell.d.ts +0 -18
  83. package/dist/Common/SortableTableHeaderCell/index.d.ts +0 -2
  84. package/dist/Common/SortableTableHeaderCell/types.d.ts +0 -25
  85. package/dist/Pages/GlobalConfigurations/Authorization/constants.d.ts +0 -15
  86. package/dist/Pages/GlobalConfigurations/Authorization/index.d.ts +0 -1
  87. package/src/Assets/Icon/ic-arrow-up-down.svg +0 -3
  88. package/src/Assets/Icon/ic-sort-arrow-down.svg +0 -3
  89. package/src/Common/Hooks/useUrlFilters/constants.ts +0 -9
  90. package/src/Common/Hooks/useUrlFilters/index.ts +0 -2
  91. package/src/Common/Hooks/useUrlFilters/types.ts +0 -21
  92. package/src/Common/Hooks/useUrlFilters/useUrlFilters.ts +0 -121
  93. package/src/Common/SortableTableHeaderCell/SortableTableHeaderCell.tsx +0 -44
  94. package/src/Common/SortableTableHeaderCell/index.ts +0 -2
  95. package/src/Common/SortableTableHeaderCell/types.ts +0 -26
  96. package/src/Pages/GlobalConfigurations/Authorization/constants.ts +0 -16
  97. package/src/Pages/GlobalConfigurations/Authorization/index.ts +0 -1
@@ -1,5 +1,11 @@
1
1
  import { createContext, useContext, useMemo, useState } from 'react'
2
- import { BULK_SELECTION_CONTEXT_ERROR, SELECT_ALL_ACROSS_PAGES_LOCATOR, getInvalidActionMessage } from './constants'
2
+ import { toast } from 'react-toastify'
3
+ import {
4
+ BULK_SELECTION_CONTEXT_ERROR,
5
+ CLEAR_SELECTIONS_WARNING,
6
+ SELECT_ALL_ACROSS_PAGES_LOCATOR,
7
+ getInvalidActionMessage,
8
+ } from './constants'
3
9
  import {
4
10
  BulkSelectionEvents,
5
11
  GetBulkSelectionCheckboxValuesType,
@@ -16,8 +22,6 @@ const BulkSelectionContext = createContext<UseBulkSelectionReturnType<any>>({
16
22
  handleBulkSelection: noop,
17
23
  isChecked: false,
18
24
  checkboxValue: CHECKBOX_VALUE.CHECKED,
19
- isBulkSelectionApplied: false,
20
- getSelectedIdentifiersCount: noop,
21
25
  })
22
26
 
23
27
  export const useBulkSelection = <T,>() => {
@@ -35,10 +39,6 @@ export const BulkSelectionProvider = <T,>({
35
39
  }: UseBulkSelectionProps<T>) => {
36
40
  const [selectedIdentifiers, setSelectedIdentifiers] = useState<T>({} as T)
37
41
 
38
- const isBulkSelectionApplied = selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]
39
-
40
- const getSelectedIdentifiersCount = () => Object.keys(selectedIdentifiers).length
41
-
42
42
  const setIdentifiersAfterClear = (newIdentifiers: T, selectedIds: (number | string)[]) => {
43
43
  const _newIdentifiers = JSON.parse(JSON.stringify(newIdentifiers))
44
44
  selectedIds.forEach((id) => {
@@ -50,7 +50,7 @@ export const BulkSelectionProvider = <T,>({
50
50
  const setIdentifiersAfterPageSelection = (baseObject: T) => {
51
51
  const _selectedIdentifiers = JSON.parse(JSON.stringify(selectedIdentifiers))
52
52
  // removing bulk selection across pages if present
53
- if (isBulkSelectionApplied) {
53
+ if (_selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]) {
54
54
  delete _selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]
55
55
  }
56
56
 
@@ -70,6 +70,7 @@ export const BulkSelectionProvider = <T,>({
70
70
  break
71
71
 
72
72
  case BulkSelectionEvents.CLEAR_IDENTIFIERS_AFTER_ACROSS_SELECTION: {
73
+ toast.info(CLEAR_SELECTIONS_WARNING)
73
74
  setIdentifiersAfterClear(identifiers, selectedIds)
74
75
  break
75
76
  }
@@ -80,13 +81,10 @@ export const BulkSelectionProvider = <T,>({
80
81
  }
81
82
 
82
83
  case BulkSelectionEvents.SELECT_ALL_ACROSS_PAGES: {
83
- if (isBulkSelectionApplied) {
84
+ if (selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]) {
84
85
  return
85
86
  }
86
- const selectedIdentifiersLength = getSelectedIdentifiersCount()
87
- // This is for showing a modal dialog if applicable to confirm if bulk selection is to be applied
88
- // Do note that the 'getSelectAllDialogStatus' should be called after the length check explicitly
89
- // otherwise the modal will open each time
87
+ const selectedIdentifiersLength = Object.keys(selectedIdentifiers).length
90
88
  if (selectedIdentifiersLength > 0 && getSelectAllDialogStatus() === SelectAllDialogStatus.OPEN) {
91
89
  return
92
90
  }
@@ -104,6 +102,10 @@ export const BulkSelectionProvider = <T,>({
104
102
  break
105
103
 
106
104
  case BulkSelectionEvents.SELECT_ALL_ON_PAGE: {
105
+ if (selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]) {
106
+ toast.info(CLEAR_SELECTIONS_WARNING)
107
+ }
108
+
107
109
  setIdentifiersAfterPageSelection(identifiers)
108
110
  break
109
111
  }
@@ -128,7 +130,7 @@ export const BulkSelectionProvider = <T,>({
128
130
  }
129
131
 
130
132
  // if selectedIdentifiers contains select all across pages locator then it means all are selected
131
- if (isBulkSelectionApplied) {
133
+ if (selectedIdentifiers[SELECT_ALL_ACROSS_PAGES_LOCATOR]) {
132
134
  return {
133
135
  isChecked: true,
134
136
  checkboxValue: CHECKBOX_VALUE.BULK_CHECKED,
@@ -161,10 +163,8 @@ export const BulkSelectionProvider = <T,>({
161
163
  handleBulkSelection,
162
164
  isChecked,
163
165
  checkboxValue,
164
- isBulkSelectionApplied,
165
- getSelectedIdentifiersCount,
166
166
  }),
167
- [selectedIdentifiers, handleBulkSelection, isChecked, checkboxValue, getSelectedIdentifiersCount],
167
+ [selectedIdentifiers, handleBulkSelection, isChecked, checkboxValue],
168
168
  )
169
169
 
170
170
  return <BulkSelectionContext.Provider value={value}>{children}</BulkSelectionContext.Provider>
@@ -11,3 +11,4 @@ export const BulkSelectionOptionsLabels = {
11
11
  export const SELECT_ALL_ACROSS_PAGES_LOCATOR = '*' as const
12
12
  export const getInvalidActionMessage = (action: string) => `Invalid action ${action} passed to useBulkSelection`
13
13
  export const BULK_SELECTION_CONTEXT_ERROR = 'useBulkSelection must be used within BulkSelectionContext'
14
+ export const CLEAR_SELECTIONS_WARNING = 'Selections on other pages are cleared'
@@ -26,8 +26,6 @@ export interface GetBulkSelectionCheckboxValuesType {
26
26
  export interface UseBulkSelectionReturnType<T> extends GetBulkSelectionCheckboxValuesType {
27
27
  selectedIdentifiers: T
28
28
  handleBulkSelection: ({ action, data }: HandleBulkSelectionType<T>) => void
29
- isBulkSelectionApplied: boolean
30
- getSelectedIdentifiersCount: () => number
31
29
  }
32
30
 
33
31
  export interface BulkSelectionProps {
@@ -0,0 +1 @@
1
+ export * from './utils'
@@ -0,0 +1,97 @@
1
+ import Tippy from '@tippyjs/react'
2
+ import { components } from 'react-select'
3
+ import { stopPropagation } from '../../../Common'
4
+
5
+ export const getCommonSelectStyle = (styleOverrides = {}) => ({
6
+ menuList: (base) => ({
7
+ ...base,
8
+ paddingTop: 0,
9
+ paddingBottom: 0,
10
+ }),
11
+ control: (base, state) => ({
12
+ ...base,
13
+ minHeight: '32px',
14
+ boxShadow: 'none',
15
+ backgroundColor: 'var(--N50)',
16
+ border: state.isFocused ? '1px solid var(--B500)' : '1px solid var(--N200)',
17
+ cursor: 'pointer',
18
+ }),
19
+ option: (base, state) => ({
20
+ ...base,
21
+ color: 'var(--N900)',
22
+ backgroundColor: state.isFocused ? 'var(--N100)' : 'white',
23
+ padding: '10px 12px',
24
+ }),
25
+ dropdownIndicator: (base, state) => ({
26
+ ...base,
27
+ color: 'var(--N400)',
28
+ padding: '0 8px',
29
+ transition: 'all .2s ease',
30
+ transform: state.selectProps.menuIsOpen ? 'rotate(180deg)' : 'rotate(0deg)',
31
+ }),
32
+ valueContainer: (base) => ({
33
+ ...base,
34
+ padding: '0 8px',
35
+ fontWeight: '400',
36
+ }),
37
+ loadingMessage: (base) => ({
38
+ ...base,
39
+ color: 'var(--N600)',
40
+ }),
41
+ noOptionsMessage: (base) => ({
42
+ ...base,
43
+ color: 'var(--N600)',
44
+ }),
45
+ ...styleOverrides,
46
+ })
47
+
48
+ const getCustomOptionBackgroundColor = (isSelected: boolean, isFocused: boolean) => {
49
+ if (isSelected) {
50
+ return 'var(--B100)'
51
+ }
52
+
53
+ if (isFocused) {
54
+ return 'var(--N50)'
55
+ }
56
+
57
+ return 'var(--white)'
58
+ }
59
+
60
+ export const getCustomOptionSelectionStyle =
61
+ (styleOverrides = {}) =>
62
+ (base, state) => ({
63
+ ...base,
64
+ backgroundColor: getCustomOptionBackgroundColor(state.isSelected, state.isFocused),
65
+ color: state.isSelected ? 'var(--B500)' : 'var(--N900)',
66
+ textOverflow: 'ellipsis',
67
+ fontWeight: '500',
68
+ overflow: 'hidden',
69
+ textAlign: 'left',
70
+ whiteSpace: 'nowrap',
71
+ cursor: 'pointer',
72
+ fontSize: '13px',
73
+ ...styleOverrides,
74
+ })
75
+
76
+ export const SelectOption = (props: any) => {
77
+ const { selectProps, data, showTippy, style, placement, tippyContent, tippyClass } = props
78
+ selectProps.styles.option = getCustomOptionSelectionStyle(style)
79
+ const getOption = () => (
80
+ <div onClick={stopPropagation}>
81
+ <components.Option {...props} />
82
+ </div>
83
+ )
84
+
85
+ return showTippy ? (
86
+ <Tippy
87
+ className={tippyClass || 'default-white'}
88
+ arrow={false}
89
+ placement={placement || 'right'}
90
+ content={tippyContent || data.label}
91
+ >
92
+ {getOption()}
93
+ </Tippy>
94
+ ) : (
95
+ getOption()
96
+ )
97
+ }
@@ -1 +1,3 @@
1
+ export * from './APIResponseHandler'
2
+ export * from './ReactSelect'
1
3
  export * from './BulkSelection'
@@ -0,0 +1,29 @@
1
+ interface HighlightSearchTextProps {
2
+ /**
3
+ * The text to be highlighted
4
+ */
5
+ searchText: string
6
+ /**
7
+ * The whole text string
8
+ */
9
+ text: string
10
+ /**
11
+ * The classes to be applied to the highlighted text
12
+ */
13
+ highlightClasses?: string
14
+ }
15
+
16
+ // Disabling default export since this is a helper function and we would have to export a lot of functions in future.
17
+ // eslint-disable-next-line import/prefer-default-export
18
+ export const highlightSearchText = ({ searchText, text, highlightClasses }: HighlightSearchTextProps): string => {
19
+ if (!searchText) {
20
+ return text
21
+ }
22
+
23
+ try {
24
+ const regex = new RegExp(searchText, 'gi')
25
+ return text.replace(regex, (match) => `<span class="${highlightClasses}">${match}</span>`)
26
+ } catch (error) {
27
+ return text
28
+ }
29
+ }
@@ -1 +1,3 @@
1
1
  export * from './Components'
2
+ export * from './validations'
3
+ export * from './Helpers'
@@ -0,0 +1,130 @@
1
+ export interface ValidationResponseType {
2
+ isValid: boolean
3
+ message?: string
4
+ }
5
+
6
+ const MESSAGES = {
7
+ PROVIDE_A_NUMBER: 'Please provide a number',
8
+ LOWERCASE_ALPHANUMERIC: 'Only lowercase alphanumeric characters, -, _ or . allowed',
9
+ CAN_NOT_START_END_WITH_SEPARATORS: 'Cannot start/end with -, _ or .',
10
+ getMinMaxCharMessage: (min: number, max: number) => `Minimum ${min} and maximum ${max} characters allowed`,
11
+ getMaxCharMessage: (max: number) => `Maximum ${max} characters are allowed`,
12
+ VALID_POSITIVE_NUMBER: 'This field should be a valid positive number',
13
+ VALID_POSITIVE_INTEGER: 'This field should be a valid positive integer',
14
+ MAX_SAFE_INTEGER: `Maximum allowed value is ${Number.MAX_SAFE_INTEGER}`,
15
+ }
16
+
17
+ const MAX_DESCRIPTION_LENGTH = 300
18
+
19
+ export const validateName = (name: string): ValidationResponseType => {
20
+ if (!/^.{3,50}$/.test(name)) {
21
+ return {
22
+ isValid: false,
23
+ message: MESSAGES.getMinMaxCharMessage(3, 50),
24
+ }
25
+ }
26
+
27
+ if (!/^[a-z0-9-._]+$/.test(name)) {
28
+ return {
29
+ isValid: false,
30
+ message: MESSAGES.LOWERCASE_ALPHANUMERIC,
31
+ }
32
+ }
33
+
34
+ if (!/^(?![-._]).*[^-._]$/.test(name)) {
35
+ return {
36
+ isValid: false,
37
+ message: MESSAGES.CAN_NOT_START_END_WITH_SEPARATORS,
38
+ }
39
+ }
40
+
41
+ return {
42
+ isValid: true,
43
+ }
44
+ }
45
+
46
+ export const validateDescription = (description: string): ValidationResponseType => {
47
+ if (description?.length > MAX_DESCRIPTION_LENGTH) {
48
+ return {
49
+ isValid: false,
50
+ message: MESSAGES.getMaxCharMessage(MAX_DESCRIPTION_LENGTH),
51
+ }
52
+ }
53
+
54
+ return {
55
+ isValid: true,
56
+ }
57
+ }
58
+
59
+ export const validateRequiredPositiveNumber = (value: string | number): ValidationResponseType => {
60
+ if (!value) {
61
+ return {
62
+ isValid: false,
63
+ message: MESSAGES.PROVIDE_A_NUMBER,
64
+ }
65
+ }
66
+
67
+ // TODO: Look if regex is available for this, since 0002 is not a valid number
68
+ if (!/^\d+(\.\d+)?$/.test(value.toString())) {
69
+ return {
70
+ isValid: false,
71
+ message: MESSAGES.VALID_POSITIVE_NUMBER,
72
+ }
73
+ }
74
+
75
+ const numericValue = Number(value)
76
+
77
+ if (numericValue > Number.MAX_SAFE_INTEGER) {
78
+ return {
79
+ isValid: false,
80
+ message: MESSAGES.MAX_SAFE_INTEGER,
81
+ }
82
+ }
83
+
84
+ if (numericValue <= 0) {
85
+ return {
86
+ isValid: false,
87
+ message: MESSAGES.VALID_POSITIVE_NUMBER,
88
+ }
89
+ }
90
+
91
+ return {
92
+ isValid: true,
93
+ }
94
+ }
95
+
96
+ export const validateRequiredPositiveInteger = (value: string | number): ValidationResponseType => {
97
+ if (!value) {
98
+ return {
99
+ isValid: false,
100
+ message: MESSAGES.PROVIDE_A_NUMBER,
101
+ }
102
+ }
103
+
104
+ if (!/^\d+$/.test(value.toString())) {
105
+ return {
106
+ isValid: false,
107
+ message: MESSAGES.VALID_POSITIVE_INTEGER,
108
+ }
109
+ }
110
+
111
+ const numericValue = Number(value)
112
+
113
+ if (numericValue > Number.MAX_SAFE_INTEGER) {
114
+ return {
115
+ isValid: false,
116
+ message: MESSAGES.MAX_SAFE_INTEGER,
117
+ }
118
+ }
119
+
120
+ if (numericValue <= 0) {
121
+ return {
122
+ isValid: false,
123
+ message: MESSAGES.VALID_POSITIVE_INTEGER,
124
+ }
125
+ }
126
+
127
+ return {
128
+ isValid: true,
129
+ }
130
+ }
@@ -1,8 +0,0 @@
1
- export declare const DEFAULT_PAGE_NUMBER = 1;
2
- export declare const URL_FILTER_KEYS: {
3
- readonly PAGE_SIZE: "pageSize";
4
- readonly PAGE_NUMBER: "pageNumber";
5
- readonly SEARCH_KEY: "searchKey";
6
- readonly SORT_BY: "sortBy";
7
- readonly SORT_ORDER: "sortOrder";
8
- };
@@ -1,2 +0,0 @@
1
- export { default as useUrlFilters } from './useUrlFilters';
2
- export type { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types';
@@ -1,19 +0,0 @@
1
- import { SortingOrder } from '../../Constants';
2
- export interface UseUrlFiltersProps<T> {
3
- /**
4
- * The key on which the sorting should be applied
5
- */
6
- initialSortKey?: T;
7
- }
8
- export interface UseUrlFiltersReturnType<T> {
9
- pageSize: number;
10
- changePage: (pageNumber: number) => void;
11
- changePageSize: (pageSize: number) => void;
12
- searchKey: string;
13
- handleSearch: (searchKey: string) => void;
14
- offset: number;
15
- sortBy: T;
16
- sortOrder: SortingOrder;
17
- handleSorting: (sortBy: T) => void;
18
- clearFilters: () => void;
19
- }
@@ -1,20 +0,0 @@
1
- import { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types';
2
- /**
3
- * Generic hook for implementing URL based filters.
4
- * eg: pagination, search, sort.
5
- *
6
- * The exposed handlers can be consumed directly without the need for explicit state management
7
- *
8
- * @example Default Usage:
9
- * ```tsx
10
- * const { pageSize, changePage, ...rest } = useUrlFilters()
11
- * ```
12
- *
13
- * @example Usage with custom type for sort keys and initial sort key:
14
- * ```tsx
15
- * const { sortBy, sortOrder } = useUrlFilters<'email' | 'name'>({ initialSortKey: 'email' })
16
- * ```
17
- *
18
- */
19
- declare const useUrlFilters: <T = string>({ initialSortKey }?: UseUrlFiltersProps<T>) => UseUrlFiltersReturnType<T>;
20
- export default useUrlFilters;
@@ -1,18 +0,0 @@
1
- /// <reference types="react" />
2
- import { SortableTableHeaderCellProps } from './types';
3
- /**
4
- * Reusable component for the table header cell with support for sorting icons
5
- *
6
- * @example Usage
7
- * ```tsx
8
- * <SortableTableHeaderCell
9
- * isSorted={currentSortedCell === 'cell'}
10
- * triggerSorting={() => {}}
11
- * sortOrder={SortingOrder.ASC}
12
- * title="Header Cell"
13
- * disabled={isDisabled}
14
- * />
15
- * ```
16
- */
17
- declare const SortableTableHeaderCell: ({ isSorted, triggerSorting, sortOrder, title, disabled, }: SortableTableHeaderCellProps) => JSX.Element;
18
- export default SortableTableHeaderCell;
@@ -1,2 +0,0 @@
1
- export { default as SortableTableHeaderCell } from './SortableTableHeaderCell';
2
- export type { SortableTableHeaderCellProps } from './types';
@@ -1,25 +0,0 @@
1
- import { SortingOrder } from '../Constants';
2
- export interface SortableTableHeaderCellProps {
3
- /**
4
- * If true, the cell is sorted
5
- */
6
- isSorted: boolean;
7
- /**
8
- * Callback for handling the sorting of the cell
9
- */
10
- triggerSorting: () => void;
11
- /**
12
- * Current sort order
13
- *
14
- * Note: On click, the sort order should be updated as required
15
- */
16
- sortOrder: SortingOrder;
17
- /**
18
- * Label for the cell
19
- */
20
- title: string;
21
- /**
22
- * If true, the cell is disabled
23
- */
24
- disabled: boolean;
25
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * User Status received from the API
3
- */
4
- export declare enum UserStatusDto {
5
- active = "active",
6
- inactive = "inactive"
7
- }
8
- /**
9
- * User status for the frontend
10
- */
11
- export declare enum UserStatus {
12
- active = "active",
13
- inactive = "inactive",
14
- temporary = "temporaryAccess"
15
- }
@@ -1 +0,0 @@
1
- export * from './constants';
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none">
2
- <path d="M4.125 8.5L6 10.75L7.875 8.5M4.125 3.5L6 1.25L7.875 3.5" stroke="#3B444C" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M3.5 7.50009L6.00004 10.0001M6.00004 10.0001L8.5 7.50054M6.00004 10.0001V2" stroke="#596168" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
3
- </svg>
@@ -1,9 +0,0 @@
1
- export const DEFAULT_PAGE_NUMBER = 1
2
-
3
- export const URL_FILTER_KEYS = {
4
- PAGE_SIZE: 'pageSize',
5
- PAGE_NUMBER: 'pageNumber',
6
- SEARCH_KEY: 'searchKey',
7
- SORT_BY: 'sortBy',
8
- SORT_ORDER: 'sortOrder',
9
- } as const
@@ -1,2 +0,0 @@
1
- export { default as useUrlFilters } from './useUrlFilters'
2
- export type { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types'
@@ -1,21 +0,0 @@
1
- import { SortingOrder } from '../../Constants'
2
-
3
- export interface UseUrlFiltersProps<T> {
4
- /**
5
- * The key on which the sorting should be applied
6
- */
7
- initialSortKey?: T
8
- }
9
-
10
- export interface UseUrlFiltersReturnType<T> {
11
- pageSize: number
12
- changePage: (pageNumber: number) => void
13
- changePageSize: (pageSize: number) => void
14
- searchKey: string
15
- handleSearch: (searchKey: string) => void
16
- offset: number
17
- sortBy: T
18
- sortOrder: SortingOrder
19
- handleSorting: (sortBy: T) => void
20
- clearFilters: () => void
21
- }
@@ -1,121 +0,0 @@
1
- import { useMemo } from 'react'
2
- import { useHistory, useLocation } from 'react-router-dom'
3
- import { DEFAULT_BASE_PAGE_SIZE, SortingOrder } from '../../Constants'
4
- import { DEFAULT_PAGE_NUMBER, URL_FILTER_KEYS } from './constants'
5
- import { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types'
6
-
7
- const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_KEYS
8
-
9
- /**
10
- * Generic hook for implementing URL based filters.
11
- * eg: pagination, search, sort.
12
- *
13
- * The exposed handlers can be consumed directly without the need for explicit state management
14
- *
15
- * @example Default Usage:
16
- * ```tsx
17
- * const { pageSize, changePage, ...rest } = useUrlFilters()
18
- * ```
19
- *
20
- * @example Usage with custom type for sort keys and initial sort key:
21
- * ```tsx
22
- * const { sortBy, sortOrder } = useUrlFilters<'email' | 'name'>({ initialSortKey: 'email' })
23
- * ```
24
- *
25
- */
26
- const useUrlFilters = <T = string>({ initialSortKey }: UseUrlFiltersProps<T> = {}): UseUrlFiltersReturnType<T> => {
27
- const location = useLocation()
28
- const history = useHistory()
29
- const searchParams = new URLSearchParams(location.search)
30
-
31
- const { pageSize, pageNumber, searchKey, sortBy, sortOrder } = useMemo(() => {
32
- const _pageSize = searchParams.get(PAGE_SIZE)
33
- const _pageNumber = searchParams.get(PAGE_NUMBER)
34
- const _searchKey = searchParams.get(SEARCH_KEY)
35
- const _sortOrder = searchParams.get(SORT_ORDER) as SortingOrder
36
- const _sortBy = searchParams.get(SORT_BY)
37
-
38
- const sortByKey = (_sortBy || initialSortKey || '') as T
39
- // Fallback to ascending order
40
- const sortByOrder = Object.values(SortingOrder).includes(_sortOrder) ? _sortOrder : SortingOrder.ASC
41
-
42
- return {
43
- pageSize: Number(_pageSize) || DEFAULT_BASE_PAGE_SIZE,
44
- pageNumber: Number(_pageNumber) || DEFAULT_PAGE_NUMBER,
45
- searchKey: _searchKey || '',
46
- sortBy: sortByKey,
47
- // sort order should only be applied if the key is available
48
- sortOrder: (sortByKey ? sortByOrder : '') as SortingOrder,
49
- }
50
- }, [searchParams])
51
-
52
- /**
53
- * Used for getting the required result from the API
54
- */
55
- const offset = pageSize * (pageNumber - 1)
56
-
57
- /**
58
- * Update and replace the search params in the URL.
59
- *
60
- * Note: Currently only primitive data types are supported
61
- */
62
- const _updateSearchParam = (key: string, value) => {
63
- searchParams.set(key, String(value))
64
- history.replace({ search: searchParams.toString() })
65
- }
66
-
67
- const _resetPageNumber = () => {
68
- _updateSearchParam(PAGE_NUMBER, DEFAULT_PAGE_NUMBER)
69
- }
70
-
71
- const changePage = (page: number) => {
72
- _updateSearchParam(PAGE_NUMBER, page)
73
- }
74
-
75
- const changePageSize = (_pageSize: number) => {
76
- _updateSearchParam(PAGE_SIZE, _pageSize)
77
- _resetPageNumber()
78
- }
79
-
80
- const handleSearch = (searchTerm: string) => {
81
- _updateSearchParam(SEARCH_KEY, searchTerm)
82
- _resetPageNumber()
83
- }
84
-
85
- const handleSorting = (_sortBy: T) => {
86
- let order: SortingOrder
87
- if (_sortBy === sortBy && sortOrder === SortingOrder.ASC) {
88
- order = SortingOrder.DESC
89
- } else {
90
- order = SortingOrder.ASC
91
- }
92
-
93
- _updateSearchParam(SORT_BY, _sortBy)
94
- _updateSearchParam(SORT_ORDER, order)
95
-
96
- // Reset page number on sorting change
97
- _resetPageNumber()
98
- }
99
-
100
- const clearFilters = () => {
101
- Object.values(URL_FILTER_KEYS).forEach((key) => {
102
- searchParams.delete(key)
103
- })
104
- history.replace({ search: searchParams.toString() })
105
- }
106
-
107
- return {
108
- pageSize,
109
- changePage,
110
- changePageSize,
111
- searchKey,
112
- handleSearch,
113
- offset,
114
- sortBy,
115
- sortOrder,
116
- handleSorting,
117
- clearFilters,
118
- }
119
- }
120
-
121
- export default useUrlFilters