From 9493bd5af826ea59eb6672120846f9b70b0f4587 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sun, 8 Oct 2023 10:32:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87url?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=8F=82=E6=95=B0=E9=80=89=E6=8B=A9=E5=BC=95?= =?UTF-8?q?=E6=93=8E=20(#533)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Chushen --- packages/gi-site/src/pages/Dataset/Create.tsx | 144 +++++++++++------- 1 file changed, 89 insertions(+), 55 deletions(-) diff --git a/packages/gi-site/src/pages/Dataset/Create.tsx b/packages/gi-site/src/pages/Dataset/Create.tsx index a131261b9..ebf9f9c7d 100644 --- a/packages/gi-site/src/pages/Dataset/Create.tsx +++ b/packages/gi-site/src/pages/Dataset/Create.tsx @@ -68,16 +68,19 @@ const DataSource: React.FunctionComponent = props => { //@ts-ignore const [state, setState] = React.useState<{ - active: string; + activeType: string; + activeEngine?: string; engines: Record; isReady: boolean; }>(() => { const { searchParams, path } = getSearchParams(window.location); - const active = searchParams.get('type') || 'FILE'; + const activeType = searchParams.get('type') || 'FILE'; + const activeEngine = searchParams.get('engine') ?? undefined; return { - active, + activeType, engines: {}, isReady: false, + activeEngine, }; }); @@ -136,7 +139,24 @@ const DataSource: React.FunctionComponent = props => { }); })(); }, []); - const { engines, active, isReady } = state; + const { engines, activeType, activeEngine, isReady } = state; + const currentEngines = engines[state.activeType] || []; + + const handleChangeEngine = (value?: string) => { + const { searchParams, path } = getSearchParams(window.location); + if (value) { + searchParams.set('engine', value); + } else { + searchParams.delete('engine'); + } + window.location.hash = `${path}?${searchParams.toString()}`; + setState(preState => { + return { + ...preState, + activeEngine: value, + }; + }); + }; const handleChangeType = value => { const { searchParams, path } = getSearchParams(window.location); @@ -145,74 +165,88 @@ const DataSource: React.FunctionComponent = props => { setState(preState => { return { ...preState, - active: value, + activeType: value, }; }); + + // 切换类型时同时触发更新引擎选择相关数据 + handleChangeEngine(engines[value]?.[0]?.id); }; - const currentEngines = engines[state.active] || []; + const renderEngineTabs = () => { + const content = currentEngines.map(server => { + const { component: ServerComponent, name } = server; + if (!ServerComponent) { + return null; + } + const { icon } = TYPE_ICONS[server.type || 'api']; - const content = currentEngines.map(server => { - const { component: ServerComponent, name } = server; - if (!ServerComponent) { - return null; - } - const { icon } = TYPE_ICONS[server.type || 'api']; + const TabTitle = ( +
+ {name === $i18n.get({ id: 'gi-site.pages.Dataset.Create.OfficialGVpDataService', dm: 'G6VP 官方数据服务' }) + ? 'GraphJSON' + : name} +
+ ); - const TabTitle = ( -
- {name === $i18n.get({ id: 'gi-site.pages.Dataset.Create.OfficialGVpDataService', dm: 'G6VP 官方数据服务' }) - ? 'GraphJSON' - : name} -
- ); + return ( + + {/** @ts-ignore */} + + + ); + }); return ( - - {/** @ts-ignore */} - - + + {content} + ); - }); - const emptyContent = ( - -
- {$i18n.get({ - id: 'gi-site.pages.Dataset.Create.ThisTypeOfDataSource', - dm: '该类型的数据源还在建设中,请关注我们 github 进展:https://github.com/antvis/G6VP', - })} -
-
+ }; + + const emptyTabs = ( + + +
+ {$i18n.get({ + id: 'gi-site.pages.Dataset.Create.ThisTypeOfDataSource', + dm: '该类型的数据源还在建设中,请关注我们 github 进展:https://github.com/antvis/G6VP', + })} +
+
+
); - const loadingContent = ( - -
- - {$i18n.get({ - id: 'gi-site.pages.Dataset.Create.AssetsIsLoading', - dm: 'Please wait while the asset is loading', - })} -
-
+ const loadingTabs = ( + + +
+ + {$i18n.get({ + id: 'gi-site.pages.Dataset.Create.AssetsIsLoading', + dm: 'Please wait while the asset is loading', + })} +
+
+
); - const renderTabContent = () => { + const renderTabs = () => { if (!isReady) { - return loadingContent; + return loadingTabs; } if (currentEngines.length === 0) { - return emptyContent; + return emptyTabs; } - return content; + return renderEngineTabs(); }; return ( @@ -229,12 +263,12 @@ const DataSource: React.FunctionComponent = props => { - +
- {renderTabContent()} + {renderTabs()}
);