File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,3 +36,6 @@ export function capitalize(string: any) {
3636 // Capitalize the first character and concatenate it with the rest of the string
3737 return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 )
3838}
39+
40+ export const isObjectWithKeys = ( value : any ) =>
41+ value !== null && typeof value === "object" && Object . keys ( value ) . length > 0
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616 useGlobalsInitialFiltersApplied ,
1717} from "../components/StoreProvider"
1818import { parseInitialFilters } from "../lib/store/createFiltersSlice"
19+ import { isObjectWithKeys } from "../lib/helpers"
1920
2021const searchSchema = z
2122 . object ( {
@@ -79,7 +80,7 @@ function RouteComponent() {
7980 * */
8081 useLayoutEffect ( ( ) => {
8182 // we only want to apply initial filters only once when url does not contain any filter
82- if ( ! isUrlRead && Object . keys ( activeFilters ) . length === 0 && Object . keys ( initialFilters || { } ) . length > 0 ) {
83+ if ( ! isUrlRead && ! isObjectWithKeys ( activeFilters ) && isObjectWithKeys ( initialFilters ) ) {
8384 setIsUrlRead ( )
8485 navigate ( {
8586 to : "/violations" ,
Original file line number Diff line number Diff line change @@ -137,3 +137,6 @@ export const sortAlerts = (items: any) => {
137137 else return 1
138138 } )
139139}
140+
141+ export const isObjectWithKeys = ( value : any ) =>
142+ value !== null && typeof value === "object" && Object . keys ( value ) . length > 0
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import AlertsTab from "../components/alerts/AlertsTab"
1313import { ACTIVE_FILTERS_PREFIX , PAUSED_FILTERS_PREFIX } from "../constants"
1414import { convertUrlStateToAppState , getFiltersForUrl } from "../lib/urlStateUtils"
1515import { useGlobalsActions , useFilterActions , useGlobalsInitialFiltersApplied } from "../components/StoreProvider"
16+ import { isObjectWithKeys } from "../lib/utils"
1617
1718const searchSchema = z
1819 . object ( {
@@ -80,7 +81,7 @@ function RouteComponent() {
8081 * */
8182 useLayoutEffect ( ( ) => {
8283 // we only want to apply initial filters only once when url does not contain any filter
83- if ( ! isUrlRead && Object . keys ( activeFilters ) . length === 0 && Object . keys ( initialFilters ) . length > 0 ) {
84+ if ( ! isUrlRead && ! isObjectWithKeys ( activeFilters ) && isObjectWithKeys ( initialFilters ) ) {
8485 setIsUrlRead ( )
8586 navigate ( {
8687 to : "/alerts" ,
You can’t perform that action at this time.
0 commit comments