TagSpaces is an offline, open source, document manager with tagging support
refactoring smart tags
Ilian Sapundshievb79ebc52e2a1
diff --git a/app/components/TagContainer.js b/app/components/TagContainer.jsindex 790d71d5c..609f2d500 100644--- a/app/components/TagContainer.js+++ b/app/components/TagContainer.js@@ -92,6 +92,11 @@ const TagContainer = React.memo((props: Props) => {return false;});+ let description = tag.title+ if (tag.description) {+ description = tag.title + ' - ' + tag.description+ }+return (<divrole="presentation"@@ -118,7 +123,7 @@ const TagContainer = React.memo((props: Props) => {}}><Button- title={titleOrig}+ title={description}size="small"style={{opacity: isDragging ? 0.5 : 1,diff --git a/app/components/TagLibrary.js b/app/components/TagLibrary.jsindex fc562dbf3..b319de4cd 100644--- a/app/components/TagLibrary.js+++ b/app/components/TagLibrary.js@@ -56,6 +56,7 @@ import TaggingActions from '../reducers/tagging-actions';import i18n from '../services/i18n';import { getTagColor, getTagTextColor } from '../reducers/settings';import { getSelectedEntries, isReadOnlyMode } from '../reducers/app';+import SmartTags from '../reducers/smart-tags';const isTagLibraryReadOnly = (window.ExtTagLibrary && window.ExtTagLibrary.length > 0);@@ -209,74 +210,83 @@ class TagLibrary extends React.Component<Props, State> {this.setState({ importExportMenuOpened: false });};- renderTagGroup = tagGroup => (- <div key={tagGroup.uuid}>- <ListItem- data-tid={'tagLibraryTagGroupTitle_' + tagGroup.title}- button- style={{ maxWidth: 250 }}- className={this.props.classes.listItem}- onClick={event => this.handleTagGroupTitleClick(event, tagGroup)}- onContextMenu={event => this.handleTagGroupMenu(event, tagGroup)}- title={'Number of tags in this tag group: ' + tagGroup.children.length}- >- <ListItemIcon style={{ marginRight: 0 }}>- {tagGroup.expanded ? <ArrowDownIcon /> : <ArrowRightIcon />}- </ListItemIcon>- <Typography- variant="inherit"- className={this.props.classes.header}- style={{ paddingLeft: 0 }}- data-tid="locationTitleElement"- noWrap+ renderTagGroup = (tagGroup) => {+ const isReadOnly = tagGroup.readOnly || isTagLibraryReadOnly;+ return (+ <div key={tagGroup.uuid}>+ <ListItem+ data-tid={'tagLibraryTagGroupTitle_' + tagGroup.title}+ button+ style={{ maxWidth: 250 }}+ className={this.props.classes.listItem}+ onClick={event => this.handleTagGroupTitleClick(event, tagGroup)}+ onContextMenu={event => this.handleTagGroupMenu(event, tagGroup)}+ title={'Number of tags in this tag group: ' + tagGroup.children.length}>- {tagGroup.title + ' '}- {!tagGroup.expanded && (- <span className={this.props.classes.badge}>{tagGroup.children.length}</span>+ <ListItemIcon style={{ marginRight: 0 }}>+ {tagGroup.expanded ? <ArrowDownIcon /> : <ArrowRightIcon />}+ </ListItemIcon>+ <Typography+ variant="inherit"+ className={this.props.classes.header}+ style={{ paddingLeft: 0 }}+ data-tid="locationTitleElement"+ noWrap+ >+ {tagGroup.title + ' '}+ {!tagGroup.expanded && (+ <span className={this.props.classes.badge}>{tagGroup.children.length}</span>+ )}+ </Typography>+ { !isReadOnly && (+ <ListItemSecondaryAction>+ <IconButton+ aria-label={i18n.t('core:options')}+ aria-haspopup="true"+ data-tid={'tagLibraryMoreButton_' + tagGroup.title.replace(/ /g, '_')}+ style={{ marginRight: -4 }}+ onClick={event => this.handleTagGroupMenu(event, tagGroup)}+ onContextMenu={event => this.handleTagGroupMenu(event, tagGroup)}+ >+ <MoreVertIcon />+ </IconButton>+ </ListItemSecondaryAction>)}- </Typography>- { !isTagLibraryReadOnly && (- <ListItemSecondaryAction>- <IconButton- aria-label={i18n.t('core:options')}- aria-haspopup="true"- data-tid={'tagLibraryMoreButton_' + tagGroup.title.replace(/ /g, '_')}- style={{ marginRight: -4 }}- onClick={event => this.handleTagGroupMenu(event, tagGroup)}- onContextMenu={event => this.handleTagGroupMenu(event, tagGroup)}- >- <MoreVertIcon />- </IconButton>- </ListItemSecondaryAction>- )}- </ListItem>- <Collapse in={tagGroup.expanded} unmountOnExit>- <TagGroupContainer taggroup={tagGroup} data-tid={'tagGroupContainer_' + tagGroup.title}>- {tagGroup.children && tagGroup.children.map((tag: Tag) => ((this.props.isReadOnlyMode || isTagLibraryReadOnly) ? (- <TagContainer- key={tag.id}- tag={tag}- tagGroup={tagGroup}- handleTagMenu={this.handleTagMenu}- addTags={this.props.addTags}- moveTag={this.props.moveTag}- selectedEntries={this.props.selectedEntries}- />- ) : (- <TagContainerDnd- key={tag.id}- tag={tag}- tagGroup={tagGroup}- handleTagMenu={this.handleTagMenu}- addTags={this.props.addTags}- moveTag={this.props.moveTag}- selectedEntries={this.props.selectedEntries}- />- )))}- </TagGroupContainer>- </Collapse>- </div>- );+ </ListItem>+ <Collapse in={tagGroup.expanded} unmountOnExit>+ <TagGroupContainer taggroup={tagGroup} data-tid={'tagGroupContainer_' + tagGroup.title}>+ {tagGroup.children && tagGroup.children.map((tag: Tag) => {+ if (this.props.isReadOnlyMode) {+ return (+ <TagContainer+ key={tag.id}+ tag={tag}+ tagGroup={tagGroup}+ handleTagMenu={this.handleTagMenu}+ addTags={this.props.addTags}+ moveTag={this.props.moveTag}+ selectedEntries={this.props.selectedEntries}+ />+ );+ }+ return (+ <TagContainerDnd+ key={tag.id}+ tag={tag}+ tagGroup={tagGroup}+ handleTagMenu={this.handleTagMenu}+ addTags={this.props.addTags}+ moveTag={this.props.moveTag}+ selectedEntries={this.props.selectedEntries}+ />+ );+ }+ )}+ </TagGroupContainer>+ </Collapse>+ </div>+ )+};render() {const { tagGroups, classes, allTags } = this.props;@@ -375,6 +385,7 @@ class TagLibrary extends React.Component<Props, State> {deleteTag={this.props.deleteTag}/><div className={classes.taggroupsArea} data-tid="tagLibraryTagGroupList">+ <List style={{ paddingTop: 0 }}>{SmartTags(i18n).map(this.renderTagGroup)}</List><List style={{ paddingTop: 0 }}>{tagGroups.map(this.renderTagGroup)}</List></div></div>diff --git a/app/reducers/index.js b/app/reducers/index.jsindex 8e7e9d1c7..3f8df08cc 100644--- a/app/reducers/index.js+++ b/app/reducers/index.js@@ -37,51 +37,50 @@ const blacklist = [externalTagLibrary ? 'taglibrary' : false];-const migrations = {- // 1: (state) => state,- 2: (state) => { // migration to add geo and date tags in state- const tagGroups = [...state.taglibrary];- for (const tagGroup of tagGroups) {- if (tagGroup.title === 'Smart Tags') {- let haveGeoTagging = false;- let haveDateTagging = false;- for (const tag of tagGroup.children) {- if (tag.functionality === 'geoTagging') haveGeoTagging = true;- else if (tag.functionality === 'dateTagging') haveDateTagging = true;- }- if (!haveGeoTagging) {- tagGroup.children.push({- id: 'e1f0760e-471c-4418-a404-6cb09e6f6c24',- type: 'plain',- title: 'geo-tag',- functionality: 'geoTagging',- desciption: 'Add geo coordinates as a tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- });- }- if (!haveDateTagging) {- tagGroup.children.push({- id: 'e1f0760e-471c-4418-a404-6cb09e6f6c34',- type: 'plain',- title: 'date-tag',- functionality: 'dateTagging',- desciption: 'Add custom date as a tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- });- }- break;- }- }- return {- ...state,- tagGroups- };- }-};+// const migrations = {+// 2: (state) => { // migration to add geo and date tags in state+// const tagGroups = [...state.taglibrary];+// for (const tagGroup of tagGroups) {+// if (tagGroup.title === 'Smart Tags') {+// let haveGeoTagging = false;+// let haveDateTagging = false;+// for (const tag of tagGroup.children) {+// if (tag.functionality === 'geoTagging') haveGeoTagging = true;+// else if (tag.functionality === 'dateTagging') haveDateTagging = true;+// }+// if (!haveGeoTagging) {+// tagGroup.children.push({+// id: 'e1f0760e-471c-4418-a404-6cb09e6f6c24',+// type: 'plain',+// title: 'geo-tag',+// functionality: 'geoTagging',+// desciption: 'Add geo coordinates as a tag',+// color: '#4986e7',+// textcolor: '#ffffff',+// icon: '',+// });+// }+// if (!haveDateTagging) {+// tagGroup.children.push({+// id: 'e1f0760e-471c-4418-a404-6cb09e6f6c34',+// type: 'plain',+// title: 'date-tag',+// functionality: 'dateTagging',+// desciption: 'Add custom date as a tag',+// color: '#4986e7',+// textcolor: '#ffffff',+// icon: '',+// });+// }+// break;+// }+// }+// return {+// ...state,+// tagGroups+// };+// }+// };const rootPersistConfig = {key: 'root',@@ -90,7 +89,7 @@ const rootPersistConfig = {version: 2,blacklist,debug: false,- migrate: createMigrate(migrations, { debug: true }),+ // migrate: createMigrate(migrations, { debug: true }),// https://github.com/rt2zz/redux-persist/blob/b6a60bd653d59c4fe462e2e0ea827fd76eb190e1/README.md#state-reconciler// stateReconciler: autoMergeLevel2,};diff --git a/app/reducers/smart-tags.js b/app/reducers/smart-tags.jsnew file mode 100644index 000000000..c5593678b--- /dev/null+++ b/app/reducers/smart-tags.js@@ -0,0 +1,93 @@+export default (i18n) => ([+ {+ title: i18n.t('core:smartTags'),+ uuid: 'd4b5c16a-1c3a-4561-96c7-686696cb2004',+ expanded: true,+ desciption: '',+ color: '#4986e7',+ textcolor: '#ffffff',+ readOnly: true,+ children: [+ {+ id: '05fbebfd-576c-4402-bd1b-e9900acd6661',+ type: 'plain',+ title: 'ποΈ ' + i18n.t('core:smartTagNow'),+ functionality: 'now',+ description: i18n.t('core:smartTagNowDescription'),+ color: '#4986e7',+ textcolor: '#ffffff',+ icon: '',+ },+ {+ id: '7505080c-b974-425f-8434-25cd08fb1013',+ type: 'plain',+ title: 'ποΈ ' + i18n.t('core:smartTagToday'),+ functionality: 'today',+ description: i18n.t('core:smartTagTodayDescription'),+ color: '#4986e7',+ textcolor: '#ffffff',+ icon: '',+ },+ {+ id: '841e55a0-3596-4417-9186-d035cbcb676c',+ type: 'plain',+ title: 'ποΈ ' + i18n.t('core:smartTagTomorrow'),+ functionality: 'tomorrow',+ description: i18n.t('core:smartTagTomorrowDescription'),+ color: '#4986e7',+ textcolor: '#ffffff',+ icon: '',+ },+ {+ id: '3bf2bde9-cfa1-41cc-9154-debbf853e74c',+ type: 'plain',+ title: 'ποΈ ' + i18n.t('core:smartTagYesterday'),+ functionality: 'yesterday',+ description: i18n.t('core:smartTagYesterdayDescription'),+ color: '#4986e7',+ textcolor: '#ffffff',+ icon: '',+ },+ {+ id: 'e4618609-0940-4d78-b79f-7d4221df33e2',+ type: 'plain',+ title: 'ποΈ ' + i18n.t('core:smartTagMonth'),+ functionality: 'currentMonth',+ description: i18n.t('core:smartTagMonthDescription'),+ color: '#4986e7',+ textcolor: '#ffffff',+ icon: '',+ },+ {+ id: 'b6d6c107-741e-423b-82a4-f00ae394dee4',+ type: 'plain',+ title: 'ποΈ ' + i18n.t('core:smartTagYear'),+ functionality: 'currentYear',+ description: i18n.t('core:smartTagYearDescription'),+ color: '#4986e7',+ textcolor: '#ffffff',+ icon: '',+ },+ {+ id: 'da9fd0e6-7921-4195-b8f9-dca80f132bab',+ type: 'plain',+ title: 'π '+ i18n.t('core:smartTagGeo'),+ functionality: 'geoTagging',+ description: i18n.t('core:smartTagGeoDescription'),+ color: '#4986e7',+ textcolor: '#ffffff',+ icon: '',+ },+ {+ id: '67678ddd-4979-4489-8d2d-69a964af6b0d',+ type: 'plain',+ title: 'π οΈ ' + i18n.t('core:smartTagDate'),+ functionality: 'dateTagging',+ description: i18n.t('core:smartTagDateDescription'),+ color: '#4986e7',+ textcolor: '#ffffff',+ icon: '',+ }+ ]+ }+]);diff --git a/app/reducers/tagging-actions.js b/app/reducers/tagging-actions.jsindex fdec364bf..13c031854 100644--- a/app/reducers/tagging-actions.js+++ b/app/reducers/tagging-actions.js@@ -54,16 +54,21 @@ const actions = {tag.type = 'sidecar';if (tag.functionality && tag.functionality.length > 0) {if (tag.functionality === 'geoTagging') {- // if (!isGeo(getState())) { // tag will be added later just open the Geo Dialog now- tag.path = paths[0]; // todo rethink this!- tag.title = defaultTagLocation;- dispatch(AppActions.toggleEditTagDialog(tag));- // }+ if (Pro) {+ tag.path = paths[0]; // todo rethink this!+ tag.title = defaultTagLocation;+ dispatch(AppActions.toggleEditTagDialog(tag));+ } else {+ dispatch(AppActions.showNotification(i18n.t('core:needProVersion')));+ }} else if (tag.functionality === 'dateTagging') {- tag.path = paths[0];- tag.title = formatDateTime4Tag(new Date(), true); // defaultTagDate;- dispatch(AppActions.toggleEditTagDialog(tag));- // }+ if (Pro) {+ tag.path = paths[0];+ tag.title = formatDateTime4Tag(new Date(), true); // defaultTagDate;+ dispatch(AppActions.toggleEditTagDialog(tag));+ } else {+ dispatch(AppActions.showNotification(i18n.t('core:needProVersion')));+ }} else {tag.title = generateTagValue(tag);tag.id = uuidv1();diff --git a/app/reducers/taglibrary-default.js b/app/reducers/taglibrary-default.jsindex a06d003a3..cec8a8374 100644--- a/app/reducers/taglibrary-default.js+++ b/app/reducers/taglibrary-default.js@@ -25,7 +25,6 @@ export default [title: 'ToDo Workflow',uuid: '50567824-16ba-4fda-a128-3865df97472f',expanded: true,- desciption: '',color: '#008000',textcolor: '#ffffff',children: [@@ -33,47 +32,37 @@ export default [id: uuidv1(),title: 'done',type: 'plain',- description: '',color: '#008000',textcolor: '#ffffff',- icon: '',keyBinding: ''},{id: uuidv1(),title: 'next',type: 'plain',- description: '',color: '#008000',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),title: 'maybe',type: 'plain',- description: '',color: '#008000',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),title: 'waiting',type: 'plain',- description: '',color: '#008000',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',- description: '',title: 'todo',color: '#008000',textcolor: '#ffffff',- icon: '',}]},@@ -81,7 +70,6 @@ export default [title: 'Common Tags',uuid: '17882854-44a7-4b2d-a2b1-b022846ac41d',expanded: true,- desciption: '',color: '#008000',textcolor: '#ffffff',children: [@@ -89,118 +77,22 @@ export default [id: uuidv1(),type: 'plain',title: 'book',- desciption: '',color: '#008000',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',title: 'paper',- desciption: '',color: '#008000',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',title: 'article',- desciption: '',color: '#008000',textcolor: '#ffffff',- icon: '',- }- ]- },- {- title: 'Smart Tags',- uuid: 'cfd4e8c7-94b6-4529-a1aa-a8e66c7a1f44',- expanded: true,- desciption: '',- color: '#4986e7',- textcolor: '#ffffff',- children: [- {- id: '73e5a6a7-9aed-4935-bc2d-3aa7959edae5',- type: 'plain',- title: 'now',- functionality: 'now',- desciption: 'Adds the current date and time as tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- },- {- id: '615b27eb-889c-4966-9fa0-930023f213c0',- type: 'plain',- title: 'today',- functionality: 'today',- desciption: 'Adds the current date as tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- },- {- id: '0f2d34ee-9923-4bb0-9a64-9264c15a3b57',- type: 'plain',- title: 'tomorrow',- functionality: 'tomorrow',- desciption: 'Adds tomorrow\'s date as tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- },- {- id: '8ec44eaa-5fae-498a-997d-0b9b51d2963f',- type: 'plain',- title: 'yesterday',- functionality: 'yesterday',- desciption: 'Adds the date of yesterday as tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- },- {- id: 'f31feb14-9567-41e9-9fe2-5f8de70ec8c5',- type: 'plain',- title: 'month',- functionality: 'currentMonth',- desciption: 'Adds the current year and month as tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- },- {- id: '208fa38e-115f-4440-8ea9-7550fd974576',- type: 'plain',- title: 'year',- functionality: 'currentYear',- desciption: 'Adds the current year as tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- },- {- id: 'e1f0760e-471c-4418-a404-6cb09e6f6c24',- type: 'plain',- title: 'geo-tag',- functionality: 'geoTagging',- desciption: 'Add geo coordinates as a tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',- },- {- id: 'e1f0760e-471c-4418-a404-6cb09e6f6c34',- type: 'plain',- title: 'date-tag',- functionality: 'dateTagging',- desciption: 'Add custom date as a tag',- color: '#4986e7',- textcolor: '#ffffff',- icon: '',}]},@@ -208,7 +100,6 @@ export default [title: 'Priorities',uuid: 'e21711da-ee78-4c83-bae3-e0007fe426a3',expanded: true,- desciption: '',color: '#008000',textcolor: '#ffffff',children: [@@ -219,25 +110,20 @@ export default [desciption: '',color: '#ff7537',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',title: 'medium',- desciption: '',color: '#ffad46',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',title: 'low',- desciption: '',color: '#7bd148',textcolor: '#ffffff',- icon: '',}]},@@ -245,7 +131,6 @@ export default [title: 'Ratings',uuid: '5cf5173d-738c-4413-9386-3f4411aa7b64',expanded: true,- desciption: '',color: '#ffcc24',textcolor: '#ffffff',children: [@@ -253,46 +138,36 @@ export default [id: uuidv1(),type: 'plain',title: '1star',- desciption: '',color: '#ffcc24',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',title: '2star',- desciption: '',color: '#ffcc24',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',title: '3star',- desciption: '',color: '#ffcc24',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',title: '4star',- desciption: '',color: '#ffcc24',textcolor: '#ffffff',- icon: '',},{id: uuidv1(),type: 'plain',title: '5star',- desciption: '',color: '#ffcc24',textcolor: '#ffffff',- icon: '',}]}diff --git a/app/reducers/taglibrary.js b/app/reducers/taglibrary.jsindex 165bfd751..452dfc8a8 100644--- a/app/reducers/taglibrary.js+++ b/app/reducers/taglibrary.js@@ -64,6 +64,7 @@ export type TagGroup = {expanded: boolean,description?: string,categoryId?: string,+ readOnly?: boolean,color?: string,textcolor?: string,children?: Array<Tag>