Skip to content

Commit

Permalink
refactor: after review
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Nov 3, 2024
1 parent b40903b commit d723cb8
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 109 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"extends @edx/browserslist-config"
],
"scripts": {
"build": "sh run-build-for-gh-deps.sh",
"build": "fedx-scripts webpack",
"i18n_extract": "fedx-scripts formatjs extract",
"stylelint": "stylelint \"plugins/**/*.scss\" \"src/**/*.scss\" \"scss/**/*.scss\" --config .stylelintrc.json",
"lint": "npm run stylelint && fedx-scripts eslint --ext .js --ext .jsx --ext .ts --ext .tsx .",
Expand Down
39 changes: 0 additions & 39 deletions run-build-for-gh-deps.sh

This file was deleted.

4 changes: 2 additions & 2 deletions src/course-outline/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ const useCourseOutline = ({ courseId }) => {
};

const getUnitUrl = (locator) => {
if (getConfig().ENABLE_UNIT_PAGE === 'true' || waffleFlags.useNewUnitPage) {
if (getConfig().ENABLE_UNIT_PAGE === 'true' && waffleFlags.useNewUnitPage) {
return `/course/${courseId}/container/${locator}`;
}
return `${getConfig().STUDIO_BASE_URL}/container/${locator}`;
};

const openUnitPage = (locator) => {
const url = getUnitUrl(locator);
if (getConfig().ENABLE_UNIT_PAGE === 'true' || waffleFlags.useNewUnitPage) {
if (getConfig().ENABLE_UNIT_PAGE === 'true' && waffleFlags.useNewUnitPage) {
navigate(url);
} else {
window.location.assign(url);
Expand Down
2 changes: 1 addition & 1 deletion src/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const slice = createSlice({
useNewExportPage: true,
useNewFilesUploadsPage: true,
useNewVideoUploadsPage: true,
useNewCourseOutlinePage: false,
useNewCourseOutlinePage: true,
useNewUnitPage: false,
useNewCourseTeamPage: true,
useNewCertificatesPage: true,
Expand Down
14 changes: 3 additions & 11 deletions src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,8 @@ export function fetchCourseDetail(courseId) {
export function fetchWaffleFlags(courseId) {
return async (dispatch) => {
dispatch(updateStatus({ courseId, status: RequestStatus.IN_PROGRESS }));

try {
const waffleFlags = await getWaffleFlags(courseId);
dispatch(updateStatus({ courseId, status: RequestStatus.SUCCESSFUL }));
dispatch(fetchWaffleFlagsSuccess({ waffleFlags }));
} catch (error) {
// If fetching the waffle flags is unsuccessful,
// the pages will still be accessible and display without any issues.
// eslint-disable-next-line no-console
console.error({ courseId, status: RequestStatus.NOT_FOUND });
}
const waffleFlags = await getWaffleFlags(courseId);
dispatch(updateStatus({ courseId, status: RequestStatus.SUCCESSFUL }));
dispatch(fetchWaffleFlagsSuccess({ waffleFlags }));
};
}
8 changes: 5 additions & 3 deletions src/studio-home/card-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ const CardItem: React.FC<Props> = ({
} = useSelector(getStudioHomeData);
const waffleFlags = useSelector(getWaffleFlags);

const destinationUrl: string = waffleFlags.useNewCourseOutlinePage
? path ?? url
: path ?? new URL(url, getConfig().STUDIO_BASE_URL).toString();
const destinationUrl: string = path ?? (
waffleFlags.useNewCourseOutlinePage
? url
: new URL(url, getConfig().STUDIO_BASE_URL).toString()
);
const subtitle = isLibraries ? `${org} / ${number}` : `${org} / ${number} / ${run}`;
const readOnlyItem = !(lmsLink || rerunLink || url || path);
const showActions = !(readOnlyItem || isLibraries);
Expand Down
8 changes: 6 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,19 @@ export const createCorrectInternalRoute = (checkPath) => {
basePath = basePath.slice(0, -1);
}

if (!checkPath.startsWith(basePath)) {
return `${basePath}${checkPath}`;
}

return checkPath;
};

export function getPagePath(courseId, isMfePageEnabled, urlParameter) {
if (isMfePageEnabled === 'true') {
if (urlParameter === 'tabs') {
return createCorrectInternalRoute(`/course/${courseId}/pages-and-resources`);
return `/course/${courseId}/pages-and-resources`;
}
return createCorrectInternalRoute(`/course/${courseId}/${urlParameter}`);
return `/course/${courseId}/${urlParameter}`;
}
return `${getConfig().STUDIO_BASE_URL}/${urlParameter}/${courseId}`;
}
Expand Down
50 changes: 0 additions & 50 deletions src/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { getConfig, getPath } from '@edx/frontend-platform';

import {
getFileSizeToClosestByte,
createCorrectInternalRoute,
convertObjectToSnakeCase,
deepConvertingKeysToCamelCase,
deepConvertingKeysToSnakeCase,
Expand Down Expand Up @@ -53,53 +50,6 @@ describe('FilesAndUploads utils', () => {
});
});

describe('createCorrectInternalRoute', () => {
beforeEach(() => {
getConfig.mockReset();
getPath.mockReset();
});

it('returns the correct internal route when checkPath is not prefixed with basePath', () => {
getConfig.mockReturnValue({ PUBLIC_PATH: 'example.com' });
getPath.mockReturnValue('/');

const checkPath = '/some/path';
const result = createCorrectInternalRoute(checkPath);

expect(result).toBe('/some/path');
});

it('returns the input checkPath when it is already prefixed with basePath', () => {
getConfig.mockReturnValue({ PUBLIC_PATH: 'example.com' });
getPath.mockReturnValue('/course-authoring');

const checkPath = '/course-authoring/some/path';
const result = createCorrectInternalRoute(checkPath);

expect(result).toBe('/course-authoring/some/path');
});

it('handles basePath ending with a slash correctly', () => {
getConfig.mockReturnValue({ PUBLIC_PATH: 'example.com/' });
getPath.mockReturnValue('/course-authoring/');

const checkPath = '/course-authoring/some/path';
const result = createCorrectInternalRoute(checkPath);

expect(result).toBe('/course-authoring/some/path');
});

it('returns checkPath as is when basePath is part of checkPath', () => {
getConfig.mockReturnValue({ PUBLIC_PATH: 'example.com' });
getPath.mockReturnValue('/example-base/');

const checkPath = '/example-base/some/path';
const result = createCorrectInternalRoute(checkPath);

expect(result).toBe(checkPath);
});
});

describe('convertObjectToSnakeCase', () => {
it('converts object keys to snake_case', () => {
const input = { firstName: 'John', lastName: 'Doe' };
Expand Down

0 comments on commit d723cb8

Please sign in to comment.