-
Notifications
You must be signed in to change notification settings - Fork 4
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: Call LearningAssistantSummary endpoint #68
Changes from 7 commits
c702ca1
0e65fc3
f238e09
75dfdb7
4cdc186
5c3b5cf
6a4a2aa
3625ed2
9199c92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ export const initialState = { | |
disclosureAcknowledged: false, | ||
sidebarIsOpen: false, | ||
isEnabled: false, | ||
auditTrial: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the initial state be |
||
startDate: null, | ||
expirationDate: null, | ||
}, | ||
}; | ||
|
||
export const learningAssistantSlice = createSlice({ | ||
|
@@ -44,6 +48,9 @@ export const learningAssistantSlice = createSlice({ | |
setIsEnabled: (state, { payload }) => { | ||
state.isEnabled = payload; | ||
}, | ||
setAuditTrial: (state, { payload }) => { | ||
state.auditTrial = payload; | ||
}, | ||
}, | ||
}); | ||
|
||
|
@@ -57,6 +64,7 @@ export const { | |
setDisclosureAcknowledged, | ||
setSidebarIsOpen, | ||
setIsEnabled, | ||
setAuditTrial, | ||
} = learningAssistantSlice.actions; | ||
|
||
export const { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ import { sendTrackEvent } from '@edx/frontend-platform/analytics'; | |
import { getAuthenticatedUser } from '@edx/frontend-platform/auth'; | ||
|
||
import trackChatBotMessageOptimizely from '../utils/optimizelyExperiment'; | ||
import { fetchChatResponse, fetchLearningAssistantMessageHistory, fetchLearningAssistantEnabled } from './api'; | ||
import { | ||
fetchChatResponse, | ||
fetchLearningAssistantSummary, | ||
} from './api'; | ||
import { | ||
setCurrentMessage, | ||
clearCurrentMessage, | ||
|
@@ -13,6 +16,7 @@ import { | |
setDisclosureAcknowledged, | ||
setSidebarIsOpen, | ||
setIsEnabled, | ||
setAuditTrial, | ||
} from './slice'; | ||
import { OPTIMIZELY_PROMPT_EXPERIMENT_KEY } from './optimizely'; | ||
|
||
|
@@ -73,33 +77,6 @@ export function getChatResponse(courseId, unitId, promptExperimentVariationKey = | |
}; | ||
} | ||
|
||
export function getLearningAssistantMessageHistory(courseId) { | ||
return async (dispatch) => { | ||
dispatch(setApiIsLoading(true)); | ||
|
||
try { | ||
const rawMessageList = await fetchLearningAssistantMessageHistory(courseId); | ||
|
||
if (rawMessageList.length) { | ||
const messageList = rawMessageList | ||
.map(({ timestamp, ...msg }) => ({ | ||
...msg, | ||
timestamp: new Date(timestamp), // Parse ISO time to Date() | ||
})); | ||
|
||
dispatch(setMessageList({ messageList })); | ||
|
||
// If it has chat history, then we assume the user already aknowledged. | ||
dispatch(setDisclosureAcknowledged(true)); | ||
} | ||
} catch (e) { | ||
// If fetching the messages fail, we just won't show it. | ||
} | ||
|
||
dispatch(setApiIsLoading(false)); | ||
}; | ||
} | ||
|
||
export function updateCurrentMessage(content) { | ||
return (dispatch) => { | ||
dispatch(setCurrentMessage({ currentMessage: content })); | ||
|
@@ -124,13 +101,45 @@ export function updateSidebarIsOpen(isOpen) { | |
}; | ||
} | ||
|
||
export function getIsEnabled(courseId) { | ||
export function getLearningAssistantSummary(courseId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replaced the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Could you rename this to |
||
return async (dispatch) => { | ||
dispatch(setApiIsLoading(true)); | ||
|
||
try { | ||
const data = await fetchLearningAssistantEnabled(courseId); | ||
const data = await fetchLearningAssistantSummary(courseId); | ||
|
||
// Enabled | ||
dispatch(setIsEnabled(data.enabled)); | ||
|
||
// Message History | ||
const rawMessageList = data.message_history; | ||
|
||
// If returned message history data is not empty | ||
if (rawMessageList.length) { | ||
const messageList = rawMessageList | ||
.map(({ timestamp, ...msg }) => ({ | ||
...msg, | ||
timestamp: new Date(timestamp).toString(), // Parse ISO time to Date() | ||
})); | ||
|
||
dispatch(setMessageList({ messageList })); | ||
|
||
// If it has chat history, then we assume the user already aknowledged. | ||
dispatch(setDisclosureAcknowledged(true)); | ||
} | ||
|
||
// Audit Trial | ||
const auditTrial = data.audit_trial; | ||
|
||
// If returned audit trial data is not empty | ||
if (Object.keys(auditTrial).length !== 0) { // eslint-disable-line no-undef | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the issue with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's an artifact from when I was using lodash, I'll get rid of this |
||
dispatch(setAuditTrial(auditTrial)); | ||
} | ||
} catch (error) { | ||
// NOTE: When used to not show if fetching the messages failed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify what this comment means? I'm not following. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant to use "we" instead of "when", but also I don't think this comment is necessary so I'm removing it. |
||
// But we do know since this endpoint is combined. | ||
dispatch(setApiError()); | ||
} | ||
dispatch(setApiIsLoading(false)); | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice renaming!