未验证 提交 b1a387a9 编写于 作者: R RotPublic 提交者: GitHub

修复路由跳转bug (#1163)

* fileNames

* fixgoutebug

* fixgoutebug2

* fixtype
上级 89705493
...@@ -37,6 +37,7 @@ import useComponents from '~/hooks/useComponents'; ...@@ -37,6 +37,7 @@ import useComponents from '~/hooks/useComponents';
import {useTranslation} from 'react-i18next'; import {useTranslation} from 'react-i18next';
import {fetcher} from '~/utils/fetch'; import {fetcher} from '~/utils/fetch';
import {Child} from './ProfilerPage/OperatorView/type'; import {Child} from './ProfilerPage/OperatorView/type';
import {isArray} from 'lodash';
const BASE_URI: string = import.meta.env.SNOWPACK_PUBLIC_BASE_URI; const BASE_URI: string = import.meta.env.SNOWPACK_PUBLIC_BASE_URI;
const PUBLIC_PATH: string = import.meta.env.SNOWPACK_PUBLIC_PATH; const PUBLIC_PATH: string = import.meta.env.SNOWPACK_PUBLIC_PATH;
...@@ -297,7 +298,8 @@ const Navbar: FunctionComponent = () => { ...@@ -297,7 +298,8 @@ const Navbar: FunctionComponent = () => {
const currentPath = useMemo(() => pathname.replace(BASE_URI, ''), [pathname]); const currentPath = useMemo(() => pathname.replace(BASE_URI, ''), [pathname]);
const [components] = useComponents(); const [components] = useComponents();
const routePush = (route: any, Components: any[]) => { const routePush = (route: any, component: any) => {
const Components = isArray(component) ? [...component] : [...component.values()];
if (navList.includes(routeEm[route.id])) { if (navList.includes(routeEm[route.id])) {
// debugger; // debugger;
...@@ -311,34 +313,49 @@ const Navbar: FunctionComponent = () => { ...@@ -311,34 +313,49 @@ const Navbar: FunctionComponent = () => {
} }
}; };
const newcomponents = useMemo(() => { const newcomponents = useMemo(() => {
const Components = []; const Components = new Map();
const parent: any[] = []; const parent: any[] = [];
if (navList.length > 0) { if (navList.length > 0) {
for (const item of components) { for (const item of components) {
// debugger;
// const Id: any = item.id; // const Id: any = item.id;
if (navList.includes(routeEm[item.id])) { if (navList.includes(routeEm[item.id])) {
Components.push(item); // Components.push(item);
Components.set(item.id, item);
} }
if (item.children) { if (item.children) {
for (const Route of item.children) { for (const Route of item.children) {
const flag = routePush(Route, Components); const flag = routePush(Route, Components);
if (flag && !parent.includes(item.id)) { if (flag && !parent.includes(item.id)) {
parent.push(item.id); parent.push(item.id);
Components.push(item); const newItems = {
...item,
children: [Route]
};
Components.set(item.id, newItems);
} else if (flag && parent.includes(item.id)) {
// debugger;
const newItem = Components.get(item.id);
const newItems = {
...newItem,
children: [...newItem.children, Route]
};
Components.set(item.id, newItems);
} }
} }
} }
} }
} }
return Components; console.log('Components', [...Components], Components);
// debugger;
return [...Components.values()];
}, [components, navList]); }, [components, navList]);
const componentsInNavbar = useMemo(() => newcomponents.slice(0, MAX_ITEM_COUNT_IN_NAVBAR), [newcomponents]); const componentsInNavbar = useMemo(() => newcomponents.slice(0, MAX_ITEM_COUNT_IN_NAVBAR), [newcomponents]);
const flattenMoreComponents = useMemo( const flattenMoreComponents = useMemo(
() => flatten(newcomponents.slice(MAX_ITEM_COUNT_IN_NAVBAR)), () => flatten(newcomponents.slice(MAX_ITEM_COUNT_IN_NAVBAR)),
[newcomponents] [newcomponents]
); );
const componentsInMoreMenu = useMemo( const componentsInMoreMenu: any = useMemo(
() => () =>
flattenMoreComponents.map(item => ({ flattenMoreComponents.map(item => ({
...item, ...item,
...@@ -347,18 +364,25 @@ const Navbar: FunctionComponent = () => { ...@@ -347,18 +364,25 @@ const Navbar: FunctionComponent = () => {
[currentPath, flattenMoreComponents] [currentPath, flattenMoreComponents]
); );
const [navItemsInNavbar, setNavItemsInNavbar] = useState<NavbarItemType[]>([]); const [navItemsInNavbar, setNavItemsInNavbar] = useState<NavbarItemType[]>([]);
const routesChange = (route: any) => { const routesChange = (route: any, parentPath?: any) => {
// debugger;
if (navList.includes(routeEm[route.id])) { if (navList.includes(routeEm[route.id])) {
// debugger; // debugger;
if (parentPath) {
history.push(`${parentPath}/${route.id}`);
return true;
} else {
history.push(`/${route.id}`); history.push(`/${route.id}`);
return true; return true;
}
// setDefaultRoute(route.id); // setDefaultRoute(route.id);
} }
if (route.Children) { if (route.children) {
for (const Route of route.Children) { for (const Route of route.children) {
routesChange(Route); routesChange(Route, `/${route.id}`);
} }
} }
// return false;
}; };
useEffect(() => { useEffect(() => {
// setLoading(true); // setLoading(true);
...@@ -380,12 +404,12 @@ const Navbar: FunctionComponent = () => { ...@@ -380,12 +404,12 @@ const Navbar: FunctionComponent = () => {
useEffect(() => { useEffect(() => {
setNavItemsInNavbar(oldItems => setNavItemsInNavbar(oldItems =>
componentsInNavbar.map(item => { componentsInNavbar.map(item => {
const children = item.children?.map(child => ({ const children = item.children?.map((child: any) => ({
...child, ...child,
active: child.path === currentPath active: child.path === currentPath
})); }));
if (item.children && !item.path) { if (item.children && !item.path) {
const child = item.children.find(child => child.path === currentPath); const child = item.children.find((child: any) => child.path === currentPath);
if (child) { if (child) {
return { return {
...item, ...item,
...@@ -401,7 +425,7 @@ const Navbar: FunctionComponent = () => { ...@@ -401,7 +425,7 @@ const Navbar: FunctionComponent = () => {
return { return {
...item, ...item,
...oldItem, ...oldItem,
name: item.children?.find(c => c.id === oldItem.cid)?.name ?? item.name, name: item.children?.find((c: any) => c.id === oldItem.cid)?.name ?? item.name,
active: false, active: false,
children children
}; };
......
...@@ -81,12 +81,12 @@ const routes: Route[] = [ ...@@ -81,12 +81,12 @@ const routes: Route[] = [
children: [ children: [
{ {
id: 'graphDynamic', id: 'graphDynamic',
path: '/graphDynamic', path: '/graph/graphDynamic',
component: React.lazy(() => import('~/pages/graphDynamic')) component: React.lazy(() => import('~/pages/graphDynamic'))
}, },
{ {
id: 'graphStatic', id: 'graphStatic',
path: '/graphStatic', path: '/graph/graphStatic',
component: React.lazy(() => import('~/pages/graphStatic')) component: React.lazy(() => import('~/pages/graphStatic'))
} }
] ]
......
...@@ -14,20 +14,20 @@ ...@@ -14,20 +14,20 @@
* limitations under the License. * limitations under the License.
*/ */
// export default [ export default [
// 'scalar', 'scalar',
// 'image', 'image',
// 'text', // 'text',
// 'embeddings', 'embeddings',
// 'audio', 'audio',
// 'histogram', 'histogram',
// 'hyper_parameters', 'hyper_parameters',
// 'static_graph', 'static_graph',
// 'dynamic_graph', 'dynamic_graph',
// 'pr_curve', 'pr_curve',
// 'roc_curve', 'roc_curve',
// 'profiler', 'profiler',
// 'x2paddle', 'x2paddle',
// 'fastdeploy_server' 'fastdeploy_server'
// ]; ];
export default ['x2paddle']; // export default ['dynamic_graph'];
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册