Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtron-labs/devtron-fe-common-lib",
"version": "0.6.4",
"version": "0.6.4-beta-1",
"description": "Supporting common component library",
"type": "module",
"main": "dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/Common/Hooks/useUrlFilters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface UseUrlFiltersProps<T, K> {
* Callback function for parsing the search params
*/
parseSearchParams?: (searchParams: URLSearchParams) => K
localStorageKey?: `${string}__${string}`
}

export type UseUrlFiltersReturnType<T, K = unknown> = K & {
Expand Down
19 changes: 18 additions & 1 deletion src/Common/Hooks/useUrlFilters/useUrlFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* limitations under the License.
*/

import { useMemo } from 'react'
import { useEffect, useMemo } from 'react'
import { useHistory, useLocation } from 'react-router-dom'
import { DEFAULT_BASE_PAGE_SIZE, EXCLUDED_FALSY_VALUES, SortingOrder } from '../../Constants'
import { DEFAULT_PAGE_NUMBER, URL_FILTER_KEYS } from './constants'
import { UseUrlFiltersProps, UseUrlFiltersReturnType } from './types'
import { setItemInLocalStorageIfKeyExists } from './utils'

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

Expand All @@ -42,6 +43,7 @@ const { PAGE_SIZE, PAGE_NUMBER, SEARCH_KEY, SORT_BY, SORT_ORDER } = URL_FILTER_K
const useUrlFilters = <T = string, K = unknown>({
initialSortKey,
parseSearchParams,
localStorageKey,
}: UseUrlFiltersProps<T, K> = {}): UseUrlFiltersReturnType<T, K> => {
const location = useLocation()
const history = useHistory()
Expand Down Expand Up @@ -126,6 +128,7 @@ const useUrlFilters = <T = string, K = unknown>({

const clearFilters = () => {
history.replace({ search: '' })
setItemInLocalStorageIfKeyExists(localStorageKey, '')
}

const updateSearchParams = (paramsToSerialize: Partial<K>) => {
Expand All @@ -143,10 +146,24 @@ const useUrlFilters = <T = string, K = unknown>({
searchParams.delete(key)
}
})
// Skipping primary params => pageSize, pageNumber, searchKey, sortBy, sortOrder
setItemInLocalStorageIfKeyExists(localStorageKey, JSON.stringify(parseSearchParams(searchParams)))
// Not replacing the params as it is being done by _resetPageNumber
_resetPageNumber()
}

useEffect(() => {
// if we have search string, set secondary params in local storage accordingly
if (location.search) {
localStorage.setItem(localStorageKey, JSON.stringify(parsedParams))
return
}
const localStorageValue = localStorage.getItem(localStorageKey)
if (localStorageValue) {
updateSearchParams(JSON.parse(localStorageValue))
}
}, [])

return {
pageSize,
changePage,
Expand Down
5 changes: 5 additions & 0 deletions src/Common/Hooks/useUrlFilters/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const setItemInLocalStorageIfKeyExists = (localStorageKey: string, value: string) => {
if (localStorageKey) {
localStorage.setItem(localStorageKey, value)
}
}
2 changes: 1 addition & 1 deletion src/Shared/Components/CICDHistory/History.components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { ReactComponent as ZoomOut } from '../../../Assets/Icon/ic-exit-fullscre
import './cicdHistory.scss'

export const LogResizeButton = ({
shortcutCombo = ['F'],
shortcutCombo = ['Shift', 'F'],
showOnlyWhenPathIncludesLogs = true,
fullScreenView,
setFullScreenView,
Expand Down
15 changes: 8 additions & 7 deletions src/Shared/Components/SelectPicker/FilterSelectPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import { useEffect, useMemo, useState } from 'react'
import { ReactComponent as ICFilter } from '@Icons/ic-filter.svg'
import { ReactComponent as ICFilterApplied } from '@Icons/ic-filter-applied.svg'
import { ComponentSizeType } from '@Shared/constants'
import SelectPicker from './SelectPicker.component'
import { FilterSelectPickerProps, SelectPickerOptionType, SelectPickerProps } from './type'
import { Button } from '../Button'

const FilterSelectPicker = ({
appliedFilterOptions,
Expand Down Expand Up @@ -58,14 +60,13 @@ const FilterSelectPicker = ({

return (
<div className="p-8 dc__border-top-n1">
<button
type="button"
className="dc__unset-button-styles w-100 br-4 h-28 flex bcb-5 cn-0 fw-6 lh-28 fs-12 h-28 br-4 pt-5 pr-12 pb-5 pl-12"
<Button
text="Apply"
dataTestId="filter-select-picker-apply"
onClick={handleApplyClick}
aria-label="Apply filters"
>
Apply
</button>
size={ComponentSizeType.small}
fullWidth
/>
</div>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/Shared/Components/SelectPicker/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export interface FilterSelectPickerProps
| 'shouldMenuAlignRight'
| 'optionListError'
| 'reloadOptionList'
| 'isOptionDisabled'
> {
appliedFilterOptions: SelectPickerOptionType[]
handleApplyFilter: (filtersToApply: SelectPickerOptionType<number | string>[]) => void
Expand Down