Skip to content

Commit c90bc85

Browse files
tecoholicfarhaanbukhsh
authored andcommitted
refactor: break AspectsSidebar into components, setup proper linting
1 parent 5422c87 commit c90bc85

17 files changed

+865
-422
lines changed

.eslintignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
coverage/*
22
dist/
33
node_modules/
4-
jest.config.js
4+
jest.config.js
5+
babel.config.js

.eslintrc.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line import/no-extraneous-dependencies
2-
const { createConfig } = require('@openedx/frontend-build');
3-
4-
module.exports = createConfig('eslint');
1+
module.exports = {
2+
extends: '@edx/eslint-config',
3+
};

package-lock.json

+512-117
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"preinstall": "npm run build",
1515
"build": "fedx-scripts babel -x .js,.jsx,.ts,.tsx src --out-dir dist --ignore **/*.test.jsx,**/*.test.js,**/setupTest.js && cp src/*.css dist/",
1616
"i18n_extract": "fedx-scripts formatjs extract",
17-
"lint": "fedx-scripts eslint --ext .js --ext .jsx .",
18-
"lint:fix": "fedx-scripts eslint --fix --ext .js --ext .jsx .",
17+
"lint": "fedx-scripts eslint --ext .js --ext .jsx --ext .ts --ext .tsx .",
18+
"lint:fix": "fedx-scripts eslint --fix --ext .js --ext .jsx --ext .ts --ext .tsx .",
1919
"test": "fedx-scripts jest --coverage --passWithNoTests"
2020
},
2121
"husky": {
@@ -58,9 +58,21 @@
5858
},
5959
"devDependencies": {
6060
"@edx/browserslist-config": "^1.1.1",
61+
"@edx/eslint-config": "^4.3.0",
62+
"@edx/typescript-config": "^1.1.0",
6163
"@openedx/frontend-build": "14.3.2",
64+
"@typescript-eslint/eslint-plugin": "^5.62.0",
65+
"@typescript-eslint/parser": "^5.62.0",
66+
"eslint": "^8.57.1",
67+
"eslint-config-airbnb": "^19.0.4",
68+
"eslint-config-airbnb-typescript": "^17.1.0",
69+
"eslint-plugin-import": "^2.31.0",
70+
"eslint-plugin-jsx-a11y": "^6.10.2",
71+
"eslint-plugin-react": "^7.37.5",
72+
"eslint-plugin-react-hooks": "^4.6.2",
6273
"glob": "11.0.1",
6374
"husky": "9.1.7",
64-
"jest": "29.7.0"
75+
"jest": "29.7.0",
76+
"typescript": "^4.9.5"
6577
}
6678
}

src/components/AspectsSidebar.tsx

-272
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as React from 'react';
2+
import { useIntl } from '@edx/frontend-platform/i18n';
3+
import { Button, Icon } from '@openedx/paragon';
4+
import { ArrowDropDown, ArrowDropUp, ChevronRight } from '@openedx/paragon/icons';
5+
import { Block } from '../../hooks';
6+
import messages from '../../messages';
7+
8+
interface CourseContentListProps {
9+
title: string,
10+
contentList?: Block[] | null,
11+
icon: React.FC,
12+
activateDashboard: (block: Block) => void,
13+
}
14+
15+
export function CourseContentList({
16+
title, contentList, icon, activateDashboard,
17+
}: CourseContentListProps) {
18+
const intl = useIntl();
19+
// using undefined is useful for slicing the list
20+
const [showCount, setShowCount] = React.useState<number | undefined>(5);
21+
22+
if (!contentList?.length) {
23+
return null;
24+
}
25+
26+
return (
27+
<div className="d-flex flex-column rounded-bottom py-4 px-3 bg-white border-top border-light">
28+
<h4 className="h4 mb-4">{title}</h4>
29+
{contentList?.slice(0, showCount).map(block => (
30+
<Button
31+
key={block.id}
32+
className="d-flex flex-row justify-content-start flex-grow-1 mb-2 py-1 px-0"
33+
variant="inline"
34+
onClick={() => activateDashboard(block)}
35+
>
36+
<h5 className="h5 flex-grow-1 text-left d-flex align-items-center">
37+
<Icon
38+
src={icon}
39+
size="xs"
40+
className="mr-2 text-gray"
41+
aria-hidden
42+
/>
43+
<span>{block.displayName || block.name}</span>
44+
</h5>
45+
<Icon src={ChevronRight} aria-hidden />
46+
</Button>
47+
))}
48+
{(contentList?.length > 5) && (
49+
<Button
50+
variant="tertiary"
51+
size="sm"
52+
iconAfter={showCount === 5 ? ArrowDropDown : ArrowDropUp}
53+
onClick={() => setShowCount(showCount === 5 ? undefined : 5)}
54+
>
55+
{showCount === 5 ? intl.formatMessage(messages.showMore) : intl.formatMessage(messages.showLess)}
56+
</Button>
57+
)}
58+
</div>
59+
);
60+
}

0 commit comments

Comments
 (0)