-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NETOBSERV-783 multiple page loads with quick filters #273
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const ConfigResultSample = { | ||
portNaming: { | ||
enable: true, | ||
portNames: new Map([['3100', 'loki']]) | ||
}, | ||
quickFilters: [] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,7 @@ import HistogramContainer from './metrics/histogram'; | |
export type ViewId = 'overview' | 'table' | 'topology'; | ||
|
||
export const NetflowTraffic: React.FC<{ | ||
forcedFilters?: Filter[]; | ||
forcedFilters?: Filter[] | null; | ||
isTab?: boolean; | ||
}> = ({ forcedFilters, isTab }) => { | ||
const { push } = useHistory(); | ||
|
@@ -207,7 +207,8 @@ export const NetflowTraffic: React.FC<{ | |
const [selectedElement, setSelectedElement] = React.useState<GraphElementPeer | undefined>(undefined); | ||
const searchRef = React.useRef<SearchHandle>(null); | ||
const [searchEvent, setSearchEvent] = React.useState<SearchEvent | undefined>(undefined); | ||
const isInit = React.useRef(true); | ||
//use this ref to list any props / content loading state & events to skip tick function | ||
const initState = React.useRef<Array<'initDone' | 'configLoading' | 'configLoaded' | 'forcedFiltersLoaded'>>([]); | ||
const [panels, setSelectedPanels] = useLocalStorage<OverviewPanel[]>( | ||
LOCAL_STORAGE_OVERVIEW_IDS_KEY, | ||
getDefaultOverviewPanels(), | ||
|
@@ -222,16 +223,15 @@ export const NetflowTraffic: React.FC<{ | |
}); | ||
const [columnSizes, setColumnSizes] = useLocalStorage<ColumnSizeMap>(LOCAL_STORAGE_COLS_SIZES_KEY, {}); | ||
|
||
React.useEffect(() => { | ||
loadConfig().then(setConfig); | ||
}, [setConfig]); | ||
|
||
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 | ||
|
@@ -245,23 +245,12 @@ export const NetflowTraffic: React.FC<{ | |
[setFilters, setFlows, setWarningMessage] | ||
); | ||
|
||
const resetDefaultFilters = React.useCallback(() => { | ||
updateTableFilters(getDefaultFilters()); | ||
}, [getDefaultFilters, updateTableFilters]); | ||
|
||
React.useEffect(() => { | ||
// Init state from URL | ||
if (!forcedFilters) { | ||
const filtersPromise = getFiltersFromURL(t, disabledFilters); | ||
if (filtersPromise) { | ||
filtersPromise.then(updateTableFilters); | ||
} else { | ||
resetDefaultFilters(); | ||
} | ||
} | ||
// disabling exhaustive-deps: only for init | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [forcedFilters, config]); | ||
const resetDefaultFilters = React.useCallback( | ||
(c = config) => { | ||
updateTableFilters(getDefaultFilters(c)); | ||
}, | ||
[config, getDefaultFilters, updateTableFilters] | ||
); | ||
|
||
const clearSelections = () => { | ||
setTRModalOpen(false); | ||
|
@@ -374,6 +363,14 @@ export const NetflowTraffic: React.FC<{ | |
); | ||
|
||
const tick = React.useCallback(() => { | ||
// skip tick while forcedFilters & config are not loaded | ||
// this check ensure tick will not be called during init | ||
// as it's difficult to manage react state changes | ||
if (!initState.current.includes('forcedFiltersLoaded') || !initState.current.includes('configLoaded')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to have a union type for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
console.error('tick skipped', initState.current); | ||
return; | ||
} | ||
|
||
setLoading(true); | ||
setError(undefined); | ||
const fq = buildFlowQuery(); | ||
|
@@ -455,21 +452,49 @@ export const NetflowTraffic: React.FC<{ | |
setLoading(false); | ||
break; | ||
} | ||
}, [buildFlowQuery, histogramRange, manageWarnings, range, selectedViewId, showHistogram]); | ||
}, [buildFlowQuery, histogramRange, manageWarnings, range, selectedViewId, showHistogram, initState]); | ||
|
||
usePoll(tick, interval); | ||
|
||
// tick on state change | ||
React.useEffect(() => { | ||
// Skip on init if forcedFilters not set | ||
if (isInit.current) { | ||
isInit.current = false; | ||
if (!forcedFilters) { | ||
// init function will be triggered only once | ||
if (!initState.current.includes('initDone')) { | ||
initState.current.push('initDone'); | ||
|
||
// 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); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// init will trigger this useEffect update loop as soon as config is loaded | ||
return; | ||
} | ||
|
||
if (!initState.current.includes('forcedFiltersLoaded') && forcedFilters !== undefined) { | ||
initState.current.push('forcedFiltersLoaded'); | ||
//in case forcedFilters are null, we only track config update | ||
if (forcedFilters === null) { | ||
return; | ||
} | ||
} | ||
|
||
tick(); | ||
}, [forcedFilters, tick]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [forcedFilters, config, tick, setConfig]); | ||
|
||
// Rewrite URL params on state change | ||
React.useEffect(() => { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need a distinction null vs undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming from
netflow-tab
, the prop will be undefined before being set.As we force null in
netflow-traffic-parent
, we make the distinction between the loading state from tabs and the null state from page to skip a tick before confing loaded