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: Fetches chat history when loading Xpert #64

Merged
merged 9 commits into from
Nov 13, 2024

Conversation

rijuma
Copy link
Member

@rijuma rijuma commented Nov 8, 2024

Added implementation for fetching the chat history when rendering Xpert Learning Assistant.

Additional updates

  • Added test:watch script, very useful to use when working on unit tests.
  • Updated caniuse-lite database.

Demo

Screen.Recording.2024-11-12.at.17.14.36.mov

Copy link
Member

@alangsto alangsto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one question about message sorting, but this looks like a great approach!

src/data/thunks.js Outdated Show resolved Hide resolved
@rijuma rijuma force-pushed the rijuma/fetch-chat-history branch from 885a305 to c5149f8 Compare November 8, 2024 14:40
Copy link
Member

@varshamenon4 varshamenon4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great so far! A couple of nits on naming convention but I leave it up to you as the implementer :)

src/data/api.js Outdated Show resolved Hide resolved
@@ -81,6 +81,34 @@ export function clearMessages() {
};
}

export function fetchChatHistory(courseId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: similar to feedback above, on naming. Do we want to have it be something like getLearningAssistantMessageHistory? Not sure if that is too verbose but to match the above? Also I've noticed in the past that fetch is usually used in api and for thunks you can use something like get. And having it this way could allow you to still have the LearningAssistantMessageHistory part without it having the same name (i.e. get vs fetch).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as well.

src/data/thunks.js Show resolved Hide resolved
@rijuma rijuma changed the title feat: Fethes chat history when loading Xpert (WIP) feat: Fetches chat history when loading Xpert (WIP) Nov 8, 2024
@rijuma rijuma force-pushed the rijuma/fetch-chat-history branch from c5149f8 to 5646e47 Compare November 8, 2024 16:29
@@ -30,5 +30,15 @@ async function fetchLearningAssistantEnabled(courseId) {
return data;
}

export default fetchChatResponse;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for mixing default and named exports on these type of modules.

@rijuma rijuma force-pushed the rijuma/fetch-chat-history branch from da4904a to cf367ac Compare November 12, 2024 19:14
Comment on lines +7443 to +7445
"version": "1.0.30001680",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001680.tgz",
"integrity": "sha512-rPQy70G6AGUMnbwS1z6Xg+RkHYPAi18ihs47GH0jcxIG7wArmPgY3XbS2sRdBbxJljp3thdT8BIqv9ccCypiPA==",
Copy link
Member Author

@rijuma rijuma Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the warning:

Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme

@@ -20,7 +20,8 @@
"snapshot": "fedx-scripts jest --updateSnapshot",
"start": "fedx-scripts webpack-dev-server --progress",
"test": "fedx-scripts jest --coverage --passWithNoTests",
"test:ci": "fedx-scripts jest --silent --coverage --passWithNoTests"
"test:ci": "fedx-scripts jest --silent --coverage --passWithNoTests",
"test:watch": "fedx-scripts jest --passWithNoTests --watch"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extremely helpful to have when creating unit tests.

Comment on lines -49 to +52
jest.spyOn(api, 'default').mockResolvedValue(responseMessage);
jest.spyOn(api, 'fetchChatResponse').mockResolvedValue(responseMessage);
Copy link
Member Author

@rijuma rijuma Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test update, and the similar ones below, are due to moving the fetchChatResponse() from being a default export to be a named one.

Comment on lines +82 to +86
test('calls useMessageHistory() hook', () => {
render(<Xpert courseId={courseId} contentToolsEnabled={false} unitId={unitId} />, { preloadedState: initialState });

expect(useMessageHistory).toHaveBeenCalledWith(courseId);
});
Copy link
Member Author

@rijuma rijuma Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is to confirm that Xpert is calling the new hook.

@rijuma rijuma marked this pull request as ready for review November 12, 2024 20:11
Copy link
Member

@schenedx schenedx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}));
});

it('should call the endpoint and process the results', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we think of other test cases here? Maybe error conditions?

Copy link
Member Author

@rijuma rijuma Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well.. the fail conditions are handled on the thunk usage, so it is contemplated. On the api module side any error would just throw.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having in mind that any error, whether an endpoint failure or a parsing error (payload structure) would result on not loading the chat history, like a fallback for the current default behavior.

Let me know if you want us to contemplate some custom error messaging for the user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@schenedx schenedx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rijuma rijuma changed the title feat: Fetches chat history when loading Xpert (WIP) feat: Fetches chat history when loading Xpert Nov 13, 2024
@rijuma rijuma merged commit bc2e7a1 into main Nov 13, 2024
4 checks passed
@rijuma rijuma deleted the rijuma/fetch-chat-history branch November 13, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants