TagSpaces is an offline, open source, document manager with tagging support
fixing tag color issues #799
Ilian Sapundshiev9bc1bf1e7602
diff --git a/app/components/TagContainer.js b/app/components/TagContainer.jsindex 235cdf476..4e145d45a 100644--- a/app/components/TagContainer.js+++ b/app/components/TagContainer.js@@ -23,38 +23,27 @@ 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 { type TagGroup, type Tag } from '../reducers/taglibrary';+import { type TagGroup, type Tag, getAllTags } from '../reducers/taglibrary';import { getTagColor, getTagTextColor } from '../reducers/settings';type Props = {tag: Tag,- key?: string,- defaultTextColor?: string,- tagTextColor: string,- defaultBackgroundColor?: string,- tagBackgroundColor: string,- tagGroup?: TagGroup,+ allTags: Array<Tag>,+ key: string,+ defaultTextColor: string,+ defaultBackgroundColor: 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,- tagMode?: 'default' | 'display' | 'remove',- entryPath?: string,- deleteIcon?: Object+ isDragging: boolean,+ tagMode: 'default' | 'display' | 'remove',+ entryPath: string,+ 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- };+class TagContainer extends React.Component<Props> {render() {const {key,@@ -62,15 +51,26 @@ class TagContainer extends React.Component<Props> {deleteIcon,isDragging,defaultTextColor,- tagTextColor,defaultBackgroundColor,- tagBackgroundColor,tagGroup,- entryPath+ entryPath,+ allTags} = this.props;const { tagMode } = this.props;let mode = '';+ let textColor = tag.textcolor || defaultTextColor;+ let backgroundColor = tag.color || defaultBackgroundColor;++ allTags.some((currentTag: Tag) => {+ if (currentTag.title === tag.title) {+ textColor = currentTag.textcolor;+ backgroundColor = currentTag.color;+ return true;+ }+ return false;+ });+if (tagMode === 'remove') {mode = deleteIcon || (<RemoveTagIcon@@ -96,6 +96,7 @@ class TagContainer extends React.Component<Props> {return (<div+ role="presentation"data-tid={'tagContainer_' + tag.title.replace(/ /g, '_')}key={key || tag.id || uuidv1()}onClick={event => { if (this.props.handleTagMenu) { this.props.handleTagMenu(event, tag, entryPath || tagGroup); } }}@@ -115,8 +116,8 @@ class TagContainer extends React.Component<Props> {opacity: isDragging ? 0.5 : 1,fontSize: 13,textTransform: 'none',- color: tag.textcolor || defaultTextColor || tagTextColor,- backgroundColor: tag.color || defaultBackgroundColor || tagBackgroundColor,+ color: textColor,+ backgroundColor,minHeight: 25,margin: 0,paddingTop: 0,@@ -137,8 +138,9 @@ class TagContainer extends React.Component<Props> {function mapStateToProps(state) {return {- tagBackgroundColor: getTagColor(state),- tagTextColor: getTagTextColor(state)+ allTags: getAllTags(state),+ defaultBackgroundColor: getTagColor(state),+ defaultTextColor: getTagTextColor(state)};}export default connect(mapStateToProps)(TagContainer);diff --git a/app/components/TagContainerDnd.js b/app/components/TagContainerDnd.jsindex cafdea656..bc617b7bd 100644--- a/app/components/TagContainerDnd.js+++ b/app/components/TagContainerDnd.js@@ -28,8 +28,6 @@ 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 refactorhandleTagMenu: (event: Object, tag: Tag, entryPath: string) => void,@@ -86,8 +84,6 @@ class TagContainerDnd extends React.Component<Props> {const {key,tag,- defaultTextColor,- defaultBackgroundColor,tagGroup,entryPath,handleTagMenu,@@ -100,8 +96,6 @@ class TagContainerDnd extends React.Component<Props> {<span><TagContainerkey={key}- defaultTextColor={defaultTextColor}- defaultBackgroundColor={defaultBackgroundColor}tag={tag}tagGroup={tagGroup}handleTagMenu={handleTagMenu}diff --git a/app/components/TagLibrary.js b/app/components/TagLibrary.jsindex 5aded5a93..91e4e3937 100644--- a/app/components/TagLibrary.js+++ b/app/components/TagLibrary.js@@ -257,8 +257,6 @@ class TagLibrary extends React.Component<Props, State> {{tagGroup.children && tagGroup.children.map((tag: Tag) => (<TagContainerDndkey={tag.id}- defaultTextColor={this.props.tagTextColor}- defaultBackgroundColor={this.props.tagBackgroundColor}tag={tag}tagGroup={tagGroup}handleTagMenu={this.handleTagMenu}diff --git a/app/components/TagsSelect.js b/app/components/TagsSelect.jsindex 8b6d32f94..28a7e37e4 100644--- a/app/components/TagsSelect.js+++ b/app/components/TagsSelect.js@@ -19,20 +19,17 @@import React from 'react';import { connect } from 'react-redux';-import classNames from 'classnames';import { withStyles } from '@material-ui/core/styles';import Typography from '@material-ui/core/Typography';import Paper from '@material-ui/core/Paper';-import CancelIcon from '@material-ui/icons/Cancel';import CloseIcon from '@material-ui/icons/Close';import MenuItem from '@material-ui/core/MenuItem';-import Chip from '@material-ui/core/Chip';import CreatableSelect from 'react-select/lib/Creatable';import NoSsr from '@material-ui/core/NoSsr';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 { getTagColor, getTagTextColor } from '../reducers/settings';import TagContainer from './TagContainer';const styles = theme => ({@@ -54,15 +51,6 @@ const styles = theme => ({alignItems: 'center',overflow: 'hidden',},- chip: {- margin: `${theme.spacing.unit / 2}px ${theme.spacing.unit / 4}px`,- },- chipFocused: {- backgroundColor: emphasize(- theme.palette.type === 'light' ? theme.palette.grey[300] : theme.palette.grey[700],- 0.08,- ),- },noOptionsMessage: {padding: `${theme.spacing.unit}px ${theme.spacing.unit * 2}px`,},@@ -81,17 +69,6 @@ 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,- }, */});function NoOptionsMessage(props) {@@ -172,26 +149,10 @@ function MultiValue(props) {return (<TagContainerkey={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} />}/>- /* <Chip- tabIndex={-1}- label={props.children}- style={{ fontSize: 16 }}- 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} />}- /> */);}@@ -224,10 +185,10 @@ type Props = {class TagsSelect extends React.Component<Props> {handleChange = (newValue: any, actionMeta: any) => {- /* console.group('Value Changed');- console.log(newValue);- console.log(`action: ${actionMeta.action}`);- console.groupEnd(); */+ // console.group('Value Changed');+ // console.log(JSON.stringify(newValue));+ // console.log(`action: ${actionMeta.action}`);+ // console.groupEnd();if (actionMeta.action === 'select-option') {this.props.handleChange('tagQuery', newValue, actionMeta.action);@@ -248,7 +209,14 @@ class TagsSelect extends React.Component<Props> {selectOptions.find(option => option.name === inputValue));render() {- const { classes, theme, allTags, tagQuery } = this.props;+ const {+ classes,+ theme,+ allTags,+ tagQuery,+ defaultBackgroundColor,+ defaultTextColor+ } = this.props;const selectStyles = {input: base => ({@@ -273,6 +241,8 @@ class TagsSelect extends React.Component<Props> {getNewOptionData={(inputValue, optionLabel) => ({id: inputValue,title: optionLabel,+ color: defaultBackgroundColor,+ textcolor: defaultTextColor})}styles={selectStyles}fullWidth={true}@@ -300,6 +270,8 @@ class TagsSelect extends React.Component<Props> {const mapStateToProps = state => ({allTags: getAllTags(state),+ defaultBackgroundColor: getTagColor(state),+ defaultTextColor: getTagTextColor(state)});diff --git a/app/perspectives/grid-perspective/src/index.js b/app/perspectives/grid-perspective/src/index.jsindex 200181851..d09c6b2d7 100644--- a/app/perspectives/grid-perspective/src/index.js+++ b/app/perspectives/grid-perspective/src/index.js@@ -52,8 +52,6 @@ import {} from '../../../services/utils-io';import { type Tag } from '../../../reducers/taglibrary';import {- getTagTextColor,- getTagColor,getSupportedFileTypes} from '../../../reducers/settings';import { extractTitle } from '../../../utils/paths';@@ -826,8 +824,6 @@ class GridPerspective extends React.Component<Props, State> {renderTag = (tag: Object, fsEntry) => (<TagContainer- defaultTextColor={this.props.tagTextColor}- defaultBackgroundColor={this.props.tagBackgroundColor}tag={tag}key={tag.id}entryPath={fsEntry.path}@@ -1279,8 +1275,6 @@ function mapActionCreatorsToProps(dispatch) {function mapStateToProps(state) {return {- tagTextColor: getTagTextColor(state),- tagBackgroundColor: getTagColor(state),supportedFileTypes: getSupportedFileTypes(state)};}