Skip to content

Commit 23729dc

Browse files
authored
fix: deep linking to a notebook pipe (#3843)
1 parent 288916e commit 23729dc

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/flows/context/flow.current.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import React, {
66
useState,
77
useEffect,
88
} from 'react'
9-
import {useLocation} from 'react-router-dom'
109
import {Flow, PipeData, PipeMeta} from 'src/types/flows'
1110
import {FlowListContext, FlowListProvider} from 'src/flows/context/flow.list'
1211
import {customAlphabet} from 'nanoid'
@@ -55,16 +54,6 @@ export const FlowProvider: FC = ({children}) => {
5554
}
5655
}
5756

58-
const {search} = useLocation()
59-
60-
const panel = new URLSearchParams(search).get('panel')
61-
62-
useEffect(() => {
63-
if (document && panel && currentFlow) {
64-
document.getElementById(panel)?.scrollIntoView()
65-
}
66-
}, [panel, currentFlow])
67-
6857
// NOTE this is a pretty awful mechanism, as it duplicates the source of
6958
// truth for the definition of the current flow, but i can't see a good
7059
// way around it. We need to ensure that we're still updating the values

src/flows/context/pipe.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, {FC, useContext, useMemo, useCallback} from 'react'
1+
import React, {FC, useContext, useEffect, useMemo, useCallback} from 'react'
22
import {PipeData, FluxResult} from 'src/types/flows'
33
import {FlowContext} from 'src/flows/context/flow.current'
44
import {ResultsContext} from 'src/flows/context/results'
55
import {RemoteDataState, TimeRange} from 'src/types'
6+
import {useHistory, useLocation} from 'react-router-dom'
67

78
export interface PipeContextType {
89
id: string
@@ -39,6 +40,24 @@ export const PipeProvider: FC<PipeContextProps> = ({id, children}) => {
3940
const result = results[id]
4041
const status = statuses[id]
4142

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+
4261
const updater = useCallback(
4362
(data: Partial<PipeData>) => {
4463
updateData(id, data)

0 commit comments

Comments
 (0)