Skip to content

Commit b4d39ab

Browse files
authored
Merge pull request #1994 from neo4j/preview-passing-db-info
passing dbms and db info while passing to the preview experience
2 parents 7e497b9 + 865ed0b commit b4d39ab

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

src/browser/modules/Stream/StartPreviewFrame.tsx

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,48 @@ import { Action } from 'redux'
2222
import { trackNavigateToPreview } from 'shared/modules/preview/previewDuck'
2323
import { connect } from 'react-redux'
2424
import { withBus } from 'react-suber'
25+
import { GlobalState } from 'shared/globalState'
26+
import {
27+
Connection,
28+
getActiveConnectionData
29+
} from 'shared/modules/connections/connectionsDuck'
2530

26-
export const navigateToPreview = (): void => {
27-
const path = window.location.pathname
28-
if (!path.endsWith('/preview/')) {
29-
window.location.pathname = `${path}${path.endsWith('/') ? '' : '/'}preview/`
31+
export const navigateToPreview = (
32+
db?: string | null,
33+
dbms?: string | null
34+
): void => {
35+
const url = new URL(window.location.href)
36+
37+
if (
38+
dbms &&
39+
!url.searchParams.has('dbms') &&
40+
!url.searchParams.get('connectURL')
41+
) {
42+
url.searchParams.set('dbms', dbms)
43+
}
44+
45+
if (db && !url.searchParams.has('db')) {
46+
url.searchParams.set('db', db)
47+
}
48+
49+
const previewPath = '/preview/'
50+
if (!url.pathname.endsWith(previewPath)) {
51+
url.pathname = url.pathname.replace(/\/?$/, previewPath)
52+
window.location.href = decodeURIComponent(url.toString())
3053
}
3154
}
3255

3356
type PreviewFrameProps = {
57+
connectionData: Connection | null
3458
executeTrackNavigateToPreview: () => void
3559
}
36-
const PreviewFrame = ({ executeTrackNavigateToPreview }: PreviewFrameProps) => {
60+
const PreviewFrame = ({
61+
connectionData,
62+
executeTrackNavigateToPreview
63+
}: PreviewFrameProps) => {
3764
function trackAndNavigateToPreview() {
3865
executeTrackNavigateToPreview()
39-
navigateToPreview()
66+
navigateToPreview(connectionData?.db, connectionData?.host)
4067
}
4168

4269
return (
@@ -108,4 +135,10 @@ const mapDispatchToProps = (dispatch: Dispatch<Action>) => {
108135
}
109136
}
110137

111-
export default withBus(connect(null, mapDispatchToProps)(PreviewFrame))
138+
const mapStateToProps = (state: GlobalState) => ({
139+
connectionData: getActiveConnectionData(state)
140+
})
141+
142+
export default withBus(
143+
connect(mapStateToProps, mapDispatchToProps)(PreviewFrame)
144+
)

0 commit comments

Comments
 (0)