1
1
import PropTypes from 'prop-types' ;
2
2
import classNames from 'classnames' ;
3
- import { Link } from 'react-router-dom' ;
4
- import { useDispatch , useSelector } from 'react-redux' ;
5
3
import { injectIntl , intlShape } from '@edx/frontend-platform/i18n' ;
6
- import { sendTrackEvent , sendTrackingLogEvent } from '@edx/frontend-platform/analytics' ;
7
4
8
- import { checkBlockCompletion } from '@src/courseware/data' ;
9
- import { getCourseOutline } from '@src/courseware/data/selectors' ;
10
5
import messages from '../messages' ;
11
6
import UnitIcon , { UNIT_ICON_TYPES } from './UnitIcon' ;
7
+ import UnitLinkWrapper from './UnitLinkWrapper' ;
12
8
13
9
const SidebarUnit = ( {
14
10
id,
@@ -26,43 +22,18 @@ const SidebarUnit = ({
26
22
title,
27
23
icon = UNIT_ICON_TYPES . other ,
28
24
} = unit ;
29
- const dispatch = useDispatch ( ) ;
30
- const { sequences = { } } = useSelector ( getCourseOutline ) ;
31
-
32
- const logEvent = ( eventName , widgetPlacement ) => {
33
- const findSequenceByUnitId = ( unitId ) => Object . values ( sequences ) . find ( seq => seq . unitIds . includes ( unitId ) ) ;
34
- const activeSequence = findSequenceByUnitId ( activeUnitId ) ;
35
- const targetSequence = findSequenceByUnitId ( id ) ;
36
- const payload = {
37
- id : activeUnitId ,
38
- current_tab : activeSequence . unitIds . indexOf ( activeUnitId ) + 1 ,
39
- tab_count : activeSequence . unitIds . length ,
40
- target_id : id ,
41
- target_tab : targetSequence . unitIds . indexOf ( id ) + 1 ,
42
- widget_placement : widgetPlacement ,
43
- } ;
44
-
45
- if ( activeSequence . id !== targetSequence . id ) {
46
- payload . target_tab_count = targetSequence . unitIds . length ;
47
- }
48
-
49
- sendTrackEvent ( eventName , payload ) ;
50
- sendTrackingLogEvent ( eventName , payload ) ;
51
- } ;
52
-
53
- const handleClick = ( ) => {
54
- logEvent ( 'edx.ui.lms.sequence.tab_selected' , 'left' ) ;
55
- dispatch ( checkBlockCompletion ( courseId , sequenceId , activeUnitId ) ) ;
56
- } ;
57
25
58
26
const iconType = isLocked ? UNIT_ICON_TYPES . lock : icon ;
59
27
60
28
return (
61
29
< li className = { classNames ( { 'bg-info-100' : isActive , 'border-top border-light' : ! isFirst } ) } >
62
- < Link
63
- to = { `/course/${ courseId } /${ sequenceId } /${ id } ` }
64
- className = "row w-100 m-0 d-flex align-items-center text-gray-700"
65
- onClick = { handleClick }
30
+ < UnitLinkWrapper
31
+ { ...{
32
+ sequenceId,
33
+ activeUnitId,
34
+ id,
35
+ courseId,
36
+ } }
66
37
>
67
38
< div className = "col-auto p-0" >
68
39
< UnitIcon type = { iconType } isCompleted = { complete } />
@@ -75,7 +46,7 @@ const SidebarUnit = ({
75
46
, { intl . formatMessage ( complete ? messages . completedUnit : messages . incompleteUnit ) }
76
47
</ span >
77
48
</ div >
78
- </ Link >
49
+ </ UnitLinkWrapper >
79
50
</ li >
80
51
) ;
81
52
} ;
0 commit comments