Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Improve search usability v3 (#1937)

Stanimirbcc79c9aa068
diff --git a/app/components/SearchAutocomplete.tsx b/app/components/SearchAutocomplete.tsx
index 5fab85462..6cd4089db 100644
--- a/app/components/SearchAutocomplete.tsx
+++ b/app/components/SearchAutocomplete.tsx
@@ -24,6 +24,7 @@ import withStyles from '@mui/styles/withStyles';
import makeStyles from '@mui/styles/makeStyles';
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
import Button from '@mui/material/Button';
+import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
import Tooltip from '-/components/Tooltip';
import IconButton from '@mui/material/IconButton';
import ClearSearchIcon from '@mui/icons-material/Close';
@@ -73,6 +74,7 @@ import { getTagLibrary } from '-/services/taglibrary-utils';
import { getSearches } from '-/reducers/searches';
import { getSearchOptions } from '-/components/SearchOptionsMenu';
import { SearchIcon } from '-/components/CommonIcons';
+import { dataTidFormat } from '-/services/test';
interface Props {
style?: any;
@@ -707,7 +709,7 @@ function SearchAutocomplete(props: Props) {
}));
}
- function changeOptions(action: string) {
+ function changeOptions(action: string, filter = true) {
let optionsChanged = false;
if (isAction(action, SearchActions.LOCATION)) {
if (currentOptions.current !== action) {
@@ -717,7 +719,8 @@ function SearchAutocomplete(props: Props) {
id: location.uuid,
descr: location.path,
action: ExecActions.OPEN_LOCATION,
- label: location.name
+ label: location.name,
+ filter
};
});
optionsChanged = true;
@@ -771,7 +774,8 @@ function SearchAutocomplete(props: Props) {
action: ExecActions.OPEN_BOOKMARK,
fullName: item.url,
label: item.path,
- group: group
+ group: group,
+ filter
}));
}
@@ -804,7 +808,8 @@ function SearchAutocomplete(props: Props) {
action: ExecActions.OPEN_SAVED_SEARCHES,
label: item.title,
fullName: JSON.stringify(item),
- group: group
+ group: group,
+ filter
}));
}
@@ -835,7 +840,8 @@ function SearchAutocomplete(props: Props) {
label: tag.title,
color: tag.color,
textcolor: tag.textcolor,
- group: tagGroups[j].title
+ group: tagGroups[j].title,
+ filter
});
});
}
@@ -850,7 +856,8 @@ function SearchAutocomplete(props: Props) {
id: key,
action: ExecActions.TYPE_SEARCH,
label: i18n.t('core:' + key),
- descr: value.join(', ')
+ descr: value.join(', '),
+ filter
});
});
searchOptions.current = options;
@@ -878,7 +885,8 @@ function SearchAutocomplete(props: Props) {
id: key,
action: ExecActions.SIZE_SEARCH,
label: i18n.t('core:' + key),
- descr: descr
+ descr: descr,
+ filter
});
});
searchOptions.current = options;
@@ -896,7 +904,8 @@ function SearchAutocomplete(props: Props) {
options.push({
id: key,
action: ExecActions.LAST_MODIFIED_SEARCH,
- label: i18n.t('core:' + key)
+ label: i18n.t('core:' + key),
+ filter
});
});
searchOptions.current = options;
@@ -911,7 +920,8 @@ function SearchAutocomplete(props: Props) {
options.push({
id: key,
action: ExecActions.SCOPE_SEARCH,
- label: i18n.t('core:' + key)
+ label: i18n.t('core:' + key),
+ filter
});
});
searchOptions.current = options;
@@ -928,7 +938,8 @@ function SearchAutocomplete(props: Props) {
options.push({
id: key,
action: ExecActions.ACCURACY_SEARCH,
- label: i18n.t('core:' + key)
+ label: i18n.t('core:' + key),
+ filter
});
});
searchOptions.current = options;
@@ -961,15 +972,12 @@ function SearchAutocomplete(props: Props) {
) {
const actions: Array<SearchOptionType> = [];
- function setPreviousAction(
- key: ActionType,
- option: SearchOptionType
- ): string {
+ function setActionLabel(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;
+ const action = actions.find(a => a.action === key.fullName); //[actions.length - 1];
+ if (isAction(action.action, key)) {
+ action.label = action.action + option.label;
+ action.fullName = action.action + option.label;
return option.id;
}
}
@@ -1107,21 +1115,46 @@ function SearchAutocomplete(props: Props) {
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];
+ 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;
+
+ let prevAction;
+ if (unique) {
+ prevAction = actions.find(a => a.action === searchAction);
+ }
+ if (!prevAction) {
+ prevAction = actions[actions.length - 1];
+ }
prevAction.label = searchAction + option.label;
prevAction.fullName = searchAction + option.label;
prevAction.color = option.color;
prevAction.textcolor = option.textcolor;
}
+ const tagsAND = getTags(
+ actionValues.current,
+ SearchQueryComposition.TAG_AND
+ );
+ const tagsOR = getTags(
+ actionValues.current,
+ SearchQueryComposition.TAG_OR
+ );
+ const tagsNOT = getTags(
+ actionValues.current,
+ SearchQueryComposition.TAG_NOT
+ );
+ props.setSearchQuery({
+ ...props.searchQuery,
+ tagsAND,
+ tagsOR,
+ tagsNOT,
+ executeSearch: false
+ });
+ props.setTextQuery('');
if (hasOptionsChanged) {
changeOptions(option.action);
}
@@ -1131,9 +1164,14 @@ function SearchAutocomplete(props: Props) {
}
actions.push(option);
} else if (option.action === ExecActions.TYPE_SEARCH) {
- const id = setPreviousAction(SearchQueryComposition.TYPE, option);
+ const id = setActionLabel(SearchQueryComposition.TYPE, option);
if (id) {
fileTypes.current = option.descr.split(', ');
+ props.setSearchQuery({
+ ...props.searchQuery,
+ fileTypes: fileTypes.current,
+ executeSearch: false
+ });
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1145,9 +1183,14 @@ function SearchAutocomplete(props: Props) {
}
actions.push(option);
} else if (option.action === ExecActions.SIZE_SEARCH) {
- const id = setPreviousAction(SearchQueryComposition.SIZE, option);
+ const id = setActionLabel(SearchQueryComposition.SIZE, option);
if (id) {
fileSize.current = id;
+ props.setSearchQuery({
+ ...props.searchQuery,
+ fileSize: id,
+ executeSearch: false
+ });
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1161,12 +1204,17 @@ function SearchAutocomplete(props: Props) {
}
actions.push(option);
} else if (option.action === ExecActions.LAST_MODIFIED_SEARCH) {
- const id = setPreviousAction(
+ const id = setActionLabel(
SearchQueryComposition.LAST_MODIFIED,
option
);
if (id) {
lastModified.current = id;
+ props.setSearchQuery({
+ ...props.searchQuery,
+ lastModified: id,
+ executeSearch: false
+ });
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1178,23 +1226,32 @@ function SearchAutocomplete(props: Props) {
}
actions.push(option);
} else if (option.action === ExecActions.SCOPE_SEARCH) {
- const id = setPreviousAction(SearchQueryComposition.SCOPE, option);
+ const id = setActionLabel(SearchQueryComposition.SCOPE, option);
if (id) {
setSearchBoxing(scope[id]);
+ props.setSearchQuery({
+ ...props.searchQuery,
+ searchBoxing: scope[id],
+ executeSearch: false
+ });
}
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);
+ const id = setActionLabel(SearchQueryComposition.ACCURACY, option);
if (id) {
searchType.current = accuracy[id];
+ props.setSearchQuery({
+ ...props.searchQuery,
+ searchType: accuracy[id],
+ executeSearch: false
+ });
}
if (hasOptionsChanged) {
changeOptions(option.action);
@@ -1259,11 +1316,11 @@ function SearchAutocomplete(props: Props) {
} else if (reason === 'clear') {
clearSearch();
} else if (reason === 'reset') {
- if (event.type === 'keydown' || event.type === 'click') {
+ /*if (event.type === 'keydown' || event.type === 'click') {
// textQuery.current += ' ' + inputValue.current;
props.setTextQuery('');
} else if (event.type === 'blur') {
- }
+ }*/
// executeSearch();
}
}
@@ -1494,6 +1551,9 @@ function SearchAutocomplete(props: Props) {
onClose={handleClose}*/
filterOptions={(options: Array<SearchOptionType>, state: any) => {
const filteredOptions = options.filter(option => {
+ if (option.filter === false) {
+ return true;
+ }
return (
option.label
.toLowerCase()
@@ -1511,14 +1571,9 @@ function SearchAutocomplete(props: Props) {
a => a.fullName === option || a.label === option
);
return (
- <Button
+ <Box
key={'button_' + index}
- size="small"
style={{
- fontSize: 13,
- textTransform: 'none',
- color: 'black',
- backgroundColor: 'white',
border: '1px solid gray',
minHeight: 0,
minWidth: 0,
@@ -1535,13 +1590,54 @@ function SearchAutocomplete(props: Props) {
border: 'none'
})
}}
- onClick={() => {
- handleChange(null, [option], 'remove-value');
- }}
>
- {option}
- <CloseIcon />
- </Button>
+ {isAction(action.action, SearchQueryComposition.TAG_AND) ||
+ isAction(action.action, SearchQueryComposition.TAG_OR) ||
+ isAction(action.action, SearchQueryComposition.TAG_NOT) ? (
+ <Box
+ style={{
+ fontSize: 13,
+ fontWeight: 'bold',
+ display: 'inline'
+ }}
+ >
+ {option}
+ </Box>
+ ) : (
+ <Button
+ onClick={() => {
+ changeOptions(action.action, false);
+ }}
+ data-tid={dataTidFormat('menu' + option)}
+ size="small"
+ style={{
+ color: 'black',
+ backgroundColor: 'transparent',
+ padding: 0
+ }}
+ endIcon={<ArrowDropDownIcon />}
+ >
+ {option}
+ </Button>
+ )}
+
+ {!isAction(action.action, SearchQueryComposition.SCOPE) &&
+ !isAction(
+ action.action,
+ SearchQueryComposition.ACCURACY
+ ) && (
+ <IconButton
+ onClick={() => {
+ handleChange(null, [option], 'remove-value');
+ }}
+ style={{ padding: 0, margin: 0 }}
+ data-tid={dataTidFormat('close' + option)}
+ size="small"
+ >
+ <CloseIcon />
+ </IconButton>
+ )}
+ </Box>
);
})
}
diff --git a/app/components/SearchBox.tsx b/app/components/SearchBox.tsx
index f753d1ecf..c1e4f8e89 100644
--- a/app/components/SearchBox.tsx
+++ b/app/components/SearchBox.tsx
@@ -30,6 +30,7 @@ function SearchBox(props: Props) {
const [anchorSearch, setAnchorSearch] = useState<HTMLButtonElement | null>(
null
);
+ // todo replace with props.setSearchQuery
const [textQuery, setTextQuery] = useState<string>(props.textQuery || '');
return (
diff --git a/app/components/SearchOptions.ts b/app/components/SearchOptions.ts
index 6b8d33fbb..faf356c2f 100644
--- a/app/components/SearchOptions.ts
+++ b/app/components/SearchOptions.ts
@@ -10,6 +10,7 @@ export interface SearchOptionType {
action: string;
group?: string;
searchQuery?: TS.SearchQuery;
+ filter?: boolean;
}
export type ActionType = { shortName: string; fullName?: string };
@@ -20,6 +21,7 @@ export const SearchQueryComposition = {
},
TAG_NOT: {
shortName: '-'
+ // fullName: '—'
},
TAG_OR: {
shortName: '|'
@@ -34,11 +36,11 @@ export const SearchQueryComposition = {
},
LAST_MODIFIED: {
shortName: 'lm:',
- fullName: 'last modified:'
+ fullName: 'modified:'
},
SCOPE: {
shortName: 'sc:',
- fullName: 'scope: '
+ fullName: 'scope:'
},
ACCURACY: {
shortName: 'a:',
@@ -55,27 +57,27 @@ export const SearchQueryComposition = {
export const SearchActions = {
LOCATION: {
shortName: 'l:',
- fullName: 'locations:'
+ fullName: 'locations'
},
FILTER: {
shortName: 'f:',
- fullName: 'filter:'
+ fullName: 'filter'
},
HISTORY: {
shortName: 'h:',
- fullName: 'history:'
+ fullName: 'history'
},
BOOK: {
shortName: 'b:',
- fullName: 'bookmarks:'
+ fullName: 'bookmarks'
},
SEARCH: {
shortName: 'q:',
- fullName: 'search-queries:'
+ fullName: 'search-queries'
},
SEARCH_HISTORY: {
shortName: 's:',
- fullName: 'search-history:'
+ fullName: 'search-history'
}
};