Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fixing tag dnd issues, enabling dnd of tags from one entry to another

Ilian Sapundshiev533b1530bbe5
diff --git a/app/components/TagContainer.js b/app/components/TagContainer.js
index b13b56b76..40102646b 100644
--- a/app/components/TagContainer.js
+++ b/app/components/TagContainer.js
@@ -20,14 +20,12 @@
import React from 'react';
import uuidv1 from 'uuid';
import { connect } from 'react-redux';
-import { bindActionCreators } from 'redux';
import Button from '@material-ui/core/Button';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import RemoveTagIcon from '@material-ui/icons/Close';
import { type TagGroup, type Tag, getAllTags } from '../reducers/taglibrary';
import { getTagColor, getTagTextColor } from '../reducers/settings';
-import { getSelectedEntries } from '../reducers/app';
-import TaggingActions from '../reducers/tagging-actions';
+// import { getSelectedEntries } from '../reducers/app';
type Props = {
tag: Tag,
@@ -112,7 +110,7 @@ const TagContainer = (props: Props) => {
data-tid={'tagContainer_' + tag.title.replace(/ /g, '_')}
key={key || tag.id || uuidv1()}
onClick={event => {
- if (event.ctrlKey) {
+ if (event.ctrlKey && addTags) {
const selectedEntryPaths = [];
selectedEntries.map(entry => selectedEntryPaths.push(entry.path));
addTags(selectedEntryPaths, [tag]);
@@ -128,9 +126,6 @@ const TagContainer = (props: Props) => {
onDoubleClick={event => { if (handleTagMenu) { handleTagMenu(event, tag, entryPath || tagGroup); } }}
style={{
backgroundColor: 'transparent',
- marginLeft: 4,
- marginTop: 0,
- marginBottom: 4,
display: 'inline-block'
}}
>
@@ -143,7 +138,7 @@ const TagContainer = (props: Props) => {
color: textColor,
backgroundColor,
minHeight: 25,
- margin: 0,
+ margin: 2,
paddingTop: 0,
paddingBottom: 0,
paddingRight: 3,
@@ -183,11 +178,4 @@ function mapStateToProps(state) {
};
}
-// function mapActionCreatorsToProps(dispatch) {
-// return bindActionCreators({
-// addTags: TaggingActions.addTags,
-// removeTags: TaggingActions.removeTags
-// }, dispatch);
-// }
-
export default connect(mapStateToProps)(TagContainer);
diff --git a/app/components/TagContainerDnd.js b/app/components/TagContainerDnd.js
index 931a329a1..c753b2341 100644
--- a/app/components/TagContainerDnd.js
+++ b/app/components/TagContainerDnd.js
@@ -20,34 +20,17 @@
import React from 'react';
import { DragSource } from 'react-dnd';
import type { ConnectDragPreview, ConnectDragSource } from 'react-dnd';
-// import { getEmptyImage } from 'react-dnd-html5-backend';
import DragItemTypes from './DragItemTypes';
import TagContainer from './TagContainer';
import { type TagGroup, type Tag } from '../reducers/taglibrary';
-type Props = {
- tag: Tag,
- key: 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: ConnectDragSource,
- connectDragPreview: ConnectDragPreview,
- deleteIcon: Object,
- selectedEntries: Array<string>
-};
-
const boxSource = {
beginDrag(props) {
// console.log('beginDrag', props);
return {
tagId: props.tag.id,
tag: props.tag,
- sourceTagGroupId: props.tagGroup.uuid
+ sourceTagGroupId: props.tagGroup ? props.tagGroup.uuid : undefined
};
},
@@ -57,10 +40,10 @@ const boxSource = {
// console.log('DropRESULT: ', dropResult);
// console.log('item: ', item);
- if (dropResult && dropResult.tagGroupId && dropResult.tagGroupId !== item.sourceTagGroupId) {
+ if (dropResult && dropResult.tagGroupId && dropResult.tagGroupId !== item.sourceTagGroupId && props.moveTag) {
// console.log(`Dropped ${item.tagId} from ${item.sourceTagGroupId} into ${dropResult.tagGroupId}!`);
props.moveTag(item.tagId, item.sourceTagGroupId, dropResult.tagGroupId);
- } else if (dropResult && dropResult.entryPath) {
+ } else if (dropResult && dropResult.entryPath && props.addTags) {
// console.log(`Dropped item: ${item.tag.title} onto file: ${dropResult.entryPath}!`);
if (props.selectedEntries.some(entry => entry.path === dropResult.entryPath)) {
const selectedEntryPaths = [];
@@ -73,66 +56,86 @@ const boxSource = {
}
};
-class TagContainerDnd extends React.Component<Props> {
- componentDidMount() {
- const xml = '<svg version="1.1" height="25" width="100" xmlns="http://www.w3.org/2000/svg">' +
- '<g>' +
- '<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" style="fill:' + this.props.tag.color + ';opacity:0.5" />' +
- '<text x="50%" y="55%" font-family="Roboto,Arial,Helvetica,Sans" font-size="13" dominant-baseline="middle" text-anchor="middle" fill="' + this.props.tag.textcolor + '">' + this.props.tag.title + '</text>' +
- '</g>' +
- '</svg>';
- const img = new Image();
- img.src = `data:image/svg+xml;charset=utf-8,${xml.replace(/(\r\n|\n|\r)/gm, '')}`;
- img.onload = () => this.props.connectDragPreview(img, { anchorX: 1, anchorY: 0 });
- // this.props.connectDragPreview(getEmptyImage(), { captureDraggingState: true });
- }
+type Props = {
+ tag: Tag,
+ key: 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,
+ addTags: (paths: Array<string>, tags: Array<Tag>) => void,
+ moveTag: () => void,
+ connectDragSource: ConnectDragSource,
+ connectDragPreview: ConnectDragPreview,
+ deleteIcon: Object,
+ selectedEntries: Array<string>
+};
- shouldComponentUpdate(nextProps) {
- if (this.props.tag.title !== nextProps.tag.title
- || typeof this.props.key !== typeof nextProps.key
- || (this.props.key && nextProps.key && this.props.key !== nextProps.key)
- || this.props.tag.color !== nextProps.tag.color
- || this.props.tag.textcolor !== nextProps.tag.textcolor
- || (this.props.tagGroup && this.props.tagGroup ? (this.props.tagGroup.uuid !== nextProps.tagGroup.uuid) : false)
- || this.props.isDragging !== nextProps.isDragging
- || typeof this.props.entryPath !== typeof nextProps.entryPath
- || (this.props.entryPath && this.props.entryPath !== nextProps.entryPath)
- ) {
- return true;
- }
- return false;
- }
+// class TagContainerDnd extends React.PureComponent<Props> {
+// // componentDidMount() {
+// // const xml = '<svg version="1.1" height="25" width="100" xmlns="http://www.w3.org/2000/svg">' +
+// // '<g>' +
+// // '<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" style="fill:' + this.props.tag.color + ';opacity:0.5" />' +
+// // '<text x="50%" y="55%" font-family="Roboto,Arial,Helvetica,Sans" font-size="13" dominant-baseline="middle" text-anchor="middle" fill="' + this.props.tag.textcolor + '">' + this.props.tag.title + '</text>' +
+// // '</g>' +
+// // '</svg>';
+// // const img = new Image();
+// // img.src = `data:image/svg+xml;charset=utf-8,${xml.replace(/(\r\n|\n|\r)/gm, '')}`;
+// // img.onload = () => this.props.connectDragPreview(img, { anchorX: 1, anchorY: 0 });
+// // // this.props.connectDragPreview(getEmptyImage(), { captureDraggingState: true });
+// // }
- render() {
- const {
- key,
- tag,
- tagGroup,
- entryPath,
- handleTagMenu,
- deleteIcon,
- selectedEntries,
- isDragging,
- connectDragSource,
- tagMode
- } = this.props;
+// shouldComponentUpdate(nextProps) {
+// if (this.props.tag.title !== nextProps.tag.title
+// || typeof this.props.key !== typeof nextProps.key
+// || (this.props.key && nextProps.key && this.props.key !== nextProps.key)
+// || this.props.tag.color !== nextProps.tag.color
+// || this.props.tag.textcolor !== nextProps.tag.textcolor
+// || (this.props.tagGroup && this.props.tagGroup ? (this.props.tagGroup.uuid !== nextProps.tagGroup.uuid) : false)
+// || this.props.isDragging !== nextProps.isDragging
+// || typeof this.props.entryPath !== typeof nextProps.entryPath
+// || (this.props.entryPath && this.props.entryPath !== nextProps.entryPath)
+// ) {
+// return true;
+// }
+// return false;
+// }
- return connectDragSource(
- <span>
- <TagContainer
- key={key}
- tag={tag}
- tagGroup={tagGroup}
- handleTagMenu={handleTagMenu}
- deleteIcon={deleteIcon}
- tagMode={tagMode}
- entryPath={entryPath}
- isDragging={isDragging}
- selectedEntries={selectedEntries}
- />
- </span>);
- }
-}
+// render() {
+const TagContainerDnd = (props: Props) => {
+ const {
+ key,
+ tag,
+ tagGroup,
+ entryPath,
+ handleTagMenu,
+ deleteIcon,
+ selectedEntries,
+ isDragging,
+ connectDragSource,
+ addTags,
+ tagMode
+ } = props;
+
+ return connectDragSource(
+ <span>
+ <TagContainer
+ key={key}
+ tag={tag}
+ tagGroup={tagGroup}
+ handleTagMenu={handleTagMenu}
+ deleteIcon={deleteIcon}
+ addTags={addTags}
+ tagMode={tagMode}
+ entryPath={entryPath}
+ isDragging={isDragging}
+ selectedEntries={selectedEntries}
+ />
+ </span>);
+};
export default DragSource(DragItemTypes.TAG, boxSource, (connect, monitor) => ({
connectDragSource: connect.dragSource(),
diff --git a/app/components/TagLibrary.js b/app/components/TagLibrary.js
index 90c193fcd..8c0e5a6a5 100644
--- a/app/components/TagLibrary.js
+++ b/app/components/TagLibrary.js
@@ -375,6 +375,7 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return bindActionCreators({
...TagLibraryActions, // TODO connect only the really needed
+ addTags: TaggingActions.addTags,
collectTagsFromLocation: TaggingActions.collectTagsFromLocation
}, dispatch);
}
diff --git a/app/perspectives/grid-perspective/src/index.js b/app/perspectives/grid-perspective/src/index.js
index 3ff1ec4b4..f14820d3c 100644
--- a/app/perspectives/grid-perspective/src/index.js
+++ b/app/perspectives/grid-perspective/src/index.js
@@ -74,7 +74,7 @@ import styles from './styles.css';
import FileMenu from '../../../components/menus/FileMenu';
import DirectoryMenu from '../../../components/menus/DirectoryMenu';
import EntryTagMenu from '../../../components/menus/EntryTagMenu';
-import TagContainer from '../../../components/TagContainer';
+import TagContainerDnd from '../../../components/TagContainerDnd';
import i18n from '../../../services/i18n';
import ConfirmDialog from '../../../components/dialogs/ConfirmDialog';
import AddRemoveTagsDialog from '../../../components/dialogs/AddRemoveTagsDialog';
@@ -92,6 +92,7 @@ import {
getSelectedEntries,
isLoading
} from '../../../reducers/app';
+import TaggingActions from '../../../reducers/tagging-actions';
const maxDescriptionPreviewLength = 100;
@@ -614,11 +615,13 @@ class GridPerspective extends React.Component<Props, State> {
};
renderTag = (tag: Object, fsEntry) => (
- <TagContainer
+ <TagContainerDnd
tag={tag}
key={tag.id}
entryPath={fsEntry.path}
+ addTags={this.props.addTags}
handleTagMenu={this.handleTagMenu}
+ selectedEntries={this.props.selectedEntries}
/>
);
@@ -1201,7 +1204,8 @@ class GridPerspective extends React.Component<Props, State> {
function mapActionCreatorsToProps(dispatch) {
return bindActionCreators({
moveFiles: IOActions.moveFiles,
- setSelectedEntries: AppActions.setSelectedEntries
+ setSelectedEntries: AppActions.setSelectedEntries,
+ addTags: TaggingActions.addTags
}, dispatch);
}