Convert "Pages & Resources" page to a plugin system (#638)
* feat: Make "Pages & Resources" course apps into plugins * feat: move ora_settings * feat: move proctoring * feat: move progress * feat: move teams * feat: move wiki * feat: move Xpert settings * fix: add webpack.prod.config.js * fix: clean up unused parts of package.json files * feat: Add an error message when displaying a Course App Plugin fails * chore: fix various eslint warnings * chore: fix jest tests * fix: error preventing "npm ci" from working * feat: better tests for <SettingsComponent> * chore: move xpert_unit_summary into same dir as other plugins * fix: eslint-import-resolver-webpack is a dev dependency * chore: move learning_assistant to be a plugin too * feat: for compatibility, install 2U plugins by default * fix: bug with learning_assistant package.json
This commit is contained in:
41
plugins/course-apps/xpert_unit_summary/data/api.js
Normal file
41
plugins/course-apps/xpert_unit_summary/data/api.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
||||
|
||||
export function getXpertSettingsUrl(courseId) {
|
||||
return `${getConfig().STUDIO_BASE_URL}/ai_aside/v1/${courseId}`;
|
||||
}
|
||||
|
||||
export function getXpertConfigurationStatusUrl(courseId) {
|
||||
return `${getConfig().STUDIO_BASE_URL}/ai_aside/v1/${courseId}/configurable`;
|
||||
}
|
||||
|
||||
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,
|
||||
reset: state.reset,
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getXpertPluginConfigurable(courseId) {
|
||||
const { data } = await getAuthenticatedHttpClient()
|
||||
.get(getXpertConfigurationStatusUrl(courseId));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function deleteXpertSettings(courseId) {
|
||||
const { data } = await getAuthenticatedHttpClient()
|
||||
.delete(getXpertSettingsUrl(courseId));
|
||||
|
||||
return data;
|
||||
}
|
||||
113
plugins/course-apps/xpert_unit_summary/data/thunks.js
Normal file
113
plugins/course-apps/xpert_unit_summary/data/thunks.js
Normal file
@@ -0,0 +1,113 @@
|
||||
import { updateSavingStatus, updateLoadingStatus, updateResetStatus } from 'CourseAuthoring/pages-and-resources/data/slice';
|
||||
import { RequestStatus } from 'CourseAuthoring/data/constants';
|
||||
import { addModel, updateModel } from 'CourseAuthoring/generic/model-store';
|
||||
|
||||
import {
|
||||
getXpertSettings, postXpertSettings, getXpertPluginConfigurable, deleteXpertSettings,
|
||||
} from './api';
|
||||
|
||||
export function updateXpertSettings(courseId, state) {
|
||||
return async (dispatch) => {
|
||||
dispatch(updateSavingStatus({ status: RequestStatus.IN_PROGRESS }));
|
||||
try {
|
||||
const { response } = await postXpertSettings(courseId, state);
|
||||
const { success } = response;
|
||||
if (success) {
|
||||
dispatch(updateModel({ modelType: 'XpertSettings', model: { id: 'xpert-unit-summary', enabled: state.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 fetchXpertPluginConfigurable(courseId) {
|
||||
return async (dispatch) => {
|
||||
let enabled;
|
||||
dispatch(updateLoadingStatus({ status: RequestStatus.PENDING }));
|
||||
try {
|
||||
const { response } = await getXpertPluginConfigurable(courseId);
|
||||
enabled = response?.enabled;
|
||||
} catch (e) {
|
||||
enabled = undefined;
|
||||
}
|
||||
|
||||
dispatch(addModel({
|
||||
modelType: 'XpertSettings.enabled',
|
||||
model: {
|
||||
id: 'xpert-unit-summary',
|
||||
enabled,
|
||||
},
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchXpertSettings(courseId) {
|
||||
return async (dispatch) => {
|
||||
let enabled;
|
||||
dispatch(updateLoadingStatus({ status: RequestStatus.PENDING }));
|
||||
|
||||
try {
|
||||
const { response } = await getXpertSettings(courseId);
|
||||
enabled = response?.enabled;
|
||||
} catch (e) {
|
||||
enabled = undefined;
|
||||
}
|
||||
|
||||
dispatch(addModel({
|
||||
modelType: 'XpertSettings',
|
||||
model: {
|
||||
id: 'xpert-unit-summary',
|
||||
enabled,
|
||||
},
|
||||
}));
|
||||
|
||||
dispatch(updateLoadingStatus({ status: RequestStatus.SUCCESSFUL }));
|
||||
};
|
||||
}
|
||||
|
||||
export function removeXpertSettings(courseId) {
|
||||
return async (dispatch) => {
|
||||
dispatch(updateSavingStatus({ status: RequestStatus.PENDING }));
|
||||
|
||||
try {
|
||||
const { response } = await deleteXpertSettings(courseId);
|
||||
const { success } = response;
|
||||
if (success) {
|
||||
const model = { id: 'xpert-unit-summary', enabled: undefined };
|
||||
dispatch(updateModel({ modelType: 'XpertSettings', model }));
|
||||
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 resetXpertSettings(courseId, state) {
|
||||
return async (dispatch) => {
|
||||
dispatch(updateResetStatus({ status: RequestStatus.PENDING }));
|
||||
try {
|
||||
const { response } = await postXpertSettings(courseId, state);
|
||||
const { success } = response;
|
||||
if (success) {
|
||||
dispatch(updateResetStatus({ status: RequestStatus.SUCCESSFUL }));
|
||||
return true;
|
||||
}
|
||||
dispatch(updateResetStatus({ status: RequestStatus.FAILED }));
|
||||
return false;
|
||||
} catch (error) {
|
||||
dispatch(updateResetStatus({ status: RequestStatus.FAILED }));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user