Skip to content

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

add SavedSearches dropdown menu (#1728)

Stanimirb21502f5a8b2
diff --git a/app/components/SearchInline.tsx b/app/components/SearchInline.tsx
index 4747c0568..bde265abe 100644
--- a/app/components/SearchInline.tsx
+++ b/app/components/SearchInline.tsx
@@ -22,6 +22,7 @@ import { connect } from 'react-redux';
import makeStyles from '@mui/styles/makeStyles';
import ClearSearchIcon from '@mui/icons-material/Close';
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
+import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import Button from '@mui/material/Button';
import Tooltip from '@mui/material/Tooltip';
import IconButton from '@mui/material/IconButton';
@@ -51,6 +52,7 @@ import { TS } from '-/tagspaces.namespace';
import { Pro } from '../pro';
import useFirstRender from '-/utils/useFirstRender';
import MainSearchField from '-/components/MainSearchField';
+import SavedSearchesMenu from '-/components/menus/SavedSearchesMenu';
// type PropsClasses = Record<keyof StyleProps, string>;
@@ -83,6 +85,10 @@ const useStyles = makeStyles(theme => ({
function SearchInline(props: Props) {
// const [, forceUpdate] = useReducer(x => x + 1, 0);
+ const [
+ openSavedSearches,
+ setOpenSavedSearches
+ ] = useState<null | HTMLElement>(null);
const textQuery = useRef<string>(props.searchQuery.textQuery);
const textQueryMask = useRef<string>('');
const fileTypes = useRef<Array<string>>(
@@ -297,7 +303,14 @@ function SearchInline(props: Props) {
return query;
};
+ const handleOpenSavedSearches = (
+ event: React.MouseEvent<HTMLButtonElement>
+ ) => {
+ setOpenSavedSearches(event.currentTarget);
+ };
+
const classes = useStyles();
+
function HelpTooltip(hClasses) {
return (
<Tooltip
@@ -377,109 +390,128 @@ function SearchInline(props: Props) {
const { indexing, isDesktop } = props;
return (
- <div
- style={{
- width: '100%',
- whiteSpace: 'nowrap'
- }}
- >
- <MainSearchField
- fullWidth
- id="textQuery"
- name="textQuery"
- defaultValue={textQuery.current}
- variant="outlined"
- onChange={event => {
- textQuery.current = event.target.value;
- }}
- size="small"
+ <>
+ <div
style={{
- marginTop: 10,
- width: 'calc(100% - 80px)'
+ width: '100%',
+ whiteSpace: 'nowrap'
}}
- inputRef={mainSearchField}
- margin="dense"
- autoFocus
- onKeyDown={startSearch}
- placeholder={i18n.t('core:searchTitle')}
- InputProps={{
- startAdornment: (
- <InputAdornment position="start" style={{ marginRight: 0 }}>
- {isDesktop ? (
- <Tooltip
- arrow
- classes={{ tooltip: classes.customWidth }}
- title={
- <span style={{ fontSize: 14 }}>
- {i18n.t('searchScope')}:
- <br />
- &bull; {i18n.t('location')} -{' '}
- {i18n.t('searchPlaceholder')}
- <br />
- &bull; {i18n.t('folder')} -{' '}
- {i18n.t('searchCurrentFolderWithSubFolders')}
- <br />
- &bull; {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} />
- )}
- </InputAdornment>
- ),
- endAdornment: (
- <InputAdornment position="end">
- {isDesktop && <HelpTooltip classes={classes} />}
- <Tooltip title={i18n.t('clearSearch') + ' (ESC)'}>
- <IconButton
- id="clearSearchID"
- onClick={clearSearch}
- size="small"
- edge="end"
- >
- <ClearSearchIcon />
- </IconButton>
- </Tooltip>
- </InputAdornment>
- )
- }}
- />
- <Tooltip title={indexing ? i18n.t('searchDisabledWhileIndexing') : ''}>
- <Button
- id="searchButton"
+ >
+ <MainSearchField
+ fullWidth
+ id="textQuery"
+ name="textQuery"
+ defaultValue={textQuery.current}
variant="outlined"
+ onChange={event => {
+ textQuery.current = event.target.value;
+ }}
size="small"
- disabled={indexing}
style={{
- marginRight: 10,
- marginLeft: 10,
- marginTop: 10
+ marginTop: 10,
+ width: 'calc(100% - 80px)'
}}
- color="primary"
- onClick={clickSearchButton}
- >
- {i18n.t('searchTitle')}
- </Button>
- </Tooltip>
- </div>
+ inputRef={mainSearchField}
+ margin="dense"
+ autoFocus
+ onKeyDown={startSearch}
+ placeholder={i18n.t('core:searchTitle')}
+ InputProps={{
+ startAdornment: (
+ <InputAdornment position="start" style={{ marginRight: 0 }}>
+ {isDesktop ? (
+ <Tooltip
+ arrow
+ classes={{ tooltip: classes.customWidth }}
+ title={
+ <span style={{ fontSize: 14 }}>
+ {i18n.t('searchScope')}:
+ <br />
+ &bull; {i18n.t('location')} -{' '}
+ {i18n.t('searchPlaceholder')}
+ <br />
+ &bull; {i18n.t('folder')} -{' '}
+ {i18n.t('searchCurrentFolderWithSubFolders')}
+ <br />
+ &bull; {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} />
+ )}
+ </InputAdornment>
+ ),
+ endAdornment: (
+ <InputAdornment position="end">
+ {isDesktop && (
+ <>
+ <IconButton
+ id="basic-button"
+ size="small"
+ edge="end"
+ onClick={handleOpenSavedSearches}
+ >
+ <ExpandMoreIcon style={{ color: 'lightgray' }} />
+ </IconButton>
+ <HelpTooltip classes={classes} />
+ </>
+ )}
+ <Tooltip title={i18n.t('clearSearch') + ' (ESC)'}>
+ <IconButton
+ id="clearSearchID"
+ onClick={clearSearch}
+ 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,
+ marginTop: 10
+ }}
+ color="primary"
+ onClick={clickSearchButton}
+ >
+ {i18n.t('searchTitle')}
+ </Button>
+ </Tooltip>
+ </div>
+ <SavedSearchesMenu
+ anchorEl={openSavedSearches}
+ open={Boolean(openSavedSearches)}
+ onClose={() => setOpenSavedSearches(null)}
+ />
+ </>
);
}
diff --git a/app/components/menus/SavedSearchesMenu.tsx b/app/components/menus/SavedSearchesMenu.tsx
new file mode 100644
index 000000000..36ef4ca69
--- /dev/null
+++ b/app/components/menus/SavedSearchesMenu.tsx
@@ -0,0 +1,123 @@
+/**
+ * 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 from 'react';
+import Menu from '@mui/material/Menu';
+import MenuItem from '@mui/material/MenuItem';
+import { TS } from '-/tagspaces.namespace';
+import { getSearches } from '-/reducers/searches';
+import { connect } from 'react-redux';
+import { bindActionCreators } from 'redux';
+import { actions as LocationIndexActions } from '-/reducers/location-index';
+import { getShowUnixHiddenEntries } from '-/reducers/settings';
+
+interface Props {
+ classes?: any;
+ open: boolean;
+ anchorEl: Element;
+ onClose: () => void;
+ searches: Array<TS.SearchQuery>;
+ setSearchQuery: (searchQuery: TS.SearchQuery) => void;
+ showUnixHiddenEntries: boolean;
+}
+
+function SavedSearchesMenu(props: Props) {
+ const handleSavedSearchClick = (uuid: string) => {
+ const savedSearch = props.searches.find(search => search.uuid === uuid);
+ if (!savedSearch) {
+ return true;
+ }
+
+ props.setSearchQuery({
+ ...savedSearch,
+ showUnixHiddenEntries: props.showUnixHiddenEntries
+ });
+ };
+
+ const menuItems = props.searches.map(search => (
+ <MenuItem
+ key={search.uuid}
+ onClick={() => {
+ handleSavedSearchClick(search.uuid);
+ props.onClose();
+ }}
+ >
+ {search.title}
+ </MenuItem>
+ ));
+ return (
+ <div style={{ overflowY: 'hidden' }}>
+ <Menu
+ anchorEl={props.anchorEl}
+ open={props.open}
+ onClose={props.onClose}
+ id="search-menu"
+ MenuListProps={{
+ 'aria-labelledby': 'basic-button'
+ }}
+ // onClick={() => setOpenSavedSearches(null)}
+ PaperProps={{
+ elevation: 0,
+ sx: {
+ overflow: 'visible',
+ filter: 'drop-shadow(0px 2px 8px rgba(0,0,0,0.32))',
+ mt: 1.5,
+ '& .MuiAvatar-root': {
+ width: 32,
+ height: 32,
+ ml: -0.5,
+ mr: 1
+ },
+ '&:before': {
+ content: '""',
+ display: 'block',
+ position: 'absolute',
+ top: 0,
+ right: 14,
+ width: 10,
+ height: 10,
+ bgcolor: 'background.paper',
+ transform: 'translateY(-50%) rotate(45deg)',
+ zIndex: 0
+ }
+ }
+ }}
+ transformOrigin={{ horizontal: 'right', vertical: 'top' }}
+ anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
+ >
+ {menuItems}
+ </Menu>
+ </div>
+ );
+}
+
+function mapStateToProps(state) {
+ return {
+ searches: getSearches(state),
+ showUnixHiddenEntries: getShowUnixHiddenEntries(state)
+ };
+}
+function mapDispatchToProps(dispatch) {
+ return bindActionCreators(
+ {
+ setSearchQuery: LocationIndexActions.setSearchQuery
+ },
+ dispatch
+ );
+}
+export default connect(mapStateToProps, mapDispatchToProps)(SavedSearchesMenu);