-
Notifications
You must be signed in to change notification settings - Fork 975
Validate bookmark name before creation Fixes #3188 #3190
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,15 @@ class AddEditBookmark extends ImmutableComponent { | |
this.onSave = this.onSave.bind(this) | ||
this.onRemoveBookmark = this.onRemoveBookmark.bind(this) | ||
} | ||
|
||
get isBlankTab () { | ||
return ['about:blank', 'about:newtab'].includes(this.props.currentDetail.get('location')) | ||
} | ||
|
||
get bookmarkNameValid () { | ||
return (this.props.currentDetail.get('title') || this.props.currentDetail.get('customTitle')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I'll ask for a small follow up if you don't mind, I think no title is valid for bookmarks but not bookmark folders. In that case we display as just the URL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually in case of Bookmark There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh ok great then |
||
} | ||
|
||
get isFolder () { | ||
return siteUtil.isFolder(this.props.currentDetail) | ||
} | ||
|
@@ -68,6 +74,7 @@ class AddEditBookmark extends ImmutableComponent { | |
} else { | ||
currentDetail = currentDetail.set('customTitle', e.target.value) | ||
} | ||
|
||
windowActions.setBookmarkDetail(currentDetail, this.props.originalDetail, this.props.destinationDetail) | ||
} | ||
onLocationChange (e) { | ||
|
@@ -79,6 +86,11 @@ class AddEditBookmark extends ImmutableComponent { | |
windowActions.setBookmarkDetail(currentDetail, this.props.originalDetail, this.props.destinationDetail) | ||
} | ||
onSave () { | ||
// First check if the title of the currentDetail is set | ||
if (!this.bookmarkNameValid) { | ||
return false | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you'd check |
||
|
||
const tag = this.isFolder ? siteTags.BOOKMARK_FOLDER : siteTags.BOOKMARK | ||
appActions.addSite(this.props.currentDetail, tag, this.props.originalDetail, this.props.destinationDetail) | ||
this.onClose() | ||
|
@@ -91,7 +103,7 @@ class AddEditBookmark extends ImmutableComponent { | |
if (this.props.currentDetail.get('customTitle') !== undefined) { | ||
return this.props.currentDetail.get('customTitle') | ||
} | ||
return this.props.currentDetail.get('title') | ||
return this.props.currentDetail.get('title') || '' | ||
} | ||
render () { | ||
return <Dialog onHide={this.onClose} isClickDismiss> | ||
|
@@ -125,7 +137,7 @@ class AddEditBookmark extends ImmutableComponent { | |
? <a data-l10n-id='delete' className='removeBookmarkLink link' onClick={this.onRemoveBookmark} /> | ||
: null | ||
} | ||
<Button l10nId='save' className='primaryButton' onClick={this.onSave} /> | ||
<Button l10nId='save' className={this.bookmarkNameValid ? 'primaryButton' : 'primaryButton disabled'} onClick={this.onSave} /> | ||
</div> | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ | |
.removeBookmarkLink { | ||
margin-right: auto; | ||
} | ||
|
||
.disabled { | ||
background-color: #ccc !important; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And remove this
shouldComponentUpdate
, no immutable component should need to ever override it.