Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
dec08fd2
V
VisualDL
项目概览
PaddlePaddle
/
VisualDL
大约 1 年 前同步成功
通知
88
Star
4655
Fork
642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VisualDL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
dec08fd2
编写于
5月 15, 2020
作者:
P
Peter Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: dynamic render nav items
上级
6bf7b8b1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
62 addition
and
16 deletion
+62
-16
frontend/packages/core/components/Navbar.tsx
frontend/packages/core/components/Navbar.tsx
+3
-10
frontend/packages/core/hooks/useNavItems.ts
frontend/packages/core/hooks/useNavItems.ts
+32
-0
frontend/packages/core/next.config.js
frontend/packages/core/next.config.js
+0
-1
frontend/packages/core/pages/index.tsx
frontend/packages/core/pages/index.tsx
+26
-5
frontend/packages/mock/data/components.ts
frontend/packages/mock/data/components.ts
+1
-0
未找到文件。
frontend/packages/core/components/Navbar.tsx
浏览文件 @
dec08fd2
...
...
@@ -15,19 +15,10 @@ import Icon from '~/components/Icon';
import
{
InitConfig
}
from
'
@visualdl/i18n
'
;
import
Language
from
'
~/components/Language
'
;
import
ee
from
'
~/utils/event
'
;
import
intersection
from
'
lodash/intersection
'
;
import
styled
from
'
styled-components
'
;
import
useNavItems
from
'
~/hooks/useNavItems
'
;
import
{
useRouter
}
from
'
next/router
'
;
const
buildNavItems
=
process
.
env
.
NAV_ITEMS
;
const
allNavItems
=
[
'
scalars
'
,
'
samples
'
,
'
graphs
'
,
'
high-dimensional
'
];
const
navItems
=
buildNavItems
?
intersection
(
buildNavItems
.
split
(
'
,
'
).
map
(
item
=>
item
.
trim
()),
allNavItems
)
:
allNavItems
;
const
Nav
=
styled
.
nav
`
background-color:
${
navbarBackgroundColor
}
;
color:
${
textInvertColor
}
;
...
...
@@ -103,6 +94,8 @@ const Navbar: FunctionComponent = () => {
const
{
t
,
i18n
}
=
useTranslation
(
'
common
'
);
const
{
pathname
,
basePath
}
=
useRouter
();
const
navItems
=
useNavItems
();
const
path
=
useMemo
(()
=>
pathname
.
replace
(
basePath
,
''
),
[
pathname
,
basePath
]);
const
indexUrl
=
useMemo
(()
=>
{
...
...
frontend/packages/core/hooks/useNavItems.ts
0 → 100644
浏览文件 @
dec08fd2
import
{
fetcher
}
from
'
~/utils/fetch
'
;
import
intersection
from
'
lodash/intersection
'
;
import
{
useMemo
}
from
'
react
'
;
import
useRequest
from
'
~/hooks/useRequest
'
;
const
allNavItems
=
[
'
scalars
'
,
'
samples
'
,
'
high-dimensional
'
];
export
const
navMap
=
{
scalar
:
'
scalars
'
,
image
:
'
samples
'
,
embeddings
:
'
high-dimensional
'
}
as
const
;
const
useNavItems
=
()
=>
{
const
{
data
:
components
}
=
useRequest
<
(
keyof
typeof
navMap
)[]
>
(
'
/components
'
,
fetcher
,
{
refreshInterval
:
61
*
1000
,
dedupingInterval
:
29
*
1000
,
errorRetryInterval
:
29
*
1000
,
errorRetryCount
:
Number
.
POSITIVE_INFINITY
,
revalidateOnFocus
:
true
,
revalidateOnReconnect
:
true
,
refreshWhenHidden
:
false
,
refreshWhenOffline
:
false
});
const
navItems
=
useMemo
(()
=>
intersection
(
components
?.
map
(
component
=>
navMap
[
component
])
??
[],
allNavItems
),
[
components
]);
return
navItems
;
};
export
default
useNavItems
;
frontend/packages/core/next.config.js
浏览文件 @
dec08fd2
...
...
@@ -31,7 +31,6 @@ module.exports = {
DEFAULT_LANGUAGE
,
LOCALE_PATH
,
LANGUAGES
,
NAV_ITEMS
:
process
.
env
.
NAV_ITEMS
,
PUBLIC_PATH
:
publicPath
,
API_URL
:
apiUrl
},
...
...
frontend/packages/core/pages/index.tsx
浏览文件 @
dec08fd2
import
{
NextI18NextPage
,
Router
}
from
'
~/utils/i18n
'
;
import
React
,
{
useEffect
}
from
'
react
'
;
import
{
headerHeight
,
primaryColor
,
size
}
from
'
~/utils/style
'
;
import
{
useEffect
}
from
'
react
'
;
import
HashLoader
from
'
react-spinners/HashLoader
'
;
import
styled
from
'
styled-components
'
;
import
useNavItems
from
'
~/hooks/useNavItems
'
;
const
Loading
=
styled
.
div
`
${
size
(
`calc(100vh -
${
headerHeight
}
)`
,
'
100vw
'
)}
display: flex;
justify-content: center;
align-items: center;
overscroll-behavior: none;
cursor: progress;
`
;
const
Index
:
NextI18NextPage
=
()
=>
{
const
navItmes
=
useNavItems
();
useEffect
(()
=>
{
Router
.
replace
(
'
/scalars
'
);
},
[]);
if
(
navItmes
.
length
)
{
Router
.
replace
(
`/
${
navItmes
[
0
]}
`
);
}
},
[
navItmes
]);
return
null
;
return
(
<
Loading
>
<
HashLoader
size
=
"60px"
color
=
{
primaryColor
}
/>
</
Loading
>
);
};
Index
.
getInitialProps
=
()
=>
{
return
{
namespacesRequired
:
[
'
common
'
]
namespacesRequired
:
[]
};
};
...
...
frontend/packages/mock/data/components.ts
0 → 100644
浏览文件 @
dec08fd2
export
default
[
'
scalar
'
,
'
image
'
,
'
embeddings
'
];
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录