Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions src/config/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/containers/ListView/ListViewBreadcrumb.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ListViewBreadcrumb = ({ courseId, oraName }) => (
</Hyperlink>
<p className="py-4">
<span className="h3">{oraName}</span>
<Hyperlink className="align-middle" destination={urls.ora(courseId, locationId)}>
<Hyperlink className="align-middle" destination={urls.ora(courseId, locationId())}>
<Icon src={Launch} className="d-inline-block" />
</Hyperlink>
</p>
Expand Down
2 changes: 1 addition & 1 deletion src/containers/ListView/ListViewBreadcrumb.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('ListViewBreadcrumb component', () => {
test('ora destination', () => {
expect(
el.find(Hyperlink).at(1).props().destination,
).toEqual(urls.ora(props.courseId, constants.locationId));
).toEqual(urls.ora(props.courseId, constants.locationId()));
});
});
describe('mapStateToProps', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/data/constants/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getConfig } from '@edx/frontend-platform';

export const routePath = `${getConfig().PUBLIC_PATH}:courseId`;
export const locationId = window.location.pathname.replace(getConfig().PUBLIC_PATH, '');
export const routePath = () => `${getConfig().PUBLIC_PATH}:courseId`;
export const locationId = () => window.location.pathname.replace(getConfig().PUBLIC_PATH, '');
4 changes: 2 additions & 2 deletions src/data/constants/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jest.mock('@edx/frontend-platform', () => {

describe('app constants', () => {
test('route path draws from public path and adds courseId', () => {
expect(constants.routePath).toEqual(`${platform.PUBLIC_PATH}:courseId`);
expect(constants.routePath()).toEqual(`${platform.PUBLIC_PATH}:courseId`);
});
test('locationId returns trimmed pathname', () => {
const old = window.location;
window.location = { pathName: `${platform.PUBLIC_PATH}somePath.jpg` };
expect(constants.locationId).toEqual(window.location.pathname.replace(platform.PUBLIC_PATH, ''));
expect(constants.locationId()).toEqual(window.location.pathname.replace(platform.PUBLIC_PATH, ''));
window.location = old;
});
});
2 changes: 1 addition & 1 deletion src/data/redux/thunkActions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as module from './app';
*/
export const initialize = () => (dispatch) => {
dispatch(initializeApp({
locationId,
locationId: locationId(),
onSuccess: (response) => {
dispatch(actions.app.loadIsEnabled(response.isEnabled));
dispatch(actions.app.loadOraMetadata(response.oraMetadata));
Expand Down
2 changes: 1 addition & 1 deletion src/data/redux/thunkActions/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('app thunkActions', () => {
[[dispatchedAction]] = dispatch.mock.calls;
});
it('dispatches initializeApp with locationId and onSuccess', () => {
expect(dispatchedAction.initializeApp.locationId).toEqual(locationId);
expect(dispatchedAction.initializeApp.locationId).toEqual(locationId());
expect(typeof dispatchedAction.initializeApp.onSuccess).toEqual('function');
});
describe('on success', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/data/redux/thunkActions/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const zipFiles = async (files, blobs, username) => {
}

const zipFile = await zipWriter.close();
const zipName = `${username}-${locationId}.zip`;
const zipName = `${username}-${locationId()}.zip`;
FileSaver.saveAs(zipFile, zipName);
};

Expand Down
32 changes: 16 additions & 16 deletions src/data/services/lms/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import {
* }
*/
const initializeApp = () => get(
stringifyUrl(urls.oraInitializeUrl, {
[paramKeys.oraLocation]: locationId,
stringifyUrl(urls.oraInitializeUrl(), {
[paramKeys.oraLocation]: locationId(),
}),
).then(response => response.data);

Expand All @@ -48,8 +48,8 @@ const initializeApp = () => get(
* }
*/
const fetchSubmission = (submissionUUID) => get(
stringifyUrl(urls.fetchSubmissionUrl, {
[paramKeys.oraLocation]: locationId,
stringifyUrl(urls.fetchSubmissionUrl(), {
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
}),
).then(response => response.data);
Expand All @@ -61,8 +61,8 @@ const fetchSubmission = (submissionUUID) => get(
* }
*/
const fetchSubmissionFiles = (submissionUUID) => get(
stringifyUrl(urls.fetchSubmissionFilesUrl, {
[paramKeys.oraLocation]: locationId,
stringifyUrl(urls.fetchSubmissionFilesUrl(), {
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
}),
).then(response => response.data);
Expand All @@ -78,8 +78,8 @@ const fetchSubmissionFiles = (submissionUUID) => get(
* }
*/
const fetchSubmissionStatus = (submissionUUID) => get(
stringifyUrl(urls.fetchSubmissionStatusUrl, {
[paramKeys.oraLocation]: locationId,
stringifyUrl(urls.fetchSubmissionStatusUrl(), {
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
}),
).then(response => response.data);
Expand All @@ -89,8 +89,8 @@ const fetchSubmissionStatus = (submissionUUID) => get(
* @param {string} submissionUUID
*/
const lockSubmission = (submissionUUID) => post(
stringifyUrl(urls.fetchSubmissionLockUrl, {
[paramKeys.oraLocation]: locationId,
stringifyUrl(urls.fetchSubmissionLockUrl(), {
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
}),
).then(response => response.data);
Expand All @@ -100,8 +100,8 @@ const lockSubmission = (submissionUUID) => post(
* @param {string} submissionUUID
*/
const unlockSubmission = (submissionUUID) => client().delete(
stringifyUrl(urls.fetchSubmissionLockUrl, {
[paramKeys.oraLocation]: locationId,
stringifyUrl(urls.fetchSubmissionLockUrl(), {
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
}),
).then(response => response.data);
Expand All @@ -112,8 +112,8 @@ const unlockSubmission = (submissionUUID) => client().delete(
*/
const batchUnlockSubmissions = (submissionUUIDs) => post(
stringifyUrl(
urls.batchUnlockSubmissionsUrl,
{ [paramKeys.oraLocation]: locationId },
urls.batchUnlockSubmissionsUrl(),
{ [paramKeys.oraLocation]: locationId() },
),
{ submissionUUIDs },
).then(response => response.data);
Expand All @@ -123,8 +123,8 @@ const batchUnlockSubmissions = (submissionUUIDs) => post(
* @param {object} gradeData - full grading submission data
*/
const updateGrade = (submissionUUID, gradeData) => post(
stringifyUrl(urls.updateSubmissionGradeUrl, {
[paramKeys.oraLocation]: locationId,
stringifyUrl(urls.updateSubmissionGradeUrl(), {
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
}),
gradeData,
Expand Down
22 changes: 11 additions & 11 deletions src/data/services/lms/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jest.mock('./utils', () => ({
}));

jest.mock('data/constants/app', () => ({
locationId: 'test-location-id',
locationId: () => 'test-location-id',
}));

const gradeData = 'test-grade-data';
Expand All @@ -37,10 +37,10 @@ const testAPI = ({
...otherExpected
},
}) => {
it(`returns ${method}(${urlKey}) with correct args and reoslves with response data`, () => (
it(`returns ${method}(${urlKey}) with correct args and resolves with response data`, () => (
promise.then((data) => {
expect(data[method]).toEqual({
url: stringifyUrl(urls[urlKey], urlParams),
url: stringifyUrl(urls[urlKey](), urlParams),
...otherExpected,
});
})
Expand All @@ -54,7 +54,7 @@ describe('lms service api methods', () => {
method: methodKeys.get,
expected: {
urlKey: urlKeys.oraInitializeUrl,
urlParams: { [paramKeys.oraLocation]: locationId },
urlParams: { [paramKeys.oraLocation]: locationId() },
},
});
});
Expand All @@ -65,7 +65,7 @@ describe('lms service api methods', () => {
expected: {
urlKey: urlKeys.fetchSubmissionUrl,
urlParams: {
[paramKeys.oraLocation]: locationId,
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
},
},
Expand All @@ -78,7 +78,7 @@ describe('lms service api methods', () => {
expected: {
urlKey: urlKeys.fetchSubmissionFilesUrl,
urlParams: {
[paramKeys.oraLocation]: locationId,
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
},
},
Expand All @@ -91,7 +91,7 @@ describe('lms service api methods', () => {
expected: {
urlKey: urlKeys.fetchSubmissionStatusUrl,
urlParams: {
[paramKeys.oraLocation]: locationId,
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
},
},
Expand All @@ -104,7 +104,7 @@ describe('lms service api methods', () => {
expected: {
urlKey: urlKeys.fetchSubmissionLockUrl,
urlParams: {
[paramKeys.oraLocation]: locationId,
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
},
},
Expand All @@ -117,7 +117,7 @@ describe('lms service api methods', () => {
expected: {
urlKey: urlKeys.fetchSubmissionLockUrl,
urlParams: {
[paramKeys.oraLocation]: locationId,
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
},
},
Expand All @@ -130,7 +130,7 @@ describe('lms service api methods', () => {
expected: {
urlKey: urlKeys.batchUnlockSubmissionsUrl,
urlParams: {
[paramKeys.oraLocation]: locationId,
[paramKeys.oraLocation]: locationId(),
},
data: { submissionUUIDs },
},
Expand All @@ -143,7 +143,7 @@ describe('lms service api methods', () => {
expected: {
urlKey: urlKeys.updateSubmissionGradeUrl,
urlParams: {
[paramKeys.oraLocation]: locationId,
[paramKeys.oraLocation]: locationId(),
[paramKeys.submissionUUID]: submissionUUID,
},
data: gradeData,
Expand Down
24 changes: 12 additions & 12 deletions src/data/services/lms/urls.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { StrictDict } from 'utils';
import { configuration } from 'config';
import { getConfig } from '@edx/frontend-platform';

const baseUrl = `${configuration.LMS_BASE_URL}`;
const baseUrl = () => getConfig().LMS_BASE_URL;

const api = `${baseUrl}/api/`;
const baseEsgUrl = `${api}ora_staff_grader/`;
const api = () => `${baseUrl()}/api/`;
const baseEsgUrl = () => `${api()}ora_staff_grader/`;

const oraInitializeUrl = `${baseEsgUrl}initialize`;
const fetchSubmissionUrl = `${baseEsgUrl}submission`;
const fetchSubmissionFilesUrl = `${baseEsgUrl}submission/files`;
const fetchSubmissionStatusUrl = `${baseEsgUrl}submission/status`;
const fetchSubmissionLockUrl = `${baseEsgUrl}submission/lock`;
const batchUnlockSubmissionsUrl = `${baseEsgUrl}submission/batch/unlock`;
const updateSubmissionGradeUrl = `${baseEsgUrl}submission/grade`;
const oraInitializeUrl = () => `${baseEsgUrl()}initialize`;
const fetchSubmissionUrl = () => `${baseEsgUrl()}submission`;
const fetchSubmissionFilesUrl = () => `${baseEsgUrl()}submission/files`;
const fetchSubmissionStatusUrl = () => `${baseEsgUrl()}submission/status`;
const fetchSubmissionLockUrl = () => `${baseEsgUrl()}submission/lock`;
const batchUnlockSubmissionsUrl = () => `${baseEsgUrl()}submission/batch/unlock`;
const updateSubmissionGradeUrl = () => `${baseEsgUrl()}submission/grade`;

const course = (courseId) => `${baseUrl}/courses/${courseId}`;
const course = (courseId) => `${baseUrl()}/courses/${courseId}`;

const openResponse = (courseId) => (
`${course(courseId)}/instructor#view-open_response_assessment`
Expand Down
4 changes: 2 additions & 2 deletions src/segment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The code in this file is from Segment's website:
// https://segment.com/docs/sources/website/analytics.js/quickstart/
import { configuration } from './config';
import { getConfig } from '@edx/frontend-platform';

(function () {
// Create a queue, but don't obliterate an existing one!
Expand Down Expand Up @@ -81,5 +81,5 @@ import { configuration } from './config';

// Load Analytics.js with your key, which will automatically
// load the tools you've enabled for your account. Boosh!
analytics.load(configuration.SEGMENT_KEY);
analytics.load(getConfig().SEGMENT_KEY);
}());
2 changes: 1 addition & 1 deletion src/setupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jest.mock('@edx/paragon/icons', () => ({
}));

jest.mock('data/constants/app', () => ({
locationId: 'fake-location-id',
locationId: () => 'fake-location-id',
}));

jest.mock('hooks', () => ({
Expand Down