TagSpaces is an offline, open source, document manager with tagging support
fix: Cleaning "or tags" will clean not tags in advanced search panel (#1511)
Stanimir05f5aaa0d53d
diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsxindex 08bd6f941..698f9625c 100644--- a/app/components/SearchInline.tsx+++ b/app/components/SearchInline.tsx@@ -120,7 +120,7 @@ const SearchInline = (props: Props) => {const mainSearchField = useRef<HTMLInputElement>(null);- useEffect(() => {+ /* useEffect(() => {// https://github.com/mui-org/material-ui/issues/1594const timeout = setTimeout(() => {if (mainSearchField && mainSearchField.current) {@@ -131,10 +131,30 @@ const SearchInline = (props: Props) => {return () => {clearTimeout(timeout);};- }, []);+ }, []); */useEffect(() => {- textQuery.current = props.searchQuery.textQuery;+ let txtQuery = props.searchQuery.textQuery || '';++ if (props.searchQuery.tagsAND && props.searchQuery.tagsAND.length > 0) {+ props.searchQuery.tagsAND.forEach(tag => {+ txtQuery += ' +' + tag.title;+ });+ }+ if (props.searchQuery.tagsOR && props.searchQuery.tagsOR.length > 0) {+ props.searchQuery.tagsOR.forEach(tag => {+ txtQuery += ' ?' + tag.title;+ });+ }+ if (props.searchQuery.tagsNOT && props.searchQuery.tagsNOT.length > 0) {+ props.searchQuery.tagsNOT.forEach(tag => {+ txtQuery += ' -' + tag.title;+ });+ }+ if (txtQuery !== textQuery.current) {+ textQuery.current = txtQuery;+ forceUpdate();+ }}, [props.searchQuery]);/* const mergeWithExtractedTags = (tags: Array<TS.Tag>, identifier: string) => {@@ -151,7 +171,7 @@ const SearchInline = (props: Props) => {return undefined;}; */- function getUniqueTags(tags1: Array<TS.Tag>, tags2: Array<TS.Tag>) {+ /* function getUniqueTags(tags1: Array<TS.Tag>, tags2: Array<TS.Tag>) {const mergedArray = [...tags1, ...tags2];// mergedArray have duplicates, lets remove the duplicates using Setconst set = new Set();@@ -162,7 +182,7 @@ const SearchInline = (props: Props) => {}return false;}, set);- }+ } */function escapeRegExp(string) {return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string@@ -186,7 +206,9 @@ const SearchInline = (props: Props) => {const trimmedPart = part.trim();if (trimmedPart.startsWith(identifier)) {const tagTitle = trimmedPart.substr(1).trim();- extractedTags.push({ title: tagTitle });+ extractedTags.push({+ title: tagTitle+ });}});}@@ -287,17 +309,22 @@ const SearchInline = (props: Props) => {const { indexing } = props;return (- <div style={{ width: '100%', whiteSpace: 'nowrap' }}>+ <div+ style={{+ width: '100%',+ whiteSpace: 'nowrap'+ }}+ ><MeainSearchFieldfullWidthid="textQuery"name="textQuery"- value={textQuery.current}+ defaultValue={textQuery.current}variant="outlined"onChange={event => {textQuery.current = event.target.value;// rerender- forceUpdate();+ // forceUpdate();}}size="small"style={{@@ -329,7 +356,11 @@ const SearchInline = (props: Props) => {variant="outlined"size="small"disabled={indexing}- style={{ marginRight: 10, marginLeft: 10, marginTop: 10 }}+ style={{+ marginRight: 10,+ marginLeft: 10,+ marginTop: 10+ }}// variant="outlined"color="primary"onClick={clickSearchButton}diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsxindex 3fd836519..76de2f2f1 100644--- a/app/components/SearchPopover.tsx+++ b/app/components/SearchPopover.tsx@@ -43,6 +43,7 @@ import TextField from '@material-ui/core/TextField';import InputLabel from '@material-ui/core/InputLabel';import InputAdornment from '@material-ui/core/InputAdornment';import IconButton from '@material-ui/core/IconButton';+import CloseIcon from '@material-ui/icons/Close';import Select from '@material-ui/core/Select';import FormControl from '@material-ui/core/FormControl';import MoreVertIcon from '@material-ui/icons/MoreVert';@@ -619,25 +620,27 @@ const SearchPopover = (props: Props) => {return (<div style={{ maxWidth: 400 }}><div className={classes.toolbar}>- <Typography- className={classNames(classes.panelTitle, classes.header)}- style={{ flex: 0 }}+ <Button+ size="medium"+ data-tid="searchMenu"+ startIcon={<MoreVertIcon />}+ onClick={handleSearchMenu}>{i18n.t('searchTitle')}- </Typography>+ </Button><Typographyvariant="caption"className={classes.header}- style={{ alignSelf: 'center', paddingLeft: 5, display: 'block' }}+ style={{ flex: 1 }}>{indexStatus}</Typography><IconButtonstyle={{ marginLeft: 'auto' }}data-tid="searchMenu"- onClick={handleSearchMenu}+ onClick={clearSearch}>- <MoreVertIcon />+ <CloseIcon /></IconButton></div><SearchMenudiff --git a/app/components/StoredSearches.tsx b/app/components/StoredSearches.tsxindex 2276fa95f..92cc1edae 100644--- a/app/components/StoredSearches.tsx+++ b/app/components/StoredSearches.tsx@@ -19,9 +19,12 @@import React, { useState } from 'react';import { bindActionCreators } from 'redux';import { connect } from 'react-redux';-import { Link, IconButton, Collapse, Grid, styled } from '@material-ui/core';+import { Link, IconButton, Grid, styled } from '@material-ui/core';import EditIcon from '@material-ui/icons/Edit';import SearchIcon from '@material-ui/icons/Search';+import ArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';+import ArrowRightIcon from '@material-ui/icons/KeyboardArrowRight';+import Typography from '@material-ui/core/Typography';import {actions as LocationIndexActions,getSearchQuery@@ -31,8 +34,6 @@ import i18n from '../services/i18n';import { Pro } from '../pro';import { actions as SearchActions, getSearches } from '-/reducers/searches';import { TS } from '-/tagspaces.namespace';-import ArrowDownIcon from '@material-ui/icons/KeyboardArrowDown';-import ArrowUpIcon from '@material-ui/icons/KeyboardArrowUp';interface Props {style?: any;@@ -87,53 +88,56 @@ const StoredSearches = (props: Props) => {...theme.typography.subtitle1,padding: theme.spacing(1),textAlign: 'left',- alignSelf: 'center'- // color: theme.palette.text.secondary+ alignSelf: 'center',+ color: theme.palette.text.secondary}));return (- <div style={{ ...props.style, width: '100%' }}>- <Link- underline="none"- style={{ marginLeft: 10, display: 'flex' }}- onClick={() => setStoredSearchesVisible(!storedSearchesVisible)}- >- <span>{i18n.t('core:savedSearchesTitle')} </span>- {storedSearchesVisible ? <ArrowDownIcon /> : <ArrowUpIcon />}- </Link>- {props.searches.length < 1 && <div>{i18n.t('noSavedSearches')}</div>}- <Collapse in={storedSearchesVisible} timeout="auto" unmountOnExit>- <Grid container onClick={preventDefault}>- {props.searches.map(search => (- <React.Fragment key={search.uuid}>- <Grid- item- xs={10}- style={{- display: 'flex'- }}+ <Grid container direction="row">+ <Grid item xs={2}>+ <IconButton+ style={{ minWidth: 'auto', padding: 7 }}+ onClick={() => setStoredSearchesVisible(!storedSearchesVisible)}+ >+ {storedSearchesVisible ? <ArrowDownIcon /> : <ArrowRightIcon />}+ </IconButton>+ </Grid>+ <Grid item xs={10} style={{ alignSelf: 'center' }}>+ <Typography+ variant="inherit"+ // className={props.classes.header}+ style={{ paddingLeft: 0 }}+ noWrap+ onClick={() => setStoredSearchesVisible(!storedSearchesVisible)}+ >+ {props.searches.length < 1+ ? i18n.t('noSavedSearches')+ : i18n.t('core:savedSearchesTitle')}+ </Typography>+ </Grid>+ {storedSearchesVisible &&+ props.searches.map(search => (+ <React.Fragment key={search.uuid}>+ <Grid item xs={10} style={{ display: 'flex' }}>+ <SearchIcon style={{ alignSelf: 'center' }} />+ <LinkStyled+ variant="body2"+ onClick={() => handleSavedSearchClick(search.uuid)}+ >+ {search.title}+ </LinkStyled>+ </Grid>+ <Grid item xs={2} style={{ display: 'flex' }}>+ <IconButton+ aria-label={i18n.t('core:searchEditBtn')}+ onClick={() => editSearch(search.uuid)}+ data-tid="editSearchTID">- <SearchIcon style={{ alignSelf: 'center' }} />- <LinkStyled- variant="body2"- onClick={() => handleSavedSearchClick(search.uuid)}- >- {search.title}- </LinkStyled>- </Grid>- <Grid item xs={2}>- <IconButton- aria-label={i18n.t('core:searchEditBtn')}- onClick={() => editSearch(search.uuid)}- data-tid="editSearchTID"- >- <EditIcon />- </IconButton>- </Grid>- </React.Fragment>- ))}- </Grid>- </Collapse>+ <EditIcon />+ </IconButton>+ </Grid>+ </React.Fragment>+ ))}{SaveSearchDialog && saveSearchDialogOpened !== undefined && (<SaveSearchDialogopen={saveSearchDialogOpened !== undefined}@@ -157,7 +161,7 @@ const StoredSearches = (props: Props) => {searchQuery={saveSearchDialogOpened}/>)}- </div>+ </Grid>);};diff --git a/app/components/TagContainer.tsx b/app/components/TagContainer.tsxindex 0fef67052..4bbf9a539 100644--- a/app/components/TagContainer.tsx+++ b/app/components/TagContainer.tsx@@ -82,6 +82,7 @@ const TagContainer = (props: Props) => {isTagDate = !isTagGeo && isDateTimeTag(title);}+ // TODO move this in reducerallTags.some((currentTag: TS.Tag) => {if (currentTag.title === title) {textColor = currentTag.textcolor;@@ -254,5 +255,4 @@ function mapStateToProps(state) {// selectedEntries: getSelectedEntries(state)};}--export default connect(mapStateToProps)(React.memo(TagContainer));+export default connect(mapStateToProps)(TagContainer);diff --git a/app/components/TagsSelect.tsx b/app/components/TagsSelect.tsxindex b122fb24c..4a617b4e0 100644--- a/app/components/TagsSelect.tsx+++ b/app/components/TagsSelect.tsx@@ -147,28 +147,22 @@ const TagsSelect = (props: Props) => {const tags = props.tags ? props.tags : [];- const handleTagMenu = useCallback(- (event: React.ChangeEvent<HTMLInputElement>, tag) => {- setTagMenuAnchorEl(event.currentTarget);- setSelectedTag(tag);- },- [tags]- );+ const handleTagMenu = (event: React.ChangeEvent<HTMLInputElement>, tag) => {+ setTagMenuAnchorEl(event.currentTarget);+ setSelectedTag(tag);+ };- const handleRemoveTag = useCallback(- (event, cTag: Array<TS.Tag>) => {- /* const reducedTags = [...tags];+ const handleRemoveTag = (event, cTag: Array<TS.Tag>) => {+ /* const reducedTags = [...tags];for (let i = 0; i < reducedTags.length; i += 1) {if (reducedTags[i].title === cTag.title) {reducedTags.splice(i, 1);}} */- if (cTag.length > 0) {- handleTagChange(event, cTag, 'remove-value');- }- },- [tags]- );+ if (cTag.length > 0) {+ handleTagChange(event, cTag, 'remove-value');+ }+ };const handleCloseTagMenu = () => {setTagMenuAnchorEl(null);diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex 8473adca5..a8fd408a0 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -351,7 +351,7 @@ const MainPage = (props: Props) => {// console.log('Width: ' + width + ' Height: ' + height);setDimensions({ width: w, height: h });- if (props.openedFiles.length > 0) {+ if (props.openedFiles.length > 0 && !props.isEntryInFullWidth) {const isFillWidth = h > w;if (isFillWidth !== props.isEntryInFullWidth) {props.setEntryFullWidth(isFillWidth);diff --git a/app/reducers/settings.ts b/app/reducers/settings.tsindex 045f9075c..25eadc442 100644--- a/app/reducers/settings.ts+++ b/app/reducers/settings.ts@@ -663,7 +663,7 @@ export const getCurrentTheme = (state: any) => state.settings.currentTheme;export const isGlobalKeyBindingEnabled = (state: any) =>state.settings.enableGlobalKeyboardShortcuts;export const getMainVerticalSplitSize = (state: any) =>- state.settings.mainVerticalSplitSize;+ state.settings.mainVSplitSize;export const getTagDelimiter = (state: any) => state.settings.tagDelimiter;export const getMaxSearchResults = (state: any) =>state.settings.maxSearchResult;