[NEW] Add Teams to Directory (#3181)

* Added Teams to DirectoryView

* Fix icon

* Minor tweaks

* add tests

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gerzon Z 2021-06-04 14:07:26 -04:00 committed by GitHub
parent c087780ccf
commit 91371e88d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 11 deletions

View File

@ -332,6 +332,7 @@
"My_servers": "My servers", "My_servers": "My servers",
"N_people_reacted": "{{n}} people reacted", "N_people_reacted": "{{n}} people reacted",
"N_users": "{{n}} users", "N_users": "{{n}} users",
"N_channels": "{{n}} channels",
"name": "name", "name": "name",
"Name": "Name", "Name": "Name",
"Navigation_history": "Navigation history", "Navigation_history": "Navigation history",

View File

@ -798,6 +798,10 @@ const RocketChat = {
// RC 3.13.0 // RC 3.13.0
return this.sdk.get('teams.listRoomsOfUser', { teamId, userId }); return this.sdk.get('teams.listRoomsOfUser', { teamId, userId });
}, },
getTeamInfo({ teamId }) {
// RC 3.13.0
return this.sdk.get('teams.info', { teamId });
},
convertChannelToTeam({ rid, name, type }) { convertChannelToTeam({ rid, name, type }) {
const params = { const params = {
...(type === 'c' ...(type === 'c'

View File

@ -18,7 +18,7 @@ const DirectoryItemLabel = React.memo(({ text, theme }) => {
}); });
const DirectoryItem = ({ const DirectoryItem = ({
title, description, avatar, onPress, testID, style, rightLabel, type, rid, theme title, description, avatar, onPress, testID, style, rightLabel, type, rid, theme, teamMain
}) => ( }) => (
<Touch <Touch
onPress={onPress} onPress={onPress}
@ -36,7 +36,7 @@ const DirectoryItem = ({
/> />
<View style={styles.directoryItemTextContainer}> <View style={styles.directoryItemTextContainer}>
<View style={styles.directoryItemTextTitle}> <View style={styles.directoryItemTextTitle}>
<RoomTypeIcon type={type} theme={theme} /> <RoomTypeIcon type={type} teamMain={teamMain} theme={theme} />
<Text style={[styles.directoryItemName, { color: themes[theme].titleText }]} numberOfLines={1}>{title}</Text> <Text style={[styles.directoryItemName, { color: themes[theme].titleText }]} numberOfLines={1}>{title}</Text>
</View> </View>
{ description ? <Text style={[styles.directoryItemUsername, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>{description}</Text> : null } { description ? <Text style={[styles.directoryItemUsername, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>{description}</Text> : null }
@ -56,7 +56,8 @@ DirectoryItem.propTypes = {
style: PropTypes.any, style: PropTypes.any,
rightLabel: PropTypes.string, rightLabel: PropTypes.string,
rid: PropTypes.string, rid: PropTypes.string,
theme: PropTypes.string theme: PropTypes.string,
teamMain: PropTypes.bool
}; };
DirectoryItemLabel.propTypes = { DirectoryItemLabel.propTypes = {

View File

@ -64,6 +64,11 @@ export default class DirectoryOptions extends PureComponent {
icon = 'channel-public'; icon = 'channel-public';
} }
if (itemType === 'teams') {
text = 'Teams';
icon = 'teams';
}
return ( return (
<Touch <Touch
onPress={() => changeType(itemType)} onPress={() => changeType(itemType)}
@ -105,6 +110,7 @@ export default class DirectoryOptions extends PureComponent {
</Touch> </Touch>
{this.renderItem('channels')} {this.renderItem('channels')}
{this.renderItem('users')} {this.renderItem('users')}
{this.renderItem('teams')}
{isFederationEnabled {isFederationEnabled
? ( ? (
<> <>

View File

@ -121,6 +121,8 @@ class DirectoryView extends React.Component {
logEvent(events.DIRECTORY_SEARCH_USERS); logEvent(events.DIRECTORY_SEARCH_USERS);
} else if (type === 'channels') { } else if (type === 'channels') {
logEvent(events.DIRECTORY_SEARCH_CHANNELS); logEvent(events.DIRECTORY_SEARCH_CHANNELS);
} else if (type === 'teams') {
logEvent(events.DIRECTORY_SEARCH_TEAMS);
} }
} }
@ -149,17 +151,34 @@ class DirectoryView extends React.Component {
if (result.success) { if (result.success) {
this.goRoom({ rid: result.room._id, name: item.username, t: 'd' }); this.goRoom({ rid: result.room._id, name: item.username, t: 'd' });
} }
} else { } else if (['p', 'c'].includes(item.t) && !item.teamMain) {
const { room } = await RocketChat.getRoomInfo(item._id); const { room } = await RocketChat.getRoomInfo(item._id);
this.goRoom({ this.goRoom({
rid: item._id, name: item.name, joinCodeRequired: room.joinCodeRequired, t: 'c', search: true rid: item._id, name: item.name, joinCodeRequired: room.joinCodeRequired, t: 'c', search: true
}); });
} else {
this.goRoom({
rid: item._id, name: item.name, t: item.t, search: true, teamMain: item.teamMain, teamId: item.teamId
});
} }
} }
renderHeader = () => { renderHeader = () => {
const { type } = this.state; const { type } = this.state;
const { theme } = this.props; const { theme } = this.props;
let text = 'Users';
let icon = 'user';
if (type === 'channels') {
text = 'Channels';
icon = 'channel-public';
}
if (type === 'teams') {
text = 'Teams';
icon = 'teams';
}
return ( return (
<> <>
<SearchBox <SearchBox
@ -174,8 +193,8 @@ class DirectoryView extends React.Component {
theme={theme} theme={theme}
> >
<View style={[sharedStyles.separatorVertical, styles.toggleDropdownContainer, { borderColor: themes[theme].separatorColor }]}> <View style={[sharedStyles.separatorVertical, styles.toggleDropdownContainer, { borderColor: themes[theme].separatorColor }]}>
<CustomIcon style={[styles.toggleDropdownIcon, { color: themes[theme].tintColor }]} size={20} name={type === 'users' ? 'user' : 'channel-public'} /> <CustomIcon style={[styles.toggleDropdownIcon, { color: themes[theme].tintColor }]} size={20} name={icon} />
<Text style={[styles.toggleDropdownText, { color: themes[theme].tintColor }]}>{type === 'users' ? I18n.t('Users') : I18n.t('Channels')}</Text> <Text style={[styles.toggleDropdownText, { color: themes[theme].tintColor }]}>{I18n.t(text)}</Text>
<CustomIcon name='chevron-down' size={20} style={[styles.toggleDropdownArrow, { color: themes[theme].auxiliaryTintColor }]} /> <CustomIcon name='chevron-down' size={20} style={[styles.toggleDropdownArrow, { color: themes[theme].auxiliaryTintColor }]} />
</View> </View>
</Touch> </Touch>
@ -217,12 +236,25 @@ class DirectoryView extends React.Component {
/> />
); );
} }
if (type === 'teams') {
return (
<DirectoryItem
avatar={item.name}
description={item.name}
rightLabel={I18n.t('N_channels', { n: item.roomsCount })}
type={item.t}
teamMain={item.teamMain}
{...commonProps}
/>
);
}
return ( return (
<DirectoryItem <DirectoryItem
avatar={item.name} avatar={item.name}
description={item.topic} description={item.topic}
rightLabel={I18n.t('N_users', { n: item.usersCount })} rightLabel={I18n.t('N_users', { n: item.usersCount })}
type='c' type={item.t}
{...commonProps} {...commonProps}
/> />
); );

View File

@ -32,16 +32,24 @@ describe('Join room from directory', () => {
await navigateToRoom(data.channels.detoxpublic.name); await navigateToRoom(data.channels.detoxpublic.name);
}) })
it('should back and tap directory', async() => { it('should search user and navigate', async() => {
await tapBack(); await tapBack();
await element(by.id('rooms-list-view-directory')).tap(); await element(by.id('rooms-list-view-directory')).tap();
}) await waitFor(element(by.id('directory-view'))).toExist().withTimeout(2000);
it('should search user and navigate', async() => {
await element(by.id('directory-view-dropdown')).tap(); await element(by.id('directory-view-dropdown')).tap();
await element(by.label('Users')).tap(); await element(by.label('Users')).tap();
await element(by.label('Search by')).tap(); await element(by.label('Search by')).tap();
await navigateToRoom(data.users.alternate.username); await navigateToRoom(data.users.alternate.username);
}) })
it('should search user and navigate', async() => {
await tapBack();
await element(by.id('rooms-list-view-directory')).tap();
await waitFor(element(by.id('directory-view'))).toExist().withTimeout(2000);
await element(by.id('directory-view-dropdown')).tap();
await element(by.label('Teams')).tap();
await element(by.label('Search by')).tap();
await navigateToRoom(data.teams.private.name);
})
}); });
}); });