Skip to content

Commit a711cda

Browse files
committed
Memoize getFilters
Fixes #1242. This should stop the warning spam whenever filters are used. I except performance gains to be negligble though.
1 parent 68569f8 commit a711cda

5 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/components/shared/DateTimeCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { renderValidDate } from "../../utils/dateUtils";
77
import { IconButton } from "../shared/IconButton";
88
import { ParseKeys } from "i18next";
99
import { AsyncThunk } from "@reduxjs/toolkit";
10+
import { Resource } from "../../slices/tableSlice";
1011

1112
/**
1213
* This component renders the start date cells of events in the table view
@@ -19,7 +20,7 @@ const DateTimeCell = ({
1920
loadResourceIntoTable,
2021
tooltipText,
2122
}: {
22-
resource: string
23+
resource: Resource
2324
date: string
2425
filterName: string
2526
fetchResource: AsyncThunk<any, void, any>

src/components/shared/MultiValueCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AppThunk, useAppDispatch, useAppSelector } from "../../store";
55
import { IconButton } from "../shared/IconButton";
66
import { AsyncThunk } from "@reduxjs/toolkit";
77
import { ParseKeys } from "i18next";
8+
import { Resource } from "../../slices/tableSlice";
89

910
/**
1011
* This component renders the presenters cells of events in the table view
@@ -17,7 +18,7 @@ const MultiValueCell = ({
1718
loadResourceIntoTable,
1819
tooltipText,
1920
}: {
20-
resource: string
21+
resource: Resource
2122
values: string[]
2223
filterName: string
2324
fetchResource: AsyncThunk<any, void, any>

src/components/shared/TableFilterProfiles.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { availableHotkeys } from "../../configs/hotkeysConfig";
1818
import { AsyncThunk } from "@reduxjs/toolkit";
1919
import ButtonLikeAnchor from "./ButtonLikeAnchor";
2020
import { ParseKeys } from "i18next";
21+
import { Resource } from "../../slices/tableSlice";
2122

2223
/**
2324
* This component renders the table filter profiles in the upper right corner when clicked on settings icon of the
@@ -34,7 +35,7 @@ const TableFiltersProfiles = ({
3435
setFilterSettings: (_: boolean) => void,
3536
loadResource: AsyncThunk<any, void, any>,
3637
loadResourceIntoTable: () => AppThunk,
37-
resource: string,
38+
resource: Resource,
3839
}) => {
3940
const dispatch = useAppDispatch();
4041

src/components/shared/TableFilters.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import DropDown from "./DropDown";
3131
import { AsyncThunk } from "@reduxjs/toolkit";
3232
import ButtonLikeAnchor from "./ButtonLikeAnchor";
3333
import { ParseKeys } from "i18next";
34+
import { Resource } from "../../slices/tableSlice";
3435

3536
/**
3637
* This component renders the table filters in the upper right corner of the table
@@ -42,7 +43,7 @@ const TableFilters = ({
4243
}: {
4344
loadResource: AsyncThunk<any, void, any>,
4445
loadResourceIntoTable: () => AppThunk,
45-
resource: string,
46+
resource: Resource,
4647
}) => {
4748
const { t } = useTranslation();
4849
const dispatch = useAppDispatch();

src/selectors/tableFilterSelectors.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { createSelector } from "reselect";
12
import { RootState } from "../store";
3+
import { Resource } from "../slices/tableSlice";
24

35
/**
46
* This file contains selectors regarding table filters
@@ -10,5 +12,9 @@ export const getTextFilter = (state: RootState) => state.tableFilters.textFilter
1012
export const getSelectedFilter = (state: RootState) => state.tableFilters.selectedFilter;
1113
export const getSecondFilter = (state: RootState) => state.tableFilters.secondFilter;
1214
export const getCurrentFilterResource = (state: RootState) => state.tableFilters.currentResource;
13-
export const getFilters = (state: RootState, resource: string) =>
14-
state.tableFilters.data.filter(obj => obj.resource === resource);
15+
export const getFilters = createSelector(
16+
[getAllFilters, (state, resource: Resource) => resource],
17+
(filters, resource) => {
18+
return filters.filter(obj => obj.resource === resource);
19+
}
20+
);

0 commit comments

Comments
 (0)