Skip to content

Commit

Permalink
fix: getting docId, storeId parameters (#3761)
Browse files Browse the repository at this point in the history
* fix: getting docId, storeId parameters

* useparams to get path params

---------

Co-authored-by: Henry <[email protected]>
  • Loading branch information
hardviper and HenryHengZJ authored Jan 3, 2025
1 parent d71ad22 commit b6165e3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 27 deletions.
12 changes: 6 additions & 6 deletions packages/ui/src/routes/MainRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,27 @@ const MainRoutes = {
element: <Documents />
},
{
path: '/document-stores/:id',
path: '/document-stores/:storeId',
element: <DocumentStoreDetail />
},
{
path: '/document-stores/chunks/:id/:id',
path: '/document-stores/chunks/:storeId/:fileId',
element: <ShowStoredChunks />
},
{
path: '/document-stores/:id/:name',
path: '/document-stores/:storeId/:name',
element: <LoaderConfigPreviewChunks />
},
{
path: '/document-stores/vector/:id',
path: '/document-stores/vector/:storeId',
element: <VectorStoreConfigure />
},
{
path: '/document-stores/vector/:id/:docId',
path: '/document-stores/vector/:storeId/:docId',
element: <VectorStoreConfigure />
},
{
path: '/document-stores/query/:id',
path: '/document-stores/query/:storeId',
element: <VectorStoreQuery />
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cloneDeep, set } from 'lodash'
import { memo, useEffect, useState, useRef } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'
import { FullPageChat } from 'flowise-embed-react'
import PropTypes from 'prop-types'

Expand Down Expand Up @@ -76,8 +76,7 @@ const CustomAssistantConfigurePreview = () => {
const getToolsApi = useApi(assistantsApi.getTools)
const getSpecificChatflowApi = useApi(chatflowsApi.getSpecificChatflow)

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

const [chatModelsComponents, setChatModelsComponents] = useState([])
const [chatModelsOptions, setChatModelsOptions] = useState([])
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/src/views/docstore/DocumentStoreDetail.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import * as PropTypes from 'prop-types'
import { useNavigate } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'

// material-ui
import {
Expand Down Expand Up @@ -146,8 +146,7 @@ const DocumentStoreDetails = () => {
const [anchorEl, setAnchorEl] = useState(null)
const open = Boolean(anchorEl)

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

const openPreviewSettings = (id) => {
navigate('/document-stores/' + storeId + '/' + id)
Expand Down
6 changes: 2 additions & 4 deletions packages/ui/src/views/docstore/LoaderConfigPreviewChunks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cloneDeep } from 'lodash'
import { useEffect, useState } from 'react'
import { validate as uuidValidate, v4 as uuidv4 } from 'uuid'
import { useDispatch, useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'
import ReactJson from 'flowise-react-json-view'

// Hooks
Expand Down Expand Up @@ -66,9 +66,7 @@ const LoaderConfigPreviewChunks = () => {
const getNodesByCategoryApi = useApi(nodesApi.getNodesByCategory)
const getSpecificDocumentStoreApi = useApi(documentsApi.getSpecificDocumentStore)

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

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

Expand Down
6 changes: 2 additions & 4 deletions packages/ui/src/views/docstore/ShowStoredChunks.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'
import ReactJson from 'flowise-react-json-view'

// material-ui
Expand Down Expand Up @@ -60,9 +60,7 @@ const ShowStoredChunks = () => {

const getChunksApi = useApi(documentsApi.getFileChunks)

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

const [documentChunks, setDocumentChunks] = useState([])
const [totalChunks, setTotalChunks] = useState(0)
Expand Down
6 changes: 2 additions & 4 deletions packages/ui/src/views/docstore/VectorStoreConfigure.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'
import { cloneDeep } from 'lodash'
import { v4 as uuidv4 } from 'uuid'
import moment from 'moment/moment'
Expand Down Expand Up @@ -50,9 +50,7 @@ const VectorStoreConfigure = () => {
useNotifier()
const customization = useSelector((state) => state.customization)

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

const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args))
const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args))
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/src/views/docstore/VectorStoreQuery.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState, useRef } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'
import ReactJson from 'flowise-react-json-view'
import { cloneDeep } from 'lodash'
import { v4 as uuidv4 } from 'uuid'
Expand Down Expand Up @@ -63,8 +63,7 @@ const VectorStoreQuery = () => {
const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args))
const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args))

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

const [documentChunks, setDocumentChunks] = useState([])
const [loading, setLoading] = useState(false)
Expand Down

0 comments on commit b6165e3

Please sign in to comment.