Skip to content

Commit 820dcbb

Browse files
committed
fix lint errors for part of tools/learn
1 parent 1a2e0ab commit 820dcbb

File tree

23 files changed

+278
-159
lines changed

23 files changed

+278
-159
lines changed

src-ts/tools/learn/course-certificate/certificate-view/certificate/course-card/CourseCard.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ const CourseCard: FC<CourseCardProps> = (props: CourseCardProps) => (
2626
<IconOutline.CalendarIcon />
2727
<span className='large-subtitle'>
2828
<span>Completed</span>
29-
<span>{props.completedDate && textFormatDateLocaleShortString(new Date(props.completedDate))}</span>
29+
<span>
30+
{
31+
props.completedDate && (
32+
textFormatDateLocaleShortString(new Date(props.completedDate))
33+
)
34+
}
35+
</span>
3036
</span>
3137
</div>
3238
</div>

src-ts/tools/learn/learn-lib/course-outline/collapsible-item/CollapsibleItem.tsx

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface CollapsibleItemProps {
1818
active?: string
1919
duration: LearnModule['meta']['estimatedCompletionTime']
2020
isAssessment: boolean
21-
itemId?: (item: any) => string
21+
itemId?: (item: CollapsibleListItem) => string
2222
items: Array<CollapsibleListItem>
2323
lessonsCount: number
2424
moduleKey: string
@@ -30,52 +30,67 @@ interface CollapsibleItemProps {
3030
}
3131

3232
const CollapsibleItem: FC<CollapsibleItemProps> = (props: CollapsibleItemProps) => {
33-
const [isOpen, setIsOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState<boolean>(false)
33+
const [isOpen, setIsOpen]: [
34+
boolean,
35+
Dispatch<SetStateAction<boolean>>
36+
] = useState<boolean>(false)
3437

3538
const toggle: () => void = useCallback(() => {
3639
setIsOpen(open => !open)
3740
}, [])
3841

39-
const progress: LearnModuleProgress | undefined = useMemo(() => props.progress?.find(m => m.module === props.moduleKey), [props.progress, props.moduleKey])
42+
const progress: LearnModuleProgress | undefined = useMemo(() => (
43+
props.progress?.find(m => m.module === props.moduleKey)
44+
), [props.progress, props.moduleKey])
4045

41-
const isCompleted: boolean = useMemo(() => !!progress && progress.lessonCount === progress?.completedLessons.length, [progress])
46+
const isCompleted: boolean = useMemo(() => (
47+
!!progress && progress.lessonCount === progress?.completedLessons.length
48+
), [progress])
4249

43-
const isPartial: boolean = useMemo(() => !!progress && !!progress.completedLessons.length, [progress])
50+
const isPartial: boolean = useMemo(() => (
51+
!!progress && !!progress.completedLessons.length
52+
), [progress])
4453

4554
const isItemCompleted: (key: string) => boolean = (key: string) => (
4655
!!progress?.completedLessons.find(l => l.dashedName === key)
4756
)
4857

49-
const stepLabel: (item: any, isActive: boolean, stepCount: string, label?: string) => ReactNode
50-
= (item: any, isActive: boolean, stepCount: string, label?: string) => (
51-
<StepIcon
52-
index={stepCount}
53-
completed={isItemCompleted(item.dashedName)}
54-
active={isActive}
55-
label={label}
56-
/>
57-
)
58-
59-
const renderListItem: (item: any) => ReactNode = (item: any) => {
60-
const isActive: boolean = props.itemId?.(item) === props.active
61-
const stepCount: string = item.dashedName.match(/^step-(\d+)$/i)?.[1]
62-
const label: ReactNode = stepLabel(item, isActive, stepCount, !stepCount && item.title)
63-
const key: string = props.itemId?.(item) ?? item.title
64-
65-
return (
66-
<li
67-
key={key}
68-
className={classNames(styles['item-wrap'], !stepCount && 'full-width')}
69-
onClick={() => props.onItemClick(item)}
70-
>
71-
{props.path ? (
72-
<Link className={styles['item-wrap']} to={props.path(item)}>
73-
{label}
74-
</Link>
75-
) : label}
76-
</li>
58+
const stepLabel: (
59+
item: CollapsibleListItem,
60+
isActive: boolean,
61+
stepCount?: string,
62+
label?: string
63+
) => ReactNode
64+
= (item: CollapsibleListItem, isActive: boolean, stepCount?: string, label?: string) => (
65+
<StepIcon
66+
index={stepCount}
67+
completed={isItemCompleted(item.dashedName)}
68+
active={isActive}
69+
label={label}
70+
/>
7771
)
78-
}
72+
73+
const renderListItem: (item: CollapsibleListItem) => ReactNode
74+
= (item: CollapsibleListItem) => {
75+
const isActive: boolean = props.itemId?.(item) === props.active
76+
const stepCount: string | undefined = item.dashedName.match(/^step-(\d+)$/i)?.[1]
77+
const label: ReactNode = stepLabel(item, isActive, stepCount, !stepCount && item.title)
78+
const key: string = props.itemId?.(item) ?? item.title
79+
80+
return (
81+
<li
82+
key={key}
83+
className={classNames(styles['item-wrap'], !stepCount && 'full-width')}
84+
onClick={() => props.onItemClick(item)}
85+
>
86+
{props.path ? (
87+
<Link className={styles['item-wrap']} to={props.path(item)}>
88+
{label}
89+
</Link>
90+
) : label}
91+
</li>
92+
)
93+
}
7994

8095
return (
8196
<div className={classNames(styles.wrap, isOpen ? 'is-open' : 'collapsed')}>

src-ts/tools/learn/learn-lib/course-outline/status-icon/StatusIcon.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ const StatusIcon: FC<StatusIconProps> = (props: StatusIconProps) => {
1818
props.partial && 'partial',
1919
)
2020

21-
const icon: ReactNode = useMemo(() => (
22-
props.completed
23-
? <IconSolid.CheckCircleIcon />
24-
: props.partial
25-
? <IconOutline.ClockIcon />
26-
: <IconOutline.DotsCircleHorizontalIcon />
27-
), [props.completed, props.partial])
21+
const icon: ReactNode = useMemo(() => {
22+
if (props.completed) {
23+
return <IconSolid.CheckCircleIcon />
24+
}
25+
26+
if (props.partial) {
27+
return <IconOutline.ClockIcon />
28+
}
29+
30+
return <IconOutline.DotsCircleHorizontalIcon />
31+
}, [props.completed, props.partial])
2832

2933
return (
3034
<div className={classes}>

src-ts/tools/learn/learn-lib/course-outline/step-icon/StepIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import styles from './StepIcon.module.scss'
88
interface StepIconProps {
99
active?: boolean
1010
completed?: boolean
11-
index: string
11+
index?: string
1212
label?: string
1313
}
1414

src-ts/tools/learn/learn-lib/courses-provider/courses.provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { noop } from 'lodash'
12
import { Dispatch, SetStateAction, useEffect, useState } from 'react'
23

34
import { courseGetAsync } from './courses-functions'
@@ -24,7 +25,7 @@ export function useCourses(provider: string, certification?: string): CoursesPro
2425
loading: false,
2526
ready: false,
2627
}))
27-
return
28+
return noop
2829
}
2930

3031
setState(prevState => ({

src-ts/tools/learn/learn-lib/functions/learn-xhr.functions.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ import { AxiosInstance, AxiosRequestConfig } from 'axios'
22

33
import { xhrCreateInstance, xhrGetAsync, xhrPostAsync, xhrPutAsync } from '../../../../lib'
44

5-
import { create as learnCreate } from './learn.factory'
5+
import { create as learnCreate, LearnResponseModel } from './learn.factory'
66

77
const learnXhrInstance: AxiosInstance = xhrCreateInstance()
88

99
// handle all created and updated dates
1010
learnXhrInstance.interceptors.response
1111
.use(response => {
1212

13-
if (response.data?.hasOwnProperty('createdAt')) {
13+
if (Object.prototype.hasOwnProperty.call(response.data, 'createdAt')) {
1414
response.data = learnCreate(response.data)
1515

1616
} else if (response.data?.constructor?.name === 'Array') {
1717
response.data = response.data
18-
.map((item: any) => learnCreate(item))
18+
.map(<T extends LearnResponseModel>(item: T) => learnCreate(item))
1919
}
2020

2121
return response
@@ -25,10 +25,18 @@ export async function getAsync<T>(url: string): Promise<T> {
2525
return xhrGetAsync(url, learnXhrInstance)
2626
}
2727

28-
export async function postAsync<T, R>(url: string, data: T, config?: AxiosRequestConfig<T>): Promise<R> {
28+
export async function postAsync<T, R>(
29+
url: string,
30+
data: T,
31+
config?: AxiosRequestConfig<T>,
32+
): Promise<R> {
2933
return xhrPostAsync(url, data, config, learnXhrInstance)
3034
}
3135

32-
export async function putAsync<T, R>(url: string, data: T, config?: AxiosRequestConfig<T>): Promise<R> {
36+
export async function putAsync<T, R>(
37+
url: string,
38+
data: T,
39+
config?: AxiosRequestConfig<T>,
40+
): Promise<R> {
3341
return xhrPutAsync(url, data, config, learnXhrInstance)
3442
}

src-ts/tools/learn/learn-lib/functions/learn.factory.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
interface LearnResponseModel {
1+
import { set } from 'lodash'
2+
3+
export interface LearnResponseModel {
24
createdAt?: string | Date
35
publishedAt?: string | Date
46
updatedAt?: string | Date
@@ -7,15 +9,15 @@ interface LearnResponseModel {
79
export function create<T extends LearnResponseModel>(item: T): T {
810

911
if (typeof item?.createdAt === 'string') {
10-
item.createdAt = new Date(item.createdAt)
12+
set(item, 'createdAt', new Date(item.createdAt))
1113
}
1214

1315
if (typeof item?.updatedAt === 'string') {
14-
item.updatedAt = new Date(item.updatedAt)
16+
set(item, 'updatedAt', new Date(item.updatedAt))
1517
}
1618

1719
if (typeof item?.publishedAt === 'string') {
18-
item.publishedAt = new Date(item.publishedAt)
20+
set(item, 'publishedAt', new Date(item.publishedAt))
1921
}
2022

2123
return item

src-ts/tools/learn/learn-lib/lesson-provider/lesson.provider.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { get, noop } from 'lodash'
12
import { Dispatch, SetStateAction, useEffect, useState } from 'react'
23

34
import { courseGetAsync } from '../courses-provider'
@@ -12,10 +13,14 @@ export function useLessonProvider(
1213
module?: string,
1314
lesson?: string,
1415
): LessonProviderData {
15-
const [state, setState]: [LessonProviderData, Dispatch<SetStateAction<LessonProviderData>>] = useState<LessonProviderData>({
16-
loading: false,
17-
ready: false,
18-
})
16+
const [state, setState]: [
17+
LessonProviderData,
18+
Dispatch<SetStateAction<LessonProviderData>>
19+
]
20+
= useState<LessonProviderData>({
21+
loading: false,
22+
ready: false,
23+
})
1924

2025
useEffect(() => {
2126
let mounted: boolean = true
@@ -27,7 +32,7 @@ export function useLessonProvider(
2732
loading: false,
2833
ready: false,
2934
}))
30-
return
35+
return noop
3136
}
3237

3338
setState(prevState => ({
@@ -42,8 +47,10 @@ export function useLessonProvider(
4247
return
4348
}
4449

45-
const moduleData: LearnModule | undefined = courseData?.modules.find(m => m.key === module)
46-
const lessonData: LearnLesson | undefined = moduleData?.lessons.find(l => l.dashedName === lesson)
50+
const moduleData: LearnModule | undefined
51+
= courseData?.modules.find(m => m.key === module)
52+
const lessonData: LearnLesson | undefined
53+
= moduleData?.lessons.find(l => l.dashedName === lesson)
4754

4855
const lessonUrl: string = [
4956
'learn',
@@ -57,10 +64,10 @@ export function useLessonProvider(
5764
lesson: lessonData && {
5865
...lessonData,
5966
course: {
60-
certification: courseData?.certification ?? '',
61-
certificationId: courseData?.certificationId ?? '',
62-
id: courseData?.id ?? '',
63-
title: courseData?.title ?? '',
67+
certification: get(courseData, 'certification', ''),
68+
certificationId: get(courseData, 'certificationId', ''),
69+
id: get(courseData, 'id', ''),
70+
title: get(courseData, 'title', ''),
6471
},
6572
lessonUrl,
6673
module: {

src-ts/tools/learn/learn-lib/my-course-card/completed/Completed.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getCertificatePath, getCoursePath } from '../../../learn.routes'
88
import styles from './Completed.module.scss'
99

1010
interface CompletedProps {
11-
certification: LearnCertification
11+
certification?: LearnCertification
1212
completed: string
1313
}
1414

@@ -38,13 +38,23 @@ const Completed: FC<CompletedProps> = (props: CompletedProps) => {
3838
size='xs'
3939
buttonStyle='secondary'
4040
label='View Course'
41-
route={getCoursePath(props.certification.providerName, props.certification.certification)}
41+
route={
42+
getCoursePath(
43+
props.certification.providerName,
44+
props.certification.certification,
45+
)
46+
}
4247
/>
4348
<Button
4449
size='xs'
4550
buttonStyle='secondary'
4651
label='View certificate'
47-
route={getCertificatePath(props.certification.providerName, props.certification.certification)}
52+
route={
53+
getCertificatePath(
54+
props.certification.providerName,
55+
props.certification.certification,
56+
)
57+
}
4858
/>
4959
</div>
5060
</div>

src-ts/tools/learn/learn-lib/resource-provider-provider/resource-provider.provider.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import { ResourceProviderData } from './resource-provider-data.model'
44
import { getResourceProvidersAsync } from './resource-provider-functions/resource-provider.store'
55

66
export function useResourceProvider(providerName?: string): ResourceProviderData {
7-
const [state, setState]: [ResourceProviderData, Dispatch<SetStateAction<ResourceProviderData>>] = useState<ResourceProviderData>({
8-
loading: false,
9-
ready: false,
10-
})
7+
const [state, setState]: [
8+
ResourceProviderData,
9+
Dispatch<SetStateAction<ResourceProviderData>>
10+
]
11+
= useState<ResourceProviderData>({
12+
loading: false,
13+
ready: false,
14+
})
1115

1216
useEffect(() => {
1317
if (!providerName) {

0 commit comments

Comments
 (0)