* feat: add language selection chore: update tests so we have less error message test: update test * test: update tests * chore: remove duplicate translation * chore: lint for console * chore: remove comments * chore: make sure the affect url frame refresh after the language selection change * chore: add whole_course_translation and language to courseware meta (#1305) * feat: Add feedback widget UI mock Add unit tests Fix snapshot Clean Sequence component logEvent calls Clean unit test Put feedback widget behind whole course translation flag Fix useFeedbackWidget test * chore: add src and dest translation * feat: first iteration of plugin translation chore: update plugin instruction * feat: Connect FeedbackWidget with backend services (#1325) Connect FeedbackWidget with backend services Move feedback widget to unit translation plugin * feat: Add authentication to WCT feedback endpoints (#1329) * chore: add fetch config and move feedback widget for the plugin chore: rewrite and test the api request chore: rebase chore: update translation feedback chore: test chore: add more tests * chore: rebase * chore: update requested change * chore: update package * chore: upgrade frontend-lib-special-exams and frontend-lib-learning-assistant * chore: update tests * chore: remove unneeded package * chore: update example config * chore: add source-map-loader * fix: feedback widget render error after submit feedback (#1335) * fix: feedback widget render error after submit feedback * fix: widget logic --------- Co-authored-by: Rodrigo Martin <rodrigom_94@hotmail.com>
91 lines
2.3 KiB
JavaScript
91 lines
2.3 KiB
JavaScript
import { getConfig, camelCaseObject } from '@edx/frontend-platform';
|
|
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
|
|
import { logError } from '@edx/frontend-platform/logging';
|
|
import { stringify } from 'query-string';
|
|
|
|
export const fetchTranslationConfig = async (courseId) => {
|
|
const url = `${
|
|
getConfig().LMS_BASE_URL
|
|
}/api/translatable_xblocks/config/?course_id=${encodeURIComponent(courseId)}`;
|
|
try {
|
|
const { data } = await getAuthenticatedHttpClient().get(url);
|
|
return {
|
|
enabled: data.feature_enabled,
|
|
availableLanguages: data.available_translation_languages || [
|
|
{
|
|
code: 'en',
|
|
label: 'English',
|
|
},
|
|
{
|
|
code: 'es',
|
|
label: 'Spanish',
|
|
},
|
|
],
|
|
};
|
|
} catch (error) {
|
|
logError(`Translation plugin fail to fetch from ${url}`, error);
|
|
return {
|
|
enabled: false,
|
|
availableLanguages: [],
|
|
};
|
|
}
|
|
};
|
|
|
|
export async function getTranslationFeedback({
|
|
courseId,
|
|
translationLanguage,
|
|
unitId,
|
|
userId,
|
|
}) {
|
|
const params = stringify({
|
|
translation_language: translationLanguage,
|
|
course_id: encodeURIComponent(courseId),
|
|
unit_id: encodeURIComponent(unitId),
|
|
user_id: userId,
|
|
});
|
|
const fetchFeedbackUrl = `${
|
|
getConfig().AI_TRANSLATIONS_URL
|
|
}/api/v1/whole-course-translation-feedback?${params}`;
|
|
try {
|
|
const { data } = await getAuthenticatedHttpClient().get(fetchFeedbackUrl);
|
|
return camelCaseObject(data);
|
|
} catch (error) {
|
|
logError(
|
|
`Translation plugin fail to fetch from ${fetchFeedbackUrl}`,
|
|
error,
|
|
);
|
|
return {};
|
|
}
|
|
}
|
|
|
|
export async function createTranslationFeedback({
|
|
courseId,
|
|
feedbackValue,
|
|
translationLanguage,
|
|
unitId,
|
|
userId,
|
|
}) {
|
|
const createFeedbackUrl = `${
|
|
getConfig().AI_TRANSLATIONS_URL
|
|
}/api/v1/whole-course-translation-feedback/`;
|
|
try {
|
|
const { data } = await getAuthenticatedHttpClient().post(
|
|
createFeedbackUrl,
|
|
{
|
|
course_id: courseId,
|
|
feedback_value: feedbackValue,
|
|
translation_language: translationLanguage,
|
|
unit_id: unitId,
|
|
user_id: userId,
|
|
},
|
|
);
|
|
return camelCaseObject(data);
|
|
} catch (error) {
|
|
logError(
|
|
`Translation plugin fail to create feedback from ${createFeedbackUrl}`,
|
|
error,
|
|
);
|
|
return {};
|
|
}
|
|
}
|