TagSpaces is an offline, open source, document manager with tagging support
fixing add/remove multiple tags functionality
Ilian Sapundshiev88ff6e665ed7
diff --git a/app/components/EntryContainer.js b/app/components/EntryContainer.jsindex 1f5dadf58..6c53ebf9b 100644--- a/app/components/EntryContainer.js+++ b/app/components/EntryContainer.js@@ -68,7 +68,6 @@ import {isReadOnlyMode,actions as AppActions} from '../reducers/app';-import { getAllTags } from '../reducers/taglibrary';const defaultSplitSize = 103;const openedSplitSize = 360;@@ -162,8 +161,6 @@ type Props = {autohide?: boolean) => void,removeAllTags: () => void,- allTags?: Array,- selectedEntries?: Array,deleteFile: (path: string) => void,toggleEntryFullWidth: () => void,isReadOnlyMode: boolean,@@ -180,8 +177,6 @@ type State = {openedSplitSize?: number,isEditTagsModalOpened?: boolean,selectedItem?: Object,- selectedItems?: Array,- selectedEntries?: Array,isDeleteEntryModalOpened?: boolean,shouldCopyFile?: boolean,entryPropertiesSplitSize?: number@@ -198,7 +193,6 @@ class EntryContainer extends React.Component<Props, State> {isDeleteEntryModalOpened: false,currentEntry: null,selectedItem: {},- selectedItems: [],shouldCopyFile: false,entryPropertiesSplitSize: 0};@@ -261,8 +255,7 @@ class EntryContainer extends React.Component<Props, State> {selectedItem: {...currentEntry,tags- },- selectedItems: [currentEntry.path]+ }});const { settings } = nextProps;@@ -828,16 +821,12 @@ class EntryContainer extends React.Component<Props, State> {confirmDialogContent={'confirmDialogContent'}/><AddRemoveTagsDialog- isSingleFile={true}open={isEditTagsModalOpened}onClose={() => this.setState({ isEditTagsModalOpened: false })}- selectedItem={this.state.selectedItem}- selectedItems={this.state.selectedItems}- allTags={this.props.allTags}addTags={this.props.addTags}removeTags={this.props.removeTags}removeAllTags={this.props.removeAllTags}- selectedEntries={this.props.selectedEntries}+ selectedEntries={[this.state.selectedItem]}/><a href="#" id="downloadFile">{/* Download link */}@@ -951,7 +940,6 @@ class EntryContainer extends React.Component<Props, State> {...currentEntry,tags},- selectedItems: [currentEntry.path],isEditTagsModalOpened: true});}}@@ -994,7 +982,6 @@ function mapStateToProps(state) {openedFiles: getOpenedFiles(state),settings: state.settings,isReadOnlyMode: isReadOnlyMode(state),- allTags: getAllTags(state)};}diff --git a/app/components/TagAutoSuggestion.js b/app/components/TagAutoSuggestion.jsindex 38ab3b930..2fa3cba81 100644--- a/app/components/TagAutoSuggestion.js+++ b/app/components/TagAutoSuggestion.js@@ -17,248 +17,317 @@* @flow*/-import React from 'react';-import Button from '@material-ui/core/Button';-import TextField from '@material-ui/core/TextField';-import Autosuggest from 'react-autosuggest';-// import parse from 'autosuggest-highlight/umd/parse';-import Paper from '@material-ui/core/Paper';+import React, { Component } from 'react';+import { connect } from 'react-redux';import uuidv1 from 'uuid';+import Button from '@material-ui/core/Button';+import CloseIcon from '@material-ui/icons/Close';+import Input from '@material-ui/core/Input';+import InputLabel from '@material-ui/core/InputLabel';import { withStyles } from '@material-ui/core/styles';-import MenuItem from '@material-ui/core/MenuItem';import FormControl from '@material-ui/core/FormControl';-import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';-import { type Tag } from '../reducers/taglibrary';-import TagContainer from './TagContainer';+import { type Tag, getAllTags } from '../reducers/taglibrary';import i18n from '../services/i18n';-// import { extractFileName } from '../utils/paths';--function renderInput(inputProps) {- const { classes, autoFocus, value, ref, ...other } = inputProps;- return (- <TextField- autoFocus={autoFocus}- className={classes.textField}- value={value}- inputRef={ref}- InputProps={{- classes: {- input: classes.input,- },- ...other,- }}- />- );-}+import { isStr, isArr, isNum, shape } from '../utils/misc';-function renderSuggestion(suggestion, { query, isHighlighted }) {- const parts = []; // parse(suggestion.title, matches);- return (- <MenuItem selected={isHighlighted} component="div">- <div>- {parts.map((part, index) => {- return part.highlight ? (- <span key={String(index)} style={{ fontWeight: 300 }}>- {part.text}- </span>- ) : (- <strong key={String(index)} style={{ fontWeight: 400 }}>- {part.text}- </strong>- );- })}- </div>- </MenuItem>- );-}+type Props = {+ classes: Array<string>,+ allTags?: Array<Tag>,+ onAddTag: () => void,+ onRemoveTag: () => void,+ selectedEntries?: Array,+ newlyAddedTags?: Array+};-function renderSuggestionsContainer(options) {- return (- <Paper {...options.containerProps} square>- {options.children}- </Paper>- );-}+type State = {+ query?: string,+ tags?: Array<Object>,+ suggestions?: Array<Object>,+ isValidQuery?: boolean,+ targetTagGroupColor?: string+};-const styles = theme => ({- container: {- flexGrow: 1,+const styles = {+ component: {position: 'relative',- height: 120+ width: '640px',+ height: '260px',+ maxWidth: '100%',+ overflow: 'visible'},- suggestionsContainerOpen: {- marginTop: theme.spacing.unit,- marginBottom: theme.spacing.unit * 2,+ componentTip: {+ display: 'none',+ padding: '10px 0 0 0',+ fontSize: '12px',+ color: '#f44336',+ '&.active': {+ display: 'block'+ }+ },+ fieldContainer: {+ position: 'relative',+ display: 'flex',+ flexDirection: 'row',+ justifyContent: 'space-between',+ alignItems: 'center'+ },+ fieldBox: {+ width: '100%',+ position: 'relative',+ display: 'flex',+ flexDirection: 'row',+ justifyContent: 'space-between',+ alignItems: 'center'+ },+ tagField: {+ width: '100%'+ },+ addTagButton: {+ width: '120px',+ margin: '16px 0 0 16px'+ },+ suggestions: {position: 'absolute',- display: 'block',- top: '31px',- border: '1px solid #aaa',- backgroundColor: '#fff',- fontFamily: 'Open Sans,sans-serif',- fontWeight: 300,- fontSize: '16px',- borderBottomLeftRadius: '4px',- borderBottomRightRadius: '4px',- zIndex: 7777,+ top: 52,left: 0,- right: 0+ right: 0,+ margin: '0 auto',+ width: 'calc(100% - 2px)',+ maxHeight: '200px',+ overflowY: 'overlay',+ overflowX: 'hidden',+ display: 'none',+ backgroundColor: '#fff',+ zIndex: 100,+ boxShadow: '0 1px 1px 0 rgba(0, 0, 0, 0.16),0 1px 1px 0 rgba(239, 239, 239, 0.12)',+ '&.active': {+ display: 'block'+ }},- suggestion: {- display: 'block'+ addSuggestion: {+ width: '100%',+ border: 'none',+ backgroundColor: 'transparent',+ textAlign: 'left',+ transition: 'all 0.15s ease-in-out',+ padding: '12px',+ '&:not(:last-child)': {+ borderBottom: '1px solid rgba(0, 0, 0, 0.16)'+ },+ '&:hover, &:active, &:focus': {+ border: 'none',+ outline: 'none',+ cursor: 'pointer',+ backgroundColor: '#1dd19f',+ color: '#fff',+ transition: 'all 0.15s ease-in-out'+ }},- suggestionsList: {+ tags: {+ display: 'flex',+ flexDirection: 'row',+ justifyContent: 'flex-start',+ alignItems: 'flex-start',+ flexWrap: 'wrap',+ padding: '10px 0 0 0',margin: 0,- padding: 0,- listStyleType: 'none'+ backgroundColor: '#f9f7f7',+ borderRadius: 4,+ '&.active': {+ margin: '20px 0 0 0'+ }},- textField: {- width: '85%'- },- root: {- marginTop: '15px',+ tag: {display: 'flex',- justifyContent: 'center',- flexWrap: 'wrap',- padding: theme.spacing.unit / 3,+ 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'},- alignAddButton: {- top: '20%'+ removeTagButton: {+ border: 'none',+ backgroundColor: '#008000',+ padding: 0,+ position: 'relative',+ left: 4,+ top: 1,+ '&:hover, &:active, &:focus': {+ cursor: 'pointer',+ outline: 'none'+ }}-});--type Props = {- allTags: Array<Tag>,- classes: Object,- updateSelectedTags: (tags: Array<Tag>) => void-};--type State = {- value?: string,- suggestions?: Array<Object>,- tagContainerSuggestions?: Array<Object>-};+}-class TagAutoSuggestion extends React.Component<Props, State> {+class TagAutoSuggestion extends Component<Props, State> {state = {- value: '',+ query: '',+ tags: [],suggestions: [],- tagContainerSuggestions: []+ isValidQuery: true,+ targetTagGroupColor: '#008000'};- handleTagSearchChange = (event) => {- this.setState({- value: event.target.value- });+ componentWillReceiveProps = ({ selectedItem = {} }) => {+ const { tags = [] } = selectedItem;+ this.setState({ tags });+ this.setState({ query: '' });};- handleRemoveTag = (event, tag) => {- const tagsData = [...this.state.tagContainerSuggestions];- const tagToDelete = tagsData.indexOf(tag);- tagsData.splice(tagToDelete, 1);- this.setState({ tagContainerSuggestions: tagsData });- this.props.updateSelectedTags(tagsData);- };+ sanitizeQuery = query => query.trim();- handleSuggestionsFetchRequested = ({ value }) => {- this.setState({- suggestions: this.getSuggestions(value)- });+ validateQuery = query => {+ const isMatchingLength = query.length > 1;+ const hasSpecialCharacters = /[[\]{}()*+?.,\\^$|#%&\s]/.test(query);+ return isMatchingLength && !hasSpecialCharacters;};- handleSuggestionsClearRequested = () => {- this.setState({- suggestions: []- });+ onGetSuggestions = query => {+ const { allTags = [] } = this.props;+ const suggestions = allTags.filter(tag => tag.title.indexOf(query) > -1);+ this.setState({ query, suggestions });};- handleAddTag = () => {- const tagContainerSuggestions = this.state.tagContainerSuggestions;- const value = this.state.value;- // find by value/title- tagContainerSuggestions.push({- uuid: uuidv1(),- title: value,- value- });+ onChangeQuery = query => {+ const sanitizedQuery = this.sanitizeQuery(query);+ const isValidQuery = this.validateQuery(sanitizedQuery);this.setState({- value: '',- tagContainerSuggestions+ isValidQuery,+ query: sanitizedQuery});- this.props.updateSelectedTags(tagContainerSuggestions);};- getSuggestions = (value) => {- const queryValue = value.trim().toLowerCase();- const queryLength = queryValue.length;- let count = 0;+ onAddTag = (tag = {}) => {+ const { query, targetTagGroupColor } = this.state;- return queryLength === 0- ? []- : this.props.allTags.filter(suggestion => {- const keep =- count < 5 && suggestion.title.toLowerCase().slice(0, queryLength) === queryValue;- if (keep) {- count += 1;- }- return keep;- });- }+ const addedTag = isStr(tag.title) ? tag : {+ id: uuidv1(),+ color: targetTagGroupColor,+ description: query,+ title: query,+ type: 'plain'+ };++ this.props.onAddTag(addedTag);+ this.setState({ query: '' });+ };- renderTagSuggestions = tag => (- <TagContainer- key={tag.uuid}- tag={tag}- handleRemoveTag={this.handleRemoveTag}- tagMode={'remove'}- />- );+ onRemoveTag = (tag = {}) => {+ this.props.onRemoveTag(tag);+ };render() {+ const { classes, selectedItem = {}, selectedEntries, newlyAddedTags } = this.props;+ const { query, isValidQuery, suggestions = [] } = this.state;+ const suggestionsLength = suggestions.length;+ let { tags = [] } = selectedItem;++ /* if (isArr(selectedEntries)) {+ const uniqueEntries = shape(selectedEntries).filterByUnique('uuid').fetch();+ const tagsOnly = shape(uniqueEntries).reduceTo('tags').fetch();++ tags = shape(tagsOnly)+ .filterByDuplicate('title', uniqueEntries.length)+ .filterByUnique('title')+ .fetch();+ } */+return (- <div>- <FormControl fullWidth={true}>- { /*<Autosuggest- theme={{- container: this.props.classes.container,- suggestionsContainerOpen: this.props.classes.suggestionsContainerOpen,- suggestionsList: this.props.classes.suggestionsList,- suggestion: this.props.classes.suggestion,- textField: this.props.classes.textField- }}- renderInputComponent={renderInput}- suggestions={this.state.suggestions}- onSuggestionsFetchRequested={this.handleSuggestionsFetchRequested}- onSuggestionsClearRequested={this.handleSuggestionsClearRequested}- renderSuggestionsContainer={renderSuggestionsContainer}- getSuggestionValue={suggestion => suggestion.title}- renderSuggestion={renderSuggestion}- inputProps={{- autoFocus: true,- classes: this.props.classes,- placeholder: i18n.t('core:tagOperationTagsPlaceholder'),- value: this.state.value,- onChange: this.handleTagSearchChange,- }}- /> */ }- <ListItemSecondaryAction className={this.props.classes.alignAddButton}>- <Button- data-tid="addTag"- color="primary"- onClick={this.handleAddTag}+ <div+ className={`component ${classes.component}`}+ data-component="tag-autosuggestion"+ style={{+ height: 260+ }}+ >+ <FormControl fullWidth={true} className={classes.fieldContainer}>+ <div className={classes.fieldBox}>+ <InputLabel+ htmlFor="name-disabled"+ shrink={query !== ''}+ focused={query !== ''}+ error={!isValidQuery && query !== ''}>- {i18n.t('core:addTags')}- </Button>- </ListItemSecondaryAction>- </FormControl>- <FormControl fullWidth={true}>- <Paper className={this.props.classes.root}>- {this.state.tagContainerSuggestions && this.state.tagContainerSuggestions.map(this.renderTagSuggestions)}- </Paper>- {i18n.t('core:editTagNamesRestrictionsHelp')}+ {i18n.t('core:tagOperationTagsPlaceholder')}+ </InputLabel>+ <Input+ className={classes.tagField}+ value={query}+ error={!isValidQuery && query !== ''}+ onChange={event => this.onChangeQuery(event.target.value)}+ onKeyUp={event => {+ if (event.key === 'Enter') {+ return false;+ }+ this.onGetSuggestions(event.target.value);+ }}+ onKeyDown={event => {+ if (event.key !== 'Enter') {+ return false;+ }+ this.onAddTag();+ }}+ />+ </div>+ <Button+ disabled={!isValidQuery || query === ''}+ className={classes.addTagButton}+ data-tid="addTag"+ color="primary"+ onClick={this.onAddTag}+ >{i18n.t('core:addTag')}</Button></FormControl>+ {query !== '' && (+ <div+ className={`suggestions ${classes.suggestions} ${isValidQuery && suggestionsLength > 0 ? 'active' : ''}`}+ title={i18n.t('core:existingTags')}+ >+ {suggestions.map(suggestion => (+ <button+ className={`trigger add-suggestion ${classes.addSuggestion}`}+ key={suggestion.title}+ title={`${i18n.t('core:addTag')} '${suggestion.title}'`}+ onClick={() => this.onAddTag(suggestion)}+ >+ {suggestion.title}+ </button>+ ))}+ </div>+ )}+ {newlyAddedTags && newlyAddedTags.length > 0 && (+ <div className={`tags ${classes.tags} ${tags.length > 0 ? 'active' : ''}`}>+ {newlyAddedTags.map(tag => (+ <div key={tag.title} className={`tag ${classes.tag}`}>+ <span className="text">{tag.title}</span>+ <button+ className={`trigger remove-tag ${classes.removeTagButton}`}+ title={`${i18n.t('core:removeTag')} '${tag.title}'`}+ onClick={() => {+ this.onRemoveTag(tag);+ }}+ >+ <CloseIcon style={{ fill: '#fff', pointerEvents: 'none' }} />+ </button>+ </div>+ ))}+ </div>+ )}+ <div className={`component-tip ${classes.componentTip} ${!isValidQuery && query !== '' ? 'active' : ''}`}>+ <span className="text">+ {i18n.t('core:editTagNamesRestrictionsHelp')}+ </span>+ </div></div>);}}-export default withStyles(styles)(TagAutoSuggestion);+const mapStateToProps = state => ({+ allTags: getAllTags(state),+});++export default connect(mapStateToProps)(withStyles(styles)(TagAutoSuggestion));diff --git a/app/components/TagAutosuggestion/index.js b/app/components/TagAutosuggestion/index.jsdeleted file mode 100644index 91f3dbca2..000000000--- a/app/components/TagAutosuggestion/index.js+++ /dev/null@@ -1,22 +0,0 @@-/**- * 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 TagAutosuggestion from './script';--export default TagAutosuggestion;diff --git a/app/components/TagAutosuggestion/script/index.js b/app/components/TagAutosuggestion/script/index.jsdeleted file mode 100644index fa851a0c4..000000000--- a/app/components/TagAutosuggestion/script/index.js+++ /dev/null@@ -1,290 +0,0 @@-/**- * 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, { Component } from 'react';-import { connect } from 'react-redux';-import uuidv1 from 'uuid';-import Button from '@material-ui/core/Button';-import CloseIcon from '@material-ui/icons/Close';-import Input from '@material-ui/core/Input';-import InputLabel from '@material-ui/core/InputLabel';-import { withStyles } from '@material-ui/core/styles';-import FormControl from '@material-ui/core/FormControl';-import ConfirmDialog from '../../dialogs/ConfirmDialog';-import { type Tag, getTagGroups } from '../../../reducers/taglibrary';-import i18n from '../../../services/i18n';-import styles from '../style';-import { isStr, isArr, isNum, shape } from '../../../utils/misc';--type Props = {- classes: Array<string>,- allTags?: Array<Tag>,- selectedItem?: Object,- selectedItems: Array<string>,- addTags: (paths: Array<string>, tags: Array<Tag>) => void,- removeTags: (paths: Array<string>, tags: Array<Tag>) => void,- removeAllTags: (paths: Array<string>) => void,- tagGroups: Array,- selectedEntries?: Array,- isModalOpened?: boolean,- newlyAddedTags?: Array-};--type State = {- query?: string,- tags?: Array,- suggestions?: Array,- isValidQuery?: boolean,- isConfirmDialogOpened?: boolean,- tagForDeletion?: Object,- targetTagGroupColor?: string-};--class TagAutoSuggestion extends Component<Props, State> {- state = {- query: '',- tags: [],- suggestions: [],- isValidQuery: true,- isConfirmDialogOpened: false,- tagForDeletion: {},- targetTagGroupColor: '#008000'- };-- componentWillReceiveProps = ({ selectedItem = {}, isModalOpened }) => {- const { tags = [] } = selectedItem;- this.setState({ tags });-- if (!isModalOpened) {- this.setState({ query: '' });- }- };-- /**- * @description Sanitize query- * @param query- * @returns {*}- */- sanitizeQuery = query => query.trim();-- /**- * @description Validate query- * @param query- * @returns {boolean}- */- validateQuery = query => {- const isMatchingLength = query.length > 1;- const hasSpecialCharacters = /[[\]{}()*+?.,\\^$|#%&\s]/.test(query);- return isMatchingLength && !hasSpecialCharacters;- };-- /**- * @description On get suggestions- * @param query- */- onGetSuggestions = query => {- const { allTags = [] } = this.props;- const suggestions = allTags.filter(tag => tag.title.indexOf(query) > -1);- this.setState({ query, suggestions });- };-- /**- * @description On change query- * @param query- */- onChangeQuery = query => {- const sanitizedQuery = this.sanitizeQuery(query);- const isValidQuery = this.validateQuery(sanitizedQuery);- this.setState({- isValidQuery,- query: sanitizedQuery- });- };-- /**- * @description On add tag- * @param tag- */- onAddTag = (tag = {}) => {- const { addTags } = this.props;- const { query, targetTagGroupColor } = this.state;-- const addedTag = isStr(tag.title) ? tag : {- id: uuidv1(),- color: targetTagGroupColor,- description: query,- title: query,- type: 'plain'- };-- addTags(addedTag);- this.setState({ query: '' });- };-- /**- * @description On remove tag- * @param tag- */- onRemoveTag = (tag = {}) => {- const { removeTags } = this.props;- removeTags(tag);- };-- render() {- const { classes, selectedItem = {}, selectedEntries, newlyAddedTags, height } = this.props;- const { query, isValidQuery, suggestions = [] } = this.state;- const suggestionsLength = suggestions.length;- let { tags = [] } = selectedItem;-- if (isArr(selectedEntries)) {- const uniqueEntries = shape(selectedEntries).filterByUnique('uuid').fetch();- const tagsOnly = shape(uniqueEntries).reduceTo('tags').fetch();-- tags = shape(tagsOnly)- .filterByDuplicate('title', uniqueEntries.length)- .filterByUnique('title')- .fetch();- }-- return (- <div- className={`component ${classes.component}`}- data-component="tag-autosuggestion"- style={{- height: isNum(height) ? height : '260px'- }}- >-- <ConfirmDialog- open={this.state.isConfirmDialogOpened}- onClose={() => {- this.setState({- tagForDeletion: {},- isConfirmDialogOpened: false- });- }}- title={i18n.t('core:titleConfirm')}- content={i18n.t('core:confirmTagDeletion')}- confirmCallback={result => {- if (result) {- const { tagForDeletion } = this.state;- this.onRemoveTag(tagForDeletion);- }- }}- cancelDialogTID={'cancelTagDeletionDialog'}- confirmDialogTID={'confirmTagDeletionDialog'}- confirmDialogContent={'confirmTagDeletionDialogContent'}- />-- <FormControl fullWidth={true} className={classes.fieldContainer}>-- <div className={classes.fieldBox}>- <InputLabel- htmlFor="name-disabled"- shrink={query !== ''}- focused={query !== ''}- error={!isValidQuery && query !== ''}- >- {i18n.t('core:tagOperationTagsPlaceholder')}- </InputLabel>-- <Input- className={classes.tagField}- value={query}- error={!isValidQuery && query !== ''}- onChange={event => this.onChangeQuery(event.target.value)}- onKeyUp={event => {- if (event.key === 'Enter') {- return false;- }- this.onGetSuggestions(event.target.value);- }}- onKeyDown={event => {- if (event.key !== 'Enter') {- return false;- }- this.onAddTag();- }}- />- </div>-- <Button- disabled={!isValidQuery || query === ''}- className={classes.addTagButton}- data-tid="addTag"- color="primary"- onClick={this.onAddTag}- >{i18n.t('core:addTag')}</Button>-- </FormControl>-- {query !== '' && (- <div- className={`suggestions ${classes.suggestions} ${isValidQuery && suggestionsLength > 0 ? 'active' : ''}`}- title={i18n.t('core:existingTags')}- >- {suggestions.map(suggestion => (- <button- className={`trigger add-suggestion ${classes.addSuggestion}`}- key={suggestion.title}- title={`${i18n.t('core:addTag')} '${suggestion.title}'`}- onClick={() => this.onAddTag(suggestion)}- >- {suggestion.title}- </button>- ))}- </div>- )}-- {newlyAddedTags.length > 0 && (- <div className={`tags ${classes.tags} ${tags.length > 0 ? 'active' : ''}`}>- {newlyAddedTags.map(tag => (- <div key={tag.title} className={`tag ${classes.tag}`}>- <span className="text">{tag.title}</span>-- <button- className={`trigger remove-tag ${classes.removeTagButton}`}- title={`${i18n.t('core:removeTag')} '${tag.title}'`}- onClick={() => {- this.onRemoveTag(tag);- }}- >- <CloseIcon style={{ fill: '#fff', pointerEvents: 'none' }} />- </button>- </div>- ))}- </div>- )}-- <div className={`component-tip ${classes.componentTip} ${!isValidQuery && query !== '' ? 'active' : ''}`}>- <span className="text">- {i18n.t('core:editTagNamesRestrictionsHelp')}- </span>- </div>-- </div>- );- }-}--const mapStateToProps = state => ({- tagGroups: getTagGroups(state)-});--export default connect(mapStateToProps)(withStyles(styles)(TagAutoSuggestion));diff --git a/app/components/TagAutosuggestion/style/index.js b/app/components/TagAutosuggestion/style/index.jsdeleted file mode 100644index 074fae36f..000000000--- a/app/components/TagAutosuggestion/style/index.js+++ /dev/null@@ -1,134 +0,0 @@-/**- * 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- */--export default () => ({- component: {- position: 'relative',- width: '640px',- height: '260px',- maxWidth: '100%',- overflow: 'visible'- },- componentTip: {- display: 'none',- padding: '10px 0 0 0',- fontSize: '12px',- color: '#f44336',- '&.active': {- display: 'block'- }- },- fieldContainer: {- position: 'relative',- display: 'flex',- flexDirection: 'row',- justifyContent: 'space-between',- alignItems: 'center'- },- fieldBox: {- width: '100%',- position: 'relative',- display: 'flex',- flexDirection: 'row',- justifyContent: 'space-between',- alignItems: 'center'- },- tagField: {- width: '100%'- },- addTagButton: {- width: '120px',- margin: '16px 0 0 16px'- },- suggestions: {- position: 'absolute',- top: 52,- left: 0,- right: 0,- margin: '0 auto',- width: 'calc(100% - 2px)',- maxHeight: '200px',- overflowY: 'overlay',- overflowX: 'hidden',- display: 'none',- backgroundColor: '#fff',- zIndex: 100,- boxShadow: '0 1px 1px 0 rgba(0, 0, 0, 0.16),0 1px 1px 0 rgba(239, 239, 239, 0.12)',- '&.active': {- display: 'block'- }- },- addSuggestion: {- width: '100%',- border: 'none',- backgroundColor: 'transparent',- textAlign: 'left',- transition: 'all 0.15s ease-in-out',- padding: '12px',- '&:not(:last-child)': {- borderBottom: '1px solid rgba(0, 0, 0, 0.16)'- },- '&:hover, &:active, &:focus': {- border: 'none',- outline: 'none',- cursor: 'pointer',- backgroundColor: '#1dd19f',- color: '#fff',- transition: 'all 0.15s ease-in-out'- }- },- tags: {- display: 'flex',- flexDirection: 'row',- justifyContent: 'flex-start',- alignItems: 'flex-start',- flexWrap: 'wrap',- padding: '10px 0 0 0',- margin: 0,- backgroundColor: '#f9f7f7',- borderRadius: 4,- '&.active': {- margin: '20px 0 0 0'- }- },- 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'- },- removeTagButton: {- border: 'none',- backgroundColor: '#008000',- padding: 0,- position: 'relative',- left: 4,- top: 1,- '&:hover, &:active, &:focus': {- cursor: 'pointer',- outline: 'none'- }- }-});diff --git a/app/components/dialogs/AddRemoveTagsDialog.js b/app/components/dialogs/AddRemoveTagsDialog.jsindex 3bacd13e3..ad83b81ce 100644--- a/app/components/dialogs/AddRemoveTagsDialog.js+++ b/app/components/dialogs/AddRemoveTagsDialog.js@@ -24,55 +24,32 @@ import DialogActions from '@material-ui/core/DialogActions';import DialogContent from '@material-ui/core/DialogContent';import DialogTitle from '@material-ui/core/DialogTitle';import GenericDialog from './GenericDialog';-import { type Tag, getAllTags } from '../../reducers/taglibrary';-import TagAutosuggestion from '../TagAutosuggestion/';+import { type Tag } from '../../reducers/taglibrary';+import TagAutoSuggestion from '../TagAutoSuggestion';import i18n from '../../services/i18n';-import ConfirmDialog from '../dialogs/ConfirmDialog';-import { isArr, isObj, shape } from '../../utils/misc';type Props = {open: boolean,+ selectedEntries?: Array<Object>,onClose: () => void,- selectedItems?: Array<Object>,- selectedItem?: Object,addTags: (paths: Array<string>, tags: Array<Tag>) => void,- allTags?: Array<Tag>,- selectedEntries?: Array,- isSingleFile?: boolean,removeTags: (paths: Array<string>, tags: Array<Tag>) => void,removeAllTags: (paths: Array<string>) => void};type State = {- inputError?: boolean,disableConfirmButton?: boolean,open?: boolean,- tags?: Array<Tag>,- selectedTags?: Array<Tag>,- selectedItem?: Object,+ newlyAddedTags?: Array<Tag>,isConfirmDialogOpened?: boolean};class AddRemoveTagsDialog extends React.Component<Props, State> {state = {- inputError: false,disableConfirmButton: true,newlyAddedTags: [],open: false,- tags: [],- selectedTags: [],- selectedItem: {},- isConfirmDialogOpened: false,- isRemoveAllTags: true- };-- onRemoveAllTags = () => {- const { selectedItem, removeAllTags } = this.props;- removeAllTags([selectedItem.path]);- };-- onRemoveNewlyAddedTags = () => {- this.setState({ newlyAddedTags: [] });+ isConfirmDialogOpened: false};onAddTag = (tag) => {@@ -87,24 +64,21 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {this.setState({ newlyAddedTags: modifiedTags });};+ onClose = () => {+ this.setState({newlyAddedTags: []});+ this.props.onClose();+ }+render() {const {open,- allTags,- selectedItems,- selectedItem,- selectedEntries,- isSingleFile = false,+ selectedEntries = [],addTags,removeTags,removeAllTags,onClose} = this.props;- const { newlyAddedTags, isRemoveAllTags } = this.state;-- const selectedEntriesTagCount = !isSingleFile- ? isArr(selectedEntries) && isObj(selectedEntries[0]) ? shape(selectedEntries).reduceTo('tags').fetch().length : 0- : isObj(selectedItem) && isArr(selectedItem.tags) ? selectedItem.tags.length : 0;+ const { newlyAddedTags = [] } = this.state;return (<GenericDialog@@ -115,52 +89,11 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {)}renderContent={() => (<DialogContent>-- <ConfirmDialog- open={this.state.isConfirmDialogOpened}- onClose={() => {- this.setState({- isConfirmDialogOpened: false- });- }}- title={i18n.t('core:confirm')}- content={i18n.t(`core:${isRemoveAllTags ? 'confirmAllTagsDeletion' : 'confirmSelectedTagsDeletion'}`)}- confirmCallback={result => {- if (result) {- if (isRemoveAllTags) {- this.onRemoveAllTags();- } else {- if (!isArr(selectedEntries)) {- removeTags([selectedItem.path], newlyAddedTags);- } else {- const paths = shape(selectedEntries)- .filterByUnique('uuid')- .reduceTo('path')- .fetch();- removeTags(paths, newlyAddedTags);- }- this.onRemoveNewlyAddedTags();- onClose();- }- this.onRemoveNewlyAddedTags();- onClose();- }- }}- cancelDialogTID={'cancelAllTagsDeletionDialog'}- confirmDialogTID={'confirmAllTagsDeletionDialog'}- confirmDialogContent={'confirmAllTagsDeletionDialogContent'}- />-- <TagAutosuggestion- isModalOpened={open}- selectedItem={selectedItem}- selectedItems={selectedItems}+ <TagAutoSuggestionselectedEntries={selectedEntries}newlyAddedTags={newlyAddedTags}- allTags={allTags}- addTags={this.onAddTag}- removeTags={this.onRemoveTag}- removeAllTags={removeAllTags}+ onAddTag={this.onAddTag}+ onRemoveTag={this.onRemoveTag}/></DialogContent>)}@@ -168,48 +101,57 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {<DialogActions><Buttondata-tid="cancel"- onClick={() => {- this.onRemoveNewlyAddedTags();- onClose();- }}+ onClick={this.onClose}>{i18n.t('core:cancel')}</Button><Button- data-tid="cleanTags"- disabled={selectedEntriesTagCount === 0}- onClick={() => this.setState({ isConfirmDialogOpened: true })}+ data-tid="cleanTagsMultipleEntries"+ disabled={selectedEntries.length < 1}+ onClick={() => {+ if (selectedEntries && selectedEntries.length > 0) {+ const paths = [];+ selectedEntries.map((entry) => {+ paths.push(entry.path);+ return true;+ });+ removeAllTags(paths);+ }+ this.onClose();+ }}>{i18n.t('core:tagOperationCleanTags')}</Button><Button- data-tid="ok"- disabled={newlyAddedTags.length === 0}+ data-tid="removeTagsMultipleEntries"+ disabled={newlyAddedTags.length === 0 || selectedEntries.length < 1}onClick={() => {- this.setState({- isConfirmDialogOpened: true,- isRemoveAllTags: false- });+ if (selectedEntries && selectedEntries.length > 0) {+ const paths = [];+ selectedEntries.map((entry) => {+ paths.push(entry.path);+ return true;+ });+ removeTags(paths, newlyAddedTags);+ }+ this.onClose();}}>{i18n.t('core:tagOperationRemoveTag')}</Button><Button- data-tid="ok"- color="primary"- disabled={newlyAddedTags.length === 0}+ data-tid="addTagsMultipleEntries"+ disabled={newlyAddedTags.length < 1 || selectedEntries.length < 1}onClick={() => {- if (!isArr(selectedEntries)) {- addTags([selectedItem.path], newlyAddedTags);- } else {- const paths = shape(selectedEntries)- .filterByUnique('uuid')- .reduceTo('path')- .fetch();+ if (selectedEntries && selectedEntries.length > 0) {+ const paths = [];+ selectedEntries.map((entry) => {+ paths.push(entry.path);+ return true;+ });addTags(paths, newlyAddedTags);}- this.onRemoveNewlyAddedTags();- onClose();+ this.onClose();}}>{i18n.t('core:tagOperationAddTag')}@@ -221,10 +163,4 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {}}-function mapStateToProps(state) {- return {- allTags: getAllTags(state),- };-}--export default connect(mapStateToProps)(AddRemoveTagsDialog);+export default AddRemoveTagsDialog;diff --git a/app/components/dialogs/CreateFileDialog.js b/app/components/dialogs/CreateFileDialog.jsindex bfe6dcf07..a512055df 100644--- a/app/components/dialogs/CreateFileDialog.js+++ b/app/components/dialogs/CreateFileDialog.js@@ -41,7 +41,7 @@ import InputAdornment from '@material-ui/core/InputAdornment';import GenericDialog, { onEnterKeyHandler } from './GenericDialog';import i18n from '../../services/i18n';import { type Tag } from '../../reducers/taglibrary';-import TagAutosuggestion from '../TagAutosuggestion/';+import TagAutoSuggestion from '../TagAutoSuggestion';import { formatDateTime4Tag } from '../../utils/misc';import AppConfig from '../../config';import TaggingActions from '../../reducers/tagging-actions';@@ -268,7 +268,7 @@ class CreateFileDialog extends React.Component<Props, State> {</ListItem>{/* <FormControl fullWidth={true} style={{ overflow: 'visible', margin: '0 0 10px 0' }}><FormHelperText>{i18n.t('core:fileTags')}</FormHelperText>- <TagAutosuggestion+ <TagAutoSuggestionheight={120}isModalOpened={open}selectedItem={{}}diff --git a/app/perspectives/grid-perspective/src/index.js b/app/perspectives/grid-perspective/src/index.jsindex ddf361337..fec4ab2dd 100644--- a/app/perspectives/grid-perspective/src/index.js+++ b/app/perspectives/grid-perspective/src/index.js@@ -233,7 +233,6 @@ type Props = {};type State = {- selectedItem?: Object,fileContextMenuAnchorEl?: Object | null,fileContextMenuOpened?: boolean,dirContextMenuAnchorEl?: Object | null,@@ -258,12 +257,11 @@ type State = {isFileRenameDialogOpened?: boolean,selectedEntryPath?: string,selectedTag?: Tag | null,- selectedEntries?: Array+ selectedEntries?: Array<Object>};class GridPerspective extends React.Component<Props, State> {state = {- selectedItem: {},fileContextMenuOpened: false,fileContextMenuAnchorEl: null,dirContextMenuOpened: false,@@ -626,16 +624,14 @@ class GridPerspective extends React.Component<Props, State> {selectedEntryPath: fsEntry.path,selectedEntries: event.ctrlKey? [...selectedEntries, fsEntry]- : [fsEntry],- selectedItem: fsEntry+ : [fsEntry]});} else {this.setState({dirContextMenuOpened: true,dirContextMenuAnchorEl: event.currentTarget,selectedEntryPath: fsEntry.path,- selectedEntries: [fsEntry],- selectedItem: fsEntry+ selectedEntries: [fsEntry]});}};@@ -1069,14 +1065,12 @@ class GridPerspective extends React.Component<Props, State> {</div></div><AddRemoveTagsDialog- selectedItem={this.state.selectedItem}open={this.state.isAddRemoveTagsDialogOpened}onClose={this.handleCloseDialogs}- selectedEntries={this.props.selectedEntries}- selectedItems={[this.state.selectedEntryPath]}addTags={this.props.addTags}removeTags={this.props.removeTags}removeAllTags={this.props.removeAllTags}+ selectedEntries={this.state.selectedEntries}/><MoveCopyFilesDialogopen={this.state.isMoveCopyFilesDialogOpened}