Skip to content

Commit

Permalink
fix quick filters default not set
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinsonneau committed Jan 31, 2023
1 parent ac6edfa commit 1778961
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions web/src/components/netflow-traffic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,15 @@ export const NetflowTraffic: React.FC<{
});
const [columnSizes, setColumnSizes] = useLocalStorage<ColumnSizeMap>(LOCAL_STORAGE_COLS_SIZES_KEY, {});

const getQuickFilters = React.useCallback(() => parseQuickFilters(t, config.quickFilters), [t, config]);
const getQuickFilters = React.useCallback((c = config) => parseQuickFilters(t, c.quickFilters), [t, config]);

const getDefaultFilters = React.useCallback(() => {
const quickFilters = getQuickFilters();
return quickFilters.filter(qf => qf.default).flatMap(qf => qf.filters);
}, [getQuickFilters]);
const getDefaultFilters = React.useCallback(
(c = config) => {
const quickFilters = getQuickFilters(c);
return quickFilters.filter(qf => qf.default).flatMap(qf => qf.filters);
},
[config, getQuickFilters]
);

// updates table filters and clears up the table for proper visualization of the
// updating process
Expand All @@ -242,9 +245,12 @@ export const NetflowTraffic: React.FC<{
[setFilters, setFlows, setWarningMessage]
);

const resetDefaultFilters = React.useCallback(() => {
updateTableFilters(getDefaultFilters());
}, [getDefaultFilters, updateTableFilters]);
const resetDefaultFilters = React.useCallback(
(c = config) => {
updateTableFilters(getDefaultFilters(c));
},
[config, getDefaultFilters, updateTableFilters]
);

const clearSelections = () => {
setTRModalOpen(false);
Expand Down Expand Up @@ -456,22 +462,21 @@ export const NetflowTraffic: React.FC<{
if (!initState.current.includes('initDone')) {
initState.current.push('initDone');

// init state from URL
if (!forcedFilters) {
const filtersPromise = getFiltersFromURL(t, disabledFilters);
if (filtersPromise) {
filtersPromise.then(updateTableFilters);
} else {
resetDefaultFilters();
}
}

// load config only once and track its state
if (!initState.current.includes('configLoading')) {
initState.current.push('configLoading');
loadConfig().then(v => {
initState.current.push('configLoaded');
setConfig(v);
if (forcedFilters === null) {
//set filters from url or freshly loaded quick filters defaults
const filtersPromise = getFiltersFromURL(t, disabledFilters);
if (filtersPromise) {
filtersPromise.then(updateTableFilters);
} else {
resetDefaultFilters(v);
}
}
});
}

Expand Down

0 comments on commit 1778961

Please sign in to comment.