Skip to content

Commit 6cf6262

Browse files
committed
nav
1 parent 0eccb97 commit 6cf6262

11 files changed

Lines changed: 112 additions & 66 deletions

File tree

chat2db-client/.umirc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default defineConfig({
5050
},
5151
{
5252
path: '/',
53-
redirect: '/connections',
53+
component: 'main',
5454
},
5555
],
5656
},

chat2db-client/src/blocks/CreateConnection/index.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ type IEditConnectionDetail = IConnectionDetails | null | Pick<IConnectionDetails
1313

1414
interface IProps {
1515
className?: string;
16-
onSubmit?: (data: IConnectionDetails) => void; // 点击保存或修改的回调,我会把数据给你
17-
connectionDetail: IEditConnectionDetail;
16+
onSubmit?: (data: IConnectionDetails) => Promise<any>; // 点击保存或修改的回调,我会把数据给你
17+
connectionDetail: IEditConnectionDetail | null | undefined;
1818
noPermission?: boolean;
1919
}
2020

2121
export default memo<IProps>((props) => {
2222
const { className, onSubmit, connectionDetail: externalConnectionDetail } = props;
23-
const [connectionDetail, setConnectionDetail] = useState<IEditConnectionDetail>(externalConnectionDetail);
23+
const [connectionDetail, setConnectionDetail] = useState<IEditConnectionDetail | null | undefined>(
24+
externalConnectionDetail,
25+
);
2426

2527
useEffect(() => {
2628
setConnectionDetail(externalConnectionDetail);
@@ -32,9 +34,9 @@ export default memo<IProps>((props) => {
3234
});
3335
}
3436

35-
function handleSubmit(data: IConnectionDetails) {
36-
onSubmit?.(data);
37-
}
37+
// function handleSubmit(data: IConnectionDetails) {
38+
// return onSubmit?.(data);
39+
// }
3840

3941
return (
4042
<div className={classnames(styles.box, className)}>
@@ -49,11 +51,11 @@ export default memo<IProps>((props) => {
4951
setConnectionDetail(null);
5052
}}
5153
connectionData={connectionDetail as any}
52-
submit={handleSubmit}
54+
submit={onSubmit}
5355
/>
5456
</div>
5557
)}
56-
{!connectionDetail && (
58+
{connectionDetail === null && (
5759
<div className={styles.dataBaseListBox}>
5860
<div className={styles.dataBaseList}>
5961
{databaseTypeList.map((t) => {

chat2db-client/src/blocks/Tree/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import LoadingContent from '@/components/Loading/LoadingContent';
1515

1616
interface IProps {
1717
className?: string;
18-
initialData: ITreeNode[] | null;
18+
treeData: ITreeNode[] | null;
1919
searchValue: string;
2020
}
2121
interface TreeNodeIProps {
@@ -31,12 +31,12 @@ interface IContext {
3131
export const Context = createContext<IContext>({} as any);
3232

3333
const Tree = (props: IProps) => {
34-
const { className, initialData, searchValue } = props;
34+
const { className, treeData: outerTreeData, searchValue } = props;
3535
const [treeData, setTreeData] = useState<ITreeNode[] | null>(null);
3636

3737
useEffect(() => {
38-
setTreeData(initialData);
39-
}, [initialData]);
38+
setTreeData(outerTreeData);
39+
}, [outerTreeData]);
4040

4141
const treeNodes = useMemo(() => {
4242
return treeData?.map((item, index) => {

chat2db-client/src/components/ConnectionEdit/index.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface IProps {
3131
closeCreateConnection: () => void;
3232
connectionData: IConnectionDetails;
3333
submitCallback?: any;
34-
submit?: (data: IConnectionDetails) => void;
34+
submit?: (data: IConnectionDetails) => Promise<any>;
3535
}
3636

3737
export interface ICreateConnectionFunction {
@@ -170,7 +170,7 @@ const ConnectionEdit = forwardRef((props: IProps, ref: ForwardedRef<ICreateConne
170170

171171
// 测试、保存、修改连接
172172
function saveConnection(type: submitType) {
173-
let p = getData();
173+
const p = getData();
174174

175175
if (type !== submitType.SAVE) {
176176
p.id = backfillData.id;
@@ -181,19 +181,25 @@ const ConnectionEdit = forwardRef((props: IProps, ref: ForwardedRef<ICreateConne
181181
p.environmentId = envList[0].value;
182182
}
183183

184-
if ((type === submitType.SAVE || type === submitType.UPDATE) && submit) {
185-
submit?.(p);
186-
return;
187-
}
188-
189-
const api: any = connectionService[type](p);
190184
const loadingsButton = type === submitType.TEST ? 'testButton' : 'confirmButton';
191185

192186
setLoading({
193187
...loadings,
194188
[loadingsButton]: true,
195189
});
196190

191+
if ((type === submitType.SAVE) && submit) {
192+
submit?.(p).finally(() => {
193+
setLoading({
194+
...loadings,
195+
[loadingsButton]: false,
196+
});
197+
});
198+
return;
199+
}
200+
201+
const api: any = connectionService[type](p);
202+
197203
api
198204
.then((res: any) => {
199205
if (type === submitType.TEST) {
@@ -209,13 +215,14 @@ const ConnectionEdit = forwardRef((props: IProps, ref: ForwardedRef<ICreateConne
209215
: i18n('common.message.addedSuccessfully'),
210216
);
211217

218+
setBackfillData({
219+
...backfillData,
220+
id: res,
221+
});
222+
212223
if (type === submitType.SAVE) {
213-
setBackfillData({
214-
...backfillData,
215-
id: res,
216-
});
224+
submitCallback?.();
217225
}
218-
submitCallback?.();
219226
}
220227
})
221228
.finally(() => {

chat2db-client/src/components/ConsoleEditor/components/SelectBoundInfo/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ const SelectBoundInfo = memo(
122122
historyService.updateSavedConsole({
123123
id: boundInfo.consoleId,
124124
dataSourceId: currentData.value,
125-
dataSourceName: currentData.label
125+
dataSourceName: currentData.label,
126+
type: currentData.type,
126127
})
127128
};
128129

chat2db-client/src/pages/main/connection/index.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import useClickAndDoubleClick from '@/hooks/useClickAndDoubleClick';
2323

2424
// ----- store -----
2525
import { useConnectionStore, getConnectionList } from '@/pages/main/store/connection';
26+
import { setMainPageActiveTab } from '@/pages/main/store/main';
27+
import { setCurrentConnectionDetails } from '@/pages/main/workspace/store/common';
28+
2629

2730
import styles from './index.less';
2831

@@ -35,18 +38,19 @@ const ConnectionsPage = () => {
3538
const volatileRef = useRef<any>();
3639
const [connectionActiveId, setConnectionActiveId] = useState<IConnectionListItem['id'] | null>(null);
3740
const [isFileUploadModalOpen, setIsFileUploadModalOpen] = useState(false);
38-
const [connectionDetail, setConnectionDetail] = useState<IConnectionDetails | null>(null);
41+
const [connectionDetail, setConnectionDetail] = useState<IConnectionDetails | null | undefined>(null);
3942

4043
// 处理列表单击事件
4144
const handleMenuItemSingleClick = (t: IConnectionListItem) => {
4245
if (connectionActiveId !== t.id) {
4346
setConnectionActiveId(t.id);
4447
}
45-
}
48+
};
4649

4750
// 处理列表双击事件
4851
const handleMenuItemDoubleClick = (t: IConnectionListItem) => {
49-
setConnectionActiveId(t.id);
52+
setCurrentConnectionDetails(t);
53+
setMainPageActiveTab('workspace')
5054
};
5155

5256
// 处理列表单击和双击事件
@@ -57,7 +61,7 @@ const ConnectionsPage = () => {
5761
if (!connectionActiveId) {
5862
return;
5963
}
60-
setConnectionDetail(null);
64+
setConnectionDetail(undefined);
6165
connectionService
6266
.getDetails({ id: connectionActiveId })
6367
.then((res) => {
@@ -68,8 +72,8 @@ const ConnectionsPage = () => {
6872
});
6973
}, [connectionActiveId]);
7074

71-
//
72-
const createDropdownItems = (t) => {
75+
//
76+
const createDropdownItems = (t) => {
7377
const handelDelete = (e) => {
7478
// 禁止冒泡到menuItem
7579
e.domEvent?.stopPropagation?.();
@@ -79,12 +83,12 @@ const ConnectionsPage = () => {
7983
setConnectionActiveId(null);
8084
}
8185
});
82-
}
86+
};
8387

8488
const enterWorkSpace = (e) => {
8589
e.domEvent?.stopPropagation?.();
8690
handleMenuItemDoubleClick(t);
87-
}
91+
};
8892

8993
return [
9094
{
@@ -95,11 +99,11 @@ const ConnectionsPage = () => {
9599
{
96100
key: 'delete',
97101
label: <MenuLabel icon="&#xe6a7;" label={i18n('connection.button.remove')} />,
98-
onClick: handelDelete
102+
onClick: handelDelete,
99103
},
100-
]
101-
}
102-
104+
];
105+
};
106+
103107
const renderConnectionMenuList = () => {
104108
return connectionList?.map((t) => {
105109
return (
@@ -114,7 +118,9 @@ const ConnectionsPage = () => {
114118
className={classnames(styles.menuItem, {
115119
[styles.menuItemActive]: connectionActiveId === t.id,
116120
})}
117-
onClick={()=>{handleClickConnectionMenu(t)} }
121+
onClick={() => {
122+
handleClickConnectionMenu(t);
123+
}}
118124
>
119125
<div className={classnames(styles.menuItemsTitle)}>
120126
<span className={styles.envTag} style={{ background: t.environment.color.toLocaleLowerCase() }} />
@@ -133,13 +139,15 @@ const ConnectionsPage = () => {
133139
};
134140

135141
const onSubmit = (data) => {
136-
connectionService.save({
137-
...data,
138-
}).then((res) => {
139-
getConnectionList();
140-
setConnectionActiveId(res);
141-
});
142-
}
142+
return connectionService
143+
.save({
144+
...data,
145+
})
146+
.then((res) => {
147+
getConnectionList();
148+
setConnectionActiveId(res);
149+
});
150+
};
143151

144152
return (
145153
<>
@@ -160,9 +168,15 @@ const ConnectionsPage = () => {
160168
</Button>
161169
)}
162170
</div>
163-
<LoadingContent className={styles.layoutRight} isLoading={!connectionDetail && !!connectionActiveId}>
171+
<LoadingContent
172+
className={styles.layoutRight}
173+
isLoading={connectionDetail === undefined && !!connectionActiveId}
174+
>
164175
<CreateConnection connectionDetail={connectionDetail} onSubmit={onSubmit} />
165176
</LoadingContent>
177+
{/* <div className={styles.layoutRight}>
178+
<CreateConnection connectionDetail={connectionDetail} onSubmit={onSubmit} />
179+
</div> */}
166180
</div>
167181

168182
<FileUploadModal

chat2db-client/src/pages/main/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { ILoginUser, IRole } from '@/typings/user';
1414
// ----- hooks -----
1515
import getConnection from '@/hooks/getConnection';
1616

17+
// ----- store -----
18+
import { useMainStore, setMainPageActiveTab } from '@/pages/main/store/main';
19+
1720
// ----- block -----
1821
import Workspace from './workspace';
1922
import Dashboard from './dashboard';
@@ -22,6 +25,7 @@ import Team from './team';
2225
import Setting from '@/blocks/Setting';
2326

2427
import styles from './index.less';
28+
import { useUpdateEffect } from '@/hooks';
2529

2630
const initNavConfig: INavItem[] = [
2731
{
@@ -62,13 +66,18 @@ function MainPage() {
6266
const navigate = useNavigate();
6367
const [navConfig, setNavConfig] = useState<INavItem[]>(initNavConfig);
6468
const [userInfo, setUserInfo] = useState<ILoginUser>();
65-
const [activeNavKey, setActiveNavKey] = useState<string>(window.location.pathname.split('/')[1]);
69+
const mainPageActiveTab = useMainStore(state=> state.mainPageActiveTab)
70+
const [activeNavKey, setActiveNavKey] = useState<string>(window.location.pathname.split('/')[1] || mainPageActiveTab);
6671

6772
useEffect(() => {
6873
handleInitPage();
6974
getConnection();
7075
}, []);
7176

77+
useUpdateEffect(() => {
78+
switchingNav(mainPageActiveTab)
79+
}, [mainPageActiveTab]);
80+
7281
// 切换tab
7382
useEffect(() => {
7483
// 获取当前地址栏的tab
@@ -108,6 +117,7 @@ function MainPage() {
108117

109118
const switchingNav = (key: string) => {
110119
setActiveNavKey(key);
120+
setMainPageActiveTab(key)
111121
};
112122

113123
const handleLogout = () => {

chat2db-client/src/pages/main/team/datasource-management/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function DataSourceManagement() {
2323
showQuickJumper: true,
2424
// pageSizeOptions: ['10', '20', '30', '40'],
2525
});
26-
const [showCreateConnection, setShowCreateConnection] = useState(false)
26+
const [showCreateConnection, setShowCreateConnection] = useState(false);
2727
const connectionInfo = useRef<IConnectionDetails | null>(null);
2828

2929
const [drawerInfo, setDrawerInfo] = useState<{ open: boolean; type: AffiliationType; id?: number }>({
@@ -140,20 +140,21 @@ function DataSourceManagement() {
140140
}
141141
};
142142

143-
const handleConfirmConnection = async (data: IConnectionDetails) => {
143+
const handleConfirmConnection = (data: IConnectionDetails) => {
144144
if (JSON.stringify(connectionInfo.current) === '{}') {
145-
return;
145+
return new Promise((resolve) => {
146+
resolve(true);
147+
});
146148
}
147149
connectionInfo.current = data;
148150

149151
const isUpdate = isValid(connectionInfo?.current?.id);
150152
const requestApi = isUpdate ? updateDataSource : createDataSource;
151-
try {
152-
await requestApi({ ...connectionInfo.current });
153+
return requestApi({ ...connectionInfo.current }).then(() => {
153154
message.success(isUpdate ? i18n('common.tips.updateSuccess') : i18n('common.tips.createSuccess'));
154155
setShowCreateConnection(false);
155156
queryDataSourceList();
156-
} catch {}
157+
});
157158
};
158159

159160
return (

0 commit comments

Comments
 (0)