From 8ac4e6ffd1e0f41c6cbd9fe15472224bfc6038f3 Mon Sep 17 00:00:00 2001
From: Teresa Hoang <125500434+teresaqhoang@users.noreply.github.com>
Date: Mon, 10 Apr 2023 09:36:49 -0700
Subject: [PATCH] Simplifying state + removing unused components (#371)
### Motivation and Context
Removing unused parts of app, including chatSlice from redux and filter
icon in ChatList
### Description
Consolidated ChatState into ConversationsState, will manage state from
conversations array.
Commenting out Filter icon under "Conversations" list until we're ready
to implement
Changed login error to be more helpful to error cases we've observed
---
samples/apps/copilot-chat-app/README.md | 2 +-
.../apps/copilot-chat-app/WebApp/README.md | 4 +-
.../apps/copilot-chat-app/WebApp/env.example | 2 +-
.../apps/copilot-chat-app/WebApp/src/App.tsx | 19 ++--
.../copilot-chat-app/WebApp/src/Constants.ts | 2 +-
.../WebApp/src/components/Login.tsx | 15 ++--
.../src/components/chat/ChatHistoryItem.tsx | 12 +--
.../WebApp/src/components/chat/ChatRoom.tsx | 10 +--
.../WebApp/src/components/chat/ChatStatus.tsx | 5 +-
.../components/chat/chat-list/ChatList.tsx | 90 ++++++++++---------
.../WebApp/src/libs/useChat.ts | 34 +++----
.../WebApp/src/redux/app/store.ts | 4 +-
.../WebApp/src/redux/features/app/AppState.ts | 2 -
.../WebApp/src/redux/features/app/appSlice.ts | 8 +-
.../src/redux/features/chat/chatSlice.ts | 49 ----------
.../{chat => conversations}/ChatState.ts | 0
.../conversations/ConversationsState.ts | 26 +++---
.../conversations/conversationsSlice.ts | 20 +++--
18 files changed, 128 insertions(+), 176 deletions(-)
delete mode 100644 samples/apps/copilot-chat-app/WebApp/src/redux/features/chat/chatSlice.ts
rename samples/apps/copilot-chat-app/WebApp/src/redux/features/{chat => conversations}/ChatState.ts (100%)
diff --git a/samples/apps/copilot-chat-app/README.md b/samples/apps/copilot-chat-app/README.md
index 06983324b722..1928666e2e64 100644
--- a/samples/apps/copilot-chat-app/README.md
+++ b/samples/apps/copilot-chat-app/README.md
@@ -94,7 +94,7 @@ and these components are functional:
2. Copy `.env.example` into a new file with the name “`.env`” and make the
following configuration changes to match your instance:
3. Use the Application (client) ID from the Azure Portal steps above and
- paste the GUID into the `.env` file next to `REACT_APP_CHAT_CLIENT_ID= `
+ paste the GUID into the `.env` file next to `REACT_APP_AAD_CLIENT_ID= `
4. Execute the command `yarn install`
5. Execute the command `yarn start`
diff --git a/samples/apps/copilot-chat-app/WebApp/README.md b/samples/apps/copilot-chat-app/WebApp/README.md
index 780871752bf4..fd37d251e3ec 100644
--- a/samples/apps/copilot-chat-app/WebApp/README.md
+++ b/samples/apps/copilot-chat-app/WebApp/README.md
@@ -26,12 +26,12 @@ The Copilot Chat sameple showcases how to build an enriched intelligent app, wit
1. Ensure the SKWebApi is running at `https://localhost:40443/`. See [SKWebApi README](../SKWebApi/README.md) for instructions.
2. Create an `.env` file to this folder root with the following variables and fill in with your information, where
- `REACT_APP_CHAT_CLIENT_ID=` is the GUID copied from the **Application (client) ID** from your app registration in the Azure Portal and
+ `REACT_APP_AAD_CLIENT_ID=` is the GUID copied from the **Application (client) ID** from your app registration in the Azure Portal and
`REACT_APP_BACKEND_URI=` is the URI where your backend is running.
```
REACT_APP_BACKEND_URI=https://localhost:40443/
- REACT_APP_CHAT_CLIENT_ID=
+ REACT_APP_AAD_CLIENT_ID=
```
3. **Run** the following command `yarn install` (if you have never run the app before) and/or `yarn start` from the command line.
diff --git a/samples/apps/copilot-chat-app/WebApp/env.example b/samples/apps/copilot-chat-app/WebApp/env.example
index 437ecce2f32e..78c20e110024 100644
--- a/samples/apps/copilot-chat-app/WebApp/env.example
+++ b/samples/apps/copilot-chat-app/WebApp/env.example
@@ -1,2 +1,2 @@
REACT_APP_BACKEND_URI=http://localhost:40443/
-REACT_APP_CHAT_CLIENT_ID=
\ No newline at end of file
+REACT_APP_AAD_CLIENT_ID=
\ No newline at end of file
diff --git a/samples/apps/copilot-chat-app/WebApp/src/App.tsx b/samples/apps/copilot-chat-app/WebApp/src/App.tsx
index 2dadf7248bdf..142b5a95f5e0 100644
--- a/samples/apps/copilot-chat-app/WebApp/src/App.tsx
+++ b/samples/apps/copilot-chat-app/WebApp/src/App.tsx
@@ -33,13 +33,13 @@ const useClasses = makeStyles({
justifyContent: 'space-between',
},
persona: {
- marginRight: '20px'
- }
+ marginRight: '20px',
+ },
});
enum AppState {
ProbeForBackend,
- Chat
+ Chat,
}
const App: FC = () => {
@@ -50,9 +50,10 @@ const App: FC = () => {
const account = msalInstance.getActiveAccount();
useEffect(() => {
- // TODO: Load Conversations from BE
+ // TODO: Load conversations from BE
const keys = Object.keys(conversations);
dispatch(setSelectedConversation(keys[0]));
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
@@ -61,15 +62,15 @@ const App: FC = () => {
- {appState === AppState.ProbeForBackend &&
+ {appState === AppState.ProbeForBackend && (
setAppState(AppState.Chat)}
/>
- }
- {appState === AppState.Chat &&
+ )}
+ {appState === AppState.Chat && (
-
+
Copilot Chat {
- }
+ )}
);
diff --git a/samples/apps/copilot-chat-app/WebApp/src/Constants.ts b/samples/apps/copilot-chat-app/WebApp/src/Constants.ts
index 8aa2f4b45334..c0d64a95742b 100644
--- a/samples/apps/copilot-chat-app/WebApp/src/Constants.ts
+++ b/samples/apps/copilot-chat-app/WebApp/src/Constants.ts
@@ -6,7 +6,7 @@ export const Constants = {
msal: {
method: 'redirect', // 'redirect' | 'popup'
auth: {
- clientId: process.env.REACT_APP_CHAT_CLIENT_ID as string,
+ clientId: process.env.REACT_APP_AAD_CLIENT_ID as string,
authority: `https://login.microsoftonline.com/common`,
},
cache: {
diff --git a/samples/apps/copilot-chat-app/WebApp/src/components/Login.tsx b/samples/apps/copilot-chat-app/WebApp/src/components/Login.tsx
index 9a63cc9ba4e0..fa65072e0b2a 100644
--- a/samples/apps/copilot-chat-app/WebApp/src/components/Login.tsx
+++ b/samples/apps/copilot-chat-app/WebApp/src/components/Login.tsx
@@ -20,8 +20,12 @@ export const Login: React.FC = () => {
const handleError = (error: any) => {
console.error(error);
- setErrorMessage((error as Error).message);
- }
+ setErrorMessage(
+ `Login failed. Check that you have a valid REACT_APP_AAD_CLIENT_ID set in your .env file. See ${
+ (error as Error).name
+ } in console for more details.`,
+ );
+ };
const handleSignIn = async (): Promise => {
try {
@@ -38,11 +42,8 @@ export const Login: React.FC = () => {
useEffect(() => {
handleSignIn();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
- return (
-