8
8
TextFilter ,
9
9
MultiSelectDropdownFilter ,
10
10
} from '@openedx/paragon' ;
11
- import { injectIntl , intlShape } from '@edx/frontend-platform/i18n' ;
11
+ import { useIntl } from '@edx/frontend-platform/i18n' ;
12
12
13
13
import { gradingStatuses , submissionFields } from 'data/services/lms/constants' ;
14
14
import lmsMessages from 'data/services/lms/messages' ;
@@ -25,113 +25,108 @@ import messages from './messages';
25
25
/**
26
26
* <SubmissionsTable />
27
27
*/
28
- export class SubmissionsTable extends React . Component {
29
- get gradeStatusOptions ( ) {
30
- return Object . keys ( gradingStatuses ) . map ( statusKey => ( {
31
- name : this . translate ( lmsMessages [ gradingStatuses [ statusKey ] ] ) ,
32
- value : gradingStatuses [ statusKey ] ,
33
- } ) ) ;
34
- }
28
+ export const SubmissionsTable = ( {
29
+ isIndividual,
30
+ listData,
31
+ loadSelectionForReview,
32
+ } ) => {
33
+ const intl = useIntl ( ) ;
35
34
36
- get userLabel ( ) {
37
- return this . translate ( this . props . isIndividual ? messages . username : messages . teamName ) ;
38
- }
35
+ const translate = ( ...args ) => intl . formatMessage ( ...args ) ;
39
36
40
- get userAccessor ( ) {
41
- return this . props . isIndividual
42
- ? submissionFields . username
43
- : submissionFields . teamName ;
44
- }
37
+ const gradeStatusOptions = Object . keys ( gradingStatuses ) . map ( statusKey => ( {
38
+ name : translate ( lmsMessages [ gradingStatuses [ statusKey ] ] ) ,
39
+ value : gradingStatuses [ statusKey ] ,
40
+ } ) ) ;
45
41
46
- get dateSubmittedLabel ( ) {
47
- return this . translate ( this . props . isIndividual
48
- ? messages . learnerSubmissionDate
49
- : messages . teamSubmissionDate ) ;
50
- }
42
+ const userLabel = translate ( isIndividual ? messages . username : messages . teamName ) ;
43
+
44
+ const userAccessor = isIndividual
45
+ ? submissionFields . username
46
+ : submissionFields . teamName ;
51
47
52
- formatDate = ( { value } ) => {
48
+ const dateSubmittedLabel = translate ( isIndividual
49
+ ? messages . learnerSubmissionDate
50
+ : messages . teamSubmissionDate ) ;
51
+
52
+ const formatDate = ( { value } ) => {
53
53
const date = new Date ( moment ( value ) ) ;
54
54
return date . toLocaleString ( ) ;
55
55
} ;
56
56
57
- formatGrade = ( { value : score } ) => (
57
+ const formatGrade = ( { value : score } ) => (
58
58
score === null ? '-' : `${ score . pointsEarned } /${ score . pointsPossible } `
59
59
) ;
60
60
61
- formatStatus = ( { value } ) => ( < StatusBadge status = { value } /> ) ;
62
-
63
- translate = ( ...args ) => this . props . intl . formatMessage ( ...args ) ;
61
+ const formatStatus = ( { value } ) => ( < StatusBadge status = { value } /> ) ;
64
62
65
- handleViewAllResponsesClick = ( data ) => ( ) => {
63
+ const handleViewAllResponsesClick = ( data ) => ( ) => {
66
64
const getSubmissionUUID = ( row ) => row . original . submissionUUID ;
67
- this . props . loadSelectionForReview ( data . map ( getSubmissionUUID ) ) ;
65
+ loadSelectionForReview ( data . map ( getSubmissionUUID ) ) ;
68
66
} ;
69
67
70
- render ( ) {
71
- if ( ! this . props . listData . length ) {
72
- return null ;
73
- }
74
- return (
75
- < div className = "submissions-table" >
76
- < DataTable
77
- data-testid = "data-table"
78
- isFilterable
79
- FilterStatusComponent = { FilterStatusComponent }
80
- numBreakoutFilters = { 2 }
81
- defaultColumnValues = { { Filter : TextFilter } }
82
- isSelectable
83
- isSortable
84
- isPaginated
85
- itemCount = { this . props . listData . length }
86
- initialState = { { pageSize : 10 , pageIndex : 0 } }
87
- data = { this . props . listData }
88
- tableActions = { [
89
- < TableAction handleClick = { this . handleViewAllResponsesClick } /> ,
90
- ] }
91
- bulkActions = { [
92
- < SelectedBulkAction handleClick = { this . handleViewAllResponsesClick } /> ,
93
- ] }
94
- columns = { [
95
- {
96
- Header : this . userLabel ,
97
- accessor : this . userAccessor ,
98
- } ,
99
- {
100
- Header : this . dateSubmittedLabel ,
101
- accessor : submissionFields . dateSubmitted ,
102
- Cell : this . formatDate ,
103
- disableFilters : true ,
104
- } ,
105
- {
106
- Header : this . translate ( messages . grade ) ,
107
- accessor : submissionFields . score ,
108
- Cell : this . formatGrade ,
109
- disableFilters : true ,
110
- } ,
111
- {
112
- Header : this . translate ( messages . gradingStatus ) ,
113
- accessor : submissionFields . gradingStatus ,
114
- Cell : this . formatStatus ,
115
- Filter : MultiSelectDropdownFilter ,
116
- filter : 'includesValue' ,
117
- filterChoices : this . gradeStatusOptions ,
118
- } ,
119
- ] }
120
- >
121
- < DataTable . TableControlBar />
122
- < DataTable . Table />
123
- < DataTable . TableFooter />
124
- </ DataTable >
125
- </ div >
126
- ) ;
68
+ if ( ! listData . length ) {
69
+ return null ;
127
70
}
128
- }
71
+
72
+ return (
73
+ < div className = "submissions-table" >
74
+ < DataTable
75
+ data-testid = "data-table"
76
+ isFilterable
77
+ FilterStatusComponent = { FilterStatusComponent }
78
+ numBreakoutFilters = { 2 }
79
+ defaultColumnValues = { { Filter : TextFilter } }
80
+ isSelectable
81
+ isSortable
82
+ isPaginated
83
+ itemCount = { listData . length }
84
+ initialState = { { pageSize : 10 , pageIndex : 0 } }
85
+ data = { listData }
86
+ tableActions = { [
87
+ < TableAction handleClick = { handleViewAllResponsesClick } /> ,
88
+ ] }
89
+ bulkActions = { [
90
+ < SelectedBulkAction handleClick = { handleViewAllResponsesClick } /> ,
91
+ ] }
92
+ columns = { [
93
+ {
94
+ Header : userLabel ,
95
+ accessor : userAccessor ,
96
+ } ,
97
+ {
98
+ Header : dateSubmittedLabel ,
99
+ accessor : submissionFields . dateSubmitted ,
100
+ Cell : formatDate ,
101
+ disableFilters : true ,
102
+ } ,
103
+ {
104
+ Header : translate ( messages . grade ) ,
105
+ accessor : submissionFields . score ,
106
+ Cell : formatGrade ,
107
+ disableFilters : true ,
108
+ } ,
109
+ {
110
+ Header : translate ( messages . gradingStatus ) ,
111
+ accessor : submissionFields . gradingStatus ,
112
+ Cell : formatStatus ,
113
+ Filter : MultiSelectDropdownFilter ,
114
+ filter : 'includesValue' ,
115
+ filterChoices : gradeStatusOptions ,
116
+ } ,
117
+ ] }
118
+ >
119
+ < DataTable . TableControlBar />
120
+ < DataTable . Table />
121
+ < DataTable . TableFooter />
122
+ </ DataTable >
123
+ </ div >
124
+ ) ;
125
+ } ;
129
126
SubmissionsTable . defaultProps = {
130
127
listData : [ ] ,
131
128
} ;
132
129
SubmissionsTable . propTypes = {
133
- // injected
134
- intl : intlShape . isRequired ,
135
130
// redux
136
131
isIndividual : PropTypes . bool . isRequired ,
137
132
listData : PropTypes . arrayOf ( PropTypes . shape ( {
@@ -155,4 +150,4 @@ export const mapDispatchToProps = {
155
150
loadSelectionForReview : thunkActions . grading . loadSelectionForReview ,
156
151
} ;
157
152
158
- export default injectIntl ( connect ( mapStateToProps , mapDispatchToProps ) ( SubmissionsTable ) ) ;
153
+ export default connect ( mapStateToProps , mapDispatchToProps ) ( SubmissionsTable ) ;
0 commit comments