TagSpaces is an offline, open source, document manager with tagging support
ui-improvements for the search (#1510)
Stanimirbb447ba37564
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex 25ed155c3..a3f1044d4 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -64,7 +64,10 @@ import PathBreadcrumbs from './PathBreadcrumbs';import { enhanceOpenedEntry } from '-/services/utils-io';import SearchInline from '-/components/SearchInline';import SearchPopover from '-/components/SearchPopover';-import { getSearchQuery } from '-/reducers/location-index';+import {+ actions as LocationIndexActions,+ getSearchQuery+} from '-/reducers/location-index';const GridPerspective = React.lazy(() =>import(@@ -159,13 +162,6 @@ const styles: any = (theme: any) => ({display: 'flex',flexDirection: 'column'},- toolbar: {- paddingLeft: 5,- paddingRight: 5,- paddingTop: 5,- display: 'flex'- // overflowX: AppConfig.isFirefox ? 'auto' : 'overlay'- },topPanel: {// height: 50,width: '100%',@@ -229,7 +225,7 @@ interface Props {isReadOnlyMode: boolean;isDesktopMode: boolean;showNotification: (content: string) => void;- openSearchPanel: () => void;+ // openSearchPanel: () => void;toggleDrawer?: () => void;drawerOpened: boolean;setCurrentDirectoryPerspective: (perspective: string) => void;@@ -244,6 +240,8 @@ interface Props {toggleUploadDialog: () => void;progress?: Array<any>;searchQuery: TS.SearchQuery;+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;+ openCurrentDirectory: () => void;}const FolderContainer = (props: Props) => {@@ -382,15 +380,13 @@ const FolderContainer = (props: Props) => {const {currentDirectoryPath = '',loadDirectoryContent,- searchResultCount,+ // searchResultCount,classes,- maxSearchResults,- openSearchPanel,+ // maxSearchResults,toggleDrawer,drawerOpened,isDesktopMode,theme,- loadParentDirectoryContent,currentDirectoryPerspective,currentLocationPath,setSelectedEntries,@@ -400,13 +396,13 @@ const FolderContainer = (props: Props) => {// rightPanelWidth} = props;- let searchResultCounterText = searchResultCount + ' ' + i18n.t('entries');+ /* let searchResultCounterText = searchResultCount + ' ' + i18n.t('entries');if (searchResultCount >= maxSearchResults) {searchResultCounterText ='Max. search count reached, showing only the first ' +searchResultCount +' entries.';- }+ } */const currentPerspective =currentDirectoryPerspective || perspectives.DEFAULT;@@ -455,18 +451,16 @@ const FolderContainer = (props: Props) => {<div data-tid="folderContainerTID" style={{ position: 'relative' }}><div className={classes.mainPanel}><div className={classes.topPanel}>- <div className={classes.toolbar}>- <Button+ <div style={{ paddingLeft: 5, display: 'flex' }}>+ <IconButtonid="mobileMenuButton"style={{- marginLeft: -8,- transform: drawerOpened ? 'rotate(0deg)' : 'rotate(180deg)',- maxHeight: 40+ transform: drawerOpened ? 'rotate(0deg)' : 'rotate(180deg)'}}onClick={toggleDrawer}><MenuIcon />- </Button>+ </IconButton>{/* <CounterBadgeshowZero={true}title={searchResultCounterText}@@ -477,32 +471,33 @@ const FolderContainer = (props: Props) => {openSearchPanel();}}/> */}- <Button- id="toggleSearch"- style={{- marginLeft: -8,- maxHeight: 40+ <IconButton+ data-tid="toggleSearch"+ onClick={() => {+ if (isSearchVisible) {+ props.setSearchQuery({});+ props.openCurrentDirectory();+ } else {+ setSearchVisible(!isSearchVisible);+ }+ return true;}}- size="small"- onClick={() => setSearchVisible(!isSearchVisible)}><SearchIcon />- </Button>+ </IconButton>{isSearchVisible ? (<><SearchInline />- <Button+ <IconButtonid="advancedButton"title={i18n.t('core:advancedSearch')}data-tid="advancedSearch"onClick={(event: React.MouseEvent<HTMLButtonElement>) =>setAnchorSearch(event.currentTarget)}- // @ts-ignore- className={[classes.button, classes.upgradeButton].join(' ')}><AdvancedSearchIcon />- </Button>+ </IconButton><Popoveropen={Boolean(anchorSearch)}anchorEl={anchorSearch}@@ -660,10 +655,12 @@ function mapActionCreatorsToProps(dispatch) {loadParentDirectoryContent: AppActions.loadParentDirectoryContent,setSelectedEntries: AppActions.setSelectedEntries,showNotification: AppActions.showNotification,- openSearchPanel: AppActions.openSearchPanel,+ // openSearchPanel: AppActions.openSearchPanel,setCurrentDirectoryPerspective: AppActions.setCurrentDirectoryPerspective,updateCurrentDirEntry: AppActions.updateCurrentDirEntry,- setCurrentDirectoryColor: AppActions.setCurrentDirectoryColor+ setCurrentDirectoryColor: AppActions.setCurrentDirectoryColor,+ setSearchQuery: LocationIndexActions.setSearchQuery,+ openCurrentDirectory: AppActions.openCurrentDirectory},dispatch);diff --git a/app/components/PathBreadcrumbs.tsx b/app/components/PathBreadcrumbs.tsxindex 323d94dcb..81551209e 100644--- a/app/components/PathBreadcrumbs.tsx+++ b/app/components/PathBreadcrumbs.tsx@@ -46,7 +46,7 @@ const StyledBreadcrumb = withStyles((theme: Theme) => ({const NoWrapBreadcrumb = withStyles({root: {- marginTop: 5+ marginTop: 10},ol: {flexWrap: 'nowrap'diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsxindex 0ffeff155..0e9939ec1 100644--- a/app/components/SearchInline.tsx+++ b/app/components/SearchInline.tsx@@ -19,8 +19,12 @@import React, { useEffect, useReducer, useRef, useState } from 'react';import { bindActionCreators } from 'redux';import { connect } from 'react-redux';-import { makeStyles, Theme } from '@material-ui/core/styles';+import { withStyles } from '@material-ui/core/styles';import ClearSearchIcon from '@material-ui/icons/Clear';+import Button from '@material-ui/core/Button';+import IconButton from '@material-ui/core/IconButton';+import InputAdornment from '@material-ui/core/InputAdornment';+import TextField from '@material-ui/core/TextField';import { actions as AppActions, getDirectoryPath } from '../reducers/app';import {actions as LocationIndexActions,@@ -32,22 +36,11 @@ import {getMaxSearchResults,getShowUnixHiddenEntries} from '-/reducers/settings';-import { styles, StyleProps } from './SearchInline.css';import i18n from '../services/i18n';import { FileTypeGroups } from '-/services/search';import { TS } from '-/tagspaces.namespace';-import {- FormControl,- IconButton,- InputAdornment,- TextField,- OutlinedInput,- ButtonGroup,- Button,- Grid-} from '@material-ui/core';-type PropsClasses = Record<keyof StyleProps, string>;+// type PropsClasses = Record<keyof StyleProps, string>;interface Props {style?: any;@@ -57,7 +50,7 @@ interface Props {loadDirectoryContent: (path: string, generateThumbnails: boolean) => void;openURLExternally: (url: string) => void;searchQuery: TS.SearchQuery; // () => any;- setSearchResults: (entries: Array<any>) => void;+ openCurrentDirectory: () => void;setSearchQuery: (searchQuery: TS.SearchQuery) => void;currentDirectory: string;indexedEntriesCount: number;@@ -66,10 +59,7 @@ interface Props {showUnixHiddenEntries: boolean;}-const useStyles = makeStyles<Theme, StyleProps>(styles);-const SearchInline = (props: Props) => {- const classes: PropsClasses = useStyles({} as StyleProps);const [, forceUpdate] = useReducer(x => x + 1, 0);const textQuery = useRef<string>(props.searchQuery.textQuery);const fileTypes = useRef<Array<string>>(@@ -126,7 +116,7 @@ const SearchInline = (props: Props) => {textQuery.current = props.searchQuery.textQuery;}, [props.searchQuery]);- const mergeWithExtractedTags = (tags: Array<TS.Tag>, identifier: string) => {+ /* const mergeWithExtractedTags = (tags: Array<TS.Tag>, identifier: string) => {const extractedTags = parseTextQuery(identifier);if (tags) {if (extractedTags.length > 0) {@@ -138,7 +128,7 @@ const SearchInline = (props: Props) => {return extractedTags;}return undefined;- };+ }; */function getUniqueTags(tags1: Array<TS.Tag>, tags2: Array<TS.Tag>) {const mergedArray = [...tags1, ...tags2];@@ -169,7 +159,6 @@ const SearchInline = (props: Props) => {);}const textQueryParts = query.split(' ');- let newTextQuery = '';if (textQueryParts) {// && textQueryParts.length > 1) {textQueryParts.forEach(part => {@@ -177,16 +166,9 @@ const SearchInline = (props: Props) => {if (trimmedPart.startsWith(identifier)) {const tagTitle = trimmedPart.substr(1).trim();extractedTags.push({ title: tagTitle });- } /* else if (trimmedPart.startsWith('-')) {- // add to searchQuery.tagsNOT- } else if (trimmedPart.startsWith('?')) {- // add to searchQuery.tagsOR- */ else {- newTextQuery += trimmedPart + ' ';}});}- textQuery.current = newTextQuery.trim();return extractedTags;};@@ -197,17 +179,11 @@ const SearchInline = (props: Props) => {const startSearch = event => {if (event.key === 'Enter' || event.keyCode === 13) {executeSearch();+ } else if (event.key === 'Escape' || event.keyCode === 27) {+ clearSearch();}};- function openCurrentDirectory() {- if (props.currentDirectory) {- props.loadDirectoryContent(props.currentDirectory, false);- } else {- props.setSearchResults([]);- }- }-const clearSearch = () => {textQuery.current = '';searchBoxing.current = 'location';@@ -224,16 +200,42 @@ const SearchInline = (props: Props) => {forceIndexing.current = false;fileSize.current = '';props.setSearchQuery({});- openCurrentDirectory();+ props.openCurrentDirectory();+ };++ const removeTagsFromQuery = (+ tags: Array<TS.Tag>,+ query: string,+ identifier: string+ ) => {+ if (tags) {+ let newQuery = query+ .trim()+ .replace(+ new RegExp(escapeRegExp(identifier) + '\\s+', 'g'),+ identifier+ );+ tags.forEach(tag => {+ newQuery = newQuery.replace(identifier + tag.title, '');+ });++ return newQuery.trim();+ }++ return query;};const executeSearch = () => {const { searchAllLocations, searchLocationIndex } = props;- const tagsAND = mergeWithExtractedTags(props.searchQuery.tagsAND, '+');- const tagsOR = mergeWithExtractedTags(props.searchQuery.tagsOR, '?');- const tagsNOT = mergeWithExtractedTags(props.searchQuery.tagsNOT, '-');+ let query = textQuery.current;+ const tagsAND = parseTextQuery('+'); // mergeWithExtractedTags(props.searchQuery.tagsAND, '+');+ query = removeTagsFromQuery(tagsAND, query, '+');+ const tagsOR = parseTextQuery('?'); // mergeWithExtractedTags(props.searchQuery.tagsOR, '?');+ query = removeTagsFromQuery(tagsOR, query, '?');+ const tagsNOT = parseTextQuery('-'); // mergeWithExtractedTags(props.searchQuery.tagsNOT, '-');+ query = removeTagsFromQuery(tagsNOT, query, '-');const searchQuery: TS.SearchQuery = {- textQuery: textQuery.current,+ textQuery: query,tagsAND,tagsOR,tagsNOT,@@ -261,22 +263,40 @@ const SearchInline = (props: Props) => {}};+ const MeainSearchField = withStyles({+ root: {+ '& input': {+ padding: 7+ },+ overflow: 'hidden',+ borderRadius: 7,+ // backgroundColor: '#fcfcfb',+ '&:hover': {+ backgroundColor: '#fff'+ }+ }+ })(TextField);+const { indexing } = props;return (<div style={{ width: '100%', whiteSpace: 'nowrap' }}>- <TextField+ <MeainSearchFieldfullWidthid="textQuery"name="textQuery"value={textQuery.current}- // variant="filled"+ variant="outlined"onChange={event => {textQuery.current = event.target.value;// rerenderforceUpdate();}}- style={{ marginTop: 0, width: 'calc(100% - 80px)', marginRight: 10 }}+ size="small"+ style={{+ marginTop: 9,+ width: 'calc(100% - 80px)'+ }}inputRef={mainSearchField}margin="dense"autoFocus@@ -302,6 +322,7 @@ const SearchInline = (props: Props) => {variant="outlined"size="small"disabled={indexing}+ style={{ marginRight: 10, marginLeft: 10, marginTop: 10 }}// variant="outlined"color="primary"onClick={clickSearchButton}@@ -332,7 +353,7 @@ function mapDispatchToProps(dispatch) {createLocationsIndexes: LocationIndexActions.createLocationsIndexes,loadDirectoryContent: AppActions.loadDirectoryContent,openURLExternally: AppActions.openURLExternally,- setSearchResults: AppActions.setSearchResults+ openCurrentDirectory: AppActions.openCurrentDirectory},dispatch);diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsxindex 3ba37a46c..3fd836519 100644--- a/app/components/SearchPopover.tsx+++ b/app/components/SearchPopover.tsx@@ -96,7 +96,7 @@ interface Props {searches: Array<TS.SearchQuery>;addSearches: (searches: Array<TS.SearchQuery>) => void;showUnixHiddenEntries: boolean;- openSearchPanel: () => void;+ // openSearchPanel: () => void;onClose: () => void;}@@ -1148,8 +1148,8 @@ function mapDispatchToProps(dispatch) {loadDirectoryContent: AppActions.loadDirectoryContent,openURLExternally: AppActions.openURLExternally,setSearchResults: AppActions.setSearchResults,- addSearches: SearchActions.addSearches,- openSearchPanel: AppActions.openSearchPanel+ addSearches: SearchActions.addSearches+ // openSearchPanel: AppActions.openSearchPanel},dispatch);diff --git a/app/components/menus/EntryTagMenu.tsx b/app/components/menus/EntryTagMenu.tsxindex 0bedab6ec..6431a30da 100644--- a/app/components/menus/EntryTagMenu.tsx+++ b/app/components/menus/EntryTagMenu.tsx@@ -44,7 +44,7 @@ interface Props {removeTags: (paths: Array<string>, tags: Array<TS.Tag>) => void;searchLocationIndex?: (searchQuery: TS.SearchQuery) => void;maxSearchResults?: number;- openSearchPanel?: () => void;+ // openSearchPanel?: () => void;setIsAddTagDialogOpened?: (tag: TS.Tag) => void;toggleEditTagDialog?: (tag: TS.Tag) => void;isReadOnlyMode?: boolean;@@ -73,7 +73,7 @@ const EntryTagMenu = (props: Props) => {function showFilesWithThisTag() {if (props.selectedTag) {- props.openSearchPanel();+ // props.openSearchPanel();props.searchLocationIndex({tagsAND: [props.selectedTag],maxSearchResults: props.maxSearchResults@@ -177,7 +177,7 @@ function mapDispatchToProps(dispatch) {return bindActionCreators({searchLocationIndex: LocationIndexActions.searchLocationIndex,- openSearchPanel: AppActions.openSearchPanel,+ // openSearchPanel: AppActions.openSearchPanel,toggleEditTagDialog: AppActions.toggleEditTagDialog},dispatchdiff --git a/app/components/menus/LocationMenu.tsx b/app/components/menus/LocationMenu.tsxindex 04fd6c2b8..9c674e94f 100644--- a/app/components/menus/LocationMenu.tsx+++ b/app/components/menus/LocationMenu.tsx@@ -80,7 +80,7 @@ const LocationMenu = (props: Props) => {id="locationMenuButton"onClick={event => setLocationChooserMenuAnchorEl(event.currentTarget)}title={currentLocation && currentLocation.name}- style={{ paddingRight: 0, paddingLeft: 11 }}+ style={{ marginTop: 5, paddingRight: 5, paddingLeft: 5 }}>{currentLocation? locationIcon // this.state.currentLocation.namediff --git a/app/components/menus/TagGroupMenu.tsx b/app/components/menus/TagGroupMenu.tsxindex 45d8e6dbf..276b8129a 100644--- a/app/components/menus/TagGroupMenu.tsx+++ b/app/components/menus/TagGroupMenu.tsx@@ -55,7 +55,7 @@ interface Props {collectTagsFromLocation: (tagGroup: TS.TagGroup) => void;handleCloseTagGroupMenu: () => void;searchLocationIndex: (searchQuery: TS.SearchQuery) => void;- openSearchPanel: () => void;+ // openSearchPanel: () => void;maxSearchResults: number;}@@ -92,7 +92,7 @@ const TagGroupMenu = (props: Props) => {function showFilesWithTags() {if (props.selectedTagGroupEntry) {- props.openSearchPanel();+ // props.openSearchPanel();props.searchLocationIndex({tagsOR: props.selectedTagGroupEntry.children,maxSearchResults: props.maxSearchResults@@ -190,7 +190,7 @@ function mapStateToProps(state) {function mapDispatchToProps(dispatch) {return bindActionCreators({- openSearchPanel: AppActions.openSearchPanel,+ // openSearchPanel: AppActions.openSearchPanel,searchLocationIndex: LocationIndexActions.searchLocationIndex},dispatchdiff --git a/app/components/menus/TagMenu.tsx b/app/components/menus/TagMenu.tsxindex 2c150ea5b..2a7bb2add 100644--- a/app/components/menus/TagMenu.tsx+++ b/app/components/menus/TagMenu.tsx@@ -43,7 +43,7 @@ interface Props {onClose: () => void;selectedTag?: TS.Tag;searchLocationIndex: (searchQuery: TS.SearchQuery) => void;- openSearchPanel: () => void;+ // openSearchPanel: () => void;showEditTagDialog: () => void;showDeleteTagDialog: () => void;maxSearchResults: number;@@ -58,7 +58,7 @@ interface Props {const TagMenu = (props: Props) => {function showFilesWithThisTag() {if (props.selectedTag) {- props.openSearchPanel();+ // props.openSearchPanel();props.searchLocationIndex({tagsAND: [props.selectedTag],maxSearchResults: props.maxSearchResults@@ -134,7 +134,7 @@ function mapStateToProps(state) {function mapDispatchToProps(dispatch) {return bindActionCreators({- openSearchPanel: AppActions.openSearchPanel,+ // openSearchPanel: AppActions.openSearchPanel,searchLocationIndex: LocationIndexActions.searchLocationIndex,addTags: TaggingActions.addTags},diff --git a/app/containers/MainPage.tsx b/app/containers/MainPage.tsxindex 812ee4d7a..8473adca5 100644--- a/app/containers/MainPage.tsx+++ b/app/containers/MainPage.tsx@@ -169,7 +169,7 @@ interface Props {openPrevFile: (path?: string) => void; // needed by electron-menusopenLocationManagerPanel: () => void;openTagLibraryPanel: () => void;- openSearchPanel: () => void;+ // openSearchPanel: () => void;openHelpFeedbackPanel: () => void;closeAllVerticalPanels: () => void;leftSplitSize: number;@@ -403,6 +403,7 @@ const MainPage = (props: Props) => {showFolderNavigator: props.openLocationManagerPanel,showTagLibrary: props.openTagLibraryPanel,openSearch: () => props.setSearchQuery({ textQuery: '' }), // props.openSearchPanel,+ closeSearch: () => props.setSearchQuery({}),showHelp: props.openHelpFeedbackPanel};@@ -412,6 +413,7 @@ const MainPage = (props: Props) => {showFolderNavigator: props.keyBindings.showFolderNavigator,showTagLibrary: props.keyBindings.showTagLibrary,openSearch: props.keyBindings.openSearch,+ closeSearch: props.keyBindings.Escape,showHelp: props.keyBindings.showHelp};@@ -760,7 +762,7 @@ function mapDispatchToProps(dispatch) {reflectCreateEntries: AppActions.reflectCreateEntries,openLocationManagerPanel: AppActions.openLocationManagerPanel,openTagLibraryPanel: AppActions.openTagLibraryPanel,- openSearchPanel: AppActions.openSearchPanel,+ // openSearchPanel: AppActions.openSearchPanel,openHelpFeedbackPanel: AppActions.openHelpFeedbackPanel,closeAllVerticalPanels: AppActions.closeAllVerticalPanels,toggleDeleteMultipleEntriesDialog:diff --git a/app/containers/RendererListener.ts b/app/containers/RendererListener.tsindex 97f33a1cf..63e213c13 100644--- a/app/containers/RendererListener.ts+++ b/app/containers/RendererListener.ts@@ -31,7 +31,7 @@ export default function listen(props) {props.toggleCreateFileDialog();break;case 'open-search':- props.openSearchPanel();+ props.setSearchQuery({ textQuery: '' });break;case 'open-location-manager-panel':props.openLocationManagerPanel();diff --git a/app/electron-tray-menu.ts b/app/electron-tray-menu.tsindex d6d84c8d7..56a5d3103 100644--- a/app/electron-tray-menu.ts+++ b/app/electron-tray-menu.ts@@ -52,7 +52,7 @@ export default function buildTrayIconMenu(mainPageProps: any, i18n, isMacLike) {},{label: i18n.t('showSearch') + cKey + '+Shift+F',- click: mainPageProps.openSearchPanel+ click: mainPageProps.openSearch},{type: 'separator'diff --git a/app/main.dev.ts b/app/main.dev.tsindex a72d004c8..c400e2bd3 100644--- a/app/main.dev.ts+++ b/app/main.dev.ts@@ -307,7 +307,7 @@ function buildTrayMenu() {{showTagSpaces,resumePlayback,- openSearchPanel: showSearch,+ openSearch: showSearch,toggleCreateFileDialog: newTextFile,openNextFile: getNextFile,openPrevFile: getPreviousFile,@@ -322,7 +322,7 @@ function buildAppMenu() {buildDesktopMenu({showTagSpaces,- openSearchPanel: showSearch,+ openSearch: showSearch,toggleCreateFileDialog: newTextFile,openNextFile: getNextFile,openPrevFile: getPreviousFile,diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex c851af51e..a7f7f6e37 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -724,7 +724,7 @@ const GridPerspective = (props: Props) => {return (<divstyle={{- height: 'calc(100% - 51px)'+ height: 'calc(100% - 48px)'}}><MainToolbardiff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 18f846db7..62d8546fa 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -2097,6 +2097,17 @@ export const actions = {) => {const { currentLocationId } = getState().app;return currentLocationId === uuid;+ },+ openCurrentDirectory: () => (+ dispatch: (actions: Object) => void,+ getState: () => any+ ) => {+ const { currentDirectoryPath } = getState().app;+ if (currentDirectoryPath) {+ dispatch(actions.loadDirectoryContent(currentDirectoryPath, false));+ } else {+ dispatch(actions.setSearchResults([]));+ }}};diff --git a/app/reducers/keybindings-default.ts b/app/reducers/keybindings-default.tsindex dd984ceb2..29b308c40 100644--- a/app/reducers/keybindings-default.ts+++ b/app/reducers/keybindings-default.ts@@ -56,6 +56,10 @@ export default function keyBindings(isMacLike) {name: 'prevDocument',command: 'up'},+ {+ name: 'Escape',+ command: 'Escape'+ },{name: 'showHelp',command: 'f1'diff --git a/app/services/electron-menus.ts b/app/services/electron-menus.tsindex cce99ab33..611bcbaee 100644--- a/app/services/electron-menus.ts+++ b/app/services/electron-menus.ts@@ -120,7 +120,7 @@ export default function buildDesktopMenu(props: any, i18n) {},{label: i18n.t('showSearch'),- click: props.openSearchPanel+ click: props.openSearch},{label: i18n.t('showDevTools'),