-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Convert components/sidebar to TS (#25429)
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
- Loading branch information
1 parent
6c1a7b1
commit 6b41aa6
Showing
14 changed files
with
129 additions
and
83 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...teor/client/components/Sidebar/Content.js → ...eor/client/components/Sidebar/Content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
...eteor/client/components/Sidebar/Header.js → ...teor/client/components/Sidebar/Header.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...teor/client/components/Sidebar/Sidebar.js → ...eor/client/components/Sidebar/Sidebar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
apps/meteor/client/components/Sidebar/SidebarItemsAssembler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
import React, { memo, FC } from 'react'; | ||
|
||
import { SidebarItem } from '../../lib/createSidebarItems'; | ||
import SidebarNavigationItem from './SidebarNavigationItem'; | ||
|
||
type SidebarItemsAssemblerProps = { | ||
items: SidebarItem[]; | ||
currentPath?: string; | ||
}; | ||
|
||
const SidebarItemsAssembler: FC<SidebarItemsAssemblerProps> = ({ items, currentPath }) => { | ||
const t = useTranslation(); | ||
return ( | ||
<> | ||
{items.map(({ href, pathSection, i18nLabel, name, icon, permissionGranted, pathGroup, tag }) => ( | ||
<SidebarNavigationItem | ||
permissionGranted={permissionGranted} | ||
pathGroup={pathGroup || ''} | ||
pathSection={href || pathSection || ''} | ||
icon={icon} | ||
label={t((i18nLabel || name) as Parameters<typeof t>[0])} | ||
key={i18nLabel || name} | ||
currentPath={currentPath} | ||
tag={t.has(tag as Parameters<typeof t>[0]) ? t(tag as Parameters<typeof t>[0]) : undefined} | ||
/> | ||
))} | ||
; | ||
</> | ||
); | ||
}; | ||
|
||
export default memo(SidebarItemsAssembler); |
42 changes: 42 additions & 0 deletions
42
apps/meteor/client/components/Sidebar/SidebarNavigationItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Box, Icon, IconProps, Tag } from '@rocket.chat/fuselage'; | ||
import { useRoutePath } from '@rocket.chat/ui-contexts'; | ||
import React, { memo, useMemo, FC } from 'react'; | ||
|
||
import SidebarGenericItem from './SidebarGenericItem'; | ||
|
||
type SidebarNavigationItemProps = { | ||
permissionGranted?: (() => boolean) | boolean; | ||
pathGroup: string; | ||
pathSection: string; | ||
icon?: IconProps['name']; | ||
label?: string; | ||
tag?: string; | ||
currentPath?: string; | ||
}; | ||
|
||
const SidebarNavigationItem: FC<SidebarNavigationItemProps> = ({ | ||
permissionGranted, | ||
pathGroup, | ||
pathSection, | ||
icon, | ||
label, | ||
currentPath, | ||
tag, | ||
}) => { | ||
const params = useMemo(() => ({ group: pathGroup }), [pathGroup]); | ||
const path = useRoutePath(pathSection, params); | ||
const isActive = path === currentPath || false; | ||
if (permissionGranted === false || (typeof permissionGranted === 'function' && !permissionGranted())) { | ||
return null; | ||
} | ||
return ( | ||
<SidebarGenericItem active={isActive} href={path} key={path}> | ||
{icon && <Icon name={icon} size='x20' mi='x4' />} | ||
<Box withTruncatedText fontScale='p2' mi='x4' color='info'> | ||
{label} {tag && <Tag style={{ display: 'inline', backgroundColor: '#000', color: '#FFF', marginLeft: 4 }}>{tag}</Tag>} | ||
</Box> | ||
</SidebarGenericItem> | ||
); | ||
}; | ||
|
||
export default memo(SidebarNavigationItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import Content from './Content'; | ||
import GenericItem from './GenericItem'; | ||
import Header from './Header'; | ||
import ItemsAssembler from './ItemsAssembler'; | ||
import ListItem from './ListItem'; | ||
import NavigationItem from './NavigationItem'; | ||
import Sidebar from './Sidebar'; | ||
import GenericItem from './SidebarGenericItem'; | ||
import SidebarItemsAssembler from './SidebarItemsAssembler'; | ||
import NavigationItem from './SidebarNavigationItem'; | ||
|
||
export default Object.assign(Sidebar, { | ||
Content, | ||
Header, | ||
GenericItem, | ||
NavigationItem, | ||
ItemsAssembler, | ||
ItemsAssembler: SidebarItemsAssembler, | ||
ListItem, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters