Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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.1",
"version": "0.6.1-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
}

export type UseUrlFiltersReturnType<T, K = unknown> = K & {
Expand Down
25 changes: 24 additions & 1 deletion src/Common/Hooks/useUrlFilters/useUrlFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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'
Expand Down Expand Up @@ -42,6 +42,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 +127,7 @@ const useUrlFilters = <T = string, K = unknown>({

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

const updateSearchParams = (paramsToSerialize: Partial<K>) => {
Expand All @@ -143,10 +145,31 @@ const useUrlFilters = <T = string, K = unknown>({
searchParams.delete(key)
}
})
localStorage.setItem(localStorageKey, JSON.stringify(parseSearchParams(searchParams)))
// Not replacing the params as it is being done by _resetPageNumber
_resetPageNumber()
}

useEffect(() => {
if (!localStorageKey) {
return
}
if (
Object.keys(parsedParams).some(
(key) =>
(Array.isArray(parsedParams[key]) && parsedParams[key].length) ||
(typeof parsedParams[key] === 'string' && !!parsedParams[key]),
)
) {
localStorage.setItem(localStorageKey, JSON.stringify(parsedParams))
} else {
const localStorageValue = localStorage.getItem(localStorageKey)
if (localStorageValue) {
updateSearchParams(JSON.parse(localStorageValue))
}
}
}, [])

return {
pageSize,
changePage,
Expand Down
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