diff --git a/chat2db-client/src/blocks/Tree/hooks/useGetRightClickMenu.ts b/chat2db-client/src/blocks/Tree/hooks/useGetRightClickMenu.ts index 84cee72c..13d6a653 100644 --- a/chat2db-client/src/blocks/Tree/hooks/useGetRightClickMenu.ts +++ b/chat2db-client/src/blocks/Tree/hooks/useGetRightClickMenu.ts @@ -12,8 +12,8 @@ import { ITreeConfigItem, treeConfig } from '../treeConfig'; import { useMemo } from 'react'; // ----- store ----- -import { createConsole, addWorkspaceTab } from '@/store/console'; -import { useWorkspaceStore } from '@/store/workspace'; +import { createConsole, addWorkspaceTab } from '@/pages/main/workspace/store/console'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; // ---- functions ----- import { openView, openFunction, openProcedure, openTrigger } from '../functions/openAsyncSql'; diff --git a/chat2db-client/src/components/ConnectionEdit/index.tsx b/chat2db-client/src/components/ConnectionEdit/index.tsx index 70304f27..987a7ec9 100644 --- a/chat2db-client/src/components/ConnectionEdit/index.tsx +++ b/chat2db-client/src/components/ConnectionEdit/index.tsx @@ -15,7 +15,7 @@ import LoadingGracile from '@/components/Loading/LoadingGracile'; import Driver from './components/Driver'; // ----- store ----- -import { useConnectionStore } from '@/store/connection'; +import { useConnectionStore } from '@/pages/main/store/connection'; const { Option } = Select; diff --git a/chat2db-client/src/components/ConsoleEditor/components/OperationLine/index.tsx b/chat2db-client/src/components/ConsoleEditor/components/OperationLine/index.tsx index 03ab4d40..ca702618 100644 --- a/chat2db-client/src/components/ConsoleEditor/components/OperationLine/index.tsx +++ b/chat2db-client/src/components/ConsoleEditor/components/OperationLine/index.tsx @@ -55,7 +55,7 @@ const OperationLine = (props: IProps) => {
- {/* */} +
); diff --git a/chat2db-client/src/components/ConsoleEditor/components/SelectBoundInfo/index.tsx b/chat2db-client/src/components/ConsoleEditor/components/SelectBoundInfo/index.tsx index 5e19602f..f5765df2 100644 --- a/chat2db-client/src/components/ConsoleEditor/components/SelectBoundInfo/index.tsx +++ b/chat2db-client/src/components/ConsoleEditor/components/SelectBoundInfo/index.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useMemo, useState } from 'react'; import { IBoundInfo } from '../../index'; import { Dropdown } from 'antd'; -import { useConnectionStore } from '@/store/connection'; +import { useConnectionStore } from '@/pages/main/store/connection'; import connectionService from '@/service/connection'; import styles from './index.less'; diff --git a/chat2db-client/src/components/CreateDatabase/index.tsx b/chat2db-client/src/components/CreateDatabase/index.tsx index 203fd9c8..aacdaba4 100644 --- a/chat2db-client/src/components/CreateDatabase/index.tsx +++ b/chat2db-client/src/components/CreateDatabase/index.tsx @@ -8,7 +8,7 @@ import sqlService from '@/service/sql'; import i18n from '@/i18n'; import { debounce } from 'lodash'; import { DatabaseTypeCode } from '@/constants'; -import { setOpenCreateDatabaseModal } from '@/store/workspace/modal'; +import { setOpenCreateDatabaseModal } from '@/pages/main/workspace/store/modal'; interface IProps { relyOnParams: { diff --git a/chat2db-client/src/components/CustomLayout/index.tsx b/chat2db-client/src/components/CustomLayout/index.tsx index da5b63f4..d4ea881f 100644 --- a/chat2db-client/src/components/CustomLayout/index.tsx +++ b/chat2db-client/src/components/CustomLayout/index.tsx @@ -1,8 +1,8 @@ import React, { memo } from 'react'; import styles from './index.less'; import classnames from 'classnames'; -import { useWorkspaceStore } from '@/store/workspace'; -import { togglePanelLeft, togglePanelRight } from '@/store/workspace/config'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; +import { togglePanelLeft, togglePanelRight } from '@/pages/main/workspace/store/config'; interface IProps { className?: string; diff --git a/chat2db-client/src/hooks/useCreateConsole.ts b/chat2db-client/src/hooks/useCreateConsole.ts index ce556c41..6dbb1ded 100644 --- a/chat2db-client/src/hooks/useCreateConsole.ts +++ b/chat2db-client/src/hooks/useCreateConsole.ts @@ -1,4 +1,5 @@ -import { setWorkspaceTabList, useConsoleStore, setActiveConsoleId } from '@/store/console'; +import { setWorkspaceTabList, setActiveConsoleId } from '@/pages/main/workspace/store/console'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; import { ConsoleStatus, ConsoleOpenedStatus, WorkspaceTabType, DatabaseTypeCode } from '@/constants' import historyService from '@/service/history'; @@ -14,7 +15,7 @@ interface ICreateConsoleParams { } function useCreateConsole() { - const { workspaceTabList } = useConsoleStore(state => { + const { workspaceTabList } = useWorkspaceStore(state => { return { workspaceTabList: state.workspaceTabList, } diff --git a/chat2db-client/src/hooks/useGetConnection.ts b/chat2db-client/src/hooks/useGetConnection.ts index 18edd3d1..a74515fa 100644 --- a/chat2db-client/src/hooks/useGetConnection.ts +++ b/chat2db-client/src/hooks/useGetConnection.ts @@ -1,9 +1,9 @@ import { useEffect } from 'react'; import connectionService from '@/service/connection'; -import { setConnectionEnvList, getConnectionList } from '@/store/connection'; -import { useWorkspaceStore } from '@/store/workspace'; -import { setCurrentConnectionDetails } from '@/store/workspace/common'; +import { setConnectionEnvList, getConnectionList } from '@/pages/main/store/connection'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; +import { setCurrentConnectionDetails } from '@/pages/main/workspace/store/common'; const useGetConnection = () => { diff --git a/chat2db-client/src/pages/main/connection/index.tsx b/chat2db-client/src/pages/main/connection/index.tsx index 1641f5ae..f556cd80 100644 --- a/chat2db-client/src/pages/main/connection/index.tsx +++ b/chat2db-client/src/pages/main/connection/index.tsx @@ -22,7 +22,7 @@ import MenuLabel from '@/components/MenuLabel'; import useClickAndDoubleClick from '@/hooks/useClickAndDoubleClick'; // ----- store ----- -import { useConnectionStore, getConnectionList } from '@/store/connection'; +import { useConnectionStore, getConnectionList } from '@/pages/main/store/connection'; import styles from './index.less'; diff --git a/chat2db-client/src/pages/main/index.tsx b/chat2db-client/src/pages/main/index.tsx index 2c852ef3..4d3cc90e 100644 --- a/chat2db-client/src/pages/main/index.tsx +++ b/chat2db-client/src/pages/main/index.tsx @@ -88,19 +88,13 @@ function MainPage(props: IProps) { if (!activeNav) { return; } - // activeNav 发生变化,同步到全局状态管理 + activeNav.isLoad = true; dispatch({ type: 'mainPage/updateCurPage', payload: activeNav.key, }); - // activeNav 发生变化 如果没有选中连接并且不在connections 那么需要跳转到 连接页面 - // if (!curConnection?.id && activeNav.key !== 'connections') { - // setActiveNav(navConfig[2]); - // } - // activeNav 变化 同步地址栏变化 - // change url,but no page refresh - // window.history.pushState({}, "", `/#/${activeNav.key}`); + }, [activeNav]); useEffect(() => { diff --git a/chat2db-client/src/store/connection/index.ts b/chat2db-client/src/pages/main/store/connection/index.ts similarity index 100% rename from chat2db-client/src/store/connection/index.ts rename to chat2db-client/src/pages/main/store/connection/index.ts diff --git a/chat2db-client/src/store/monaco/index.ts b/chat2db-client/src/pages/main/store/monaco/index.ts similarity index 100% rename from chat2db-client/src/store/monaco/index.ts rename to chat2db-client/src/pages/main/store/monaco/index.ts diff --git a/chat2db-client/src/pages/main/workspace/components/NewTableList/index.tsx b/chat2db-client/src/pages/main/workspace/components/NewTableList/index.tsx index ba51ef2e..a95699c0 100644 --- a/chat2db-client/src/pages/main/workspace/components/NewTableList/index.tsx +++ b/chat2db-client/src/pages/main/workspace/components/NewTableList/index.tsx @@ -2,7 +2,7 @@ import React, { memo, useEffect, useState } from 'react'; import styles from './index.less'; import classnames from 'classnames'; -import { useWorkspaceStore } from '@/store/workspace'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; // ----- components ----- import OperationLine from '../OperationLine'; diff --git a/chat2db-client/src/pages/main/workspace/components/OperationLine/index.tsx b/chat2db-client/src/pages/main/workspace/components/OperationLine/index.tsx index fa006f27..38c62612 100644 --- a/chat2db-client/src/pages/main/workspace/components/OperationLine/index.tsx +++ b/chat2db-client/src/pages/main/workspace/components/OperationLine/index.tsx @@ -10,7 +10,7 @@ import { DatabaseTypeCode } from '@/constants'; import Iconfont from '@/components/Iconfont'; // ----- store ----- -import { useWorkspaceStore } from '@/store/workspace'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; interface IProps { searchValue: string; diff --git a/chat2db-client/src/pages/main/workspace/components/WorkspaceExtend/index.tsx b/chat2db-client/src/pages/main/workspace/components/WorkspaceExtend/index.tsx index 437664f4..3a13019b 100644 --- a/chat2db-client/src/pages/main/workspace/components/WorkspaceExtend/index.tsx +++ b/chat2db-client/src/pages/main/workspace/components/WorkspaceExtend/index.tsx @@ -4,7 +4,7 @@ import classnames from 'classnames'; import { Popover } from 'antd'; import Iconfont from '@/components/Iconfont'; import Output from '@/components/Output'; -import { useWorkspaceStore } from '@/store/workspace'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; import i18n from '@/i18n'; interface IProps { diff --git a/chat2db-client/src/pages/main/workspace/components/WorkspaceLeftHeader/index.tsx b/chat2db-client/src/pages/main/workspace/components/WorkspaceLeftHeader/index.tsx index 8f207ee4..cc1b9cfe 100644 --- a/chat2db-client/src/pages/main/workspace/components/WorkspaceLeftHeader/index.tsx +++ b/chat2db-client/src/pages/main/workspace/components/WorkspaceLeftHeader/index.tsx @@ -4,9 +4,9 @@ import classnames from 'classnames'; import styles from './index.less'; // ---- store ---- -import { useConnectionStore } from '@/store/connection'; -import { useWorkspaceStore } from '@/store/workspace'; -import { setCurrentConnectionDetails } from '@/store/workspace/common'; +import { useConnectionStore } from '@/pages/main/store/connection'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; +import { setCurrentConnectionDetails } from '@/pages/main/workspace/store/common'; // ----- components ----- import Iconfont from '@/components/Iconfont'; diff --git a/chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx b/chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx index be05a8fe..228d10f4 100644 --- a/chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx +++ b/chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx @@ -20,8 +20,8 @@ import Iconfont from '@/components/Iconfont'; import ShortcutKey from '@/components/ShortcutKey'; // ---- store ----- -import { useConsoleStore, getSavedConsoleList, setActiveConsoleId, setWorkspaceTabList } from '@/store/console'; -import { useWorkspaceStore } from '@/store/workspace'; +import { getSavedConsoleList, setActiveConsoleId, setWorkspaceTabList } from '@/pages/main/workspace/store/console'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; // ----- services ----- import historyService from '@/service/history'; @@ -29,7 +29,8 @@ import historyService from '@/service/history'; import indexedDB from '@/indexedDB'; const WorkspaceTabs = memo(() => { - const { activeConsoleId, consoleList, workspaceTabList } = useConsoleStore((state) => { + + const { activeConsoleId, consoleList, workspaceTabList } = useWorkspaceStore((state) => { return { consoleList: state.consoleList, activeConsoleId: state.activeConsoleId, diff --git a/chat2db-client/src/pages/main/workspace/index.tsx b/chat2db-client/src/pages/main/workspace/index.tsx index 92e02e51..f2d8b75c 100644 --- a/chat2db-client/src/pages/main/workspace/index.tsx +++ b/chat2db-client/src/pages/main/workspace/index.tsx @@ -1,7 +1,7 @@ import React, { memo, useRef } from 'react'; import classnames from 'classnames'; -import { useWorkspaceStore } from '@/store/workspace'; +import { useWorkspaceStore } from '@/pages/main/workspace/store'; import DraggableContainer from '@/components/DraggableContainer'; import WorkspaceLeft from './components/WorkspaceLeft'; diff --git a/chat2db-client/src/store/workspace/common.ts b/chat2db-client/src/pages/main/workspace/store/common.ts similarity index 100% rename from chat2db-client/src/store/workspace/common.ts rename to chat2db-client/src/pages/main/workspace/store/common.ts diff --git a/chat2db-client/src/store/workspace/config.ts b/chat2db-client/src/pages/main/workspace/store/config.ts similarity index 100% rename from chat2db-client/src/store/workspace/config.ts rename to chat2db-client/src/pages/main/workspace/store/config.ts diff --git a/chat2db-client/src/store/console/index.ts b/chat2db-client/src/pages/main/workspace/store/console.ts similarity index 71% rename from chat2db-client/src/store/console/index.ts rename to chat2db-client/src/pages/main/workspace/store/console.ts index 963fac34..42105387 100644 --- a/chat2db-client/src/store/console/index.ts +++ b/chat2db-client/src/pages/main/workspace/store/console.ts @@ -1,7 +1,4 @@ -import { UseBoundStoreWithEqualityFn, createWithEqualityFn } from 'zustand/traditional'; -import { devtools } from 'zustand/middleware'; -import { shallow } from 'zustand/shallow'; -import { StoreApi } from 'zustand'; +import { useWorkspaceStore } from './index'; import { IConsole, ICreateConsoleParams } from '@/typings'; import { IWorkspaceTab } from '@/typings/workspace'; import historyService from '@/service/history'; @@ -13,37 +10,32 @@ export interface IConsoleStore { workspaceTabList: IWorkspaceTab[] | null; } -const initConsoleStore = { +export const initConsoleStore = { consoleList: null, activeConsoleId: null, workspaceTabList: null, } -export const useConsoleStore: UseBoundStoreWithEqualityFn> = createWithEqualityFn( - devtools(() => (initConsoleStore)), - shallow -); - export const getSavedConsoleList = () => { historyService.getSavedConsoleList({ tabOpened: 'y', pageNo: 1, pageSize: 20, }).then((res) => { - useConsoleStore.setState({ consoleList: res?.data }); + useWorkspaceStore.setState({ consoleList: res?.data }); }); } export const setActiveConsoleId = (id: IConsoleStore['activeConsoleId']) => { - useConsoleStore.setState({ activeConsoleId: id }); + useWorkspaceStore.setState({ activeConsoleId: id }); } export const setWorkspaceTabList = (items: IConsoleStore['workspaceTabList']) => { - useConsoleStore.setState({ workspaceTabList: items }); + useWorkspaceStore.setState({ workspaceTabList: items }); } export const createConsole = (params: ICreateConsoleParams)=>{ - const workspaceTabList = useConsoleStore.getState().workspaceTabList; + const workspaceTabList = useWorkspaceStore.getState().workspaceTabList; const newConsole = { ...params, name: params.name || 'create console', @@ -71,7 +63,7 @@ export const createConsole = (params: ICreateConsoleParams)=>{ } export const addWorkspaceTab = (params: IWorkspaceTab) => { - const workspaceTabList = useConsoleStore.getState().workspaceTabList; + const workspaceTabList = useWorkspaceStore.getState().workspaceTabList; if(workspaceTabList?.findIndex((item) => item?.id === params?.id) !== -1){ setActiveConsoleId(params.id); return; diff --git a/chat2db-client/src/store/workspace/index.ts b/chat2db-client/src/pages/main/workspace/store/index.ts similarity index 91% rename from chat2db-client/src/store/workspace/index.ts rename to chat2db-client/src/pages/main/workspace/store/index.ts index ed98612b..024311e1 100644 --- a/chat2db-client/src/store/workspace/index.ts +++ b/chat2db-client/src/pages/main/workspace/store/index.ts @@ -4,7 +4,7 @@ import { shallow } from 'zustand/shallow'; import { StoreApi } from 'zustand'; import { initConfigStore, IConfigStore } from './config'; -import { consoleStore, IConsoleStore } from './console'; +import { initConsoleStore, IConsoleStore } from './console'; import { initCommonStore, ICommonStore } from './common'; import { initModalStore , IModalStore } from './modal'; @@ -13,8 +13,8 @@ export type IStore = IConfigStore & IConsoleStore & ICommonStore & IModalStore; export const useWorkspaceStore: UseBoundStoreWithEqualityFn> = createWithEqualityFn( devtools( persist( - (set) => ({ - ...consoleStore(set), + () => ({ + ...initConsoleStore, ...initConfigStore, ...initCommonStore, ...initModalStore, diff --git a/chat2db-client/src/store/workspace/modal.ts b/chat2db-client/src/pages/main/workspace/store/modal.ts similarity index 100% rename from chat2db-client/src/store/workspace/modal.ts rename to chat2db-client/src/pages/main/workspace/store/modal.ts diff --git a/chat2db-client/src/store/workspace/console.ts b/chat2db-client/src/store/workspace/console.ts deleted file mode 100644 index e4fc8e6b..00000000 --- a/chat2db-client/src/store/workspace/console.ts +++ /dev/null @@ -1,43 +0,0 @@ -export interface IConsoleStore { - activeTab: { - activeConsole: { - id: string | number | null; - }; - activeSearchResult: { - id: string | number | null; - }; - }; - setActiveConsole: (props: IActiveTabData) => void; - setActiveSearchResult: (props: IActiveTabData) => void; -} - -type IActiveTabData = { - id: string | number; -} | null - -export const consoleStore = (set): IConsoleStore => ({ - activeTab: { - activeConsole: { - id: null, - }, - activeSearchResult: { - id: null, - }, - }, - setActiveConsole: (activeConsole: IActiveTabData) => { - return set((state) => ({ - activeTab: { - ...state.activeTab, - activeConsole, - }, - })); - }, - setActiveSearchResult: (activeSearchResult: IActiveTabData) => { - return set((state) => ({ - activeTab: { - ...state.activeTab, - activeSearchResult, - }, - })); - }, -});