|
1 | | -import React, {FC, useContext, useMemo, useCallback} from 'react' |
| 1 | +import React, {FC, useContext, useEffect, useMemo, useCallback} from 'react' |
2 | 2 | import {PipeData, FluxResult} from 'src/types/flows' |
3 | 3 | import {FlowContext} from 'src/flows/context/flow.current' |
4 | 4 | import {ResultsContext} from 'src/flows/context/results' |
5 | 5 | import {RemoteDataState, TimeRange} from 'src/types' |
| 6 | +import {useHistory, useLocation} from 'react-router-dom' |
6 | 7 |
|
7 | 8 | export interface PipeContextType { |
8 | 9 | id: string |
@@ -39,6 +40,24 @@ export const PipeProvider: FC<PipeContextProps> = ({id, children}) => { |
39 | 40 | const result = results[id] |
40 | 41 | const status = statuses[id] |
41 | 42 |
|
| 43 | + const history = useHistory() |
| 44 | + const {search} = useLocation() |
| 45 | + |
| 46 | + const panel = new URLSearchParams(search).get('panel') |
| 47 | + const statusValues = Object.values(statuses).every( |
| 48 | + stat => stat !== undefined && stat !== RemoteDataState.Loading |
| 49 | + ) |
| 50 | + |
| 51 | + useEffect(() => { |
| 52 | + if (panel && statusValues) { |
| 53 | + document.getElementById(panel)?.scrollIntoView() |
| 54 | + setTimeout(() => { |
| 55 | + // then remove the deep linked panel from the URL? |
| 56 | + history.push(window.location.pathname) |
| 57 | + }, 1000) |
| 58 | + } |
| 59 | + }, [history, panel, statusValues]) |
| 60 | + |
42 | 61 | const updater = useCallback( |
43 | 62 | (data: Partial<PipeData>) => { |
44 | 63 | updateData(id, data) |
|
0 commit comments