TagSpaces is an offline, open source, document manager with tagging support
Tsn212 use autosuggestion for selecting tags for the search (#768)
Stanimir80ec1962c08a
diff --git a/app/components/EntryProperties.js b/app/components/EntryProperties.jsindex cb06d7b73..bec9ba616 100644--- a/app/components/EntryProperties.js+++ b/app/components/EntryProperties.js@@ -19,6 +19,8 @@import React, { Component } from 'react';import marked from 'marked';+import { bindActionCreators } from 'redux';+import { connect } from 'react-redux';import { withStyles } from '@material-ui/core/styles';import Grid from '@material-ui/core/Grid';import FormControl from '@material-ui/core/FormControl';@@ -27,7 +29,6 @@ import TextField from '@material-ui/core/TextField';import Paper from '@material-ui/core/Paper';import Button from '@material-ui/core/Button';import DOMPurify from 'dompurify';-import TagContainer from './TagContainer';import TagDropContainer from './TagDropContainer';import EntryTagMenu from './menus/EntryTagMenu';import ColorPickerDialog from './dialogs/ColorPickerDialog';@@ -39,6 +40,8 @@ import { extractContainingDirectoryPath } from '../utils/paths';import AppConfig from '../config';import { Pro } from '../pro';import PlatformIO from '../services/platform-io';+import TagsSelect from './TagsSelect';+import TaggingActions from '../reducers/tagging-actions';const styles = theme => ({entryProperties: {@@ -152,13 +155,15 @@ type Props = {shouldReload?: boolean | null,settings: Object,shouldCopyFile?: boolean,- removeTags: () => void,editTagForEntry: () => void,onEditTags: () => void,renameFile: () => void,renameDirectory: () => void,normalizeShouldCopyFile: () => void,- showNotification: () => void+ showNotification: () => void,+ addTags: () => void,+ removeTags: () => void,+ removeAllTags: () => void};type State = {@@ -364,7 +369,31 @@ class EntryProperties extends Component<Props, State> {this.setState({ [name]: value });};- renderTags = (tag: Object) => (+ handleChange = (name, value, action) => {+ if (action === 'remove-value') {+ this.state.tags.map((tag) => {+ if (value.findIndex(obj => obj.title === tag.title) === -1) {+ this.props.removeTags([this.state.path], [tag]);+ }+ return tag;+ });+ } else if (action === 'clear') {+ this.props.removeAllTags([this.state.path]);+ } else { // create-option or select-option+ value.map((tag) => {+ if (this.state.tags.findIndex(obj => obj.title === tag.title) === -1) {+ this.props.addTags([this.state.path], [tag]);+ }+ return tag;+ });+ }++ this.setState({+ tags: value+ });+ };++ /* renderTags = (tag: Object) => (<TagContainerkey={tag.id ? tag.id : tag.title}defaultTextColor={this.props.settings.tagTextColor}@@ -372,7 +401,7 @@ class EntryProperties extends Component<Props, State> {tag={tag}handleTagMenu={this.handleTagMenu}/>- );+ ); */render() {const {@@ -401,7 +430,9 @@ class EntryProperties extends Component<Props, State> {selectedTag,isMoveCopyFilesDialogOpened} = this.state;-+ if (!path || path === '') {+ return <div />;+ }return (<div className={classes.entryProperties}><Grid container spacing={8}>@@ -478,25 +509,19 @@ class EntryProperties extends Component<Props, State> {</Typography></div><div className="grid-item">- <Button+ {/* <Buttoncolor="primary"data-tid="ok"className={classes.button}onClick={onEditTags}>{i18n.t('core:addEntryTags')}- </Button>+ </Button> */}</div></div><Paper className={classes.tags}><TagDropContainer entryPath={path}>- {tags && tags.length > 0 ? (- tags.map(this.renderTags)- ) : (- <div className={classes.dropText}>- {i18n.t('core:dropHere')}- </div>- )}+ <TagsSelect tagQuery={tags} handleChange={this.handleChange} /></TagDropContainer></Paper></div>@@ -704,4 +729,9 @@ class EntryProperties extends Component<Props, State> {}}-export default withStyles(styles)(EntryProperties);+function mapDispatchToProps(dispatch) {+ return bindActionCreators({ addTags: TaggingActions.addTags, removeTags: TaggingActions.removeTags, removeAllTags: TaggingActions.removeAllTags }, dispatch);+}+export default withStyles(styles)(+ connect(undefined, mapDispatchToProps)(EntryProperties)+);diff --git a/app/components/Search.js b/app/components/Search.jsindex 61a2584e6..592a2a21f 100644--- a/app/components/Search.js+++ b/app/components/Search.js@@ -42,7 +42,7 @@ import IconButton from '@material-ui/core/IconButton';import Select from '@material-ui/core/Select';import FormControl from '@material-ui/core/FormControl';import FormHelperText from '@material-ui/core/FormHelperText';-import TagSelect from './TagsSelect';+import TagsSelect from './TagsSelect';import { actions as AppActions, getIndexedEntriesCount, isIndexing, getDirectoryPath } from '../reducers/app';import { getMaxSearchResults } from '../reducers/settings';import styles from './SidePanels.css';@@ -177,7 +177,7 @@ class Search extends React.Component<Props, State> {disabled={indexing}>{/* <InputLabel htmlFor="searchTags">{i18n.t('core:searchTags')}</InputLabel> */}- <TagSelect tagQuery={this.state.tagQuery} handleChange={this.handleChange} />+ <TagsSelect tagQuery={this.state.tagQuery} handleChange={this.handleChange} />{/* <Inputid="tagQuery"name="tagQuery"diff --git a/app/components/TagContainer.js b/app/components/TagContainer.jsindex 75731e63c..f6368e53d 100644--- a/app/components/TagContainer.js+++ b/app/components/TagContainer.js@@ -18,68 +18,61 @@*/import React from 'react';+import uuidv1 from 'uuid';+import { connect } from 'react-redux';import Button from '@material-ui/core/Button';import MoreVertIcon from '@material-ui/icons/MoreVert';import RemoveTagIcon from '@material-ui/icons/Close';-import { DragSource } from 'react-dnd';-import DragItemTypes from './DragItemTypes';import { type TagGroup, type Tag } from '../reducers/taglibrary';+import { getTagColor, getTagTextColor } from '../reducers/settings';type Props = {tag: Tag,- key: string,- defaultTextColor: string,- defaultBackgroundColor: string,- tagGroup: TagGroup,+ key?: string,+ defaultTextColor?: string,+ tagTextColor: string,+ defaultBackgroundColor?: string,+ tagBackgroundColor: string,+ tagGroup?: TagGroup,handleTagMenu: (event: Object, tag: Tag, tagGroup: TagGroup) => void, // TODO refactorhandleTagMenu: (event: Object, tag: Tag, entryPath: string) => void,handleRemoveTag: (event: Object, tag: Tag) => void,- isDragging: boolean,+ isDragging?: boolean,tagMode?: 'default' | 'display' | 'remove',entryPath?: string,- connectDragSource: (param: Object) => void-};--const boxSource = {- beginDrag(props) {- // console.log('beginDrag', props);- return {- tagId: props.tag.id,- tag: props.tag,- sourceTagGroupId: props.tagGroup.uuid- };- },-- endDrag(props, monitor) {- const item = monitor.getItem();- const dropResult = monitor.getDropResult();-- // console.log('DropRESULT: ', dropResult);- // console.log('item: ', item);- if (dropResult && dropResult.tagGroupId && dropResult.tagGroupId !== item.sourceTagGroupId) {- // console.log(`Dropped ${item.tagId} from ${item.sourceTagGroupId} into ${dropResult.tagGroupId}!`);- props.moveTag(item.tagId, item.sourceTagGroupId, dropResult.tagGroupId);- } else if (dropResult && dropResult.entryPath) {- // console.log(`Dropped item: ${item.tag.title} onto file: ${dropResult.entryPath}!`);- props.addTags([dropResult.entryPath], [item.tag]);- }- }+ deleteIcon?: Object};class TagContainer extends React.Component<Props> {+ static defaultProps = {+ isDragging: false,+ tagMode: 'default',+ key: undefined,+ tagGroup: undefined,+ entryPath: undefined,+ deleteIcon: undefined,+ defaultTextColor: undefined,+ defaultBackgroundColor: undefined+ };+render() {const {+ key,tag,+ deleteIcon,+ isDragging,defaultTextColor,+ tagTextColor,defaultBackgroundColor,+ tagBackgroundColor,tagGroup,entryPath} = this.props;- const { isDragging, connectDragSource, tagMode } = this.props;+ const { tagMode } = this.props;let mode = '';if (tagMode === 'remove') {- mode = (+ mode = deleteIcon || (<RemoveTagIcondata-tid={'tagRemoveButton_' + tag.title.replace(/ /g, '_')}style={{@@ -101,13 +94,13 @@ class TagContainer extends React.Component<Props> {);}- return connectDragSource(+ return (<divdata-tid={'tagContainer_' + tag.title.replace(/ /g, '_')}- key={this.props.key}- onClick={event => this.props.handleTagMenu(event, tag, entryPath || tagGroup)}- onContextMenu={event => this.props.handleTagMenu(event, tag, entryPath || tagGroup)}- onDoubleClick={event => this.props.handleTagMenu(event, tag, entryPath || tagGroup)}+ key={key || tag.id || uuidv1()}+ onClick={event => { if (this.props.handleTagMenu) { this.props.handleTagMenu(event, tag, entryPath || tagGroup); } }}+ onContextMenu={event => { if (this.props.handleTagMenu) { this.props.handleTagMenu(event, tag, entryPath || tagGroup); } }}+ onDoubleClick={event => { if (this.props.handleTagMenu) { this.props.handleTagMenu(event, tag, entryPath || tagGroup); } }}style={{backgroundColor: 'transparent',marginLeft: 4,@@ -122,8 +115,8 @@ class TagContainer extends React.Component<Props> {opacity: isDragging ? 0.5 : 1,fontSize: 13,textTransform: 'none',- color: tag.textcolor ? tag.textcolor : defaultTextColor,- backgroundColor: tag.color ? tag.color : defaultBackgroundColor,+ color: tag.textcolor || defaultTextColor || tagTextColor,+ backgroundColor: tag.color || defaultBackgroundColor || tagBackgroundColor,minHeight: 25,margin: 0,paddingTop: 0,@@ -133,7 +126,6 @@ class TagContainer extends React.Component<Props> {}}><span>- {/* {tag.icon && tag.icon.length > 0 && tag.icon + ' '} TODO icon impl */}{tag.title}</span>{mode}@@ -143,7 +135,10 @@ class TagContainer extends React.Component<Props> {}}-export default DragSource(DragItemTypes.TAG, boxSource, (connect, monitor) => ({- connectDragSource: connect.dragSource(),- isDragging: monitor.isDragging()-}))(TagContainer);+function mapStateToProps(state) {+ return {+ tagBackgroundColor: getTagColor(state),+ tagTextColor: getTagTextColor(state)+ };+}+export default connect(mapStateToProps)(TagContainer);diff --git a/app/components/TagContainerDnd.js b/app/components/TagContainerDnd.jsnew file mode 100644index 000000000..ffaf9767a--- /dev/null+++ b/app/components/TagContainerDnd.js@@ -0,0 +1,104 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * @flow+ */++import React from 'react';+import { DragSource } from 'react-dnd';+import DragItemTypes from './DragItemTypes';+import TagContainer from './TagContainer';+import { type TagGroup, type Tag } from '../reducers/taglibrary';++type Props = {+ tag: Tag,+ key: string,+ defaultTextColor: string,+ defaultBackgroundColor: string,+ tagGroup: TagGroup,+ handleTagMenu: (event: Object, tag: Tag, tagGroup: TagGroup) => void, // TODO refactor+ handleTagMenu: (event: Object, tag: Tag, entryPath: string) => void,+ handleRemoveTag: (event: Object, tag: Tag) => void,+ isDragging: boolean,+ tagMode?: 'default' | 'display' | 'remove',+ entryPath?: string,+ connectDragSource: (param: Object) => void,+ deleteIcon: Object+};++const boxSource = {+ beginDrag(props) {+ // console.log('beginDrag', props);+ return {+ tagId: props.tag.id,+ tag: props.tag,+ sourceTagGroupId: props.tagGroup.uuid+ };+ },++ endDrag(props, monitor) {+ const item = monitor.getItem();+ const dropResult = monitor.getDropResult();++ // console.log('DropRESULT: ', dropResult);+ // console.log('item: ', item);+ if (dropResult && dropResult.tagGroupId && dropResult.tagGroupId !== item.sourceTagGroupId) {+ // console.log(`Dropped ${item.tagId} from ${item.sourceTagGroupId} into ${dropResult.tagGroupId}!`);+ props.moveTag(item.tagId, item.sourceTagGroupId, dropResult.tagGroupId);+ } else if (dropResult && dropResult.entryPath) {+ // console.log(`Dropped item: ${item.tag.title} onto file: ${dropResult.entryPath}!`);+ props.addTags([dropResult.entryPath], [item.tag]);+ }+ }+};++class TagContainerDnd extends React.Component<Props> {+ render() {+ const {+ key,+ tag,+ defaultTextColor,+ defaultBackgroundColor,+ tagGroup,+ entryPath,+ handleTagMenu,+ deleteIcon+ } = this.props;+ const { isDragging, connectDragSource, tagMode } = this.props;++ return connectDragSource(+ <span>+ <TagContainer+ key={key}+ defaultTextColor={defaultTextColor}+ defaultBackgroundColor={defaultBackgroundColor}+ tag={tag}+ tagGroup={tagGroup}+ handleTagMenu={handleTagMenu}+ deleteIcon={deleteIcon}+ tagMode={tagMode}+ entryPath={entryPath}+ isDragging={isDragging}+ />+ </span>+ );+ }+}++export default DragSource(DragItemTypes.TAG, boxSource, (connect, monitor) => ({+ connectDragSource: connect.dragSource(),+ isDragging: monitor.isDragging()+}))(TagContainerDnd);diff --git a/app/components/TagLibrary.js b/app/components/TagLibrary.jsindex 4318db4be..126fede59 100644--- a/app/components/TagLibrary.js+++ b/app/components/TagLibrary.js@@ -43,7 +43,7 @@ import DeleteForever from '@material-ui/icons/DeleteForever';import Menu from '@material-ui/core/Menu';import MenuItem from '@material-ui/core/MenuItem';// import { Toolbar } from '@material-ui/core/Toolbar';-import TagContainer from './TagContainer';+import TagContainerDnd from './TagContainerDnd';import ConfirmDialog from './dialogs/ConfirmDialog';import styles from './SidePanels.css';import CreateTagGroupDialog from './dialogs/CreateTagGroupDialog';@@ -254,7 +254,7 @@ class TagLibrary extends React.Component<Props, State> {<Collapse in={tagGroup.expanded} unmountOnExit><TagGroupContainer taggroup={tagGroup} data-tid={'tagGroupContainer_' + tagGroup.title}>{tagGroup.children && tagGroup.children.map((tag: Tag) => (- <TagContainer+ <TagContainerDndkey={tag.id}defaultTextColor={this.props.tagTextColor}defaultBackgroundColor={this.props.tagBackgroundColor}diff --git a/app/components/TagsSelect.js b/app/components/TagsSelect.jsindex 10902691c..8eb50a0fc 100644--- a/app/components/TagsSelect.js+++ b/app/components/TagsSelect.js@@ -33,6 +33,7 @@ import TextField from '@material-ui/core/TextField';import { emphasize } from '@material-ui/core/styles/colorManipulator';import i18n from '../services/i18n';import { type Tag, getAllTags } from '../reducers/taglibrary';+import TagContainer from './TagContainer';const styles = theme => ({root: {@@ -80,21 +81,17 @@ const styles = theme => ({left: 0,right: 0,},+ /* paper: {+ position: 'fixed', // 'absolute',+ marginTop: theme.spacing.unit,+ left: 45,+ right: 0,+ maxWidth: 350,+ zIndex: 1+ }, *//* divider: {height: theme.spacing.unit * 2,}, */- tag: {- // display: 'flex',- // flexDirection: 'row',- // justifyContent: 'space-between',- alignItems: 'center',- borderRadius: '4px',- backgroundColor: '#008000',- color: 'white',- padding: '2px 6px',- boxShadow: '0 1px 1px 0 rgba(0, 0, 0, 0.16),0 1px 1px 0 rgba(239, 239, 239, 0.12)',- margin: '0 0 10px 10px'- }});function NoOptionsMessage(props) {@@ -173,17 +170,28 @@ function ValueContainer(props) {function MultiValue(props) {return (- <Chip+ <TagContainer+ key={props.data.id || props.data.title}+ defaultTextColor={props.data.textcolor}+ defaultBackgroundColor={props.data.color}+ tag={props.data}+ tagMode={'remove'}+ // tagGroup={tagGroup}+ // handleTagMenu={this.handleTagMenu}+ // addTags={this.props.addTags}+ deleteIcon={<CloseIcon {...props.removeProps} />}+ />+ /* <ChiptabIndex={-1}label={props.children}style={{ fontSize: 16 }}- className={classNames(props.selectProps.classes.chip, props.selectProps.classes.tag, {+ className={classNames(props.selectProps.classes.chip, {[props.selectProps.classes.chipFocused]: props.isFocused})}onDelete={props.removeProps.onClick}// deleteIcon={<CloseIcon style={{ fill: '#fff' }} {...props.removeProps} />}deleteIcon={<CancelIcon {...props.removeProps} />}- />+ /> */);}@@ -203,7 +211,7 @@ const components = {Option,Placeholder,SingleValue,- ValueContainer,+ ValueContainer};type Props = {@@ -216,20 +224,20 @@ type Props = {class TagsSelect extends React.Component<Props> {handleChange = (newValue: any, actionMeta: any) => {- console.group('Value Changed');+ /* console.group('Value Changed');console.log(newValue);console.log(`action: ${actionMeta.action}`);- console.groupEnd();+ console.groupEnd(); */if (actionMeta.action === 'select-option') {- this.props.handleChange('tagQuery', newValue);+ this.props.handleChange('tagQuery', newValue, actionMeta.action);} else if (actionMeta.action === 'create-option') {this.props.allTags.push(newValue);- this.props.handleChange('tagQuery', newValue);+ this.props.handleChange('tagQuery', newValue, actionMeta.action);} else if (actionMeta.action === 'remove-value') {- this.props.handleChange('tagQuery', newValue);+ this.props.handleChange('tagQuery', newValue, actionMeta.action);} else if (actionMeta.action === 'clear') {- this.props.handleChange('tagQuery', []);+ this.props.handleChange('tagQuery', [], actionMeta.action);}};@@ -256,11 +264,11 @@ class TagsSelect extends React.Component<Props> {<div className={classes.root}><NoSsr><CreatableSelect- isClearable+ isClearable={false}classes={classes}options={allTags}getOptionLabel={(option) => option.title}- getOptionValue={(option) => option.id}+ getOptionValue={(option) => option.id || option.title}isValidNewOption={this.isValidNewOption}getNewOptionData={(inputValue, optionLabel) => ({id: inputValue,@@ -281,6 +289,7 @@ class TagsSelect extends React.Component<Props> {// onCreateOption={this.handleCreate}placeholder={i18n.t('core:searchTags')}isMulti+ formatCreateLabel={(label) => label}// isSearchable/></NoSsr>diff --git a/app/components/dialogs/AddRemoveTagsDialog.js b/app/components/dialogs/AddRemoveTagsDialog.jsindex 82eeed23f..98cbfd9ee 100644--- a/app/components/dialogs/AddRemoveTagsDialog.js+++ b/app/components/dialogs/AddRemoveTagsDialog.js@@ -24,7 +24,7 @@ import DialogContent from '@material-ui/core/DialogContent';import DialogTitle from '@material-ui/core/DialogTitle';import GenericDialog from './GenericDialog';import { type Tag } from '../../reducers/taglibrary';-import TagAutoSuggestion from '../TagAutoSuggestion';+import TagsSelect from '../TagsSelect';import i18n from '../../services/i18n';type Props = {@@ -51,7 +51,13 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {isConfirmDialogOpened: false};- onAddTag = (tag) => {+ handleChange = (name, value) => {+ this.setState({+ newlyAddedTags: value+ });+ };++ /* onAddTag = (tag) => {const { newlyAddedTags } = this.state;newlyAddedTags.push(tag);this.setState({ newlyAddedTags });@@ -61,12 +67,12 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {const { newlyAddedTags } = this.state;const modifiedTags = newlyAddedTags.filter(addedTag => addedTag.title !== tag.title);this.setState({ newlyAddedTags: modifiedTags });- };+ }; */onClose = () => {- this.setState({newlyAddedTags: []});+ this.setState({ newlyAddedTags: [] });this.props.onClose();- }+ };render() {const {@@ -88,12 +94,13 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {)}renderContent={() => (<DialogContent>- <TagAutoSuggestion+ <TagsSelect tagQuery={newlyAddedTags} handleChange={this.handleChange} />+ {/* <TagAutoSuggestionselectedEntries={selectedEntries}newlyAddedTags={newlyAddedTags}onAddTag={this.onAddTag}onRemoveTag={this.onRemoveTag}- />+ /> */}</DialogContent>)}renderActions={() => (diff --git a/app/components/dialogs/ImportExportTagGroupsDialog.js b/app/components/dialogs/ImportExportTagGroupsDialog.jsindex f755127b3..ce0087f0f 100644--- a/app/components/dialogs/ImportExportTagGroupsDialog.js+++ b/app/components/dialogs/ImportExportTagGroupsDialog.js@@ -189,7 +189,6 @@ class ImportExportTagGroupsDialog extends React.Component<Props, State> {<TagContainertag={tag}tagMode="display"- key={tag.id}/>))}</TagGroupContainer>diff --git a/app/perspectives/grid-perspective/src/index.js b/app/perspectives/grid-perspective/src/index.jsindex 5f2f0929f..0926d8de2 100644--- a/app/perspectives/grid-perspective/src/index.js+++ b/app/perspectives/grid-perspective/src/index.js@@ -794,6 +794,7 @@ class GridPerspective extends React.Component<Props, State> {defaultTextColor={this.props.tagTextColor}defaultBackgroundColor={this.props.tagBackgroundColor}tag={tag}+ key={tag.id}entryPath={fsEntry.path}handleTagMenu={this.handleTagMenu}/>diff --git a/app/reducers/tagging-actions.js b/app/reducers/tagging-actions.jsindex b99db5817..ba0289d12 100644--- a/app/reducers/tagging-actions.js+++ b/app/reducers/tagging-actions.js@@ -93,25 +93,27 @@ const actions = {const entryProperties = await PlatformIO.getPropertiesPromise(path);- // TODO: Handle adding already added tagsif (!entryProperties.isFile || settings.persistTagsInSidecarFile) {// Handling adding tags in sidecarloadMetaDataPromise(path).then(fsEntryMeta => {- const newTags = [- ...fsEntryMeta.tags,- ...tags- ];- const updatedFsEntryMeta = {- ...fsEntryMeta,- tags: newTags,- };- saveMetaDataPromise(path, updatedFsEntryMeta).then(() => {- dispatch(AppActions.reflectUpdateSidecarTags(path, newTags));- return true;- }).catch((err) => {- console.warn('Error adding tags for ' + path + ' with ' + err);- dispatch(AppActions.showNotification('Adding tags failed', 'error', true));- });+ const uniqueTags = getNonExistingTags(tags, extractTags(path, settings.tagDelimiter), fsEntryMeta.tags);+ if (uniqueTags.length > 0) {+ const newTags = [+ ...fsEntryMeta.tags,+ ...uniqueTags+ ];+ const updatedFsEntryMeta = {+ ...fsEntryMeta,+ tags: newTags,+ };+ saveMetaDataPromise(path, updatedFsEntryMeta).then(() => {+ dispatch(AppActions.reflectUpdateSidecarTags(path, newTags));+ return true;+ }).catch((err) => {+ console.warn('Error adding tags for ' + path + ' with ' + err);+ dispatch(AppActions.showNotification('Adding tags failed', 'error', true));+ });+ }return true;}).catch(() => {const newFsEntryMeta = {@@ -126,20 +128,39 @@ const actions = {});});} else {- const fileName = extractFileName(path);- const containingDirectoryPath = extractContainingDirectoryPath(path);- const extractedTags = extractTags(path, settings.tagDelimiter);- for (let i = 0; i < tags.length; i += 1) {- // check if tag is already in the tag array- if (extractedTags.indexOf(tags[i].title) < 0) {- // Adding the new tag- extractedTags.push(tags[i].title);+ loadMetaDataPromise(path).then(fsEntryMeta => {+ const extractedTags = extractTags(path, settings.tagDelimiter);+ const uniqueTags = getNonExistingTags(tags, extractedTags, fsEntryMeta.tags);+ if (uniqueTags.length > 0) {+ const fileName = extractFileName(path);+ const containingDirectoryPath = extractContainingDirectoryPath(path);++ for (let i = 0; i < uniqueTags.length; i += 1) {+ extractedTags.push(uniqueTags[i].title);+ }+ const newFilePath = containingDirectoryPath + AppConfig.dirSeparator + generateFileName(fileName, extractedTags, settings.tagDelimiter);+ dispatch(AppActions.renameFile(path, newFilePath));}- }- const newFilePath = containingDirectoryPath + AppConfig.dirSeparator + generateFileName(fileName, extractedTags, settings.tagDelimiter);- dispatch(AppActions.renameFile(path, newFilePath));+ return true;+ }).catch(error => {+ console.warn('Error check tag exist in SideCar for ' + path + ' with ' + error);+ });}// dispatch collectRecentTags(tags);++ function getNonExistingTags(newTagsArray: Array<Tag>, fileTagsArray: Array<string>, sideCarTagsArray: Array<Tag>) {+ const newTags = [];+ for (let i = 0; i < newTagsArray.length; i += 1) {+ // check if tag is already in the fileTagsArray+ if (fileTagsArray.indexOf(newTagsArray[i].title) === -1) {+ // check if tag is already in the sideCarTagsArray+ if (sideCarTagsArray.findIndex(sideCarTag => sideCarTag.title === newTagsArray[i].title) === -1) {+ newTags.push(newTagsArray[i]);+ }+ }+ }+ return newTags;+ }},editTagForEntry: (path: string, tag: Tag, newTagTitle: string) => (dispatch: (actions: Object) => void,diff --git a/package.json b/package.jsonindex b05da0394..f4edda9ca 100644--- a/package.json+++ b/package.json@@ -210,8 +210,8 @@"react-beautiful-dnd": "^2.3.1","react-color": "^2.14.1","react-datetime": "^2.14.0",- "react-dnd": "^4.0.5",- "react-dnd-html5-backend": "^4.0.5",+ "react-dnd": "^6.0.0",+ "react-dnd-html5-backend": "^6.0.0","react-dom": "^16.4.0","react-hot-loader": "^4.3.3","react-hotkeys": "^1.1.4",diff --git a/yarn.lock b/yarn.lockindex 56848e2e8..d819708d9 100644--- a/yarn.lock+++ b/yarn.lock@@ -978,11 +978,6 @@ atob@^2.1.1:resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==-autobind-decorator@^2.1.0:- version "2.2.1"- resolved "https://registry.yarnpkg.com/autobind-decorator/-/autobind-decorator-2.2.1.tgz#acabfddec272b9c98323dab5dc94f63c61b35855"- integrity sha512-XXC/B4Cm5X/Rv8etlFcpxUHdIhcs4U3tf8bsg50gUV8J6kq1Uij25xeBoSeuUwdKs2NMhwy+p9T4VNS8/ujp9w==-autoprefixer@^6.0.0, autoprefixer@^6.3.1:version "6.7.7"resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-6.7.7.tgz#1dbd1c835658e35ce3f9984099db00585c782014"@@ -4064,15 +4059,15 @@ [email protected]:parse-color "^1.0.0"sanitize-filename "^1.6.1"-dnd-core@^4.0.5:- version "4.0.5"- resolved "https://registry.yarnpkg.com/dnd-core/-/dnd-core-4.0.5.tgz#3b83d138d0d5e265c73ec978dec5e1ed441dc665"- integrity sha1-O4PRONDV4mXHPsl43sXh7UQdxmU=+dnd-core@^6.0.0:+ version "6.0.0"+ resolved "https://registry.yarnpkg.com/dnd-core/-/dnd-core-6.0.0.tgz#d347266ebd72f0a2de6ecf5e26e4ef006ebde84b"+ integrity sha512-WnnFSbnC3grP/XJ+xfxgM8DyIsts3Q/rfgE6WGRWs6tCQcwILputNNm/Kw+WPS2N1e46hRy5iPl2pYwkP9kK9Q==dependencies:asap "^2.0.6"invariant "^2.2.4"- lodash "^4.17.10"- redux "^4.0.0"+ lodash "^4.17.11"+ redux "^4.0.1"dns-equal@^1.0.0:version "1.0.0"@@ -8116,7 +8111,7 @@ lodash.uniq@^4.5.0:resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=-lodash@^4.0.0, lodash@^4.0.1, lodash@^4.1.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1, lodash@^4.6.1, lodash@^4.8.0, lodash@~4.17.10:+lodash@^4.0.0, lodash@^4.0.1, lodash@^4.1.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1, lodash@^4.6.1, lodash@^4.8.0, lodash@~4.17.10:version "4.17.11"resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==@@ -10391,26 +10386,25 @@ react-deep-force-update@^1.0.0:resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-1.1.2.tgz#3d2ae45c2c9040cbb1772be52f8ea1ade6ca2ee1"integrity sha512-WUSQJ4P/wWcusaH+zZmbECOk7H5N2pOIl0vzheeornkIMhu+qrNdGFm0bDZLCb0hSF0jf/kH1SgkNGfBdTc4wA==-react-dnd-html5-backend@^4.0.5:- version "4.0.6"- resolved "https://registry.yarnpkg.com/react-dnd-html5-backend/-/react-dnd-html5-backend-4.0.6.tgz#4144ed5de8a79d322b0849142cbcb1b39d8db40d"- integrity sha1-QUTtXeinnTIrCEkULLyxs52NtA0=+react-dnd-html5-backend@^6.0.0:+ version "6.0.0"+ resolved "https://registry.yarnpkg.com/react-dnd-html5-backend/-/react-dnd-html5-backend-6.0.0.tgz#e70ad62a5df95cc993739aab1f1ffe0e725a9878"+ integrity sha512-NRaApaf3IBrE/LgOCoTqbsI1MT5HKIBDkyMF1zoJUy+slW/RLjLuxMC2gYU1Y89Ra/e7CQ5Hw/gJY7oIXLK32g==dependencies:- autobind-decorator "^2.1.0"- dnd-core "^4.0.5"- lodash "^4.17.10"- shallowequal "^1.0.2"+ dnd-core "^6.0.0"+ lodash "^4.17.11"-react-dnd@^4.0.5:- version "4.0.5"- resolved "https://registry.yarnpkg.com/react-dnd/-/react-dnd-4.0.5.tgz#4d10a93700b604778b0ba2309b20d705201e71da"- integrity sha1-TRCpNwC2BHeLC6IwmyDXBSAecdo=+react-dnd@^6.0.0:+ version "6.0.0"+ resolved "https://registry.yarnpkg.com/react-dnd/-/react-dnd-6.0.0.tgz#0780eafaa47293bf12dc8f79cf1e48ede8ba72f1"+ integrity sha512-XI14rxF5eeGk8045xh/6KbjfLSzgkfNdQCqwkR5qAvBf0QYvkGAUz1AQfLrQudFs/DVw7WiCoCohRzJR1Kyn9Q==dependencies:- dnd-core "^4.0.5"- hoist-non-react-statics "^2.5.0"+ dnd-core "^6.0.0"+ hoist-non-react-statics "^3.1.0"invariant "^2.1.0"- lodash "^4.17.10"- shallowequal "^1.0.2"+ lodash "^4.17.11"+ recompose "^0.30.0"+ shallowequal "^1.1.0"react-dom@^16.4.0:version "16.6.3"@@ -10873,7 +10867,7 @@ rechoir@^0.6.2:dependencies:resolve "^1.1.6"-"[email protected] - 0.30.0":+"[email protected] - 0.30.0", recompose@^0.30.0:version "0.30.0"resolved "https://registry.yarnpkg.com/recompose/-/recompose-0.30.0.tgz#82773641b3927e8c7d24a0d87d65aeeba18aabd0"integrity sha512-ZTrzzUDa9AqUIhRk4KmVFihH0rapdCSMFXjhHbNrjAWxBuUD/guYlyysMnuHjlZC/KRiOKRtB4jf96yYSkKE8w==@@ -10975,7 +10969,7 @@ redux@^3.7.2:loose-envify "^1.1.0"symbol-observable "^1.0.3"-redux@^4.0.0:+redux@^4.0.1:version "4.0.1"resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.1.tgz#436cae6cc40fbe4727689d7c8fae44808f1bfef5"integrity sha512-R7bAtSkk7nY6O/OYMVR9RiBI+XghjF9rlbl5806HJbQph0LJVHZrU5oaO4q70eUKiqMRqm4y07KLTlMZ2BlVmg==@@ -11634,7 +11628,7 @@ shallowequal@^0.2.2:dependencies:lodash.keys "^3.1.2"-shallowequal@^1.0.2:+shallowequal@^1.0.2, shallowequal@^1.1.0:version "1.1.0"resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==