Skip to content

Commit 00ed0d7

Browse files
authored
Merge pull request #2314 from daiyam/tags
tag enhancements
2 parents cfc84f3 + cae6fd4 commit 00ed0d7

File tree

10 files changed

+89
-23
lines changed

10 files changed

+89
-23
lines changed

browser/components/NoteItem.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ const TagElement = ({ tagName }) => (
2424
/**
2525
* @description Tag element list component.
2626
* @param {Array|null} tags
27+
* @param {boolean} showTagsAlphabetically
2728
* @return {React.Component}
2829
*/
29-
const TagElementList = tags => {
30+
const TagElementList = (tags, showTagsAlphabetically) => {
3031
if (!isArray(tags)) {
3132
return []
3233
}
3334

34-
const tagElements = tags.map(tag => TagElement({ tagName: tag }))
35-
36-
return tagElements
35+
if (showTagsAlphabetically) {
36+
return _.sortBy(tags).map(tag => TagElement({ tagName: tag }))
37+
} else {
38+
return tags.map(tag => TagElement({ tagName: tag }))
39+
}
3740
}
3841

3942
/**
@@ -55,7 +58,8 @@ const NoteItem = ({
5558
pathname,
5659
storageName,
5760
folderName,
58-
viewType
61+
viewType,
62+
showTagsAlphabetically
5963
}) => (
6064
<div
6165
styleName={isActive ? 'item--active' : 'item'}
@@ -93,7 +97,7 @@ const NoteItem = ({
9397
<div styleName='item-bottom'>
9498
<div styleName='item-bottom-tagList'>
9599
{note.tags.length > 0
96-
? TagElementList(note.tags)
100+
? TagElementList(note.tags, showTagsAlphabetically)
97101
: <span
98102
style={{ fontStyle: 'italic', opacity: 0.5 }}
99103
styleName='item-bottom-tagList-empty'

browser/components/TagListItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const TagListItem = ({name, handleClickTagListItem, handleClickNarrowToTag, hand
2525
<button styleName={isActive ? 'tagList-item-active' : 'tagList-item'} onClick={() => handleClickTagListItem(name)}>
2626
<span styleName='tagList-item-name'>
2727
{`# ${name}`}
28-
<span styleName='tagList-item-count'>{count}</span>
28+
<span styleName='tagList-item-count'>{count !== 0 ? count : ''}</span>
2929
</span>
3030
</button>
3131
</div>

browser/main/Detail/MarkdownNoteDetail.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class MarkdownNoteDetail extends React.Component {
348348
}
349349

350350
render () {
351-
const { data, location } = this.props
351+
const { data, location, config } = this.props
352352
const { note, editorType } = this.state
353353
const storageKey = note.storage
354354
const folderKey = note.folder
@@ -399,6 +399,8 @@ class MarkdownNoteDetail extends React.Component {
399399
<TagSelect
400400
ref='tags'
401401
value={this.state.note.tags}
402+
saveTagsAlphabetically={config.ui.saveTagsAlphabetically}
403+
showTagsAlphabetically={config.ui.showTagsAlphabetically}
402404
data={data}
403405
onChange={this.handleUpdateTag.bind(this)}
404406
/>

browser/main/Detail/SnippetNoteDetail.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ class SnippetNoteDetail extends React.Component {
756756
<TagSelect
757757
ref='tags'
758758
value={this.state.note.tags}
759+
saveTagsAlphabetically={config.ui.saveTagsAlphabetically}
760+
showTagsAlphabetically={config.ui.showTagsAlphabetically}
759761
data={data}
760762
onChange={(e) => this.handleChange(e)}
761763
/>

browser/main/Detail/TagSelect.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ class TagSelect extends React.Component {
179179
}
180180

181181
render () {
182-
const { value, className } = this.props
182+
const { value, className, showTagsAlphabetically } = this.props
183183

184184
const tagList = _.isArray(value)
185-
? value.map((tag) => {
185+
? (showTagsAlphabetically ? _.sortBy(value) : value).map((tag) => {
186186
return (
187187
<span styleName='tag'
188188
key={tag}

browser/main/NoteList/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ class NoteList extends React.Component {
993993
folderName={this.getNoteFolder(note).name}
994994
storageName={this.getNoteStorage(note).name}
995995
viewType={viewType}
996+
showTagsAlphabetically={config.ui.showTagsAlphabetically}
996997
/>
997998
)
998999
}

browser/main/SideNav/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import i18n from 'browser/lib/i18n'
2020
import context from 'browser/lib/context'
2121
import { remote } from 'electron'
2222

23+
function matchActiveTags (tags, activeTags) {
24+
return _.every(activeTags, v => tags.indexOf(v) >= 0)
25+
}
26+
2327
class SideNav extends React.Component {
2428
// TODO: should not use electron stuff v0.7
2529

@@ -202,12 +206,20 @@ class SideNav extends React.Component {
202206

203207
tagListComponent () {
204208
const { data, location, config } = this.props
205-
const relatedTags = this.getRelatedTags(this.getActiveTags(location.pathname), data.noteMap)
209+
const activeTags = this.getActiveTags(location.pathname)
210+
const relatedTags = this.getRelatedTags(activeTags, data.noteMap)
206211
let tagList = _.sortBy(data.tagNoteMap.map(
207212
(tag, name) => ({ name, size: tag.size, related: relatedTags.has(name) })
208-
), ['name']).filter(
213+
).filter(
209214
tag => tag.size > 0
210-
)
215+
), ['name'])
216+
if (config.ui.enableLiveNoteCounts && activeTags.length !== 0) {
217+
const notesTags = data.noteMap.map(note => note.tags)
218+
tagList = tagList.map(tag => {
219+
tag.size = notesTags.filter(tags => tags.includes(tag.name) && matchActiveTags(tags, activeTags)).length
220+
return tag
221+
})
222+
}
211223
if (config.sortTagsBy === 'COUNTER') {
212224
tagList = _.sortBy(tagList, item => (0 - item.size))
213225
}

browser/main/modals/PreferencesModal/UiTab.js

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class UiTab extends React.Component {
7171
showCopyNotification: this.refs.showCopyNotification.checked,
7272
confirmDeletion: this.refs.confirmDeletion.checked,
7373
showOnlyRelatedTags: this.refs.showOnlyRelatedTags.checked,
74+
showTagsAlphabetically: this.refs.showTagsAlphabetically.checked,
75+
saveTagsAlphabetically: this.refs.saveTagsAlphabetically.checked,
76+
enableLiveNoteCounts: this.refs.enableLiveNoteCounts.checked,
7477
disableDirectWrite: this.refs.uiD2w != null
7578
? this.refs.uiD2w.checked
7679
: false
@@ -249,16 +252,6 @@ class UiTab extends React.Component {
249252
{i18n.__('Show a confirmation dialog when deleting notes')}
250253
</label>
251254
</div>
252-
<div styleName='group-checkBoxSection'>
253-
<label>
254-
<input onChange={(e) => this.handleUIChange(e)}
255-
checked={this.state.config.ui.showOnlyRelatedTags}
256-
ref='showOnlyRelatedTags'
257-
type='checkbox'
258-
/>&nbsp;
259-
{i18n.__('Show only related tags')}
260-
</label>
261-
</div>
262255
{
263256
global.process.platform === 'win32'
264257
? <div styleName='group-checkBoxSection'>
@@ -274,6 +267,52 @@ class UiTab extends React.Component {
274267
</div>
275268
: null
276269
}
270+
<div styleName='group-header2'>Tags</div>
271+
272+
<div styleName='group-checkBoxSection'>
273+
<label>
274+
<input onChange={(e) => this.handleUIChange(e)}
275+
checked={this.state.config.ui.saveTagsAlphabetically}
276+
ref='saveTagsAlphabetically'
277+
type='checkbox'
278+
/>&nbsp;
279+
{i18n.__('Save tags of a note in alphabetical order')}
280+
</label>
281+
</div>
282+
283+
<div styleName='group-checkBoxSection'>
284+
<label>
285+
<input onChange={(e) => this.handleUIChange(e)}
286+
checked={this.state.config.ui.showTagsAlphabetically}
287+
ref='showTagsAlphabetically'
288+
type='checkbox'
289+
/>&nbsp;
290+
{i18n.__('Show tags of a note in alphabetical order')}
291+
</label>
292+
</div>
293+
294+
<div styleName='group-checkBoxSection'>
295+
<label>
296+
<input onChange={(e) => this.handleUIChange(e)}
297+
checked={this.state.config.ui.showOnlyRelatedTags}
298+
ref='showOnlyRelatedTags'
299+
type='checkbox'
300+
/>&nbsp;
301+
{i18n.__('Show only related tags')}
302+
</label>
303+
</div>
304+
305+
<div styleName='group-checkBoxSection'>
306+
<label>
307+
<input onChange={(e) => this.handleUIChange(e)}
308+
checked={this.state.config.ui.enableLiveNoteCounts}
309+
ref='enableLiveNoteCounts'
310+
type='checkbox'
311+
/>&nbsp;
312+
{i18n.__('Enable live count of notes')}
313+
</label>
314+
</div>
315+
277316
<div styleName='group-header2'>Editor</div>
278317

279318
<div styleName='group-section'>

locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@
178178
"Allow dangerous html tags": "Allow dangerous html tags",
179179
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.",
180180
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠",
181+
"Save tags of a note in alphabetical order": "Save tags of a note in alphabetical order",
182+
"Show tags of a note in alphabetical order": "Show tags of a note in alphabetical order",
183+
"Enable live count of notes": "Enable live count of notes",
181184
"Enable smart table editor": "Enable smart table editor",
182185
"Snippet Default Language": "Snippet Default Language"
183186
}

locales/fr.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@
154154
"Allow dangerous html tags": "Accepter les tags html dangereux",
155155
"Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convertir des flèches textuelles en jolis signes. ⚠ Cela va interferérer avec les éventuels commentaires HTML dans votre Markdown.",
156156
"⚠ You have pasted a link referring an attachment that could not be found in the storage location of this note. Pasting links referring attachments is only supported if the source and destination location is the same storage. Please Drag&Drop the attachment instead! ⚠": "⚠ Vous avez collé un lien qui référence une pièce-jointe qui n'a pas pu être récupéré dans le dossier de stockage de la note. Coller des liens qui font référence à des pièces-jointes ne fonctionne que si la source et la destination et la même. Veuillez plutôt utiliser du Drag & Drop ! ⚠",
157+
"Save tags of a note in alphabetical order": "Sauvegarder les tags d'une note en ordre alphabétique",
158+
"Show tags of a note in alphabetical order": "Afficher les tags d'une note par ordre alphabétique",
159+
"Enable live count of notes": "Activer le comptage live des notes",
157160
"Enable smart table editor": "Activer l'intelligent éditeur de tableaux",
158161
"Snippet Default Language": "Langage par défaut d'un snippet",
159162
"Delete Note": "Supprimer la note"

0 commit comments

Comments
 (0)