Skip to content

Commit e2a7583

Browse files
authored
feat: add deep linking to a pipe (#3521)
1 parent d58cfc7 commit e2a7583

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

src/flows/components/Sidebar.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
DapperScrollbars,
77
Dropdown,
88
} from '@influxdata/clockface'
9+
import {useDispatch} from 'react-redux'
910
import {FlowContext} from 'src/flows/context/flow.current'
1011
import {FlowQueryContext} from 'src/flows/context/flow.query'
1112
import {SidebarContext} from 'src/flows/context/sidebar'
@@ -14,6 +15,13 @@ import {ControlSection, ControlAction, Submenu} from 'src/types/flows'
1415
import ClientList from 'src/flows/components/ClientList'
1516
import './Sidebar.scss'
1617
import {event} from 'src/cloud/utils/reporting'
18+
import {notify} from 'src/shared/actions/notifications'
19+
20+
// Constants
21+
import {
22+
panelCopyLinkSuccess,
23+
panelCopyLinkFail,
24+
} from 'src/shared/copy/notifications'
1725

1826
export const SubSideBar: FC = () => {
1927
const {flow} = useContext(FlowContext)
@@ -115,6 +123,7 @@ const Sidebar: FC = () => {
115123
const {flow, updateMeta, add, remove} = useContext(FlowContext)
116124
const {getPanelQueries} = useContext(FlowQueryContext)
117125
const {id, hide, menu, showSub} = useContext(SidebarContext)
126+
const dispatch = useDispatch()
118127

119128
const sections = ([
120129
{
@@ -129,6 +138,24 @@ const Sidebar: FC = () => {
129138
remove(id)
130139
},
131140
},
141+
{
142+
title: 'Share',
143+
action: () => {
144+
const {type} = flow.data.byID[id]
145+
event('notebook_share_panel', {notebooksCellType: type})
146+
const url = new URL(
147+
`${window.location.origin}${window.location.pathname}?panel=${id}`
148+
).toString()
149+
try {
150+
navigator.clipboard.writeText(url)
151+
event('panel_share_success', {notebooksCellType: type})
152+
dispatch(notify(panelCopyLinkSuccess()))
153+
} catch {
154+
event('panel_share_failure', {notebooksCellType: type})
155+
dispatch(notify(panelCopyLinkFail()))
156+
}
157+
},
158+
},
132159
{
133160
title: 'Duplicate',
134161
action: () => {

src/flows/components/panel/FlowPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const FlowPanel: FC<Props> = ({
159159

160160
return (
161161
<>
162-
<div className={panelClassName}>
162+
<div className={panelClassName} id={id}>
163163
<div className="flow-panel--header">
164164
<div className="flow-panel--node-wrapper">
165165
<div className="flow-panel--node" />

src/flows/context/flow.current.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React, {
66
useState,
77
useEffect,
88
} from 'react'
9+
import {useLocation} from 'react-router-dom'
910
import {Flow, PipeData, PipeMeta} from 'src/types/flows'
1011
import {FlowListContext, FlowListProvider} from 'src/flows/context/flow.list'
1112
import {v4 as UUID} from 'uuid'
@@ -53,6 +54,16 @@ export const FlowProvider: FC = ({children}) => {
5354
}
5455
}
5556

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

src/shared/copy/notifications.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,16 @@ export const notebookRunFail = (projectName: string): Notification => ({
12251225
message: `${projectName} run failed`,
12261226
})
12271227

1228+
export const panelCopyLinkSuccess = (): Notification => ({
1229+
...defaultSuccessNotification,
1230+
message: `Panel link copied successfully!`,
1231+
})
1232+
1233+
export const panelCopyLinkFail = (): Notification => ({
1234+
...defaultErrorNotification,
1235+
message: `Failed to copy the panel link`,
1236+
})
1237+
12281238
export const notebookCreateFail = (): Notification => ({
12291239
...defaultErrorNotification,
12301240
message: `Failed to create Notebook, please try again.`,

0 commit comments

Comments
 (0)