LeftSider.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import { Link } from "react-router";
  2. import { useIntl } from "react-intl";
  3. import { useParams } from "react-router";
  4. import type { MenuProps } from "antd";
  5. import { Affix, Layout } from "antd";
  6. import { Menu } from "antd";
  7. import {
  8. AppstoreOutlined,
  9. HomeOutlined,
  10. TeamOutlined,
  11. } from "@ant-design/icons";
  12. import { useAppSelector } from "../../hooks";
  13. import { currentUser } from "../../reducers/current-user";
  14. const { Sider } = Layout;
  15. const onClick: MenuProps["onClick"] = (e) => {
  16. console.log("click ", e);
  17. };
  18. type IWidgetHeadBar = {
  19. selectedKeys?: string;
  20. openKeys?: string[];
  21. };
  22. const LeftSiderWidget = ({ selectedKeys = "", openKeys }: IWidgetHeadBar) => {
  23. //Library head bar
  24. const user = useAppSelector(currentUser);
  25. const intl = useIntl(); //i18n
  26. const { studioname } = useParams();
  27. const linkRecent = "/studio/" + studioname + "/recent/list";
  28. const linkChannel = "/studio/" + studioname + "/channel/list";
  29. const linkGroup = "/studio/" + studioname + "/group/list";
  30. const linkUserdict = "/studio/" + studioname + "/dict/list";
  31. const linkTerm = "/studio/" + studioname + "/term/list";
  32. const linkArticle = "/studio/" + studioname + "/article/list";
  33. const linkAnalysis = "/studio/" + studioname + "/exp/list";
  34. const linkCourse = "/studio/" + studioname + "/course/list";
  35. const linkSetting = "/studio/" + studioname + "/setting";
  36. const urlBase = `/studio/${studioname}`;
  37. const items: MenuProps["items"] = [
  38. {
  39. label: intl.formatMessage({
  40. id: "columns.studio.basic.title",
  41. }),
  42. key: "basic",
  43. icon: <HomeOutlined />,
  44. children: [
  45. {
  46. label: (
  47. <Link to={`/studio/${studioname}/palicanon`}>
  48. {intl.formatMessage({
  49. id: "columns.studio.palicanon.title",
  50. })}
  51. </Link>
  52. ),
  53. key: "palicanon",
  54. disabled: true,
  55. },
  56. {
  57. label: (
  58. <Link to={linkRecent}>
  59. {intl.formatMessage({
  60. id: "columns.studio.recent.title",
  61. })}
  62. </Link>
  63. ),
  64. key: "recent",
  65. },
  66. {
  67. label: (
  68. <Link to={linkChannel}>
  69. {intl.formatMessage({
  70. id: "columns.studio.channel.title",
  71. })}
  72. </Link>
  73. ),
  74. key: "channel",
  75. },
  76. {
  77. label: (
  78. <Link to={linkAnalysis}>
  79. {intl.formatMessage({
  80. id: "columns.exp.title",
  81. })}
  82. </Link>
  83. ),
  84. key: "analysis",
  85. },
  86. {
  87. label: intl.formatMessage({
  88. id: "columns.studio.setting.title",
  89. }),
  90. key: "setting",
  91. children: [
  92. {
  93. label: (
  94. <Link to={linkSetting}>
  95. {intl.formatMessage({
  96. id: "buttons.general",
  97. })}
  98. </Link>
  99. ),
  100. key: "general",
  101. },
  102. {
  103. label: (
  104. <Link to={`${urlBase}/ai/models/list`}>
  105. {intl.formatMessage({
  106. id: "buttons.ai-models",
  107. })}
  108. </Link>
  109. ),
  110. key: "models",
  111. },
  112. ],
  113. },
  114. ],
  115. },
  116. {
  117. label: intl.formatMessage({
  118. id: "columns.studio.advance.title",
  119. }),
  120. key: "advance",
  121. icon: <AppstoreOutlined />,
  122. children: [
  123. {
  124. label: intl.formatMessage({
  125. id: "labels.task",
  126. }),
  127. key: "task",
  128. children: [
  129. {
  130. label: (
  131. <Link to={`${urlBase}/task/hall`}>
  132. {intl.formatMessage({
  133. id: "labels.task.hall",
  134. })}
  135. </Link>
  136. ),
  137. key: "task_hall",
  138. },
  139. {
  140. label: (
  141. <Link to={`${urlBase}/task/list`}>
  142. {intl.formatMessage({
  143. id: "labels.task.mine",
  144. })}
  145. </Link>
  146. ),
  147. key: "task_mine",
  148. },
  149. {
  150. label: (
  151. <Link to={`${urlBase}/task/projects`}>
  152. {intl.formatMessage({
  153. id: "labels.task.my.project",
  154. })}
  155. </Link>
  156. ),
  157. key: "task_projects",
  158. },
  159. {
  160. label: (
  161. <Link to={`${urlBase}/task/workflows`}>
  162. {intl.formatMessage({
  163. id: "labels.task.workflows",
  164. })}
  165. </Link>
  166. ),
  167. key: "task_workflows",
  168. },
  169. ],
  170. },
  171. {
  172. label: (
  173. <Link to={linkCourse}>
  174. {intl.formatMessage({
  175. id: "columns.library.course.title",
  176. })}
  177. </Link>
  178. ),
  179. key: "course",
  180. },
  181. {
  182. label: (
  183. <Link to={linkUserdict}>
  184. {intl.formatMessage({
  185. id: "columns.studio.userdict.title",
  186. })}
  187. </Link>
  188. ),
  189. key: "userdict",
  190. },
  191. {
  192. label: (
  193. <Link to={linkTerm}>
  194. {intl.formatMessage({
  195. id: "columns.studio.term.title",
  196. })}
  197. </Link>
  198. ),
  199. key: "term",
  200. },
  201. {
  202. label: (
  203. <Link to={linkArticle}>
  204. {intl.formatMessage({
  205. id: "columns.studio.article.title",
  206. })}
  207. </Link>
  208. ),
  209. key: "article",
  210. },
  211. {
  212. label: (
  213. <Link to={`/studio/${studioname}/anthology/list`}>
  214. {intl.formatMessage({
  215. id: "columns.studio.anthology.title",
  216. })}
  217. </Link>
  218. ),
  219. key: "anthology",
  220. },
  221. {
  222. label: (
  223. <Link to={`/studio/${studioname}/attachment/list`}>
  224. {intl.formatMessage({
  225. id: "columns.studio.attachment.title",
  226. })}
  227. </Link>
  228. ),
  229. key: "attachment",
  230. disabled: user?.roles?.includes("uploader") ? false : true,
  231. },
  232. {
  233. label: (
  234. <Link to={`/studio/${studioname}/tags/list`}>
  235. {intl.formatMessage({
  236. id: "columns.studio.tag.title",
  237. })}
  238. </Link>
  239. ),
  240. key: "tag",
  241. },
  242. ].filter((value) => value.disabled !== true),
  243. },
  244. {
  245. label: intl.formatMessage({ id: "labels.collaboration" }),
  246. key: "collaboration",
  247. icon: <TeamOutlined />,
  248. children: [
  249. {
  250. label: (
  251. <Link to={linkGroup}>
  252. {intl.formatMessage({
  253. id: "columns.studio.group.title",
  254. })}
  255. </Link>
  256. ),
  257. key: "group",
  258. disabled: user?.roles?.includes("basic"),
  259. },
  260. {
  261. label: (
  262. <Link to={`/studio/${studioname}/invite/list`}>
  263. {intl.formatMessage({
  264. id: "columns.studio.invite.title",
  265. })}
  266. </Link>
  267. ),
  268. key: "invite",
  269. disabled: user?.roles?.includes("basic"),
  270. },
  271. {
  272. label: (
  273. <Link to={`/studio/${studioname}/transfer/list`}>
  274. {intl.formatMessage({
  275. id: "columns.studio.transfer.title",
  276. })}
  277. </Link>
  278. ),
  279. key: "transfer",
  280. },
  281. ],
  282. },
  283. ];
  284. return (
  285. <Affix offsetTop={0}>
  286. <div
  287. style={{
  288. height: "100vh",
  289. overflowY: "scroll",
  290. }}
  291. >
  292. <Sider width={200} breakpoint="lg" className="site-layout-background">
  293. <Menu
  294. theme="light"
  295. onClick={onClick}
  296. defaultSelectedKeys={[selectedKeys]}
  297. defaultOpenKeys={["basic", "advance", "collaboration"].concat(
  298. openKeys ?? ""
  299. )}
  300. mode="inline"
  301. items={items}
  302. />
  303. </Sider>
  304. </div>
  305. </Affix>
  306. );
  307. };
  308. export default LeftSiderWidget;