Skip to content

Commit d345458

Browse files
committed
fix(juno): prevent apps from crash when there are no initialFilters
1 parent a41d9d6 commit d345458

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

apps/doop/src/lib/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

apps/doop/src/routes/violations.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
useGlobalsInitialFiltersApplied,
1717
} from "../components/StoreProvider"
1818
import { parseInitialFilters } from "../lib/store/createFiltersSlice"
19+
import { isObjectWithKeys } from "../lib/helpers"
1920

2021
const 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",

apps/supernova/src/lib/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

apps/supernova/src/routes/alerts.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import AlertsTab from "../components/alerts/AlertsTab"
1313
import { ACTIVE_FILTERS_PREFIX, PAUSED_FILTERS_PREFIX } from "../constants"
1414
import { convertUrlStateToAppState, getFiltersForUrl } from "../lib/urlStateUtils"
1515
import { useGlobalsActions, useFilterActions, useGlobalsInitialFiltersApplied } from "../components/StoreProvider"
16+
import { isObjectWithKeys } from "../lib/utils"
1617

1718
const 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",

0 commit comments

Comments
 (0)