Skip to content

Commit 4e7b8ea

Browse files
authored
Merge pull request #648 from ibi-group/mtc-service-alerts-character-count-up
MTC Service Alerts: Change Character limit validation
2 parents 4c00f7e + 9602d0a commit 4e7b8ea

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

lib/alerts/components/AlertEditor.js

+31-14
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,14 @@ export default class AlertEditor extends Component<Props> {
7070

7171
validateAndSave = () => {
7272
const {alert, saveAlert} = this.props
73-
const {affectedEntities, description, end, start, title} = alert
73+
const {affectedEntities, end, start, title} = alert
7474
const momentEnd = moment(end)
7575
const momentStart = moment(start)
7676

7777
// alert title must not be blank nor just whitespace
7878
if (!title.trim()) {
7979
return window.alert('You must specify an alert title')
8080
}
81-
// alert title/description must meet character limits (for display purposes)
82-
if (title.length > ALERT_TITLE_CHAR_LIMIT) {
83-
return window.alert(`Alert title must be ${ALERT_TITLE_CHAR_LIMIT} characters or less`)
84-
}
85-
if (description && description.length > ALERT_DESCRIPTION_CHAR_LIMIT) {
86-
return window.alert(`Alert description must be ${ALERT_DESCRIPTION_CHAR_LIMIT} characters or less`)
87-
}
8881
if (!end || !start || !momentEnd.isValid() || !momentStart.isValid()) {
8982
return window.alert('Alert must have a valid start and end date')
9083
}
@@ -146,7 +139,14 @@ export default class AlertEditor extends Component<Props> {
146139
const descriptionCharactersRemaining = alert.description
147140
? ALERT_DESCRIPTION_CHAR_LIMIT - alert.description.length
148141
: ALERT_DESCRIPTION_CHAR_LIMIT
149-
const canPublish = alert.affectedEntities.length &&
142+
const titleCharacterCount = alert.title
143+
? alert.title.length
144+
: 0
145+
const descriptionCharactersCount = alert.description
146+
? alert.description.length
147+
: 0
148+
const canPublish =
149+
alert.affectedEntities.length &&
150150
checkEntitiesForFeeds(alert.affectedEntities, publishableFeeds)
151151
const canEdit = checkEntitiesForFeeds(alert.affectedEntities, editableFeeds)
152152
const editingIsDisabled = alert.published && !canPublish ? true : !canEdit
@@ -221,10 +221,17 @@ export default class AlertEditor extends Component<Props> {
221221
: 'text-danger'
222222
}
223223
style={{fontWeight: 400}}>
224-
{titleCharactersRemaining}
224+
{titleCharacterCount}
225225
</span>
226226
<h5 style={{margin: '0px'}}>
227227
<small>
228+
{titleCharacterCount > ALERT_TITLE_CHAR_LIMIT &&
229+
(
230+
<span className='text-danger'>
231+
WARNING: Alert title longer than {ALERT_TITLE_CHAR_LIMIT} characters may get truncated in some dissemination channels. <br />
232+
</span>
233+
)
234+
}
228235
Note: alert title serves as text for eTID alerts. Use
229236
descriptive language so it can serve as a standalone
230237
alert.
@@ -290,7 +297,7 @@ export default class AlertEditor extends Component<Props> {
290297
</Col>
291298
</Row>
292299
<Row>
293-
<Col xs={12} sm={6}>
300+
<Col xs={12}>
294301
<FormGroup controlId='formControlsDescription'>
295302
<ControlLabel>
296303
Description
@@ -302,18 +309,28 @@ export default class AlertEditor extends Component<Props> {
302309
: 'text-danger'
303310
}
304311
style={{fontWeight: 400}}>
305-
{descriptionCharactersRemaining}
312+
{descriptionCharactersCount}
306313
</span>
314+
{descriptionCharactersCount > ALERT_DESCRIPTION_CHAR_LIMIT &&
315+
(
316+
<h5 style={{margin: '0px'}}>
317+
<small className='text-danger'>
318+
WARNING: Alert description longer than {ALERT_DESCRIPTION_CHAR_LIMIT} characters may get truncated in some dissemination channels.
319+
</small>
320+
</h5>
321+
)
322+
}
307323
</ControlLabel>
308324
<FormControl
309325
componentClass='textarea'
310326
placeholder='Detailed description of alert...'
311327
defaultValue={alert.description}
312328
name='description'
313-
onChange={this._onChange} />
329+
onChange={this._onChange}
330+
style={{ minHeight: '89px' }} />
314331
</FormGroup>
315332
</Col>
316-
<Col xs={12} sm={6}>
333+
<Col xs={12}>
317334
<FormGroup controlId='formControlsURL'>
318335
<ControlLabel>URL</ControlLabel>
319336
<FormControl

0 commit comments

Comments
 (0)