TagSpaces is an offline, open source, document manager with tagging support
Search UI Improvements (#1822)
Stanimir5da3551f68bf
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex bb2c59afb..e2b71102a 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -51,7 +51,8 @@ import {getSelectedEntries,getProgress,getEditedEntryPaths,- getSearchResultsCount+ getSearchResultsCount,+ isSearchMode} from '../reducers/app';import TaggingActions from '../reducers/tagging-actions';import LoadingLazy from '../components/LoadingLazy';@@ -219,16 +220,13 @@ interface Props {goBack: () => void;goForward: () => void;searchResultsCount: number;+ isSearchMode: boolean;}function FolderContainer(props: Props) {const havePrevOpenedFile = React.useRef<boolean>(false);const firstRender = useFirstRender();- useEffect(() => {- setSearchVisible(false);- }, [props.currentDirectoryPath]);-useEffect(() => {if (!firstRender &&@@ -283,21 +281,18 @@ function FolderContainer(props: Props) {}}, [props.editedEntryPaths]);- useEffect(() => {- if (!props.searchQuery || Object.keys(props.searchQuery).length === 0) {+ /*useEffect(() => {+ if (props.searchResultsCount === -2) {setSearchVisible(false);} else {setSearchVisible(true);}- }, [props.searchQuery]);+ }, [props.isSearchMode]);*/const [isRenameEntryDialogOpened, setIsRenameEntryDialogOpened] = useState<boolean>(false);- const [isSearchVisible, setSearchVisible] = useState<boolean>(false);- const [anchorSearch, setAnchorSearch] = useState<HTMLButtonElement | null>(- null- );+ // const [isSearchVisible, setSearchVisible] = useState<boolean>(false);const {currentDirectoryPath = '',@@ -579,12 +574,10 @@ function FolderContainer(props: Props) {</IconButton></Tooltip>)}- <SearchBox- open={isSearchVisible}- anchorSearch={anchorSearch}- setAnchorSearch={setAnchorSearch}- />- {!isSearchVisible && (+ {props.isSearchMode ? (+ /* todo rethink if open props is needed */+ <SearchBox open={props.isSearchMode} />+ ) : (<><divstyle={{@@ -614,8 +607,17 @@ function FolderContainer(props: Props) {minWidth: 40,width: 200}}- onKeyDown={() => setSearchVisible(!isSearchVisible)}- onClick={() => setSearchVisible(!isSearchVisible)}+ onKeyDown={+ () =>+ props.setSearchQuery(+ props.isSearchMode ? {} : { textQuery: '' }+ )+ }+ onClick={() =>+ props.setSearchQuery(+ props.isSearchMode ? {} : { textQuery: '' }+ )+ }margin="dense"placeholder={i18n.t('core:searchTitle')}InputProps={{@@ -721,7 +723,8 @@ function mapStateToProps(state) {// keyBindings: getKeyBindingObject(state),defaultPerspective: getDefaultPerspective(state),editedEntryPaths: getEditedEntryPaths(state),- searchResultsCount: getSearchResultsCount(state)+ searchResultsCount: getSearchResultsCount(state),+ isSearchMode: isSearchMode(state)};}@@ -777,7 +780,8 @@ const areEqual = (prevProp: Props, nextProp: Props) =>nextProp.language === prevProp.language &&nextProp.windowHeight === prevProp.windowHeight &&nextProp.searchQuery === prevProp.searchQuery &&- nextProp.searchResultsCount === prevProp.searchResultsCount;+ nextProp.searchResultsCount === prevProp.searchResultsCount &&+ nextProp.isSearchMode === prevProp.isSearchMode;export default connect(mapStateToProps,diff --git a/app/components/SearchAutocomplete.tsx b/app/components/SearchAutocomplete.tsxnew file mode 100644index 000000000..efc57cd1e--- /dev/null+++ b/app/components/SearchAutocomplete.tsx@@ -0,0 +1,1480 @@+/**+ * 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, { useEffect, useReducer, useRef, useState } from 'react';+import { bindActionCreators } from 'redux';+import { connect } from 'react-redux';+import format from 'date-fns/format';+import makeStyles from '@mui/styles/makeStyles';+import HelpOutlineIcon from '@mui/icons-material/HelpOutline';+import Button from '@mui/material/Button';+import Tooltip from '-/components/Tooltip';+import IconButton from '@mui/material/IconButton';+import {+ actions as AppActions,+ getCurrentLocationId,+ getDirectoryPath,+ isSearchMode+} from '../reducers/app';+import {+ actions as LocationIndexActions,+ getIndexedEntriesCount,+ isIndexing,+ getSearchQuery+} from '../reducers/location-index';+import {+ isDesktopMode,+ getMaxSearchResults,+ getShowUnixHiddenEntries,+ getCurrentLanguage+} from '-/reducers/settings';+import i18n from '-/services/i18n';+import { FileTypeGroups } from '-/services/search';+import { TS } from '-/tagspaces.namespace';+import { Pro } from '-/pro';+import useFirstRender from '-/utils/useFirstRender';+import SavedSearchesMenu from '-/components/menus/SavedSearchesMenu';+import AppConfig from '-/AppConfig';+import { Autocomplete, Box, TextField } from '@mui/material';+import {+ accuracy,+ ActionType,+ ExecActions,+ FileSize,+ findAction,+ isAction,+ LastModified,+ scope,+ ScopeType,+ SearchActions,+ SearchOptions,+ SearchOptionType,+ SearchQueryComposition+} from '-/components/SearchOptions';+import { getCurrentLocation, getLocations } from '-/reducers/locations';+import CloseIcon from '@mui/icons-material/Close';+import { getTagLibrary } from '-/services/taglibrary-utils';+import { getBookmarks } from '../../extensions/tagspacespro/modules/bookmarks';+import { getSearches } from '-/reducers/searches';++interface Props {+ style?: any;+ watchForChanges: () => void;+ searchLocationIndex: (searchQuery: TS.SearchQuery) => void;+ createLocationsIndexes: () => void;+ searchAllLocations: (searchQuery: TS.SearchQuery) => void;+ // loadDirectoryContent: (path: string, generateThumbnails: boolean, loadDirMeta?: boolean) => void;+ openURLExternally: (url: string) => void;+ searchQuery: TS.SearchQuery; // () => any;+ // openCurrentDirectory: () => void;+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;+ openLink: (url: string, options?: any) => void;+ currentDirectory: string;+ indexedEntriesCount: number;+ maxSearchResults: number;+ indexing: boolean;+ showUnixHiddenEntries: boolean;+ isDesktop: boolean;+ open: boolean;+ locations: TS.Location[];+ currentLocation: TS.Location;+ openLocationById: (locationId: string) => void;+ isSearchMode: boolean;+ exitSearchMode: () => void;+ setSearchFilter: (filter) => void;+ currentLocationId: string;+ openFsEntry: (fsEntry: TS.FileSystemEntry) => void;+ searches: Array<TS.SearchQuery>;+}++const useStyles = makeStyles(theme => ({+ customWidth: {+ maxWidth: 550+ },+ noMaxWidth: {+ maxWidth: 'none'+ }+}));++function SearchAutocomplete(props: Props) {+ // const [, forceUpdate] = useReducer(x => x + 1, 0);+ const [+ openSavedSearches,+ setOpenSavedSearches+ ] = useState<null | HTMLElement>(null);+ const searchOptions = useRef<Array<SearchOptionType>>(SearchOptions);+ const currentOptions = useRef<string>(undefined);+ // const textQuery = useRef<string>(props.searchQuery.textQuery || ''); // rethink to use inputValue instead+ const textQueryMask = useRef<string>('');+ const fileTypes = useRef<Array<string>>(+ props.searchQuery.fileTypes+ ? props.searchQuery.fileTypes+ : FileTypeGroups.any+ );+ const [ignored, forceUpdate] = useReducer(x => x + 1, 0);++ /*function parseSearchQuery(textQuery: string) {+ if (textQuery) {+ return execActions(textQuery.split(' '), []);+ }+ return [];+ }*/++ const actionValues = useRef<Array<SearchOptionType>>(+ [] //parseSearchQuery(textQueryMask.current)+ );+ const inputValue = useRef<string>(props.searchQuery.textQuery || ''); //getInputValue());++ // const searchBoxing = useRef<'location' | 'folder' | 'global'>(+ // props.searchQuery.searchBoxing ? props.searchQuery.searchBoxing : 'location'+ // );+ const [searchBoxing, setSearchBoxing] = useState<ScopeType>(+ props.searchQuery.searchBoxing || 'location'+ );++ const searchType = useRef<'fuzzy' | 'semistrict' | 'strict'>(+ props.searchQuery.searchType ? props.searchQuery.searchType : 'fuzzy'+ );+ const lastModified = useRef<string>(+ props.searchQuery.lastModified ? props.searchQuery.lastModified : ''+ );+ const tagTimePeriod = useRef<string>('');+ const tagTimePeriodHelper = useRef<string>(' ');+ const tagTimePeriodFrom = useRef<number | null>(+ props.searchQuery.tagTimePeriodFrom+ ? props.searchQuery.tagTimePeriodFrom+ : null+ );+ const tagTimePeriodTo = useRef<number | null>(+ props.searchQuery.tagTimePeriodTo ? props.searchQuery.tagTimePeriodTo : null+ );+ const [tagPlaceLat, setTagPlaceLat] = useState<number | null>(null);+ const [tagPlaceLong, setTagPlaceLong] = useState<number | null>(null);+ // const [tagPlaceRadius, setTagPlaceRadius] = useState<number>(0);+ const forceIndexing = useRef<boolean>(+ props.searchQuery.forceIndexing ? props.searchQuery.forceIndexing : false+ );+ const fileSize = useRef<string>(+ props.searchQuery.fileSize ? props.searchQuery.fileSize : ''+ );++ const mainSearchField = useRef<HTMLInputElement>(null);+ const isOpen = useRef<boolean>(true);++ const firstRender = useFirstRender();++ useEffect(() => {+ if (!firstRender) {+ if (+ props.open &&+ (inputValue.current.length > 0 || actionValues.current.length > 0)+ ) {+ executeSearch();+ }+ }+ }, [props.currentLocation]);++ useEffect(() => {+ if (!firstRender) {+ if (!props.isSearchMode) {+ clearSearch();+ }+ }+ }, [props.isSearchMode]);++ /* let searchBoxingName = i18n.t('location');+ if (searchBoxing === 'global') {+ searchBoxingName = i18n.t('globalSearch');+ } else if (searchBoxing === 'folder') {+ searchBoxingName = i18n.t('folder');+ }*/++ useEffect(() => {+ if (Object.keys(props.searchQuery).length > 0) {+ let emptySearch = true;+ textQueryMask.current = '';++ if (props.searchQuery.tagsAND && props.searchQuery.tagsAND.length > 0) {+ props.searchQuery.tagsAND.forEach(tag => {+ textQueryMask.current += ' +' + tag.title;+ });+ emptySearch = false;+ }+ if (props.searchQuery.tagsOR && props.searchQuery.tagsOR.length > 0) {+ props.searchQuery.tagsOR.forEach(tag => {+ textQueryMask.current += ' |' + tag.title;+ });+ emptySearch = false;+ }+ if (props.searchQuery.tagsNOT && props.searchQuery.tagsNOT.length > 0) {+ props.searchQuery.tagsNOT.forEach(tag => {+ textQueryMask.current += ' -' + tag.title;+ });+ emptySearch = false;+ }++ // inputValue.current = getInputValue();+ if (inputValue.current) {+ emptySearch = false;+ }+ /* if (textQueryMask.current) {+ txtQuery = textQuery.current.replace(textQueryMask.current, '').trim();+ } else if (textQuery.current) {+ txtQuery = textQuery.current; // props.searchQuery.textQuery;+ } else {+ txtQuery = '';+ } */+ const searchQuery = {+ ...props.searchQuery,+ textQuery: inputValue.current+ };+ /* if (textQuery.current) {+ txtQuery = textQuery.current.replace(tagsMask, '');+ } else {+ txtQuery = props.searchQuery.textQuery || '';+ }+ */+ /*textQuery.current =+ inputValue.current + ' ' + textQueryMask.current.trim();*/+ if (mainSearchField.current) {+ mainSearchField.current.value =+ inputValue.current ++ (textQueryMask.current ? ' ' + textQueryMask.current.trim() : '');+ }+ if (props.searchQuery.searchBoxing) {+ setSearchBoxing(props.searchQuery.searchBoxing);+ // searchBoxing.current = props.searchQuery.searchBoxing;+ emptySearch = false;+ }+ if (props.searchQuery.fileTypes) {+ fileTypes.current = props.searchQuery.fileTypes;+ emptySearch = false;+ }+ if (props.searchQuery.searchType) {+ searchType.current = props.searchQuery.searchType;+ emptySearch = false;+ }+ if (props.searchQuery.lastModified) {+ lastModified.current = props.searchQuery.lastModified;+ emptySearch = false;+ }+ if (props.searchQuery.tagTimePeriodFrom) {+ tagTimePeriodFrom.current = props.searchQuery.tagTimePeriodFrom;+ emptySearch = false;+ }+ if (props.searchQuery.tagTimePeriodTo) {+ tagTimePeriodTo.current = props.searchQuery.tagTimePeriodTo;+ emptySearch = false;+ }+ if (props.searchQuery.forceIndexing) {+ forceIndexing.current = props.searchQuery.forceIndexing;+ }+ if (props.searchQuery.fileSize) {+ fileSize.current = props.searchQuery.fileSize;+ emptySearch = false;+ }+ if (!emptySearch) {+ if (searchBoxing === 'global') {+ props.searchAllLocations(searchQuery);+ } else {+ props.searchLocationIndex(searchQuery);+ }+ }+ }+ }, [props.searchQuery]);++ /*function getInputValue() {+ const txtQuery = removeActionsFromQuery(+ inputValue.current.trim(),+ actionValues.current+ );+ // txtQuery = removeAllTagsFromSearchQuery(txtQuery);+ if (txtQuery) {+ return txtQuery;+ }+ return '';+ }*/+ /*const toggleSearchBoxing = () => {+ if (searchBoxing === 'location') {+ setSearchBoxing('folder');+ } else if (searchBoxing === 'folder' && Pro) {+ setSearchBoxing('global');+ } else {+ setSearchBoxing('location');+ }+ };*/++ const clickSearchButton = () => {+ executeSearch();+ };++ const onKeyDownHandler = event => {+ if (event.key === 'Enter' || event.keyCode === 13) {+ if (!isOpen.current) {+ executeSearch();+ } else {+ isOpen.current = false;+ forceUpdate();+ }+ } else if (event.key === 'Escape' || event.keyCode === 27) {+ clearSearch();+ // props.openCurrentDirectory();+ } else if (event.key === 'ArrowDown' || event.keyCode === 40) {+ if (!isOpen.current) {+ isOpen.current = true;+ forceUpdate();+ }+ } else if (event.key === 'Backspace' || event.keyCode === 8) {+ if (inputValue.current.length === 0 && actionValues.current.length > 0) {+ actionValues.current = actionValues.current.slice(0, -1);+ resetActions(actionValues.current);+ isOpen.current = true;+ forceUpdate();+ }+ } else {+ isOpen.current = true;+ }+ };++ function resetValues() {+ inputValue.current = '';+ setSearchBoxing('location');+ searchType.current = 'fuzzy';+ fileTypes.current = FileTypeGroups.any;+ lastModified.current = '';+ tagTimePeriod.current = '';+ tagTimePeriodHelper.current = ' ';+ tagTimePeriodFrom.current = null;+ tagTimePeriodTo.current = null;+ setTagPlaceLat(null);+ setTagPlaceLong(null);+ forceIndexing.current = false;+ fileSize.current = '';+ }+ const clearSearch = () => {+ resetValues();+ props.setSearchQuery({});+ // props.setSearchResults([]);+ props.watchForChanges();+ // props.openCurrentDirectory();+ };++ function removeActionsFromQuery(+ query: string,+ actions: Array<SearchOptionType>+ ) {+ if (actions && actions.length > 0) {+ const queryArr = query+ .split(' ')+ .filter(q => actions.some(action => q !== action.label));+ return queryArr.join(' ');+ }+ return query;+ }++ /*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 handleOpenSavedSearches = (+ event: React.MouseEvent<HTMLButtonElement>+ ) => {+ setOpenSavedSearches(event.currentTarget);+ };++ const classes = useStyles();++ function HelpTooltip(hClasses) {+ return (+ <Tooltip+ classes={{ tooltip: hClasses.customWidth }}+ title={+ <span style={{ fontSize: 14 }}>+ The search query consists of a tag part and a search term. This term+ is optional and can be a single word. The tag part can have one or+ more tags preceded by the following symbols:+ <ul>+ <li>+ + will add only entries having this tag in the search results+ (logical AND)+ </li>+ <li>+ | will include all entries having this tag in the search results+ (logical OR)+ </li>+ <li>+ - will exclude entries having this tags from the search results+ </li>+ </ul>+ Example queries:+ <ul>+ <li>+ "italy +beach -sunset" - will find all files and folders having+ italy in their name and the tag beach but not sunset+ </li>+ <li>+ "|beach |sunset" - will find all files and folder having the+ tags beach or sunset+ </li>+ </ul>+ </span>+ }+ >+ <IconButton size="small" edge="end">+ <HelpOutlineIcon style={{ color: 'lightgray' }} />+ </IconButton>+ </Tooltip>+ );+ }++ function getTags(+ actions: Array<SearchOptionType>,+ action: ActionType+ ): TS.Tag[] {+ if (actions.length > 0) {+ const actionsArr = actions.filter(a => isAction(a.action, action));+ if (actionsArr.length > 0) {+ return actionsArr.map(a => ({+ title:+ a.label.indexOf(action.shortName) === 0+ ? a.label.substring(action.shortName.length)+ : action.fullName && a.label.indexOf(action.fullName) === 0+ ? a.label.substring(action.fullName.length)+ : a.label+ }));+ }+ }+ return [];+ }++ const executeSearch = () => {+ let query = inputValue.current;+ if (+ query.startsWith('ts:?ts') ||+ query.startsWith(AppConfig.tsProtocol + '?ts')+ ) {+ props.openLink(query, { fullWidth: false });+ clearSearch();+ return;+ }+ const tagsAND = getTags(+ actionValues.current,+ SearchQueryComposition.TAG_AND+ );+ const tagsOR = getTags(actionValues.current, SearchQueryComposition.TAG_OR);+ const tagsNOT = getTags(+ actionValues.current,+ SearchQueryComposition.TAG_NOT+ );+ // const tagsAND = parseTextQuery(textQuery.current, '+');+ // query = removeTagsFromQuery(tagsAND, query, '+');+ // const tagsOR = parseTextQuery(textQuery.current, '|');+ // query = removeTagsFromQuery(tagsOR, query, '|');+ // const tagsNOT = parseTextQuery(textQuery.current, '-');+ // query = removeTagsFromQuery(tagsNOT, query, '-');+ // query = removeActionsFromQuery(query, actionValues.current);++ const searchQuery: TS.SearchQuery = {+ textQuery: query,+ tagsAND,+ tagsOR,+ tagsNOT,+ searchBoxing,+ searchType: searchType.current,+ fileTypes: fileTypes.current,+ lastModified: lastModified.current,+ fileSize: fileSize.current,+ tagTimePeriodFrom: tagTimePeriodFrom.current,+ tagTimePeriodTo: tagTimePeriodTo.current,+ tagPlaceLat,+ tagPlaceLong,+ // tagPlaceRadius,+ maxSearchResults: props.maxSearchResults,+ currentDirectory: props.currentDirectory,+ forceIndexing: forceIndexing.current,+ showUnixHiddenEntries: props.showUnixHiddenEntries+ };+ console.log('Search object: ' + JSON.stringify(searchQuery));+ props.setSearchQuery(searchQuery);+ };++ const { indexing, isDesktop, open } = props;++ /*function parseOptions(options: Array<any>) {++ const parsed = [];+ let prevAction;+ for (let i = 0; i < options.length; i++) {+ const option = options[i];+ let label, action;+ if (typeof option === 'object') {+ label = option.label;+ action = option.label;+ } else {+ label = option;+ action = Object.values(SearchActions).find(a => option.startsWith(a));+ }+ if (!action) {+ parsed.push(option);+ }+ prevAction = action;+ }+ return parsed;+ }*/+ function changeOptions(action: string) {+ let optionsChanged = false;+ if (isAction(action, SearchActions.LOCATION)) {+ if (currentOptions.current !== action) {+ currentOptions.current = action;+ searchOptions.current = props.locations.map(location => {+ return {+ id: location.uuid,+ descr: location.path,+ action: ExecActions.OPEN_LOCATION,+ label: location.name+ };+ });+ optionsChanged = true;+ }+ } else if (isAction(action, SearchActions.HISTORY)) {+ if (currentOptions.current !== action) {+ currentOptions.current = action;++ const historyKeys = Pro && Pro.history ? Pro.history.historyKeys : {};+ const fileOpenHistoryItems: Array<TS.HistoryItem> = Pro+ ? Pro.history.getHistory(historyKeys.fileOpenKey)+ : [];+ const folderOpenHistoryItems: Array<TS.HistoryItem> = Pro+ ? Pro.history.getHistory(historyKeys.folderOpenKey)+ : [];+ const fileEditHistoryItems: Array<TS.HistoryItem> = Pro+ ? Pro.history.getHistory(historyKeys.fileEditKey)+ : [];+ function getOptions(+ items: TS.HistoryItem[],+ group: string+ ): SearchOptionType[] {+ if (!items) {+ return [];+ }+ return items.map((item: TS.HistoryItem) => ({+ id: item.lid,+ descr:+ '(' + format(item.creationTimeStamp, 'yyyy-MM-dd HH:mm') + ')',+ action: ExecActions.OPEN_HISTORY,+ fullName: item.url,+ label: item.path,+ group: group+ }));+ }++ searchOptions.current = [+ ...getOptions(fileOpenHistoryItems, i18n.t('core:fileOpenHistory')),+ ...getOptions(+ folderOpenHistoryItems,+ i18n.t('core:folderOpenHistory')+ ),+ ...getOptions(fileEditHistoryItems, i18n.t('core:fileEditHistory'))+ ];+ }+ } else if (isAction(action, SearchActions.BOOK)) {+ if (currentOptions.current !== action) {+ currentOptions.current = action;+ const bookmarks: Array<TS.BookmarkItem> =+ Pro && Pro.bookmarks && Pro.bookmarks.getBookmarks();++ function getOptions(+ items: TS.BookmarkItem[],+ group: string+ ): SearchOptionType[] {+ if (!items) {+ return [];+ }+ return items.map((item: TS.BookmarkItem) => ({+ id: item.creationTimeStamp.toString(),+ descr:+ '(' + format(item.creationTimeStamp, 'yyyy-MM-dd HH:mm') + ')',+ action: ExecActions.OPEN_BOOKMARK,+ fullName: item.url,+ label: item.path,+ group: group+ }));+ }++ searchOptions.current = getOptions(+ bookmarks,+ i18n.t('core:searchBookmarks')+ );+ }+ } else if (isAction(action, SearchActions.SEARCH)) {+ if (currentOptions.current !== action) {+ currentOptions.current = action;++ function getOptions(+ items: TS.SearchQuery[],+ group: string+ ): SearchOptionType[] {+ if (!items) {+ return [];+ }+ return items.map((item: TS.SearchQuery) => ({+ id: item.uuid,+ action: ExecActions.OPEN_SAVED_SEARCHES,+ label: item.title,+ fullName: JSON.stringify(item),+ group: group+ }));+ }++ searchOptions.current = getOptions(+ props.searches,+ i18n.t('core:savedSearchesTitle')+ );+ }+ } else if (+ isAction(action, SearchQueryComposition.TAG_AND) ||+ isAction(action, SearchQueryComposition.TAG_OR) ||+ isAction(action, SearchQueryComposition.TAG_NOT)+ ) {+ /*if (+ currentOptions.current !== SearchQueryComposition.TAG_AND ||+ currentOptions.current !== SearchQueryComposition.TAG_OR ||+ currentOptions.current !== SearchQueryComposition.TAG_NOT+ ) {*/+ currentOptions.current = action;+ const searchAction = toExecAction(action);+ const tagGroups = getTagLibrary();+ const options = [];+ for (let j = 0; j < tagGroups.length; j++) {+ tagGroups[j].children.forEach((tag: TS.Tag) => {+ options.push({+ id: tag.id,+ action: searchAction,+ label: tag.title,+ color: tag.color,+ textcolor: tag.textcolor,+ group: tagGroups[j].title+ });+ });+ }+ searchOptions.current = options;+ optionsChanged = true;+ } else if (isAction(action, SearchQueryComposition.TYPE)) {+ if (currentOptions.current !== SearchQueryComposition.TYPE.shortName) {+ currentOptions.current = action;+ const options = [];+ Object.entries(FileTypeGroups).forEach(([key, value]) => {+ options.push({+ id: key,+ action: ExecActions.TYPE_SEARCH,+ label: i18n.t('core:' + key),+ descr: value.join(', ')+ });+ });+ searchOptions.current = options;+ optionsChanged = true;+ }+ } else if (isAction(action, SearchQueryComposition.SIZE)) {+ if (currentOptions.current !== SearchQueryComposition.SIZE.shortName) {+ currentOptions.current = action;+ const options = [];++ Object.entries(FileSize).forEach(([key, value]) => {+ let descr = '';+ if (value > 0) {+ if (value < 1000000) {+ descr = value / 1000 + 'KB';+ } else if (value < 1000000000) {+ descr = value / 1000000 + 'MB';+ } else if (value === 1000000000) {+ descr = value / 1000000000 + 'G';+ } else {+ descr = 'over 1GB';+ }+ }+ options.push({+ id: key,+ action: ExecActions.SIZE_SEARCH,+ label: i18n.t('core:' + key),+ descr: descr+ });+ });+ searchOptions.current = options;+ optionsChanged = true;+ }+ } else if (isAction(action, SearchQueryComposition.LAST_MODIFIED)) {+ if (+ currentOptions.current !==+ SearchQueryComposition.LAST_MODIFIED.shortName+ ) {+ currentOptions.current = action;+ const options = [];++ Object.entries(LastModified).forEach(([key, value]) => {+ options.push({+ id: key,+ action: ExecActions.LAST_MODIFIED_SEARCH,+ label: i18n.t('core:' + key)+ });+ });+ searchOptions.current = options;+ optionsChanged = true;+ }+ } else if (isAction(action, SearchQueryComposition.SCOPE)) {+ if (currentOptions.current !== SearchQueryComposition.SCOPE.shortName) {+ currentOptions.current = action;+ const options = [];++ Object.entries(scope).forEach(([key, value]) => {+ options.push({+ id: key,+ action: ExecActions.SCOPE_SEARCH,+ label: i18n.t('core:' + key)+ });+ });+ searchOptions.current = options;+ optionsChanged = true;+ }+ } else if (isAction(action, SearchQueryComposition.ACCURACY)) {+ if (+ currentOptions.current !== SearchQueryComposition.ACCURACY.shortName+ ) {+ currentOptions.current = action;+ const options = [];++ Object.entries(accuracy).forEach(([key, value]) => {+ options.push({+ id: key,+ action: ExecActions.ACCURACY_SEARCH,+ label: i18n.t('core:' + key)+ });+ });+ searchOptions.current = options;+ optionsChanged = true;+ }+ } else {+ currentOptions.current = action;+ const execActionsArr = Object.values(ExecActions);+ if (execActionsArr.includes(action)) {+ searchOptions.current = SearchOptions.filter(+ option => option.group === 'query'+ );+ optionsChanged = true;+ } else {+ searchOptions.current = SearchOptions;+ }+ }++ if (optionsChanged) {+ isOpen.current = true;+ forceUpdate();+ }+ }++ function execActions(+ options: Array<any>,+ previousActions = [],+ hasOptionsChanged = true+ ) {+ const actions: Array<SearchOptionType> = [];++ function setPreviousAction(+ key: ActionType,+ option: SearchOptionType+ ): string {+ if (actions.length > 0) {+ const prevAction = actions[actions.length - 1];+ if (isAction(prevAction.action, key)) {+ prevAction.label = prevAction.action + option.label;+ prevAction.fullName = prevAction.action + option.label;+ return option.id;+ }+ }+ return undefined;+ }++ for (let i = 0; i < options.length; i++) {+ let option: SearchOptionType;+ if (typeof options[i] === 'object') {+ option = { ...options[i] };+ } else {+ const action = findAction(options[i]);+ option = {+ label: options[i],+ fullName: action,+ action: action+ };+ }+ const prevAction = previousActions.find(+ obj =>+ obj.action === option.action &&+ (obj.label === option.label || obj.fullName === option.fullName)+ );+ if (!prevAction) {+ if (isAction(option.action, SearchActions.LOCATION)) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ actions.push(option);+ } else if (option.action === ExecActions.OPEN_LOCATION) {+ // props.exitSearchMode();+ searchOptions.current = SearchOptions;+ currentOptions.current = undefined;+ props.openLocationById(option.id);+ return [];+ } else if (isAction(option.action, SearchActions.FILTER)) {+ actions.push(option);+ isOpen.current = false;+ } else if (isAction(option.action, SearchActions.HISTORY)) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ isOpen.current = true;+ }+ actions.push(option);+ } else if (isAction(option.action, SearchActions.BOOK)) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ isOpen.current = true;+ }+ actions.push(option);+ } else if (isAction(option.action, SearchActions.SEARCH)) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ isOpen.current = true;+ }+ actions.push(option);+ } else if (option.action === ExecActions.OPEN_HISTORY) {+ const item: TS.HistoryItem = {+ path: option.label,+ url: option.fullName,+ lid: option.id,+ creationTimeStamp: 0+ };+ Pro.history.openItem(+ item,+ props.currentLocationId,+ props.openLink,+ props.openLocationById,+ props.openFsEntry+ );+ searchOptions.current = SearchOptions;+ currentOptions.current = undefined;+ isOpen.current = false;+ return [];+ } else if (option.action === ExecActions.OPEN_BOOKMARK) {+ const item: TS.HistoryItem = {+ path: option.label,+ url: option.fullName,+ lid: undefined,+ creationTimeStamp: 0+ };+ Pro.history.openItem(+ item,+ props.currentLocationId,+ props.openLink,+ props.openLocationById,+ props.openFsEntry+ );+ searchOptions.current = SearchOptions;+ currentOptions.current = undefined;+ isOpen.current = false;+ return [];+ } else if (option.action === ExecActions.OPEN_SAVED_SEARCHES) {+ props.setSearchQuery(JSON.parse(option.fullName));+ searchOptions.current = SearchOptions;+ currentOptions.current = undefined;+ isOpen.current = false;+ return [];+ } else if (+ isAction(option.action, SearchQueryComposition.TAG_AND) ||+ isAction(option.action, SearchQueryComposition.TAG_OR) ||+ isAction(option.action, SearchQueryComposition.TAG_NOT)+ ) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ actions.push(option);+ } else if (+ option.action === ExecActions.TAG_SEARCH_AND ||+ option.action === ExecActions.TAG_SEARCH_OR ||+ option.action === ExecActions.TAG_SEARCH_NOT+ ) {+ const searchAction: string =+ option.action === ExecActions.TAG_SEARCH_AND+ ? SearchQueryComposition.TAG_AND.shortName+ : option.action === ExecActions.TAG_SEARCH_NOT+ ? SearchQueryComposition.TAG_NOT.shortName+ : SearchQueryComposition.TAG_OR.shortName;+ // executeSearch();++ if (actions.length > 0) {+ const prevAction = actions[actions.length - 1];+ prevAction.label = searchAction + option.label;+ prevAction.fullName = searchAction + option.label;+ prevAction.color = option.color;+ prevAction.textcolor = option.textcolor;+ }+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ } else if (isAction(option.action, SearchQueryComposition.TYPE)) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ actions.push(option);+ } else if (option.action === ExecActions.TYPE_SEARCH) {+ const id = setPreviousAction(SearchQueryComposition.TYPE, option);+ if (id) {+ fileTypes.current = option.descr.split(', ');+ }+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ // executeSearch();+ } else if (isAction(option.action, SearchQueryComposition.SIZE)) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ actions.push(option);+ } else if (option.action === ExecActions.SIZE_SEARCH) {+ const id = setPreviousAction(SearchQueryComposition.SIZE, option);+ if (id) {+ fileSize.current = id;+ }+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ // executeSearch();+ } else if (+ isAction(option.action, SearchQueryComposition.LAST_MODIFIED)+ ) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ actions.push(option);+ } else if (option.action === ExecActions.LAST_MODIFIED_SEARCH) {+ const id = setPreviousAction(+ SearchQueryComposition.LAST_MODIFIED,+ option+ );+ if (id) {+ lastModified.current = id;+ }+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ // executeSearch();+ } else if (isAction(option.action, SearchQueryComposition.SCOPE)) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ actions.push(option);+ } else if (option.action === ExecActions.SCOPE_SEARCH) {+ const id = setPreviousAction(SearchQueryComposition.SCOPE, option);+ if (id) {+ setSearchBoxing(scope[id]);+ }+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ // executeSearch();+ } else if (isAction(option.action, SearchQueryComposition.ACCURACY)) {+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ actions.push(option);+ } else if (option.action === ExecActions.ACCURACY_SEARCH) {+ const id = setPreviousAction(SearchQueryComposition.ACCURACY, option);+ if (id) {+ searchType.current = accuracy[id];+ }+ if (hasOptionsChanged) {+ changeOptions(option.action);+ }+ // executeSearch();+ } else if (option.action === undefined) {+ // text query+ inputValue.current = option.label;++ const pAction = actions[actions.length - 1];+ if (pAction && isAction(pAction.action, SearchActions.FILTER)) {+ const filterArr = options.filter(+ o => !(typeof o === 'object') && o.action === undefined+ );+ if (filterArr.length > 0) {+ props.setSearchFilter(filterArr.join(' '));+ isOpen.current = false;+ return actions;+ }+ }+ }+ } else {+ actions.push(prevAction);+ }+ }+ // setTextQuery(actions);+ return actions;+ }++ /*function setTextQuery(actions) {+ let txtQuery = '';+ if (actions.length > 0) {+ actions.forEach(action => {+ if (+ action.action === ExecActions.TAG_SEARCH_AND ||+ ExecActions.TAG_SEARCH_OR ||+ ExecActions.TAG_SEARCH_NOT+ ) {+ txtQuery += ' ' + action.label;+ }+ });+ }+ textQuery.current =+ txtQuery.trim() + (inputValue.current ? ' ' + inputValue.current : '');+ }*/++ function handleInputChange(event: any, value: string, reason: string) {+ // handleChange(event, value.split(' '), 'createOption');+ if (reason === 'input') {+ const valueArr = value.split(' ');+ actionValues.current = execActions(+ [...actionValues.current, ...valueArr],+ actionValues.current+ );+ const inputArr = valueArr.filter(+ action => !actionValues.current.some(v => v.label === action)+ );+ inputValue.current = inputArr.join(' ');+ //textQuery.current += ' ' + inputValue.current;+ forceUpdate();+ } else if (reason === 'clear') {+ clearSearch();+ } else if (reason === 'reset') {+ if (event.type === 'keydown') {+ // textQuery.current += ' ' + inputValue.current;+ inputValue.current = '';+ } else if (event.type === 'blur') {+ }+ // executeSearch();+ }+ }++ function toExecAction(action: string) {+ if (isAction(action, SearchQueryComposition.TAG_AND)) {+ return ExecActions.TAG_SEARCH_AND;+ }+ if (isAction(action, SearchQueryComposition.TAG_NOT)) {+ return ExecActions.TAG_SEARCH_NOT;+ }+ if (isAction(action, SearchQueryComposition.TAG_OR)) {+ return ExecActions.TAG_SEARCH_OR;+ }+ return action;+ }++ function handleChange(event: Object, selected: Array<any>, reason: string) {+ if (reason === 'selectOption') {+ actionValues.current = execActions(selected, actionValues.current);+ forceUpdate();+ } else if (reason === 'createOption') {+ const actions = [];+ let prevOption;+ for (let i = 0; i < selected.length; i++) {+ const option = selected[i];+ if (option.action === undefined && prevOption) {+ let action = findAction(prevOption, true);+ if (action) {+ actions.push({+ label: option,+ action: toExecAction(action)+ });+ } else {+ actions.push(option);+ }+ } else {+ actions.push(option);+ }+ prevOption = option;+ }+ actionValues.current = execActions(actions, actionValues.current);+ forceUpdate();+ } else if (reason === 'remove-value') {+ actionValues.current = actionValues.current.filter(+ v => !(selected.includes(v.label) || selected.includes(v.fullName))+ );+ resetActions(actionValues.current);+ forceUpdate();+ // reset default search filters+ /*for (let i = 0; i < selected.length; i++) {+ const action = findAction(selected[i]);+ if (isAction(action, SearchQueryComposition.TYPE)) {+ fileTypes.current = [];+ } else if (isAction(action, SearchQueryComposition.SIZE)) {+ fileSize.current = '';+ }+ }++ if (actionValues.current.length === 0) {+ searchOptions.current = SearchOptions;+ currentOptions.current = undefined;+ // textQuery.current = ''; todo remove tagsAnd from search query+ } else {+ const prevAction =+ actionValues.current[actionValues.current.length - 1];+ changeOptions(toExecAction(prevAction.action));+ // textQuery.current = actionValues.current.map(v => v.label).join(' ');+ }+ // executeSearch();+ isOpen.current = true;*/+ } /*else if (reason === 'clear') {+ props.setSearchQuery({});+ }*/+ }++ function resetActions(actions) {+ resetValues();+ if (actions.length === 0) {+ searchOptions.current = SearchOptions;+ currentOptions.current = undefined;+ // textQuery.current = ''; todo remove tagsAnd from search query+ } else {+ actionValues.current = execActions(actions, [], false);+ searchOptions.current = SearchOptions.filter(+ option => option.group === 'query'+ );+ currentOptions.current = undefined;+ }+ }++ /*const handleOpen = React.useCallback(() => {+ isOpen.current = true;+ }, []);++ const handleClose = React.useCallback(() => {+ isOpen.current = false;+ }, []);*/++ if (!open) {+ return null;+ }+ return (+ <>+ <div+ style={{+ width: '100%',+ whiteSpace: 'nowrap',+ display: 'flex',+ alignItems: 'center'+ }}+ >+ <Autocomplete+ id="textQuery"+ multiple+ /*autoFocus*/+ /*openOnFocus*/+ freeSolo+ autoSelect+ autoComplete+ handleHomeEndKeys+ /*defaultValue={['one']}*/+ value={actionValues.current.map(v =>+ v.fullName ? v.fullName : v.label+ )}+ onChange={handleChange}+ inputValue={inputValue.current}+ onInputChange={handleInputChange}+ open={isOpen.current}+ /*onOpen={handleOpen}+ onClose={handleClose}*/+ renderTags={value =>+ value.map((option, index: number) => {+ const action = actionValues.current.find(+ a => a.fullName === option || a.label === option+ );+ return (+ <Button+ key={'button_' + index}+ size="small"+ style={{+ fontSize: 13,+ textTransform: 'none',+ color: 'black',+ backgroundColor: 'green',+ minHeight: 0,+ minWidth: 0,+ margin: 2,+ paddingTop: 0,+ paddingBottom: 0,+ paddingRight: 0,+ paddingLeft: 5,+ borderRadius: 5,+ ...(action &&+ action.color && {+ color: action.textcolor,+ backgroundColor: action.color+ })+ }}+ onClick={() => {+ handleChange(null, [option], 'remove-value');+ }}+ >+ {option}+ <CloseIcon />+ </Button>+ );+ })+ }+ /*inputValue={inputValue}+ onInputChange={(event, newInputValue) => {+ setInputValue(newInputValue);+ }}*/+ options={searchOptions.current}+ groupBy={option => option.group}+ renderOption={(props, option) => (+ <Box component="li" {...props}>+ {option.color ? (+ <Button+ size="small"+ style={{+ fontSize: 13,+ textTransform: 'none',+ color: option.textcolor,+ backgroundColor: option.color,+ minHeight: 0,+ minWidth: 0,+ margin: 2,+ paddingTop: 0,+ paddingBottom: 0,+ paddingRight: 5,+ paddingLeft: 5,+ borderRadius: 5+ }}+ >+ {option.label}+ </Button>+ ) : (+ <>+ <b>{option.label}</b>+ {option.descr}+ </>+ )}+ </Box>+ )}+ /*getOptionLabel={(option: SearchOptionType) =>+ option.label + ': ' + option.descr+ }*/+ sx={{ width: 'calc(100% - 80px)' }}+ onKeyDown={onKeyDownHandler}+ renderInput={params => (+ <TextField+ {...params}+ onBlur={() => {+ isOpen.current = false;+ forceUpdate();+ }}+ onFocus={() => {+ isOpen.current = true;+ forceUpdate();+ }}+ fullWidth+ /*id="textQuery"+ name="textQuery"*/+ label={i18n.t('core:searchTitle')}+ /*defaultValue={textQuery.current}*/+ /*onChange={event => {+ textQuery.current = event.target.value;+ }}*/+ /*style={{+ width: 'calc(100% - 80px)'+ }}*/+ /*inputRef={mainSearchField}*/+ autoFocus+ /*onKeyDown={startSearch}*/+ placeholder={i18n.t('core:searchTitle')}+ size="small"+ margin="dense"+ variant="outlined"+ /*InputProps={{+ startAdornment: (+ <InputAdornment position="start" style={{ marginRight: 0 }}>+ {isDesktop ? (+ <>+ <Tooltip+ classes={{ tooltip: classes.customWidth }}+ title={+ <span style={{ fontSize: 14 }}>+ {i18n.t('searchScope')}:+ <br />+ • {i18n.t('location')} -{' '}+ {i18n.t('searchPlaceholder')}+ <br />+ • {i18n.t('folder')} -{' '}+ {i18n.t('searchCurrentFolderWithSubFolders')}+ <br />+ • {i18n.t('globalSearch')} -{' '}+ {i18n.t('searchInAllLocationTooltip')} (+ {i18n.t('betaStatus')})<br />+ </span>+ }+ >+ <Typography+ variant="overline"+ display="block"+ onClick={toggleSearchBoxing}+ style={{+ border: '1px solid gray',+ borderRadius: 5,+ lineHeight: 'inherit',+ paddingLeft: 3,+ paddingRight: 3+ }}+ >+ {searchBoxingName}+ </Typography>+ </Tooltip>+ <HelpTooltip classes={classes} />+ </>+ ) : (+ <HelpTooltip classes={classes} />+ )}+ </InputAdornment>+ ),+ endAdornment: (+ <InputAdornment position="end">+ {isDesktop && (+ <Tooltip title={i18n.t('core:savedSearchesTitle')}>+ <IconButton+ size="small"+ edge="end"+ onClick={handleOpenSavedSearches}+ >+ <ExpandMoreIcon />+ </IconButton>+ </Tooltip>+ )}+ <Tooltip title={i18n.t('clearSearch') + ' (ESC)'}>+ <IconButton+ id="clearSearchID"+ onClick={() => {+ clearSearch();+ // props.openCurrentDirectory();+ }}+ size="small"+ edge="end"+ >+ <ClearSearchIcon />+ </IconButton>+ </Tooltip>+ </InputAdornment>+ )+ }}*/+ />+ )}+ />+ <Tooltip title={indexing ? i18n.t('searchDisabledWhileIndexing') : ''}>+ <Button+ id="searchButton"+ variant="outlined"+ size="small"+ disabled={indexing}+ style={{+ marginRight: 10,+ marginLeft: 10+ }}+ color="primary"+ onClick={clickSearchButton}+ >+ {i18n.t('searchTitle')}+ </Button>+ </Tooltip>+ </div>+ <SavedSearchesMenu+ anchorEl={openSavedSearches}+ open={Boolean(openSavedSearches)}+ onClose={() => setOpenSavedSearches(null)}+ />+ </>+ );+}++function mapStateToProps(state) {+ return {+ indexing: isIndexing(state),+ searchQuery: getSearchQuery(state),+ isDesktop: isDesktopMode(state),+ currentDirectory: getDirectoryPath(state),+ indexedEntriesCount: getIndexedEntriesCount(state),+ maxSearchResults: getMaxSearchResults(state),+ showUnixHiddenEntries: getShowUnixHiddenEntries(state),+ language: getCurrentLanguage(state),+ locations: getLocations(state),+ currentLocation: getCurrentLocation(state),+ isSearchMode: isSearchMode(state),+ currentLocationId: getCurrentLocationId(state),+ searches: getSearches(state)+ };+}++function mapDispatchToProps(dispatch) {+ return bindActionCreators(+ {+ searchAllLocations: LocationIndexActions.searchAllLocations,+ setSearchQuery: LocationIndexActions.setSearchQuery,+ searchLocationIndex: LocationIndexActions.searchLocationIndex,+ createLocationsIndexes: LocationIndexActions.createLocationsIndexes,+ // loadDirectoryContent: AppActions.loadDirectoryContent,+ openLink: AppActions.openLink,+ openURLExternally: AppActions.openURLExternally,+ // openCurrentDirectory: AppActions.openCurrentDirectory,+ watchForChanges: AppActions.watchForChanges,+ openLocationById: AppActions.openLocationById,+ exitSearchMode: AppActions.exitSearchMode,+ setSearchFilter: AppActions.setSearchFilter,+ openFsEntry: AppActions.openFsEntry+ },+ dispatch+ );+}++/*const areEqual = (prevProp, nextProp) =>+ nextProp.open === prevProp.open &&+ nextProp.language === prevProp.language &&+ nextProp.indexing === prevProp.indexing &&+ nextProp.searchQuery === prevProp.searchQuery &&+ nextProp.currentDirectory === prevProp.currentDirectory &&+ nextProp.indexedEntriesCount === prevProp.indexedEntriesCount;*/++export default connect(mapStateToProps, mapDispatchToProps)(SearchAutocomplete); // (React.memo(SearchAutocomplete, areEqual));diff --git a/app/components/SearchBox.tsx b/app/components/SearchBox.tsxindex 66dedd9e2..ec16fe4fb 100644--- a/app/components/SearchBox.tsx+++ b/app/components/SearchBox.tsx@@ -16,7 +16,7 @@**/-import React from 'react';+import React, { useEffect, useState } from 'react';import Tooltip from '-/components/Tooltip';import IconButton from '@mui/material/IconButton';import i18n from '-/services/i18n';@@ -25,35 +25,49 @@ import AdvancedSearchIcon from '@mui/icons-material/TuneOutlined';import DropDownIcon from '@mui/icons-material/ArrowDropDownOutlined';import Popover from '@mui/material/Popover';import SearchPopover from '-/components/SearchPopover';+import SearchAutocomplete from '-/components/SearchAutocomplete';+import Autocomplete from '@mui/material/Autocomplete';+import { TextField } from '@mui/material';+import { SearchOptions } from '-/components/SearchOptions';interface Props {open: boolean;- setAnchorSearch: (HTMLButtonElement) => void;- anchorSearch: HTMLButtonElement | null;}function SearchBox(props: Props) {+ const [anchorSearch, setAnchorSearch] = useState<HTMLButtonElement | null>(+ null+ );+ // const searchInlineRef = React.useRef<HTMLDivElement | null>(null);++ /* useEffect(() => {+ if (props.open && searchInlineRef.current) {+ setAnchorSearchItems(searchInlineRef.current);+ }+ }, [searchInlineRef.current, props.open]);*/+return (<>- <SearchInline open={props.open} />+ <SearchAutocomplete open={props.open} />+ {/*<SearchInline open={props.open} />*/}{props.open && (<><Tooltip title={i18n.t('core:advancedSearch')}><IconButtonid="advancedButton"data-tid="advancedSearch"- onClick={(event: React.MouseEvent<HTMLButtonElement>) =>- props.setAnchorSearch(event.currentTarget)- }+ onClick={(event: React.MouseEvent<HTMLButtonElement>) => {+ setAnchorSearch(event.currentTarget);+ }}><AdvancedSearchIcon /><DropDownIcon /></IconButton></Tooltip><Popover- open={Boolean(props.anchorSearch)}- anchorEl={props.anchorSearch}- onClose={() => props.setAnchorSearch(null)}+ open={Boolean(anchorSearch)}+ anchorEl={anchorSearch}+ onClose={() => setAnchorSearch(null)}anchorOrigin={{vertical: 'bottom',horizontal: 'right'@@ -69,7 +83,7 @@ function SearchBox(props: Props) {horizontal: 'right'}}>- <SearchPopover onClose={() => props.setAnchorSearch(null)} />+ <SearchPopover onClose={() => setAnchorSearch(null)} /></Popover></>)}diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsxindex b4a8d1888..978282371 100644--- a/app/components/SearchInline.tsx+++ b/app/components/SearchInline.tsx@@ -204,10 +204,11 @@ function SearchInline(props: Props) {}*/textQuery.current = txtQuery + ' ' + textQueryMask.current.trim();- mainSearchField.current.value =- txtQuery +- (textQueryMask.current ? ' ' + textQueryMask.current.trim() : '');- // }+ if (mainSearchField.current) {+ mainSearchField.current.value =+ txtQuery ++ (textQueryMask.current ? ' ' + textQueryMask.current.trim() : '');+ }if (props.searchQuery.searchBoxing) {setSearchBoxing(props.searchQuery.searchBoxing);// searchBoxing.current = props.searchQuery.searchBoxing;diff --git a/app/components/SearchOptions.ts b/app/components/SearchOptions.tsnew file mode 100644index 000000000..073e5ed44--- /dev/null+++ b/app/components/SearchOptions.ts@@ -0,0 +1,276 @@+export interface SearchOptionType {+ id?: string;+ label: string;+ fullName?: string;+ descr?: string;+ color?: string;+ textcolor?: string;+ action: string;+ group?: string;+}++export type ActionType = { shortName: string; fullName?: string };++export const SearchQueryComposition = {+ TAG_AND: {+ shortName: '+'+ },+ TAG_NOT: {+ shortName: '-'+ },+ TAG_OR: {+ shortName: '|'+ },+ TYPE: {+ shortName: 't:',+ fullName: 'type:'+ },+ SIZE: {+ shortName: 's:',+ fullName: 'size:'+ },+ LAST_MODIFIED: {+ shortName: 'lm:',+ fullName: 'lastmod:'+ },+ SCOPE: {+ shortName: 'sc:',+ fullName: 'scope:'+ },+ ACCURACY: {+ shortName: 'a:',+ fullName: 'accuracy:'+ }+};++/*export const searchMode = {+ NOT_IN_SEARCH_MODE: 'NOT_IN_SEARCH_MODE',+ // search mode but search is not started+ INITIAL_SEARCH_MODE: 'NOT_IN_SEARCH_MODE'+};*/++export const SearchActions = {+ LOCATION: {+ shortName: 'l:',+ fullName: 'location:'+ },+ FILTER: {+ shortName: 'f:',+ fullName: 'filter:'+ },+ HISTORY: {+ shortName: 'h:',+ fullName: 'history:'+ },+ BOOK: {+ shortName: 'b:',+ fullName: 'bookmark:'+ },+ SEARCH: {+ shortName: 'sav:',+ fullName: 'search:'+ }+};++/*export const SearchCommandFullNames = {+ TYPE: 'type:',+ SIZE: 'size:',+ LAST_MODIFIED: 'lastmod:',+ SCOPE: 'scope:',+ ACCURACY: 'accuracy:',+ LOCATION: 'location:',+ FILTER: 'filter:',+ HISTORY: 'history:',+ BOOK: 'bookmark:',+ SEARCH: 'search:'+};*/++export const ExecActions = {+ OPEN_LOCATION: 'open_location',+ OPEN_HISTORY: 'open_history',+ OPEN_BOOKMARK: 'open_bookmark',+ OPEN_SAVED_SEARCHES: 'open_saved_searches',+ TAG_SEARCH_AND: 'tag_search_and',+ TAG_SEARCH_NOT: 'tag_search_not',+ TAG_SEARCH_OR: 'tag_search_or',+ TYPE_SEARCH: 'type_search',+ SIZE_SEARCH: 'size_search',+ LAST_MODIFIED_SEARCH: 'last_modified_search',+ SCOPE_SEARCH: 'scope_search',+ ACCURACY_SEARCH: 'accuracy_search'+};++export const FileSize = {+ sizeEmpty: 0,+ sizeTiny: 10000, // 10KB+ sizeVerySmall: 100000, // 100KB+ sizeSmall: 1000000, // 1MB+ sizeMedium: 50000000, // 50 mB+ sizeLarge: 1000000000, // 1GB+ sizeHuge: 1000000001 // over 1GB+};++export const LastModified = {+ today: 86400000, // 1 day+ yesterday: 172800000, // 48 hours+ past7Days: 604800000, // 7 days+ past30Days: 2592000000, // 30 days+ past6Months: 15778476000, // 6 months+ pastYear: 31556952000, // 1 year+ moreThanYear: 31556952001 // over 1 year+};+export const scope = {+ location: 'location',+ folder: 'folder',+ global: 'global'+};++export const accuracy = {+ fuzzy: 'fuzzy',+ semistrict: 'semistrict',+ strict: 'strict'+};++export type ScopeType = 'location' | 'folder' | 'global';++/*export function toActionFullName(action): string {+ const actions = {+ ...SearchQueryComposition,+ ...SearchActions+ };+ const actionFind = Object.entries(actions).find(a => a[1] === action);+ if (actionFind && SearchCommandFullNames[actionFind[0]]) {+ return SearchCommandFullNames[actionFind[0]];+ }+ return action;+}*/++export function isAction(action: string, actionType: ActionType): boolean {+ return (+ action !== undefined &&+ (action === actionType.shortName || action === actionType.fullName)+ );+}++export function findAction(option: string, equal = false): string {+ const actions: Array<ActionType> = [+ ...Object.values(SearchQueryComposition),+ ...Object.values(SearchActions)+ ];+ let action = actions.find(a =>+ equal+ ? option === a.shortName || option === a.fullName+ : option.startsWith(a.shortName) || option.startsWith(a.fullName)+ );+ if (action) {+ return action.fullName ? action.fullName : action.shortName;+ /*action = Object.values(SearchCommandFullNames).find(a =>+ equal ? option === a : option.startsWith(a)+ );*/+ }+ return undefined;+}++export const SearchOptions: Array<SearchOptionType> = [+ {+ id: SearchActions.LOCATION.shortName,+ label: SearchActions.LOCATION.shortName,+ fullName: SearchActions.LOCATION.fullName,+ action: SearchActions.LOCATION.shortName,+ descr: 'filter and open location',+ group: 'actions'+ },+ {+ id: SearchActions.FILTER.shortName,+ label: SearchActions.FILTER.shortName,+ fullName: SearchActions.FILTER.fullName,+ action: SearchActions.FILTER.shortName,+ descr: 'filter the current directory items',+ group: 'actions'+ },+ {+ id: SearchActions.HISTORY.shortName,+ label: SearchActions.HISTORY.shortName,+ fullName: SearchActions.HISTORY.fullName,+ action: SearchActions.HISTORY.shortName,+ descr: 'filter and open all recent file and folders',+ group: 'actions'+ },+ {+ id: SearchActions.BOOK.shortName,+ label: SearchActions.BOOK.shortName,+ fullName: SearchActions.BOOK.fullName,+ action: SearchActions.BOOK.shortName,+ descr: 'filter and open the bookmarks',+ group: 'actions'+ },+ {+ id: SearchActions.SEARCH.shortName,+ label: SearchActions.SEARCH.shortName,+ fullName: SearchActions.SEARCH.fullName,+ action: SearchActions.SEARCH.shortName,+ descr: 'filter and run saved searched',+ group: 'actions'+ },+ {+ id: SearchQueryComposition.TAG_AND.shortName,+ label: SearchQueryComposition.TAG_AND.shortName,+ action: SearchQueryComposition.TAG_AND.shortName,+ descr: 'Tag AND',+ group: 'query'+ },+ {+ id: SearchQueryComposition.TAG_NOT.shortName,+ label: SearchQueryComposition.TAG_NOT.shortName,+ action: SearchQueryComposition.TAG_NOT.shortName,+ descr: 'Tag NOT',+ group: 'query'+ },+ {+ id: SearchQueryComposition.TAG_OR.shortName,+ label: SearchQueryComposition.TAG_OR.shortName,+ action: SearchQueryComposition.TAG_OR.shortName,+ descr: 'Tag OR',+ group: 'query'+ },+ {+ id: SearchQueryComposition.TYPE.shortName,+ label: SearchQueryComposition.TYPE.shortName,+ fullName: SearchQueryComposition.TYPE.fullName,+ action: SearchQueryComposition.TYPE.shortName,+ descr: 'filter by file type: document, video, files, folders',+ group: 'query'+ },+ {+ id: SearchQueryComposition.SIZE.shortName,+ label: SearchQueryComposition.SIZE.shortName,+ fullName: SearchQueryComposition.SIZE.fullName,+ action: SearchQueryComposition.SIZE.shortName,+ descr: 'list sizes from advanced search',+ group: 'query'+ },+ {+ id: SearchQueryComposition.LAST_MODIFIED.shortName,+ label: SearchQueryComposition.LAST_MODIFIED.shortName,+ fullName: SearchQueryComposition.LAST_MODIFIED.fullName,+ action: SearchQueryComposition.LAST_MODIFIED.shortName,+ descr: 'list last modified options from advanced search',+ group: 'query'+ },+ {+ id: SearchQueryComposition.SCOPE.shortName,+ label: SearchQueryComposition.SCOPE.shortName,+ fullName: SearchQueryComposition.SCOPE.fullName,+ action: SearchQueryComposition.SCOPE.shortName,+ descr: 'scope of the search: location, folder, global',+ group: 'query'+ },+ {+ id: SearchQueryComposition.ACCURACY.shortName,+ label: SearchQueryComposition.ACCURACY.shortName,+ fullName: SearchQueryComposition.ACCURACY.fullName,+ action: SearchQueryComposition.ACCURACY.shortName,+ descr: 'accuracy: fuzzy, semi strict, strict',+ group: 'query'+ }+];diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsxindex c21b4b058..853d9de62 100644--- a/app/components/SearchPopover.tsx+++ b/app/components/SearchPopover.tsx@@ -94,6 +94,7 @@ interface Props {hideDrawer?: () => void;searchQuery: TS.SearchQuery; // () => any;setSearchResults: (entries: Array<any>) => void;+ exitSearchMode: () => void;setSearchQuery: (searchQuery: TS.SearchQuery) => void;currentDirectory: string;indexedEntriesCount: number;@@ -401,7 +402,7 @@ function SearchPopover(props: Props) {if (props.currentDirectory) {props.loadDirectoryContent(props.currentDirectory, false, true);} else {- props.setSearchResults([]);+ props.exitSearchMode();}}@@ -1072,7 +1073,8 @@ function mapDispatchToProps(dispatch) {createLocationsIndexes: LocationIndexActions.createLocationsIndexes,loadDirectoryContent: AppActions.loadDirectoryContent,openURLExternally: AppActions.openURLExternally,- setSearchResults: AppActions.setSearchResults+ setSearchResults: AppActions.setSearchResults,+ exitSearchMode: AppActions.exitSearchMode},dispatch);diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsxindex d32dc5e6b..99b7b0272 100644--- a/app/perspectives/grid-perspective/components/CellContent.tsx+++ b/app/perspectives/grid-perspective/components/CellContent.tsx@@ -49,7 +49,10 @@ import PlatformIO from '-/services/platform-facade';import EntryIcon from '-/components/EntryIcon';import { TS } from '-/tagspaces.namespace';import TaggingActions from '-/reducers/tagging-actions';-import { getLastThumbnailImageChange } from '-/reducers/app';+import {+ actions as AppActions,+ getLastThumbnailImageChange+} from '-/reducers/app';import { FolderIcon } from '-/components/CommonIcons';// import { getTagColor } from '-/reducers/settings';@@ -81,6 +84,7 @@ interface Props {editTagForEntry?: (path: string, tag: TS.Tag) => void;reorderTags: boolean;lastThumbnailImageChange: any;+ exitSearchMode: () => void;}function CellContent(props: Props) {@@ -502,7 +506,10 @@ function CellContent(props: Props) {backgroundColor: theme.palette.background.default}}onContextMenu={event => handleGridContextMenu(event, fsEntry)}- onDoubleClick={event => handleGridCellDblClick(event, fsEntry)}+ onDoubleClick={event => {+ props.exitSearchMode();+ handleGridCellDblClick(event, fsEntry);+ }}onClick={event => {event.stopPropagation();AppConfig.isCordovaiOS // TODO DoubleClick not fired in Cordova IOS@@ -529,7 +536,8 @@ function mapStateToProps(state) {function mapActionCreatorsToProps(dispatch) {return bindActionCreators({- editTagForEntry: TaggingActions.editTagForEntry+ editTagForEntry: TaggingActions.editTagForEntry,+ exitSearchMode: AppActions.exitSearchMode},dispatch);diff --git a/app/perspectives/grid-perspective/components/MainContainer.tsx b/app/perspectives/grid-perspective/components/MainContainer.tsxindex 668559d7a..6c8fd4018 100644--- a/app/perspectives/grid-perspective/components/MainContainer.tsx+++ b/app/perspectives/grid-perspective/components/MainContainer.tsx@@ -52,6 +52,7 @@ import {getDirectoryMeta,getLastSelectedEntry,getLastSelectedEntryPath,+ getSearchFilter,getSelectedEntries,isDeleteMultipleEntriesDialogOpened,isReadOnlyMode@@ -73,6 +74,7 @@ import { defaultSettings } from '../index';import { PerspectiveIDs } from '-/perspectives';import { fileOperationsEnabled } from '-/perspectives/common/main-container';import GlobalSearch from '-/services/search-index';+import useFirstRender from '-/utils/useFirstRender';interface Props {classes: any;@@ -117,6 +119,7 @@ interface Props {directoryMeta: TS.FileSystemEntryMeta;setDirectoryMeta: (fsEntryMeta: TS.FileSystemEntryMeta) => void;searchResultsCount: number;+ searchFilter: string;}function getSettings(directoryMeta: TS.FileSystemEntryMeta): TS.FolderSettings {@@ -177,6 +180,9 @@ function GridPerspective(props: Props) {? settings.orderBy: defaultSettings.orderBy);+ const sortedDirContent = useRef<Array<TS.FileSystemEntry>>(+ sortByCriteria(props.directoryContent, sortBy.current, orderBy.current)+ );const layoutType = useRef<string>(settings && settings.layoutType? settings.layoutType@@ -236,6 +242,7 @@ function GridPerspective(props: Props) {// true: save in default settings; false: save per folder settings; undefined - dont save changesconst isDefaultSetting = useRef<boolean>(undefined);const [ignored, forceUpdate] = useReducer(x => x + 1, 0);+ const firstRender = useFirstRender();const {classes,@@ -252,53 +259,84 @@ function GridPerspective(props: Props) {}, [props.selectedEntries]);useEffect(() => {- const perspectiveSettings = getSettings(props.directoryMeta);- showDirectories.current =- perspectiveSettings && perspectiveSettings.showDirectories !== undefined- ? perspectiveSettings.showDirectories- : defaultSettings.showDirectories;- showDescription.current =- perspectiveSettings && perspectiveSettings.showDescription !== undefined- ? perspectiveSettings.showDescription- : defaultSettings.showDescription;- showDetails.current =- perspectiveSettings && perspectiveSettings.showDetails !== undefined- ? perspectiveSettings.showDetails- : defaultSettings.showDetails;- showTags.current =- perspectiveSettings && perspectiveSettings.showTags !== undefined- ? perspectiveSettings.showTags- : defaultSettings.showTags;- layoutType.current = defaultSettings.layoutType;- orderBy.current =- perspectiveSettings && perspectiveSettings.orderBy !== undefined- ? perspectiveSettings.orderBy- : defaultSettings.orderBy;- sortBy.current =- perspectiveSettings && perspectiveSettings.sortBy !== undefined- ? perspectiveSettings.sortBy- : defaultSettings.sortBy;- singleClickAction.current =- perspectiveSettings && perspectiveSettings.singleClickAction !== undefined- ? perspectiveSettings.singleClickAction- : defaultSettings.singleClickAction;- entrySize.current =- perspectiveSettings && perspectiveSettings.entrySize !== undefined- ? perspectiveSettings.entrySize- : defaultSettings.entrySize;- thumbnailMode.current =- perspectiveSettings && perspectiveSettings.thumbnailMode !== undefined- ? perspectiveSettings.thumbnailMode- : defaultSettings.thumbnailMode;- gridPageLimit.current =- perspectiveSettings && perspectiveSettings.gridPageLimit !== undefined- ? perspectiveSettings.gridPageLimit- : defaultSettings.gridPageLimit;- forceUpdate();+ if (!firstRender) {+ sortedDirContent.current = sortByCriteria(+ props.searchFilter+ ? props.directoryContent.filter(entry =>+ entry.name+ .toLowerCase()+ .includes(props.searchFilter.toLowerCase())+ )+ : props.directoryContent,+ sortBy.current,+ orderBy.current+ );+ forceUpdate();+ }+ }, [props.searchFilter]);++ useEffect(() => {+ if (!firstRender) {+ sortedDirContent.current = sortByCriteria(+ props.directoryContent,+ sortBy.current,+ orderBy.current+ );+ forceUpdate();+ }+ }, [props.directoryContent, sortBy.current, orderBy.current]);++ useEffect(() => {+ if (!firstRender) {+ const perspectiveSettings = getSettings(props.directoryMeta);+ showDirectories.current =+ perspectiveSettings && perspectiveSettings.showDirectories !== undefined+ ? perspectiveSettings.showDirectories+ : defaultSettings.showDirectories;+ showDescription.current =+ perspectiveSettings && perspectiveSettings.showDescription !== undefined+ ? perspectiveSettings.showDescription+ : defaultSettings.showDescription;+ showDetails.current =+ perspectiveSettings && perspectiveSettings.showDetails !== undefined+ ? perspectiveSettings.showDetails+ : defaultSettings.showDetails;+ showTags.current =+ perspectiveSettings && perspectiveSettings.showTags !== undefined+ ? perspectiveSettings.showTags+ : defaultSettings.showTags;+ layoutType.current = defaultSettings.layoutType;+ orderBy.current =+ perspectiveSettings && perspectiveSettings.orderBy !== undefined+ ? perspectiveSettings.orderBy+ : defaultSettings.orderBy;+ sortBy.current =+ perspectiveSettings && perspectiveSettings.sortBy !== undefined+ ? perspectiveSettings.sortBy+ : defaultSettings.sortBy;+ singleClickAction.current =+ perspectiveSettings &&+ perspectiveSettings.singleClickAction !== undefined+ ? perspectiveSettings.singleClickAction+ : defaultSettings.singleClickAction;+ entrySize.current =+ perspectiveSettings && perspectiveSettings.entrySize !== undefined+ ? perspectiveSettings.entrySize+ : defaultSettings.entrySize;+ thumbnailMode.current =+ perspectiveSettings && perspectiveSettings.thumbnailMode !== undefined+ ? perspectiveSettings.thumbnailMode+ : defaultSettings.thumbnailMode;+ gridPageLimit.current =+ perspectiveSettings && perspectiveSettings.gridPageLimit !== undefined+ ? perspectiveSettings.gridPageLimit+ : defaultSettings.gridPageLimit;+ forceUpdate();+ }}, [props.directoryMeta]);useEffect(() => {- if (isDefaultSetting.current !== undefined) {+ if (!firstRender && isDefaultSetting.current !== undefined) {const perspectiveSettings = {showDirectories: showDirectories.current,showDescription: showDescription.current,@@ -344,12 +382,6 @@ function GridPerspective(props: Props) {gridPageLimit.current]);- const sortedDirContentMemoized = useMemo(- () =>- sortByCriteria(props.directoryContent, sortBy.current, orderBy.current),- [props.directoryContent, sortBy.current, orderBy.current]- );-const makeFirstSelectedEntryVisible = () => {if (selectedEntries && selectedEntries.length > 0) {const firstSelectedElement = document.querySelector(@@ -551,13 +583,13 @@ function GridPerspective(props: Props) {.map(fsentry => fsentry.path): [];const sortedDirectories =- props.searchResultsCount > 0- ? []- : sortedDirContentMemoized.filter(entry => !entry.isFile);+ props.searchResultsCount < 0 // not in search mode+ ? sortedDirContent.current.filter(entry => !entry.isFile)+ : [];const sortedFiles =- props.searchResultsCount > 0- ? GlobalSearch.results- : sortedDirContentMemoized.filter(entry => entry.isFile);+ props.searchResultsCount < 0 // not in search mode+ ? sortedDirContent.current.filter(entry => entry.isFile)+ : GlobalSearch.results;const locationPath = props.currentLocation? PlatformIO.getLocationPath(props.currentLocation): '';@@ -903,7 +935,8 @@ function mapStateToProps(state) {locations: getLocations(state),isDeleteMultipleEntriesDialogOpened: isDeleteMultipleEntriesDialogOpened(state- )+ ),+ searchFilter: getSearchFilter(state)};}diff --git a/app/perspectives/list/components/MainContainer.tsx b/app/perspectives/list/components/MainContainer.tsxindex f6ad411a0..6ff5caeed 100644--- a/app/perspectives/list/components/MainContainer.tsx+++ b/app/perspectives/list/components/MainContainer.tsx@@ -558,13 +558,14 @@ function GridPerspective(props: Props) {.map(fsentry => fsentry.path): [];const sortedDirectories =- props.searchResultsCount > 0- ? []- : sortedDirContentMemoized.filter(entry => !entry.isFile);+ props.searchResultsCount < 0 // not in search mode+ ? sortedDirContentMemoized.filter(entry => !entry.isFile)+ : [];const sortedFiles =- props.searchResultsCount > 0- ? GlobalSearch.results- : sortedDirContentMemoized.filter(entry => entry.isFile);+ props.searchResultsCount < 0 // not in search mode+ ? sortedDirContentMemoized.filter(entry => entry.isFile)+ : GlobalSearch.results;+const locationPath = props.currentLocation? PlatformIO.getLocationPath(props.currentLocation): '';diff --git a/app/reducers/app.ts b/app/reducers/app.tsindex 5aa3cf772..02abfc648 100644--- a/app/reducers/app.ts+++ b/app/reducers/app.ts@@ -94,7 +94,10 @@ export const types = {CLEAR_DIRECTORY_CONTENT: 'APP/CLEAR_DIRECTORY_CONTENT',// LOAD_PAGE_CONTENT: 'APP/LOAD_PAGE_CONTENT',SET_SEARCH_RESULTS: 'APP/SET_SEARCH_RESULTS',+ EXIT_SEARCH_MODE: 'APP/EXIT_SEARCH_MODE',+ ENTER_SEARCH_MODE: 'APP/ENTER_SEARCH_MODE',APPEND_SEARCH_RESULTS: 'APP/APPEND_SEARCH_RESULTS',+ SET_SEARCH_FILTER: 'APP/SET_SEARCH_FILTER',OPEN_FILE: 'APP/OPEN_FILE',TOGGLE_ENTRY_FULLWIDTH: 'APP/TOGGLE_ENTRY_FULLWIDTH',SET_ENTRY_FULLWIDTH: 'APP/SET_ENTRY_FULLWIDTH',@@ -246,7 +249,7 @@ export const initialState = {locationManagerPanelOpened: showLocations,tagLibraryPanelOpened: showTagLibrary,searchPanelOpened: showSearch,- searchResultsCount: 0,+ searchResultsCount: -1,user: window.ExtDemoUser? {attributes: window.ExtDemoUser,@@ -527,6 +530,26 @@ export default (state: any = initialState, action: any) => {isLoading: false};}+ case types.EXIT_SEARCH_MODE: {+ GlobalSearch.results = [];+ return {+ ...state,+ searchMode: false,+ searchResultsCount: -1,+ searchFilter: undefined,+ isLoading: false+ };+ }+ case types.ENTER_SEARCH_MODE: {+ GlobalSearch.results = [];+ return {+ ...state,+ searchResultsCount: -1,+ searchMode: true,+ searchFilter: undefined,+ isLoading: false+ };+ }case types.APPEND_SEARCH_RESULTS: {// const newDirEntries = [...state.currentDirectoryEntries];for (let i = 0; i < action.searchResults.length; i += 1) {@@ -544,6 +567,12 @@ export default (state: any = initialState, action: any) => {isLoading: false};}+ case types.SET_SEARCH_FILTER: {+ return {+ ...state,+ searchFilter: action.searchFilter+ };+ }case types.SET_NOTIFICATION: {return {...state,@@ -1734,10 +1763,20 @@ export const actions = {type: types.SET_SEARCH_RESULTS,searchResults}),+ exitSearchMode: () => ({+ type: types.EXIT_SEARCH_MODE+ }),+ enterSearchMode: () => ({+ type: types.ENTER_SEARCH_MODE+ }),appendSearchResults: (searchResults: Array<any> | []) => ({type: types.APPEND_SEARCH_RESULTS,searchResults}),+ setSearchFilter: (searchFilter: string) => ({+ type: types.SET_SEARCH_FILTER,+ searchFilter+ }),setCurrentLocationId: (locationId: string | null) => ({type: types.SET_CURRENLOCATIONID,locationId@@ -1748,6 +1787,7 @@ export const actions = {) => {const { currentLocationId } = getState().app;if (location.uuid !== currentLocationId) {+ // dispatch(actions.exitSearchMode());dispatch(LocationIndexActions.clearDirectoryIndex());dispatch(actions.setCurrentLocationId(location.uuid));}@@ -1869,7 +1909,7 @@ export const actions = {if (location === undefined) {location = getLocation(getState(), getState().app.currentLocationId);}- if (Pro && Pro.Watcher && location.watchForChanges) {+ if (Pro && Pro.Watcher && location && location.watchForChanges) {const perspective = getCurrentDirectoryPerspective(getState());const depth = perspective === PerspectiveIDs.KANBAN ? 3 : 1;Pro.Watcher.watchFolder(@@ -2758,3 +2798,7 @@ export const isHelpFeedbackPanelOpened = (state: any) =>state.app.helpFeedbackPanelOpened;export const getSearchResultsCount = (state: any) =>state.app.searchResultsCount;+export const isSearchMode = (state: any) =>+ state.app.searchMode;+export const getSearchFilter = (state: any) =>+ state.app.searchFilter;diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.tsindex 83a82255d..569f3d79f 100644--- a/app/reducers/location-index.ts+++ b/app/reducers/location-index.ts@@ -184,7 +184,9 @@ export const actions = {) => {dispatch(actions.setSearchQueryInt(searchQuery));if (Object.keys(searchQuery).length === 0) {- dispatch(AppActions.setSearchResults([]));+ dispatch(AppActions.exitSearchMode());+ } else {+ dispatch(AppActions.enterSearchMode());}},setSearchQueryInt: (searchQuery: TS.SearchQuery) => ({diff --git a/app/reducers/locations.ts b/app/reducers/locations.tsindex 44f1856f2..8627fc843 100644--- a/app/reducers/locations.ts+++ b/app/reducers/locations.ts@@ -288,7 +288,7 @@ export const getDefaultLocationId = (state: any): string | undefined => {let foundLocation = state.locations.find(location => location.isDefault);return foundLocation ? foundLocation.uuid : undefined;};-export const getCurrentLocation = (state: any): string | undefined => {+export const getCurrentLocation = (state: any): TS.Location | undefined => {let foundLocation = state.locations.find(location => location.uuid === state.app.currentLocationId);