TagSpaces is an offline, open source, document manager with tagging support
Extend the tag menu with add to tag group entry, enable dnd of tag from the default perspective to tag library (#1406)
Stanimir559c5b50503b
diff --git a/app/components/TagContainerDnd.tsx b/app/components/TagContainerDnd.tsxindex 6a4f35b93..1e7609691 100644--- a/app/components/TagContainerDnd.tsx+++ b/app/components/TagContainerDnd.tsx@@ -22,7 +22,7 @@ import { DragSource, ConnectDragPreview, ConnectDragSource } from 'react-dnd';import { getEmptyImage } from 'react-dnd-html5-backend';import DragItemTypes from './DragItemTypes';import TagContainer from './TagContainer';-import { TagGroup, Tag } from '-/reducers/taglibrary';+import { TagGroup, Tag, Uuid } from '-/reducers/taglibrary';import { FileSystemEntry } from '-/services/utils-io';const boxSource = {@@ -44,15 +44,19 @@ const boxSource = {if (dropResult &&dropResult.tagGroupId &&- dropResult.tagGroupId !== item.sourceTagGroupId &&- props.moveTag+ dropResult.tagGroupId !== item.sourceTagGroupId) {- // console.log(`Dropped ${item.tagId} from ${item.sourceTagGroupId} into ${dropResult.tagGroupId}!`);- props.moveTag(- item.tagTitle,- item.sourceTagGroupId,- dropResult.tagGroupId- );+ if (props.moveTag) {+ // console.log(`Dropped ${item.tagId} from ${item.sourceTagGroupId} into ${dropResult.tagGroupId}!`);+ props.moveTag(+ item.tagTitle,+ item.sourceTagGroupId,+ dropResult.tagGroupId+ );+ } else if (props.addTag) {+ // add from file DnD to tagGroup+ props.addTag(props.tag, dropResult.tagGroupId);+ }} else if (dropResult && dropResult.entryPath && props.addTags) {// console.log(`Dropped item: ${item.tag.title} onto file: ${dropResult.entryPath}!`);if (@@ -77,6 +81,7 @@ interface Props {tagMode?: 'default' | 'display' | 'remove';entryPath?: string;addTags?: (paths: Array<string>, tags: Array<Tag>) => void;+ addTag?: (tag: Tag, parentTagGroupUuid: Uuid) => void;moveTag?: () => void;connectDragSource?: ConnectDragSource;connectDragPreview?: ConnectDragPreview;diff --git a/app/components/dialogs/AddTagToTagGroupDialog.tsx b/app/components/dialogs/AddTagToTagGroupDialog.tsxnew file mode 100644index 000000000..a002c9b23--- /dev/null+++ b/app/components/dialogs/AddTagToTagGroupDialog.tsx@@ -0,0 +1,126 @@+/**+ * 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/>.+ *+ */++import React, { useState } from 'react';+import Button from '@material-ui/core/Button';+import DialogActions from '@material-ui/core/DialogActions';+import DialogContent from '@material-ui/core/DialogContent';+import DialogTitle from '@material-ui/core/DialogTitle';+import FormControl from '@material-ui/core/FormControl';+import Dialog from '@material-ui/core/Dialog';+import InputLabel from '@material-ui/core/InputLabel';+import Select from '@material-ui/core/Select';+import Input from '@material-ui/core/Input';+import MenuItem from '@material-ui/core/MenuItem';+import { connect } from 'react-redux';+import { getTagGroups, Tag, TagGroup } from '-/reducers/taglibrary';+import i18n from '-/services/i18n';+import { getTagColor, getTagTextColor } from '-/reducers/settings';++interface Props {+ open: boolean;+ onClose: () => void;+ addTag: (tag: Tag, uuid: string) => void;+ fullScreen?: boolean;+ selectedTag: Tag;+ defaultBackgroundColor?: string;+ defaultTextColor?: string;+ tagGroups: Array<TagGroup>;+}++const AddTagToTagGroupDialog = (props: Props) => {+ const [tagGroup, setTagGroup] = useState<string>(undefined);++ const handleTagGroupChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ setTagGroup(event.target.value);+ };++ const onConfirm = () => {+ const { defaultBackgroundColor, defaultTextColor, selectedTag } = props;+ if (!selectedTag.textcolor) {+ selectedTag.textcolor = defaultTextColor;+ }+ if (!selectedTag.color) {+ selectedTag.color = defaultBackgroundColor;+ }+ props.addTag(selectedTag, tagGroup);+ props.onClose();+ };++ const { fullScreen, open, onClose } = props;++ return (+ <Dialog+ open={open}+ onClose={onClose}+ fullScreen={fullScreen}+ keepMounted+ scroll="paper"+ onKeyDown={event => {+ if (event.key === 'Enter' || event.keyCode === 13) {+ event.preventDefault();+ event.stopPropagation();+ onConfirm();+ } else if (event.key === 'Escape') {+ onClose();+ }+ }}+ >+ <DialogTitle>+ {i18n.t('core:addTagToTagGroup') + ': ' + props.selectedTag.title}+ </DialogTitle>+ <DialogContent style={{ minWidth: 400 }}>+ <FormControl fullWidth={true}>+ <InputLabel htmlFor="addTagToTagGroupInput">+ {i18n.t('core:chooseTagGroup')}+ </InputLabel>+ <Select+ value={tagGroup}+ onChange={handleTagGroupChange}+ input={<Input id="addTagToTagGroupInput" />}+ >+ {props.tagGroups.map(tg => (+ <MenuItem value={tg.uuid}>{tg.title}</MenuItem>+ ))}+ </Select>+ </FormControl>+ </DialogContent>+ <DialogActions>+ <Button onClick={onClose} color="primary">+ {i18n.t('core:cancel')}+ </Button>+ <Button+ disabled={tagGroup === undefined}+ onClick={onConfirm}+ data-tid="createTagsConfirmButton"+ color="primary"+ >+ {i18n.t('core:ok')}+ </Button>+ </DialogActions>+ </Dialog>+ );+};++const mapStateToProps = state => ({+ tagGroups: getTagGroups(state),+ defaultBackgroundColor: getTagColor(state),+ defaultTextColor: getTagTextColor(state)+});++export default connect(mapStateToProps)(AddTagToTagGroupDialog);diff --git a/app/components/menus/EntryTagMenu.tsx b/app/components/menus/EntryTagMenu.tsxindex ae5b038eb..db45c4602 100644--- a/app/components/menus/EntryTagMenu.tsx+++ b/app/components/menus/EntryTagMenu.tsx@@ -21,6 +21,7 @@ import { bindActionCreators } from 'redux';import { connect } from 'react-redux';import EditIcon from '@material-ui/icons/Edit';import DeleteIcon from '@material-ui/icons/DeleteForever';+import AddIcon from '@material-ui/icons/Add';import ShowEntriesWithTagIcon from '@material-ui/icons/SearchOutlined';import ListItemIcon from '@material-ui/core/ListItemIcon';import ListItemText from '@material-ui/core/ListItemText';@@ -44,6 +45,7 @@ interface Props {searchLocationIndex?: (searchQuery: SearchQuery) => void;maxSearchResults?: number;openSearchPanel?: () => void;+ setIsAddTagDialogOpened?: (tag: Tag) => void;toggleEditTagDialog?: (tag: Tag) => void;isReadOnlyMode?: boolean;}@@ -64,6 +66,11 @@ const EntryTagMenu = (props: Props) => {setIsDeleteTagDialogOpened(true);}+ function showAddTagDialog() {+ props.onClose();+ props.setIsAddTagDialogOpened(props.selectedTag);+ }+function showFilesWithThisTag() {if (props.selectedTag) {props.openSearchPanel();@@ -96,21 +103,29 @@ const EntryTagMenu = (props: Props) => {</ListItemIcon><ListItemText primary={i18n.t('core:showFilesWithThisTag')} /></MenuItem>- <MenuItem data-tid="editTagDialogMenu" onClick={showEditTagDialog}>- <ListItemIcon>- <EditIcon />- </ListItemIcon>- <ListItemText primary={i18n.t('core:editTagTitle')} />- </MenuItem>{!props.isReadOnlyMode && (- <div>+ <>+ {props.setIsAddTagDialogOpened && (+ <MenuItem data-tid="addTagMenuTID" onClick={showAddTagDialog}>+ <ListItemIcon>+ <AddIcon />+ </ListItemIcon>+ <ListItemText primary={i18n.t('core:addTagToTagGroup')} />+ </MenuItem>+ )}+ <MenuItem data-tid="editTagDialogMenu" onClick={showEditTagDialog}>+ <ListItemIcon>+ <EditIcon />+ </ListItemIcon>+ <ListItemText primary={i18n.t('core:editTagTitle')} />+ </MenuItem><MenuItem data-tid="deleteTagMenu" onClick={showDeleteTagDialog}><ListItemIcon><DeleteIcon /></ListItemIcon><ListItemText primary={i18n.t('core:removeTag')} /></MenuItem>- </div>+ </>)}</Menu><ConfirmDialogdiff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 4b6c64084..de2f22f85 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -532,5 +532,7 @@"confirmResetColor": "Do you really want to clear this color?","maxIndexAge": "Index validity duration in minutes","maxIndexAgeHelp": "After this time the search index will be invalidated",+ "chooseTagGroup": "Choose Tag Group",+ "addTagToTagGroup": "Add Tag to Tag Group","-": "-"}diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsxindex b19ff7c17..71afb87e5 100644--- a/app/perspectives/grid-perspective/components/CellContent.tsx+++ b/app/perspectives/grid-perspective/components/CellContent.tsx@@ -33,7 +33,7 @@ import { FileSystemEntry, findColorForFileEntry } from '-/services/utils-io';import TagContainerDnd from '-/components/TagContainerDnd';import TagContainer from '-/components/TagContainer';import i18n from '-/services/i18n';-import { Tag } from '-/reducers/taglibrary';+import { Tag, Uuid } from '-/reducers/taglibrary';import PlatformIO from '-/services/platform-io';import { AppConfig } from '-/config';@@ -48,6 +48,7 @@ interface Props {supportedFileTypes: Array<Object>;thumbnailMode: any;addTags: () => void;+ addTag: (tag: Tag, parentTagGroupUuid: Uuid) => void;openFsEntry: (fsEntry: FileSystemEntry) => void;selectedEntries: Array<FileSystemEntry>;selectEntry: (fsEntry: FileSystemEntry) => void;@@ -71,6 +72,7 @@ const CellContent = (props: Props) => {supportedFileTypes,thumbnailMode,addTags,+ addTag,selectedEntries,isReadOnlyMode,handleTagMenu,@@ -403,6 +405,7 @@ const CellContent = (props: Props) => {key={fsEntry.path + tag.title}entryPath={fsEntry.path}addTags={addTags}+ addTag={addTag}handleTagMenu={handleTagMenu}selectedEntries={selectedEntries}/>diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex 9fb5ee46a..d834f040c 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -22,7 +22,7 @@ import { bindActionCreators } from 'redux';import { GlobalHotKeys } from 'react-hotkeys';import { withStyles } from '@material-ui/core/styles';import { FileSystemEntry } from '-/services/utils-io';-import { Tag } from '-/reducers/taglibrary';+import { actions as TagLibraryActions, Tag, Uuid } from '-/reducers/taglibrary';import {getSupportedFileTypes,getDesktopMode,@@ -60,6 +60,7 @@ import PlatformIO from '-/services/platform-io';import { getLocationPath } from '-/utils/paths';import GridPagination from '-/perspectives/grid-perspective/components/GridPagination';import GridSettingsDialog from '-/perspectives/grid-perspective/components/GridSettingsDialog';+import AddTagToTagGroupDialog from '-/components/dialogs/AddTagToTagGroupDialog';interface Props {classes: any;@@ -83,6 +84,7 @@ interface Props {// setLastSelectedEntry: (entryPath: string | null) => void;setSelectedEntries: (selectedEntries: Array<Object>) => void;addTags: () => void;+ addTag: (tag: Tag, parentTagGroupUuid: Uuid) => void;removeTags: (paths: Array<string>, tags: Array<Tag>) => void;removeAllTags: () => void;directoryContent: Array<FileSystemEntry>;@@ -127,6 +129,9 @@ const GridPerspective = (props: Props) => {optionsContextMenuAnchorEl,setOptionsContextMenuAnchorEl] = useState<null | HTMLElement>(null);+ const [isAddTagDialogOpened, setIsAddTagDialogOpened] = useState<Tag>(+ undefined+ );const [sortBy, setSortBy] = useState<string>(settings && settings.sortBy ? settings.sortBy : 'byName');@@ -559,6 +564,7 @@ const GridPerspective = (props: Props) => {theme,selectedEntries,addTags,+ addTag,supportedFileTypes,openFsEntry} = props;@@ -592,6 +598,7 @@ const GridPerspective = (props: Props) => {supportedFileTypes={supportedFileTypes}thumbnailMode={thumbnailMode}addTags={addTags}+ addTag={addTag}selectedEntries={selectedEntries}selectEntry={selectEntry}deselectEntry={deselectEntry}@@ -806,6 +813,14 @@ const GridPerspective = (props: Props) => {selectedEntries={props.selectedEntries}/>)}+ {isAddTagDialogOpened !== undefined && (+ <AddTagToTagGroupDialog+ open={isAddTagDialogOpened !== undefined}+ onClose={() => setIsAddTagDialogOpened(undefined)}+ addTag={props.addTag}+ selectedTag={isAddTagDialogOpened}+ />+ )}{isGridSettingsDialogOpened && (<GridSettingsDialogopen={isGridSettingsDialogOpened}@@ -861,6 +876,7 @@ const GridPerspective = (props: Props) => {anchorEl={tagContextMenuAnchorEl}open={Boolean(tagContextMenuAnchorEl)}onClose={() => setTagContextMenuAnchorEl(null)}+ setIsAddTagDialogOpened={setIsAddTagDialogOpened}selectedTag={selectedTag.current}currentEntryPath={selectedEntryPath.current} // getSelEntryPath()}removeTags={props.removeTags}@@ -911,7 +927,8 @@ function mapActionCreatorsToProps(dispatch) {openPrevFile: AppActions.openPrevFile,toggleDeleteMultipleEntriesDialog:AppActions.toggleDeleteMultipleEntriesDialog,- addTags: TaggingActions.addTags+ addTags: TaggingActions.addTags,+ addTag: TagLibraryActions.addTag},dispatch);diff --git a/app/reducers/taglibrary.ts b/app/reducers/taglibrary.tsindex 4d06d23a0..e7bb07f3e 100644--- a/app/reducers/taglibrary.ts+++ b/app/reducers/taglibrary.ts@@ -33,6 +33,7 @@ export const types = {UPDATE_TAGGROUP: 'UPDATE_TAGGROUP',// TOGGLE_TAGGROUP: 'TOGGLE_TAGGROUP',ADD_TAG: 'ADD_TAG',+ COPY_TAG: 'COPY_TAG',REMOVE_TAG: 'REMOVE_TAG',UPDATE_TAG: 'UPDATE_TAG',SORT_TAG_GROUP_UP: 'SORT_TAG_GROUP_UP',@@ -234,6 +235,30 @@ export default (state: Array<TagGroup> = defaultTagLibrary, action: any) => {}return state;}+ case types.COPY_TAG: {+ let indexForEditing = -1;+ state.forEach((tagGroup, index) => {+ if (tagGroup.uuid === action.uuid) {+ indexForEditing = index;+ }+ });++ if (indexForEditing >= 0) {+ const taggroupTags = state[indexForEditing].children;+ const copyTag = action.tag;+ if (!taggroupTags.some(tag => tag.title === copyTag.title)) {+ return [+ ...state.slice(0, indexForEditing),+ {+ ...state[indexForEditing],+ children: [...taggroupTags, copyTag]+ },+ ...state.slice(indexForEditing + 1)+ ];+ }+ }+ return state;+ }case types.UPDATE_TAG: {let tagIndexForUpdating = -1;let tagGroupIndexForUpdating = -1;@@ -464,11 +489,41 @@ export const actions = {type: types.MERGE_TAGGROUP,entry}),- addTag: (tag: string, parentTagGroupUuid: Uuid) => {- console.log('INSIDE ADD TAG');- console.log(tag, parentTagGroupUuid);- return { type: types.ADD_TAG, tag, uuid: parentTagGroupUuid };+ addTag: (tag: string | Object, parentTagGroupUuid: Uuid) => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ const { settings } = getState();+ const { tagTextColor, tagBackgroundColor } = settings;+ // console.log('INSIDE ADD TAG');+ // console.log(tag, parentTagGroupUuid);+ if (typeof tag === 'object' && tag !== null) {+ dispatch(+ actions.copyTag(+ {+ ...tag,+ // @ts-ignore+ textcolor: tag.textcolor || tagTextColor,+ // @ts-ignore+ color: tag.color || tagBackgroundColor+ },+ parentTagGroupUuid+ )+ );+ } else {+ dispatch(actions.addTagIntern(tag, parentTagGroupUuid));+ }},+ addTagIntern: (tag: string | Object, parentTagGroupUuid: Uuid) => ({+ type: types.ADD_TAG,+ tag,+ uuid: parentTagGroupUuid+ }),+ copyTag: (tag: Tag, parentTagGroupUuid: Uuid) => ({+ type: types.COPY_TAG,+ tag,+ uuid: parentTagGroupUuid+ }),editTag: (tag: Tag, parentTagGroupUuid: Uuid, origTitle: string) => ({type: types.UPDATE_TAG,tag,