-
Notifications
You must be signed in to change notification settings - Fork 13.7k
feat: Media Call History contextual bar #37739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c92c48d
WIP
gabriellsh 37886bf
Merge remote-tracking branch 'origin/develop' into feat/callHistoryCo…
gabriellsh 268c7ba
add fuselage-ui-kit
gabriellsh 338c578
Add Internal and External user components
gabriellsh 42b2350
Translations
gabriellsh f9b9d19
implement useFullStartDate
gabriellsh b20679b
Wip 2 contextualbar and more stories
gabriellsh c9d86d3
Merge branch 'develop' into feat/callHistoryContextual
gabriellsh da55d2a
Add userCard to internal user
gabriellsh c5b6081
wip blocks
gabriellsh 51b774d
Implement CallHistoryActions
gabriellsh 5dc7765
export
gabriellsh 034b8ee
fix external export
gabriellsh 409b87c
Merge remote-tracking branch 'origin/develop' into feat/callHistoryCo…
gabriellsh 987c190
use `getHistoryMessagePayload` to generate blocks and fix translation
gabriellsh 0137b94
missing translation string
gabriellsh 6b5f5b3
Merge remote-tracking branch 'origin/develop' into feat/callHistoryCo…
gabriellsh b87e8b6
export types
gabriellsh 1a94c8e
Fix contextualbar size
gabriellsh 2e26b5a
Merge remote-tracking branch 'origin/develop' into feat/callHistoryCo…
gabriellsh d3022bf
Fix Icon and make text bold
gabriellsh b925003
fix review
gabriellsh 7fb6a6a
Add tests
gabriellsh 75d8e5b
Merge branch 'develop' into feat/callHistoryContextual
gabriellsh f11015f
Fix test timezone
gabriellsh d1f2b32
Merge branch 'develop' into feat/callHistoryContextual
gabriellsh 386cbdd
Merge branch 'develop' into feat/callHistoryContextual
kodiakhq[bot] 86981c9
Merge branch 'develop' into feat/callHistoryContextual
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
86 changes: 86 additions & 0 deletions
86
packages/ui-voip/src/views/CallHistoryContextualbar/CallHistoryContextualbar.stories.tsx
This file contains hidden or 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,86 @@ | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
| import type { ReactElement } from 'react'; | ||
|
|
||
| import CallHistoryContextualbar from './CallHistoryContextualbar'; | ||
|
|
||
| const noop = () => undefined; | ||
|
|
||
| const meta = { | ||
| title: 'V2/Views/CallHistoryContextualbar', | ||
| component: CallHistoryContextualbar, | ||
| decorators: [ | ||
| mockAppRoot() | ||
| .withTranslations('en', 'core', { | ||
| Call_info: 'Call info', | ||
| Direct_message: 'Direct message', | ||
| Call: 'Call', | ||
| Call_ended_bold: '*Voice call ended*', | ||
| Incoming_voice_call: 'Incoming voice call', | ||
| Outgoing_voice_call: 'Outgoing voice call', | ||
| Duration: 'Duration', | ||
| Voice_Call_Extension: 'Voice call extension', | ||
| Call_ID: 'Call ID', | ||
| }) | ||
| .withDefaultLanguage('en-US') | ||
| .buildStoryDecorator(), | ||
| (Story): ReactElement => <Story />, | ||
| ], | ||
| } satisfies Meta<typeof CallHistoryContextualbar>; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| const externalContact = { | ||
| number: '1234567890', | ||
| }; | ||
|
|
||
| const internalContact = { | ||
| _id: '1234567890', | ||
| name: 'John Doe', | ||
| username: 'john.doe', | ||
| voiceCallExtension: '0000', | ||
| }; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| onClose: noop, | ||
| actions: { | ||
| voiceCall: noop, | ||
| videoCall: noop, | ||
| jumpToMessage: noop, | ||
| directMessage: noop, | ||
| userInfo: noop, | ||
| }, | ||
| contact: internalContact, | ||
| data: { | ||
| callId: '1234567890', | ||
| direction: 'inbound', | ||
| duration: 100, | ||
| startedAt: new Date(), | ||
| state: 'ended', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const ExternalContact: Story = { | ||
| args: { | ||
| onClose: noop, | ||
| actions: { | ||
| voiceCall: noop, | ||
| videoCall: noop, | ||
| jumpToMessage: noop, | ||
| directMessage: noop, | ||
| userInfo: noop, | ||
| }, | ||
| data: { | ||
| callId: '1234567890', | ||
| direction: 'inbound', | ||
| duration: 100, | ||
| startedAt: new Date(), | ||
| state: 'ended', | ||
| }, | ||
| contact: externalContact, | ||
| }, | ||
| }; |
156 changes: 156 additions & 0 deletions
156
packages/ui-voip/src/views/CallHistoryContextualbar/CallHistoryContextualbar.tsx
This file contains hidden or 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,156 @@ | ||
| import { Box, Button, ButtonGroup, Icon, MessageBlock } from '@rocket.chat/fuselage'; | ||
| import { UiKitComponent, UiKitMessage as UiKitMessageSurfaceRender, UiKitContext } from '@rocket.chat/fuselage-ui-kit'; | ||
| import { | ||
| Contextualbar, | ||
| ContextualbarHeader, | ||
| ContextualbarTitle, | ||
| ContextualbarClose, | ||
| ContextualbarFooter, | ||
| ContextualbarIcon, | ||
| ContextualbarScrollableContent, | ||
| InfoPanel, | ||
| InfoPanelSection, | ||
| InfoPanelLabel, | ||
| InfoPanelText, | ||
| } from '@rocket.chat/ui-client'; | ||
| import type { TFunction } from 'i18next'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import CallHistoryExternalUser from './CallHistoryExternalUser'; | ||
| import CallHistoryInternalUser from './CallHistoryInternalUser'; | ||
| import { useFullStartDate } from './useFullStartDate'; | ||
|
|
||
| type InternalCallHistoryContact = { | ||
| _id: string; | ||
| name?: string; | ||
| username: string; | ||
| voiceCallExtension?: string; | ||
| }; | ||
|
|
||
| type ExternalCallHistoryContact = { | ||
| number: string; | ||
| }; | ||
|
|
||
| type CallHistoryData = { | ||
| callId: string; | ||
| direction: 'inbound' | 'outbound'; | ||
| duration: number; | ||
| startedAt: Date; | ||
| state: 'ended' | 'not-answered' | 'failed' | 'error' | 'transferred'; | ||
| messageId?: string; | ||
| }; | ||
|
|
||
| type HistoryActions = 'voiceCall' | 'videoCall' | 'jumpToMessage' | 'directMessage' | 'userInfo'; | ||
|
|
||
| type HistoryActionCallbacks = Record<HistoryActions, () => void>; | ||
|
|
||
| type CallHistoryContextualBarProps = { | ||
| onClose: () => void; | ||
| actions: HistoryActionCallbacks; | ||
| contact: InternalCallHistoryContact | ExternalCallHistoryContact; | ||
| data: CallHistoryData; | ||
| }; | ||
|
|
||
| const isInternalCallHistoryContact = ( | ||
| contact: InternalCallHistoryContact | ExternalCallHistoryContact, | ||
| ): contact is InternalCallHistoryContact => { | ||
| return '_id' in contact; | ||
| }; | ||
|
|
||
| const contextValue = { | ||
| action: () => undefined, | ||
| rid: '', | ||
| values: {}, | ||
| }; | ||
|
|
||
| // TODO use the same function that generates the message-block payload on the server. Duration will also be displayed here. | ||
| const getBlocks = (t: TFunction) => { | ||
| return [ | ||
| { | ||
| type: 'info_card' as const, | ||
| rows: [ | ||
| { | ||
| background: 'default' as const, | ||
| elements: [ | ||
| { type: 'icon', icon: 'phone-off', variant: 'default' }, | ||
| { type: 'mrkdwn', i18n: { key: 'Call_ended_bold' }, text: t('Call_ended') }, | ||
| ] as const, | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
| }; | ||
|
|
||
| const CallHistoryContextualBar = ({ onClose, actions, contact, data }: CallHistoryContextualBarProps) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| const { voiceCall, /* videoCall, jumpToMessage, */ directMessage, userInfo /* voiceCallExtension, direction */ } = actions; | ||
| const { duration, callId, direction, startedAt } = data; | ||
|
|
||
| const date = useFullStartDate(startedAt); | ||
| return ( | ||
| <Contextualbar> | ||
| <ContextualbarHeader> | ||
| <ContextualbarIcon name='info-circled' /> | ||
| <ContextualbarTitle>{t('Call_info')}</ContextualbarTitle> | ||
| <ContextualbarClose onClick={onClose} /> | ||
| </ContextualbarHeader> | ||
| <ContextualbarScrollableContent> | ||
| <InfoPanel> | ||
| <InfoPanelSection> | ||
| {isInternalCallHistoryContact(contact) ? ( | ||
| <CallHistoryInternalUser username={contact.username} name={contact.name} _id={contact._id} onUserClick={userInfo} /> | ||
| ) : ( | ||
| <CallHistoryExternalUser number={contact.number} /> | ||
| )} | ||
| </InfoPanelSection> | ||
| <InfoPanelSection> | ||
| <Box display='flex' flexDirection='row' alignItems='center' fontScale='p1m'> | ||
| {/* TODO use `arrow-up-right` and `arrow-down-left` icons when available */} | ||
| <Icon name={direction === 'inbound' ? 'phone-in' : 'phone-out'} size='x20' mie='x4' /> | ||
| {direction === 'inbound' ? t('Incoming_voice_call') : t('Outgoing_voice_call')} | ||
| </Box> | ||
| </InfoPanelSection> | ||
| <InfoPanelSection> | ||
| <MessageBlock fixedWidth> | ||
| <UiKitContext.Provider value={contextValue}> | ||
| <UiKitComponent render={UiKitMessageSurfaceRender} blocks={getBlocks(t)} /> | ||
| </UiKitContext.Provider> | ||
| </MessageBlock> | ||
| <Box mbs={-8}>{date}</Box> | ||
| </InfoPanelSection> | ||
| <InfoPanelSection> | ||
| <InfoPanelLabel>{t('Duration')}</InfoPanelLabel> | ||
| <InfoPanelText>{duration}</InfoPanelText> | ||
| </InfoPanelSection> | ||
| <InfoPanelSection> | ||
| <InfoPanelLabel>{t('Call_ID')}</InfoPanelLabel> | ||
| <InfoPanelText>{callId}</InfoPanelText> | ||
| </InfoPanelSection> | ||
| {isInternalCallHistoryContact(contact) && contact.voiceCallExtension && ( | ||
| <InfoPanelSection> | ||
| <InfoPanelLabel>{t('Voice_Call_Extension')}</InfoPanelLabel> | ||
| <InfoPanelText>{contact.voiceCallExtension}</InfoPanelText> | ||
| </InfoPanelSection> | ||
| )} | ||
| </InfoPanel> | ||
| </ContextualbarScrollableContent> | ||
| <ContextualbarFooter> | ||
| <ButtonGroup stretch> | ||
| {isInternalCallHistoryContact(contact) && ( | ||
| <Button onClick={directMessage}> | ||
| <Icon name='balloon' size='x20' mie='x4' /> | ||
| {t('Direct_message')} | ||
| </Button> | ||
| )} | ||
| <Button success onClick={voiceCall}> | ||
| <Icon name='phone' size='x20' mie='x4' /> | ||
| {t('Call')} | ||
| </Button> | ||
| </ButtonGroup> | ||
| </ContextualbarFooter> | ||
| </Contextualbar> | ||
| ); | ||
| }; | ||
|
|
||
| export default CallHistoryContextualBar; | ||
21 changes: 21 additions & 0 deletions
21
packages/ui-voip/src/views/CallHistoryContextualbar/CallHistoryExternalUser.tsx
This file contains hidden or 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,21 @@ | ||
| import { Box, Icon, FramedIcon } from '@rocket.chat/fuselage'; | ||
|
|
||
| type CallHistoryExternalUserProps = { | ||
| number: string; | ||
| }; | ||
|
|
||
| const CallHistoryExternalUser = ({ number }: CallHistoryExternalUserProps) => { | ||
| return ( | ||
| <Box display='flex' flexDirection='row' alignItems='center'> | ||
| <Box mie={8}> | ||
| <FramedIcon icon='user' size={28} /> | ||
| </Box> | ||
| <Box mie={8}> | ||
| <Icon name='phone' size={20} /> | ||
| </Box> | ||
| <Box>{number.startsWith('+') ? number : `+${number}`}</Box> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| export default CallHistoryExternalUser; |
35 changes: 35 additions & 0 deletions
35
packages/ui-voip/src/views/CallHistoryContextualbar/CallHistoryInternalUser.tsx
This file contains hidden or 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,35 @@ | ||
| import { Box, Icon, Avatar, StatusBullet } from '@rocket.chat/fuselage'; | ||
| import { useUserDisplayName } from '@rocket.chat/ui-client'; | ||
| import { useUserAvatarPath, useUserPresence } from '@rocket.chat/ui-contexts'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| type CallHistoryInternalUserProps = { | ||
| username: string; | ||
| name?: string; | ||
| _id: string; | ||
| onUserClick: () => void; | ||
| }; | ||
|
|
||
| const CallHistoryInternalUser = ({ username, name, _id, onUserClick }: CallHistoryInternalUserProps) => { | ||
| const getUserAvatarPath = useUserAvatarPath(); | ||
|
|
||
| const avatarUrl = useMemo(() => { | ||
| return getUserAvatarPath({ username }); | ||
| }, [username, getUserAvatarPath]); | ||
|
|
||
| const displayName = useUserDisplayName({ username, name }); | ||
|
|
||
| const userStatus = useUserPresence(_id); | ||
|
|
||
| return ( | ||
| <Box display='flex' flexDirection='row' alignItems='center' role='button' onClick={onUserClick}> | ||
| <Box mie={8}>{avatarUrl ? <Avatar url={avatarUrl} size='x28' /> : <Icon name='user' size='x28' />}</Box> | ||
| <Box mie={8}> | ||
| <StatusBullet status={userStatus?.status || 'loading'} size='small' /> | ||
| </Box> | ||
| <Box>{displayName}</Box> | ||
| </Box> | ||
| ); | ||
|
gabriellsh marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| export default CallHistoryInternalUser; | ||
Empty file.
13 changes: 13 additions & 0 deletions
13
packages/ui-voip/src/views/CallHistoryContextualbar/useFullStartDate.ts
This file contains hidden or 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,13 @@ | ||
| import { useLanguage } from '@rocket.chat/ui-contexts'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| export const useFullStartDate = (startedAt: Date) => { | ||
| const locale = useLanguage(); | ||
|
|
||
| const date = useMemo(() => { | ||
| // eslint-disable-next-line new-cap | ||
| return Intl.DateTimeFormat(locale, { dateStyle: 'full', timeStyle: 'medium' }).format(startedAt); | ||
|
gabriellsh marked this conversation as resolved.
Outdated
|
||
| }, [locale, startedAt]); | ||
|
|
||
| return date; | ||
| }; | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.