Repository navigation
feat: configuration for xpert unit summaries #540
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 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
04d2312
feat: Add setting for Xpert unit summaries
davidnuon 1a34e52
style: Fix linting to 2-spaces
davidnuon ed52c90
feat: Change copy for Xpert config dialog
davidnuon b80181f
test: Add tests for XpertUnitSummarySettings
davidnuon 387c3ac
feat: Add hiding the config section for xpert summary
davidnuon a035aa2
chore: Update PagesAndResources imports
davidnuon 7f2938d
Merge branch 'master' into davidnuon/configuration-for-xpert-summaries
davidnuon ed4ba40
style: Fix lint
davidnuon 8ce5f0d
fix: Change to use STUDIO_BASE_URL instead of LMS_BASE_URL
davidnuon 0badc4e
test: Add tests for saving xpertconfigsettings
davidnuon a43ed0b
test: Update tests
davidnuon d478ead
fix: remove extraneous `await` in for setSaveError
davidnuon 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
41 changes: 41 additions & 0 deletions
41
src/pages-and-resources/xpert-unit-summary/XpertUnitSummarySettings.jsx
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,41 @@ | ||
| import React, { useCallback, useContext, useEffect } from 'react'; | ||
| import { history } from '@edx/frontend-platform'; | ||
| import { useDispatch } from 'react-redux'; | ||
|
|
||
| import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
| import { PagesAndResourcesContext } from '../PagesAndResourcesProvider'; | ||
|
|
||
| import SettingsModal from './settings-modal/SettingsModal'; | ||
| import messages from './messages'; | ||
|
|
||
| import { fetchXpertSettings } from './data/thunks'; | ||
|
|
||
| const XpertUnitSummarySettings = ({ intl }) => { | ||
| const { path: pagesAndResourcesPath, courseId } = useContext(PagesAndResourcesContext); | ||
| const dispatch = useDispatch(); | ||
|
|
||
| useEffect(() => { | ||
| dispatch(fetchXpertSettings(courseId)); | ||
| }, [courseId]); | ||
|
|
||
| const handleClose = useCallback(() => { | ||
| history.push(pagesAndResourcesPath); | ||
| }, [pagesAndResourcesPath]); | ||
|
|
||
| return ( | ||
| <SettingsModal | ||
| appId="xpert-unit-summary" | ||
| title={intl.formatMessage(messages.heading)} | ||
| enableAppHelp={intl.formatMessage(messages.enableXpertUnitSummaryHelp)} | ||
| enableAppLabel={intl.formatMessage(messages.enableXpertUnitSummaryLabel)} | ||
| learnMoreText={intl.formatMessage(messages.enableXpertUnitSummaryLink)} | ||
| onClose={handleClose} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| XpertUnitSummarySettings.propTypes = { | ||
| intl: intlShape.isRequired, | ||
| }; | ||
|
|
||
| export default injectIntl(XpertUnitSummarySettings); |
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 @@ | ||
| export default { | ||
| id: 'xpert-unit-summary', | ||
| enabled: false, | ||
| name: 'Xpert unit summaries', | ||
| description: 'Harness ChatGPT for quick, focused summaries of text and video content.', | ||
| allowedOperations: { | ||
| enable: true, | ||
| configure: true, | ||
| }, | ||
| documentationLinks: { | ||
| learnMoreConfiguration: '', | ||
| }, | ||
| }; |
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,22 @@ | ||
| import { getConfig } from '@edx/frontend-platform'; | ||
| import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
|
||
| function getXpertSettingsUrl(courseId) { | ||
| return `${getConfig().LMS_BASE_URL}/ai_aside/v1/${courseId}`; | ||
|
davidnuon marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| export async function getXpertSettings(courseId) { | ||
| const { data } = await getAuthenticatedHttpClient() | ||
| .get(getXpertSettingsUrl(courseId)); | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
| export async function postXpertSettings(courseId, state) { | ||
| const { data } = await getAuthenticatedHttpClient() | ||
| .post(getXpertSettingsUrl(courseId), { | ||
| enabled: state.enabled, | ||
| }); | ||
|
|
||
| return data; | ||
| } | ||
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,51 @@ | ||
| import { getXpertSettings, postXpertSettings } from './api'; | ||
|
|
||
| import { updateSavingStatus, updateLoadingStatus } from '../../data/slice'; | ||
| import { RequestStatus } from '../../../data/constants'; | ||
|
|
||
| import { addModel, updateModel } from '../../../generic/model-store'; | ||
|
|
||
| export function updateXpertSettings(courseId, state) { | ||
| return async (dispatch) => { | ||
| dispatch(updateSavingStatus({ status: RequestStatus.IN_PROGRESS })); | ||
| try { | ||
| const { response } = await postXpertSettings(courseId, state); | ||
| const { success, enabled } = response; | ||
| if (success) { | ||
| dispatch(updateModel({ modelType: 'XpertSettings', model: { id: 'xpert-unit-summary', enabled } })); | ||
| dispatch(updateSavingStatus({ status: RequestStatus.SUCCESSFUL })); | ||
| return true; | ||
| } | ||
|
|
||
| dispatch(updateSavingStatus({ status: RequestStatus.FAILED })); | ||
| return false; | ||
| } catch (error) { | ||
| dispatch(updateSavingStatus({ status: RequestStatus.FAILED })); | ||
| return false; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| export function fetchXpertSettings(courseId) { | ||
| return async (dispatch) => { | ||
| let enabled = false; | ||
| dispatch(updateLoadingStatus({ status: RequestStatus.PENDING })); | ||
|
|
||
| try { | ||
| const { response } = await getXpertSettings(courseId); | ||
| enabled = response?.enabled; | ||
| } catch (e) { | ||
| enabled = false; | ||
| } | ||
|
|
||
| dispatch(addModel({ | ||
| modelType: 'XpertSettings', | ||
| model: { | ||
| id: 'xpert-unit-summary', | ||
| enabled, | ||
| }, | ||
| })); | ||
|
|
||
| dispatch(updateLoadingStatus({ status: RequestStatus.SUCCESSFUL })); | ||
| }; | ||
| } |
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,7 @@ | ||
| import XpertUnitSummarySettings from './XpertUnitSummarySettings'; | ||
| import appInfo from './appInfo'; | ||
|
|
||
| export { | ||
| XpertUnitSummarySettings, | ||
| appInfo, | ||
| }; |
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,31 @@ | ||
| import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
|
||
| const messages = defineMessages({ | ||
| heading: { | ||
| id: 'course-authoring.pages-resources.xpert-unit-summary.heading', | ||
| defaultMessage: 'Configure Xpert unit summaries', | ||
| }, | ||
| enableXpertUnitSummaryLabel: { | ||
| id: 'course-authoring.pages-resources.xpert-unit-summary.enable-xpert-unit-summary.label', | ||
| defaultMessage: 'Xpert unit summaries', | ||
| }, | ||
| enableXpertUnitSummaryHelp: { | ||
| id: 'course-authoring.pages-resources.xpert-unit-summary.enable-xpert-unit-summary.help', | ||
| defaultMessage: `Enable concise summaries of text and video content. Control the availability of summaries in the settings dialog for each unit. | ||
| `, | ||
| }, | ||
| enableXpertUnitSummaryLink: { | ||
| id: 'course-authoring.pages-resources.xpert-unit-summary.enable-xpert-unit-summary.link', | ||
| defaultMessage: 'Learn more about the Xpert unit summaries', | ||
| }, | ||
| allUnitsEnabledByDefault: { | ||
| id: 'course-authoring.pages-resources.xpert-unit-summary.all-units-enabled-by-default', | ||
| defaultMessage: 'All units enabled by default', | ||
| }, | ||
| noUnitsEnabledByDefault: { | ||
| id: 'course-authoring.pages-resources.xpert-unit-summary.no-units-enabled-by-default', | ||
| defaultMessage: 'No units enabled by default', | ||
| }, | ||
| }); | ||
|
|
||
| export default messages; |
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.