MM-12491 Fix archive channels staying in LHS

* Add isArchived flag for all DM's and channels
 * Exclude search results from channel_list component to show
   results when isSearchResult flag is set
   This is to let user search for deactivated users from jumpto
This commit is contained in:
sudheer
2018-10-11 20:40:21 +05:30
parent b5b948e58f
commit 9c22be4465
5 changed files with 166 additions and 32 deletions

View File

@@ -23,7 +23,6 @@ export default class ChannelIcon extends React.PureComponent {
membersCount: PropTypes.number,
size: PropTypes.number,
status: PropTypes.string,
teammateDeletedAt: PropTypes.number,
theme: PropTypes.object.isRequired,
type: PropTypes.string.isRequired,
isArchived: PropTypes.bool.isRequired,
@@ -46,7 +45,6 @@ export default class ChannelIcon extends React.PureComponent {
size,
status,
theme,
teammateDeletedAt,
type,
isArchived,
} = this.props;
@@ -116,13 +114,6 @@ export default class ChannelIcon extends React.PureComponent {
</Text>
</View>
);
} else if (type === General.DM_CHANNEL && teammateDeletedAt) {
icon = (
<Image
source={require('assets/images/status/archive_avatar.png')}
style={{width: size, height: size, tintColor: offlineColor}}
/>
);
} else if (type === General.DM_CHANNEL) {
switch (status) {
case General.AWAY:

View File

@@ -44,7 +44,6 @@ exports[`ChannelItem should match snapshot 1`] = `
membersCount={1}
size={16}
status="online"
teammateDeletedAt={0}
theme={
Object {
"awayIndicator": "#ffbc42",
@@ -102,7 +101,9 @@ exports[`ChannelItem should match snapshot 1`] = `
</AnimatedComponent>
`;
exports[`ChannelItem should match snapshot for deactivated user 1`] = `
exports[`ChannelItem should match snapshot for deactivated user 1`] = `null`;
exports[`ChannelItem should match snapshot for deactivated user and is searchResult 1`] = `
<AnimatedComponent>
<TouchableHighlight
activeOpacity={0.85}
@@ -140,13 +141,12 @@ exports[`ChannelItem should match snapshot for deactivated user 1`] = `
channelId="channel_id"
hasDraft={false}
isActive={false}
isArchived={false}
isArchived={true}
isInfo={false}
isUnread={true}
membersCount={1}
size={16}
status="online"
teammateDeletedAt={100}
theme={
Object {
"awayIndicator": "#ffbc42",
@@ -204,6 +204,120 @@ exports[`ChannelItem should match snapshot for deactivated user 1`] = `
</AnimatedComponent>
`;
exports[`ChannelItem should match snapshot if channel is archived 1`] = `null`;
exports[`ChannelItem should match snapshot if channel is archived and is currentChannel 1`] = `
<AnimatedComponent>
<TouchableHighlight
activeOpacity={0.85}
delayPressOut={100}
onLongPress={[Function]}
onPress={[Function]}
underlayColor="rgba(69,120,191,0.5)"
>
<Component
style={
Array [
Object {
"flex": 1,
"flexDirection": "row",
"height": 44,
},
undefined,
]
}
>
<Component
style={
Object {
"backgroundColor": "#579eff",
"width": 5,
}
}
/>
<Component
style={
Array [
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"paddingLeft": 16,
},
Object {
"backgroundColor": "rgba(255,255,255,0.1)",
"paddingLeft": 11,
},
]
}
>
<ChannelIcon
channelId="channel_id"
hasDraft={false}
isActive={true}
isArchived={true}
isInfo={false}
isUnread={true}
membersCount={1}
size={16}
status="online"
theme={
Object {
"awayIndicator": "#ffbc42",
"buttonBg": "#166de0",
"buttonColor": "#ffffff",
"centerChannelBg": "#ffffff",
"centerChannelColor": "#3d3c40",
"codeTheme": "github",
"dndIndicator": "#f74343",
"errorTextColor": "#fd5960",
"linkColor": "#2389d7",
"mentionBj": "#ffffff",
"mentionColor": "#145dbf",
"mentionHighlightBg": "#ffe577",
"mentionHighlightLink": "#166de0",
"newMessageSeparator": "#ff8800",
"onlineIndicator": "#06d6a0",
"sidebarBg": "#145dbf",
"sidebarHeaderBg": "#1153ab",
"sidebarHeaderTextColor": "#ffffff",
"sidebarText": "#ffffff",
"sidebarTextActiveBorder": "#579eff",
"sidebarTextActiveColor": "#ffffff",
"sidebarTextHoverBg": "#4578bf",
"sidebarUnreadText": "#ffffff",
"type": "Mattermost",
}
}
type="O"
/>
<Component
ellipsizeMode="tail"
numberOfLines={1}
style={
Array [
Object {
"color": "rgba(255,255,255,0.4)",
"flex": 1,
"fontSize": 14,
"fontWeight": "600",
"height": "100%",
"lineHeight": 44,
"paddingRight": 40,
"textAlignVertical": "center",
},
Object {
"color": "#ffffff",
},
]
}
/>
</Component>
</Component>
</TouchableHighlight>
</AnimatedComponent>
`;
exports[`ChannelItem should match snapshot with draft 1`] = `
<AnimatedComponent>
<TouchableHighlight
@@ -248,7 +362,6 @@ exports[`ChannelItem should match snapshot with draft 1`] = `
membersCount={1}
size={16}
status="online"
teammateDeletedAt={0}
theme={
Object {
"awayIndicator": "#ffbc42",

View File

@@ -35,11 +35,11 @@ export default class ChannelItem extends PureComponent {
shouldHideChannel: PropTypes.bool,
showUnreadForMsgs: PropTypes.bool.isRequired,
status: PropTypes.string,
teammateDeletedAt: PropTypes.number,
type: PropTypes.string.isRequired,
theme: PropTypes.object.isRequired,
unreadMsgs: PropTypes.number.isRequired,
isArchived: PropTypes.bool.isRequired,
isSearchResult: PropTypes.bool,
};
static defaultProps = {
@@ -97,15 +97,15 @@ export default class ChannelItem extends PureComponent {
mentions,
shouldHideChannel,
status,
teammateDeletedAt,
theme,
type,
isArchived,
isSearchResult,
} = this.props;
// Only ever show an archived channel if it's the currently viewed channel.
// It should disappear as soon as one navigates to another channel.
if (isArchived && (currentChannelId !== channelId)) {
if (isArchived && (currentChannelId !== channelId) && !isSearchResult) {
return null;
}
@@ -173,7 +173,6 @@ export default class ChannelItem extends PureComponent {
membersCount={displayName.split(',').length}
size={16}
status={status}
teammateDeletedAt={teammateDeletedAt}
theme={theme}
type={type}
isArchived={isArchived}

View File

@@ -26,7 +26,6 @@ describe('ChannelItem', () => {
shouldHideChannel: false,
showUnreadForMsgs: true,
status: 'online',
teammateDeletedAt: 0,
type: 'O',
theme: Preferences.THEMES.default,
unreadMsgs: 1,
@@ -45,8 +44,22 @@ describe('ChannelItem', () => {
test('should match snapshot for deactivated user', () => {
const newProps = {
...baseProps,
teammateDeletedAt: 100,
type: 'D',
isArchived: true,
};
const wrapper = shallow(
<ChannelItem {...newProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot for deactivated user and is searchResult', () => {
const newProps = {
...baseProps,
type: 'D',
isArchived: true,
isSearchResult: true,
};
const wrapper = shallow(
<ChannelItem {...newProps}/>,
@@ -66,4 +79,29 @@ describe('ChannelItem', () => {
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot if channel is archived', () => {
const wrapper = shallow(
<ChannelItem
{...baseProps}
isArchived={true}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot if channel is archived and is currentChannel', () => {
const wrapper = shallow(
<ChannelItem
{...baseProps}
isArchived={true}
currentChannelId={'channel_id'}
/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.getElement()).toMatchSnapshot();
});
});

View File

@@ -29,22 +29,16 @@ function makeMapStateToProps() {
const channelDraft = getDraftForChannel(state, channel.id);
let isMyUser = false;
let teammateDeletedAt = 0;
let displayName = channel.display_name;
let isArchived = false;
const isArchived = channel.delete_at > 0;
if (channel.type === General.DM_CHANNEL) {
if (ownProps.isSearchResult) {
isMyUser = channel.id === currentUserId;
teammateDeletedAt = channel.delete_at;
} else {
isMyUser = channel.teammate_id === currentUserId;
isMyUser = channel.id === currentUserId;
if (!ownProps.isSearchResult) {
const teammate = getUser(state, channel.teammate_id);
if (teammate && teammate.delete_at) {
teammateDeletedAt = teammate.delete_at;
}
const teammateNameDisplay = getTeammateNameDisplaySetting(state);
displayName = displayUsername(teammate, teammateNameDisplay, false);
isArchived = channel.delete_at > 0;
}
}
@@ -83,7 +77,6 @@ function makeMapStateToProps() {
shouldHideChannel,
showUnreadForMsgs,
status: channel.status,
teammateDeletedAt,
theme: getTheme(state),
type: channel.type,
unreadMsgs,