Skip to content
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

feat: render cta for unsupported content #2663

Merged
merged 48 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
726716e
Initial work to detect and display unsupported content
musale Aug 15, 2023
d763cbb
Set the unsupported content component in Chat
musale Aug 15, 2023
ff7ec7c
Add styling for the unsupported content component
musale Aug 15, 2023
3339f65
Fix makeStyles keys
musale Aug 15, 2023
7b0af84
Remove unused css class
musale Aug 15, 2023
30a574a
Fix build issues
musale Aug 15, 2023
b56d9db
Move the typeguard arg to a const value
musale Aug 22, 2023
34e39fe
Change the CTA text and remove unnecessary imports
musale Aug 22, 2023
7181199
Add a targetUrl for the unsupported content
musale Aug 22, 2023
0397e88
Update the Chat to use variables from the state object
musale Aug 23, 2023
4813c19
Add a types utility
musale Aug 23, 2023
42d48ab
Set the message signals for unsupported content
musale Aug 23, 2023
9c85ed2
Merge branch 'next/mgt-chat' of github.com:microsoftgraph/microsoft-g…
musale Aug 23, 2023
2c93335
Fix import errors and file license strings
musale Aug 23, 2023
441a249
Re-introduce immer's produce
musale Aug 23, 2023
0ca7277
Merge branch 'next/mgt-chat' of github.com:microsoftgraph/microsoft-g…
musale Sep 5, 2023
7349512
Refactor functions for chat into new file
musale Sep 7, 2023
eb8a33f
Initial work to detect and display unsupported content
musale Aug 15, 2023
2ea7fa1
Set the unsupported content component in Chat
musale Aug 15, 2023
9bb8522
Add styling for the unsupported content component
musale Aug 15, 2023
5f6e988
Fix makeStyles keys
musale Aug 15, 2023
38ba409
Fix build issues
musale Aug 15, 2023
f1dcd90
Move the typeguard arg to a const value
musale Aug 22, 2023
0d1799d
Change the CTA text and remove unnecessary imports
musale Aug 22, 2023
761a42d
Add a targetUrl for the unsupported content
musale Aug 22, 2023
100dc57
Update the Chat to use variables from the state object
musale Aug 23, 2023
ba18bcc
Add a types utility
musale Aug 23, 2023
fbe8368
Set the message signals for unsupported content
musale Aug 23, 2023
e553662
Fix import errors and file license strings
musale Aug 23, 2023
6a1a060
Re-introduce immer's produce
musale Aug 23, 2023
e71c6db
Refactor functions for chat into new file
musale Sep 7, 2023
1742c23
Update yarn build artifacts
musale Sep 26, 2023
9395b28
Use a deeplink to the chat for the chat url
musale Sep 26, 2023
fbc47d7
Add a margin on top and bottom of the Unsupportedcontent
musale Sep 26, 2023
dae21fc
Merge next/mgt-chat into unsupported/content
musale Oct 2, 2023
f3ff278
Update the install-state.gz
musale Oct 2, 2023
cc2953f
Update the install-state.gz
musale Oct 2, 2023
81a4e1c
Merge branch 'unsupported-content' of github.com:microsoftgraph/micro…
musale Oct 5, 2023
91e9bb9
Merge branch 'next/mgt-chat' into unsupported-content
musale Oct 5, 2023
b6f5bf4
Fix import paths and add new install artifacts
musale Oct 5, 2023
d92a1a0
Merge branch 'next/mgt-chat' into unsupported-content
musale Oct 6, 2023
e200231
New install artifacts
musale Oct 11, 2023
c80386e
Fix regex from flagging content with anchor tag
musale Oct 11, 2023
7da8a5f
Revert unnecessary eslint guards bypassed by line
musale Oct 11, 2023
6271829
Merge branch 'next/mgt-chat' into unsupported-content
gavinbarron Oct 11, 2023
ef01172
Merge branch 'unsupported-content' of github.com:microsoftgraph/micro…
musale Oct 12, 2023
38ac132
Merge branch 'next/mgt-chat' into unsupported-content
musale Oct 12, 2023
7b7ed18
removing more unnecessary eslint suppressions
gavinbarron Oct 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mgt-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@fluentui/react": "~8.106.1",
"@fluentui/react-northstar": "^0.66.4",
"@fluentui/react-components": "^9.19.1",
"@fluentui/react-icons": "^2.0.200",
"@fluentui/react-icons": "^2.0.210",
"@microsoft/mgt-element": "*",
"@microsoft/mgt-components": "*",
"@microsoft/mgt-msal2-provider": "*",
Expand Down
47 changes: 46 additions & 1 deletion packages/mgt-chat/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import React, { useEffect, useState } from 'react';
import { ErrorBar, FluentThemeProvider, MessageThread, SendBox } from '@azure/communication-react';
import { renderToString } from 'react-dom/server';
import {
ErrorBar,
FluentThemeProvider,
MessageThread,
SendBox,
MessageProps,
MessageRenderer,
Message,
ChatMessage
} from '@azure/communication-react';
import { Person, PersonCardInteraction, Spinner } from '@microsoft/mgt-react';
import { FluentTheme } from '@fluentui/react';
import { FluentProvider, makeStyles, shorthands, teamsLightTheme } from '@fluentui/react-components';
import { useGraphChatClient } from '../../statefulClient/useGraphChatClient';
import ChatHeader from '../ChatHeader/ChatHeader';
import { registerAppIcons } from '../styles/registerIcons';
import { ManageChatMembers } from '../ManageChatMembers/ManageChatMembers';
import UnsupportedContent from '../UnsupportedContent/UnsupportedContent';
import { produce } from 'immer';

registerAppIcons();

Expand Down Expand Up @@ -37,6 +49,19 @@ const useStyles = makeStyles({
}
});

/**
* A typeguard to get the ChatMessage type
* @param msg of Message
* @returns ChatMessage
*/
const isChatMessage = (msg: Message): msg is ChatMessage => 'content' in msg;

/**
* Regex to detect unsupported content tags in content html.
*/
const unsupportedContentRegex = /<\/[atchmen]+>/;
// TODO: ^ update the values to capture as unsupported.

export const Chat = ({ chatId }: IMgtChatProps) => {
const styles = useStyles();
const chatClient = useGraphChatClient(chatId);
Expand All @@ -47,6 +72,25 @@ export const Chat = ({ chatId }: IMgtChatProps) => {
chatClient.offStateChange(setChatState);
};
}, [chatClient]);

const onRenderMessage = (messageProps: MessageProps, defaultOnRender?: MessageRenderer): JSX.Element => {
if (isChatMessage(messageProps?.message)) {
const content = messageProps.message?.content;
musale marked this conversation as resolved.
Show resolved Hide resolved

// Test that the content is supported.
if (content && unsupportedContentRegex.test(content)) {
messageProps = produce(messageProps, (draft: MessageProps) => {
musale marked this conversation as resolved.
Show resolved Hide resolved
// update the content string to the component
if (isChatMessage(draft.message)) {
draft.message.content = renderToString(<UnsupportedContent />);
}
});
}
}

return defaultOnRender ? defaultOnRender(messageProps) : <></>;
};

return (
<FluentThemeProvider fluentTheme={FluentTheme}>
<FluentProvider theme={teamsLightTheme} className={styles.fullHeight}>
Expand Down Expand Up @@ -87,6 +131,7 @@ export const Chat = ({ chatId }: IMgtChatProps) => {
<Person userId={userId} avatarSize="small" personCardInteraction={PersonCardInteraction.click} />
);
}}
onRenderMessage={onRenderMessage}
/>
</div>
<div className={styles.chatInput}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { List, ListItem } from '@fluentui/react-northstar';
import { Person, PersonViewType } from '@microsoft/mgt-react';
import { AadUserConversationMember } from '@microsoft/microsoft-graph-types';
import { styles } from './manage-chat-members.styles';
import { Dismiss24Regular, bundleIcon } from '@fluentui/react-icons';
import { Dismiss24Regular, Dismiss24Filled, bundleIcon } from '@fluentui/react-icons';

interface ListChatMembersProps {
currentUserId: string;
Expand All @@ -21,7 +21,7 @@ interface ListChatMembersProps {
closeParentPopover: () => void;
}

const RemovePerson = bundleIcon(Dismiss24Regular, () => null);
musale marked this conversation as resolved.
Show resolved Hide resolved
const RemovePerson = bundleIcon(Dismiss24Filled, Dismiss24Regular);
musale marked this conversation as resolved.
Show resolved Hide resolved

const ListChatMembers = ({ members, currentUserId, removeChatMember, closeParentPopover }: ListChatMembersProps) => {
const [removeDialogOpen, setRemoveDialogOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { makeStyles, shorthands } from '@fluentui/react-components';
import React from 'react';
import { registerAppIcons } from '../styles/registerIcons';
import { ArrowSquareUpRight24Regular } from '@fluentui/react-icons';
registerAppIcons();
musale marked this conversation as resolved.
Show resolved Hide resolved

const useStyles = makeStyles({
container: {
backgroundColor: '#ebebeb',
display: 'flex',
boxShadow: '0px 4px 8px 0px rgba(0, 0, 0, 0.14), 0px 0px 2px 0px rgba(0, 0, 0, 0.12)',
textDecorationLine: 'none',
color: '#424242',
...shorthands.margin('4px 0 0 0'),
...shorthands.borderRadius('6px'),
...shorthands.padding('16px'),
...shorthands.gap('6px'),
':hover': {
backgroundColor: '#fafafa'
},
':visited': {
color: '#424242'
}
},
cta: {
fontFamily: 'Segoe UI',
fontSize: '12px',
fontStyle: 'normal',
fontWeight: '400',
lineHeight: '16px',
textDecorationLine: 'none'
}
});

const UnsupportedContent = () => {
const styles = useStyles();
return (
// TODO: update this URL to the correct value.
<a className={styles.container} href="https://teams.microsoft.com">
musale marked this conversation as resolved.
Show resolved Hide resolved
<ArrowSquareUpRight24Regular />
<p className={styles.cta}>Go back to the main window to see this content.</p>
musale marked this conversation as resolved.
Show resolved Hide resolved
</a>
);
};

export default UnsupportedContent;
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3516,7 +3516,7 @@
"@fluentui/styles" "^0.66.4"
classnames "^2.2.6"

"@fluentui/react-icons@^2.0.196", "@fluentui/react-icons@^2.0.200":
"@fluentui/react-icons@^2.0.196":
version "2.0.200"
resolved "https://registry.yarnpkg.com/@fluentui/react-icons/-/react-icons-2.0.200.tgz#d9aa5e57f1e9b0a9d9f06f368cc73b32922d6a2f"
integrity sha512-u9hcNIUlxYxCdCD6doNPVzAfxUmfbKd68lIf300O10LZ+Sk5QPI9iFV7uBvAmUqELukWqTmzJ4USMsTeTEUCkw==
Expand All @@ -3532,6 +3532,14 @@
"@griffel/react" "^1.0.0"
tslib "^2.1.0"

"@fluentui/react-icons@^2.0.210":
version "2.0.210"
resolved "https://registry.yarnpkg.com/@fluentui/react-icons/-/react-icons-2.0.210.tgz#f3b7d6f3d004ae3f0d69bf07623dc337b19c0922"
integrity sha512-TPWLYnDYnKWpMclrHDSM/YGRfPfpRJQP3bSPwiOAv9jufT9jsGLJeXplNXjEnptPsSWQwlORk+lPTMWLm3FE5A==
dependencies:
"@griffel/react" "^1.0.0"
tslib "^2.1.0"

"@fluentui/react-icons@~1.1.145":
version "1.1.145"
resolved "https://registry.yarnpkg.com/@fluentui/react-icons/-/react-icons-1.1.145.tgz#6a0c81a1aa2632c633b8df5f4d27cc97c398ac82"
Expand Down