-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: readonly conversation indication (#17369)
* feat: add literal string replacement support for react localizer util (#17273) * feat: add literal string replacement support for react localizer util * feat: support string literal inside the component * refactor: improve naming * doc: add a comment * refactor: readonly conversaiton indication
- Loading branch information
1 parent
792f3c3
commit 07a6289
Showing
9 changed files
with
432 additions
and
160 deletions.
There are no files selected for viewing
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
77 changes: 0 additions & 77 deletions
77
src/script/components/Conversation/ReadOnlyConversationMessage.tsx
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
.../components/Conversation/ReadOnlyConversationMessage/ReadOnlyConversationMessage.test.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,94 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {render} from '@testing-library/react'; | ||
import {ConnectionStatus} from '@wireapp/api-client/lib/connection'; | ||
import {CONVERSATION_TYPE} from '@wireapp/api-client/lib/conversation'; | ||
|
||
import {withTheme} from 'src/script/auth/util/test/TestUtil'; | ||
import {ConnectionEntity} from 'src/script/connection/ConnectionEntity'; | ||
import {CONVERSATION_READONLY_STATE} from 'src/script/conversation/ConversationRepository'; | ||
import {Conversation} from 'src/script/entity/Conversation'; | ||
import {User} from 'src/script/entity/User'; | ||
|
||
import {ReadOnlyConversationMessage} from './ReadOnlyConversationMessage'; | ||
|
||
const generateConversation = ( | ||
readOnlyState: CONVERSATION_READONLY_STATE | null = null, | ||
is1To1WithBlockedUser = false, | ||
userName = 'John Doe', | ||
) => { | ||
const conversation = new Conversation(); | ||
conversation.type(CONVERSATION_TYPE.ONE_TO_ONE); | ||
conversation.readOnlyState(readOnlyState); | ||
|
||
const connection = new ConnectionEntity(); | ||
|
||
if (is1To1WithBlockedUser) { | ||
connection.status(ConnectionStatus.BLOCKED); | ||
} | ||
|
||
const user = new User('user-id', 'user-domain'); | ||
user.name(userName); | ||
conversation.participating_user_ets([user]); | ||
conversation.participating_user_ids([user.qualifiedId]); | ||
|
||
user.connection(connection); | ||
connection.userId = user.qualifiedId; | ||
|
||
return conversation; | ||
}; | ||
|
||
describe('ReadOnlyConversationMessage', () => { | ||
it('renders mls is not supported by the other user', () => { | ||
const conversation = generateConversation( | ||
CONVERSATION_READONLY_STATE.READONLY_ONE_TO_ONE_OTHER_UNSUPPORTED_MLS, | ||
false, | ||
); | ||
|
||
const {getByText} = render( | ||
withTheme(<ReadOnlyConversationMessage conversation={conversation} reloadApp={() => {}} />), | ||
); | ||
|
||
expect(getByText('otherUserNotSupportMLSMsg')).toBeDefined(); | ||
}); | ||
|
||
it('renders mls is not supported by the self user', () => { | ||
const conversation = generateConversation( | ||
CONVERSATION_READONLY_STATE.READONLY_ONE_TO_ONE_SELF_UNSUPPORTED_MLS, | ||
false, | ||
); | ||
|
||
const reloadAppMock = jest.fn(); | ||
|
||
const {getByText} = render( | ||
withTheme(<ReadOnlyConversationMessage reloadApp={reloadAppMock} conversation={conversation} />), | ||
); | ||
|
||
const reloadButton = getByText('downloadLatestMLS'); | ||
|
||
expect(getByText('selfNotSupportMLSMsgPart1')).toBeDefined(); | ||
expect(reloadButton).toBeDefined(); | ||
expect(getByText('selfNotSupportMLSMsgPart2')).toBeDefined(); | ||
|
||
reloadButton.click(); | ||
|
||
expect(reloadAppMock).toHaveBeenCalled(); | ||
}); | ||
}); |
109 changes: 109 additions & 0 deletions
109
...cript/components/Conversation/ReadOnlyConversationMessage/ReadOnlyConversationMessage.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,109 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {FC, ReactNode} from 'react'; | ||
|
||
import {Link, LinkVariant} from '@wireapp/react-ui-kit'; | ||
|
||
import {Icon} from 'Components/Icon'; | ||
import {CONVERSATION_READONLY_STATE} from 'src/script/conversation/ConversationRepository'; | ||
import {Conversation} from 'src/script/entity/Conversation'; | ||
import {useKoSubscribableChildren} from 'Util/ComponentUtil'; | ||
import {t} from 'Util/LocalizerUtil'; | ||
import {replaceReactComponents} from 'Util/LocalizerUtil/ReactLocalizerUtil'; | ||
|
||
interface ReadOnlyConversationMessageProps { | ||
reloadApp: () => void; | ||
conversation: Conversation; | ||
} | ||
|
||
export const ReadOnlyConversationMessage: FC<ReadOnlyConversationMessageProps> = ({conversation, reloadApp}) => { | ||
const { | ||
readOnlyState, | ||
is1to1, | ||
participating_user_ets: participatingUserEts, | ||
} = useKoSubscribableChildren(conversation, ['readOnlyState', 'is1to1', 'participating_user_ets']); | ||
|
||
const user = (is1to1 && participatingUserEts[0]) || null; | ||
|
||
if (!user) { | ||
// This should never happen for 1:1 conversations | ||
return null; | ||
} | ||
|
||
if (readOnlyState) { | ||
switch (readOnlyState) { | ||
case CONVERSATION_READONLY_STATE.READONLY_ONE_TO_ONE_OTHER_UNSUPPORTED_MLS: | ||
return ( | ||
<ReadOnlyConversationMessageBase> | ||
<span> | ||
{replaceReactComponents(t('otherUserNotSupportMLSMsg'), [ | ||
{ | ||
exactMatch: '{{participantName}}', | ||
render: () => <strong>{user.name()}</strong>, | ||
}, | ||
])} | ||
</span> | ||
</ReadOnlyConversationMessageBase> | ||
); | ||
case CONVERSATION_READONLY_STATE.READONLY_ONE_TO_ONE_SELF_UNSUPPORTED_MLS: | ||
return ( | ||
<ReadOnlyConversationMessageBase> | ||
<span> | ||
{replaceReactComponents(t('selfNotSupportMLSMsgPart1'), [ | ||
{ | ||
exactMatch: '{{selfUserName}}', | ||
render: () => <strong>{user.name()}</strong>, | ||
}, | ||
])} | ||
</span> | ||
<> | ||
{' '} | ||
<Link | ||
css={{fontSize: 'var(--font-size-small)', fontWeight: 'var(--font-weight-semibold)'}} | ||
onClick={reloadApp} | ||
variant={LinkVariant.PRIMARY} | ||
data-uie-name="do-update-mls" | ||
> | ||
{t('downloadLatestMLS')} | ||
</Link>{' '} | ||
<span>{t('selfNotSupportMLSMsgPart2')}</span> | ||
</> | ||
</ReadOnlyConversationMessageBase> | ||
); | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
const ReadOnlyConversationMessageBase = ({children}: {children: ReactNode}) => { | ||
return ( | ||
<div className="readonly-message-header readonly-message-container"> | ||
<div className="readonly-message-header-icon readonly-message-header-icon--svg"> | ||
<div> | ||
<Icon.Info /> | ||
</div> | ||
</div> | ||
<p className="readonly-message-header-label" data-uie-name="element-readonly-conversation"> | ||
{children} | ||
</p> | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.