Skip to content

Commit b6165e3

Browse files
fix: getting docId, storeId parameters (#3761)
* fix: getting docId, storeId parameters * useparams to get path params --------- Co-authored-by: Henry <hzj94@hotmail.com>
1 parent d71ad22 commit b6165e3

7 files changed

+18
-27
lines changed

packages/ui/src/routes/MainRoutes.jsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,27 @@ const MainRoutes = {
9898
element: <Documents />
9999
},
100100
{
101-
path: '/document-stores/:id',
101+
path: '/document-stores/:storeId',
102102
element: <DocumentStoreDetail />
103103
},
104104
{
105-
path: '/document-stores/chunks/:id/:id',
105+
path: '/document-stores/chunks/:storeId/:fileId',
106106
element: <ShowStoredChunks />
107107
},
108108
{
109-
path: '/document-stores/:id/:name',
109+
path: '/document-stores/:storeId/:name',
110110
element: <LoaderConfigPreviewChunks />
111111
},
112112
{
113-
path: '/document-stores/vector/:id',
113+
path: '/document-stores/vector/:storeId',
114114
element: <VectorStoreConfigure />
115115
},
116116
{
117-
path: '/document-stores/vector/:id/:docId',
117+
path: '/document-stores/vector/:storeId/:docId',
118118
element: <VectorStoreConfigure />
119119
},
120120
{
121-
path: '/document-stores/query/:id',
121+
path: '/document-stores/query/:storeId',
122122
element: <VectorStoreQuery />
123123
}
124124
]

packages/ui/src/views/assistants/custom/CustomAssistantConfigurePreview.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cloneDeep, set } from 'lodash'
22
import { memo, useEffect, useState, useRef } from 'react'
33
import { useDispatch, useSelector } from 'react-redux'
4-
import { useNavigate } from 'react-router-dom'
4+
import { useNavigate, useParams } from 'react-router-dom'
55
import { FullPageChat } from 'flowise-embed-react'
66
import PropTypes from 'prop-types'
77

@@ -76,8 +76,7 @@ const CustomAssistantConfigurePreview = () => {
7676
const getToolsApi = useApi(assistantsApi.getTools)
7777
const getSpecificChatflowApi = useApi(chatflowsApi.getSpecificChatflow)
7878

79-
const URLpath = document.location.pathname.toString().split('/')
80-
const customAssistantId = URLpath[URLpath.length - 1] === 'assistants' ? '' : URLpath[URLpath.length - 1]
79+
const { id: customAssistantId } = useParams()
8180

8281
const [chatModelsComponents, setChatModelsComponents] = useState([])
8382
const [chatModelsOptions, setChatModelsOptions] = useState([])

packages/ui/src/views/docstore/DocumentStoreDetail.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
33
import * as PropTypes from 'prop-types'
4-
import { useNavigate } from 'react-router-dom'
4+
import { useNavigate, useParams } from 'react-router-dom'
55

66
// material-ui
77
import {
@@ -146,8 +146,7 @@ const DocumentStoreDetails = () => {
146146
const [anchorEl, setAnchorEl] = useState(null)
147147
const open = Boolean(anchorEl)
148148

149-
const URLpath = document.location.pathname.toString().split('/')
150-
const storeId = URLpath[URLpath.length - 1] === 'document-stores' ? '' : URLpath[URLpath.length - 1]
149+
const { storeId } = useParams()
151150

152151
const openPreviewSettings = (id) => {
153152
navigate('/document-stores/' + storeId + '/' + id)

packages/ui/src/views/docstore/LoaderConfigPreviewChunks.jsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { cloneDeep } from 'lodash'
22
import { useEffect, useState } from 'react'
33
import { validate as uuidValidate, v4 as uuidv4 } from 'uuid'
44
import { useDispatch, useSelector } from 'react-redux'
5-
import { useNavigate } from 'react-router-dom'
5+
import { useNavigate, useParams } from 'react-router-dom'
66
import ReactJson from 'flowise-react-json-view'
77

88
// Hooks
@@ -66,9 +66,7 @@ const LoaderConfigPreviewChunks = () => {
6666
const getNodesByCategoryApi = useApi(nodesApi.getNodesByCategory)
6767
const getSpecificDocumentStoreApi = useApi(documentsApi.getSpecificDocumentStore)
6868

69-
const URLpath = document.location.pathname.toString().split('/')
70-
const docLoaderNodeName = URLpath[URLpath.length - 1] === 'document-stores' ? '' : URLpath[URLpath.length - 1]
71-
const storeId = URLpath[URLpath.length - 2] === 'document-stores' ? '' : URLpath[URLpath.length - 2]
69+
const { storeId, name: docLoaderNodeName } = useParams()
7270

7371
const [selectedDocumentLoader, setSelectedDocumentLoader] = useState({})
7472

packages/ui/src/views/docstore/ShowStoredChunks.jsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
3-
import { useNavigate } from 'react-router-dom'
3+
import { useNavigate, useParams } from 'react-router-dom'
44
import ReactJson from 'flowise-react-json-view'
55

66
// material-ui
@@ -60,9 +60,7 @@ const ShowStoredChunks = () => {
6060

6161
const getChunksApi = useApi(documentsApi.getFileChunks)
6262

63-
const URLpath = document.location.pathname.toString().split('/')
64-
const fileId = URLpath[URLpath.length - 1] === 'document-stores' ? '' : URLpath[URLpath.length - 1]
65-
const storeId = URLpath[URLpath.length - 2] === 'document-stores' ? '' : URLpath[URLpath.length - 2]
63+
const { storeId, fileId } = useParams()
6664

6765
const [documentChunks, setDocumentChunks] = useState([])
6866
const [totalChunks, setTotalChunks] = useState(0)

packages/ui/src/views/docstore/VectorStoreConfigure.jsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
3-
import { useNavigate } from 'react-router-dom'
3+
import { useNavigate, useParams } from 'react-router-dom'
44
import { cloneDeep } from 'lodash'
55
import { v4 as uuidv4 } from 'uuid'
66
import moment from 'moment/moment'
@@ -50,9 +50,7 @@ const VectorStoreConfigure = () => {
5050
useNotifier()
5151
const customization = useSelector((state) => state.customization)
5252

53-
const pathSegments = document.location.pathname.toString().split('/')
54-
const storeId = pathSegments[3] || null
55-
const docId = pathSegments[4] || null
53+
const { storeId, docId } = useParams()
5654

5755
const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args))
5856
const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args))

packages/ui/src/views/docstore/VectorStoreQuery.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState, useRef } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
3-
import { useNavigate } from 'react-router-dom'
3+
import { useNavigate, useParams } from 'react-router-dom'
44
import ReactJson from 'flowise-react-json-view'
55
import { cloneDeep } from 'lodash'
66
import { v4 as uuidv4 } from 'uuid'
@@ -63,8 +63,7 @@ const VectorStoreQuery = () => {
6363
const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args))
6464
const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args))
6565

66-
const URLpath = document.location.pathname.toString().split('/')
67-
const storeId = URLpath[URLpath.length - 1] === 'document-stores' ? '' : URLpath[URLpath.length - 1]
66+
const { storeId } = useParams()
6867

6968
const [documentChunks, setDocumentChunks] = useState([])
7069
const [loading, setLoading] = useState(false)

0 commit comments

Comments
 (0)