@@ -5,30 +5,39 @@ import { Button, Modal, Notice, Spinner } from '@wordpress/components';
5
5
import { useCallback , useState , RawHTML } from '@wordpress/element' ;
6
6
import { search } from '@wordpress/icons' ;
7
7
import { __ , _n , sprintf } from '@wordpress/i18n' ;
8
+ import { escapeHTML } from '@wordpress/escape-html' ;
8
9
import apiFetch from '@wordpress/api-fetch' ;
9
10
10
- /**
11
- * External dependencies
12
- */
13
- import { escape } from 'lodash' ;
14
-
15
11
/**
16
12
* Internal dependencies
17
13
*/
18
14
import CourseList from './course-list' ;
19
15
import InputControl from '../../../blocks/editor-components/input-control' ;
20
16
import useAbortController from '../hooks/use-abort-controller' ;
21
17
22
- const getAction = ( action , studentCount ) => {
18
+ const getAction = ( action , studentCount , studentDisplayName ) => {
19
+ const safeStudentDisplayName = escapeHTML ( studentDisplayName ) ;
20
+
23
21
const possibleActions = {
24
22
add : {
25
- // Translators: placeholder is the number of selected students for plural, student's name for singular.
26
- description : _n (
27
- 'Select the course(s) you would like to add <strong>%1$s</strong> to:' ,
28
- 'Select the course(s) you would like to add <strong>%1$d students</strong> to:' ,
29
- studentCount ,
30
- 'sensei-lms'
31
- ) ,
23
+ description :
24
+ studentCount > 1
25
+ ? sprintf (
26
+ // Translators: placeholder is the number of selected students.
27
+ __ (
28
+ 'Select the course(s) you would like to add <strong>%d students</strong> to:' ,
29
+ 'sensei-lms'
30
+ ) ,
31
+ studentCount
32
+ )
33
+ : sprintf (
34
+ // Translators: placeholder is the student's name.
35
+ __ (
36
+ 'Select the course(s) you would like to add <strong>%s</strong> to:' ,
37
+ 'sensei-lms'
38
+ ) ,
39
+ safeStudentDisplayName
40
+ ) ,
32
41
buttonLabel : __ ( 'Add to Course' , 'sensei-lms' ) ,
33
42
errorMessage : ( students ) =>
34
43
_n (
@@ -47,13 +56,24 @@ const getAction = ( action, studentCount ) => {
47
56
isDestructive : false ,
48
57
} ,
49
58
remove : {
50
- // Translators: placeholder is the number of selected students for plural, student's name for singular.
51
- description : _n (
52
- 'Select the course(s) you would like to remove <strong>%1$s</strong> from:' ,
53
- 'Select the course(s) you would like to remove <strong>%1$d students</strong> from:' ,
54
- studentCount ,
55
- 'sensei-lms'
56
- ) ,
59
+ description :
60
+ studentCount > 1
61
+ ? sprintf (
62
+ // Translators: placeholder is the number of selected students.
63
+ __ (
64
+ 'Select the course(s) you would like to remove <strong>%d students</strong> from:' ,
65
+ 'sensei-lms'
66
+ ) ,
67
+ studentCount
68
+ )
69
+ : sprintf (
70
+ // Translators: placeholder is the student's name.
71
+ __ (
72
+ 'Select the course(s) you would like to remove <strong>%s</strong> from:' ,
73
+ 'sensei-lms'
74
+ ) ,
75
+ safeStudentDisplayName
76
+ ) ,
57
77
buttonLabel : __ ( 'Remove from Course' , 'sensei-lms' ) ,
58
78
errorMessage : ( students ) =>
59
79
_n (
@@ -73,12 +93,24 @@ const getAction = ( action, studentCount ) => {
73
93
} ,
74
94
'reset-progress' : {
75
95
// Translators: placeholder is the number of selected students for plural, student's name for singular.
76
- description : _n (
77
- 'Select the course(s) you would like to reset or remove progress from for <strong>%1$s</strong>:' ,
78
- 'Select the course(s) you would like to reset or remove progress from for <strong>%1$d students</strong>:' ,
79
- studentCount ,
80
- 'sensei-lms'
81
- ) ,
96
+ description :
97
+ studentCount > 1
98
+ ? sprintf (
99
+ // Translators: placeholder is the number of selected students.
100
+ __ (
101
+ 'Select the course(s) you would like to reset or remove progress from for <strong>%d students</strong>:' ,
102
+ 'sensei-lms'
103
+ ) ,
104
+ studentCount
105
+ )
106
+ : sprintf (
107
+ // Translators: placeholder is the student's name.
108
+ __ (
109
+ 'Select the course(s) you would like to reset or remove progress from for <strong>%s</strong>:' ,
110
+ 'sensei-lms'
111
+ ) ,
112
+ safeStudentDisplayName
113
+ ) ,
82
114
buttonLabel : __ ( 'Reset or Remove Progress' , 'sensei-lms' ) ,
83
115
errorMessage : ( students ) =>
84
116
_n (
@@ -122,15 +154,12 @@ export const StudentModal = ( {
122
154
errorMessage,
123
155
isDestructive,
124
156
sendAction,
125
- } = getAction ( action , students . length ) ;
157
+ } = getAction ( action , students . length , studentDisplayName ) ;
126
158
const [ selectedCourses , setCourses ] = useState ( [ ] ) ;
127
159
const [ searchQuery , setSearchQuery ] = useState ( '' ) ;
128
160
const [ isSending , setIsSending ] = useState ( false ) ;
129
161
const [ error , setError ] = useState ( false ) ;
130
162
const { getSignal } = useAbortController ( ) ;
131
- const replacementString =
132
- students . length === 1 ? escape ( studentDisplayName ) : students . length ;
133
- const replacedDescription = sprintf ( description , replacementString ) ;
134
163
135
164
const send = useCallback ( async ( ) => {
136
165
setIsSending ( true ) ;
@@ -158,7 +187,7 @@ export const StudentModal = ( {
158
187
title = { __ ( 'Choose Course' , 'sensei-lms' ) }
159
188
onRequestClose = { ( ) => onClose ( ) }
160
189
>
161
- < RawHTML > { replacedDescription } </ RawHTML >
190
+ < RawHTML > { description } </ RawHTML >
162
191
163
192
< InputControl
164
193
iconRight = { search }
0 commit comments