Skip to content

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

Refactor search query editor (#2259)

Stanimir03cf01df3ec2
diff --git a/src/renderer/AppConfig.ts b/src/renderer/AppConfig.ts
index c2cb79508..3712070bc 100644
--- a/src/renderer/AppConfig.ts
+++ b/src/renderer/AppConfig.ts
@@ -30,12 +30,45 @@ AppConfig.editableFiles = [
'sh',
'sql',
];
+AppConfig.SearchTypes = {
+ any: 'any',
+ images: 'images',
+ notes: 'notes',
+ documents: 'documents',
+ audio: 'audio',
+ video: 'video',
+ archives: 'archives',
+ bookmarks: 'bookmarks',
+ ebooks: 'ebooks',
+ emails: 'emails',
+ folders: 'folders',
+ files: 'files',
+ untagged: 'untagged',
+};
+AppConfig.SearchSizes = {
+ empty: { key: 'sizeEmpty', thresholdBytes: 0 }, // empty
+ tiny: { key: 'sizeTiny', thresholdBytes: 10 * 1024 }, // 1KB - 10KB
+ verySmall: { key: 'sizeVerySmall', thresholdBytes: 100 * 1024 }, // 10KB - 100KB
+ small: { key: 'sizeSmall', thresholdBytes: 1024 * 1024 }, // 100KB - 1MB
+ medium: { key: 'sizeMedium', thresholdBytes: 100 * 1024 * 1024 }, // 1MB - 50MB
+ large: { key: 'sizeLarge', thresholdBytes: 1024 * 1024 * 1024 }, // 50MB - 1GB
+ huge: { key: 'sizeHuge', thresholdBytes: 1024 * 1024 * 1024 }, // over 1GB
+};
+AppConfig.SearchTimePeriods = {
+ today: { key: 'today' },
+ yesterday: { key: 'yesterday' },
+ past7Days: { key: 'past7Days' },
+ past30Days: { key: 'past30Days' },
+ past6Months: { key: 'past6Months' },
+ pastYear: { key: 'pastYear' },
+ moreThanYear: { key: 'moreThanYear' },
+};
AppConfig.SearchTypeGroups =
typeof window !== 'undefined' && window.ExtSearchTypeGroups !== undefined
? window.ExtSearchTypeGroups
: {
- any: [''],
- images: [
+ [AppConfig.SearchTypes.any]: [''],
+ [AppConfig.SearchTypes.images]: [
'jpg',
'jpeg',
'jfif',
@@ -56,8 +89,8 @@ AppConfig.SearchTypeGroups =
'avif',
'nef',
],
- notes: ['md', 'mdown', 'txt', 'html'],
- documents: [
+ [AppConfig.SearchTypes.notes]: ['md', 'mdown', 'txt', 'html', 'mdx'],
+ [AppConfig.SearchTypes.documents]: [
'pdf',
'doc',
'docx',
@@ -72,11 +105,43 @@ AppConfig.SearchTypeGroups =
'sldx',
'dotx',
],
- audio: ['ogg', 'mp3', 'wav', 'wave', 'flac', 'acc', 'm4a', 'opus'],
- video: ['ogv', 'mp4', 'webm', 'm4v', 'mkv', 'avi', '3gp', '3g2', 'mov'],
- archives: ['zip', 'rar', 'gz', 'tgz', 'arc', '7z'],
- bookmarks: ['url', 'lnk', 'sym', 'desktop', 'website'],
- ebooks: [
+ [AppConfig.SearchTypes.audio]: [
+ 'ogg',
+ 'mp3',
+ 'wav',
+ 'wave',
+ 'flac',
+ 'acc',
+ 'm4a',
+ 'opus',
+ ],
+ [AppConfig.SearchTypes.video]: [
+ 'ogv',
+ 'mp4',
+ 'webm',
+ 'm4v',
+ 'mkv',
+ 'avi',
+ '3gp',
+ '3g2',
+ 'mov',
+ ],
+ [AppConfig.SearchTypes.archives]: [
+ 'zip',
+ 'rar',
+ 'gz',
+ 'tgz',
+ 'arc',
+ '7z',
+ ],
+ [AppConfig.SearchTypes.bookmarks]: [
+ 'url',
+ 'lnk',
+ 'sym',
+ 'desktop',
+ 'website',
+ ],
+ [AppConfig.SearchTypes.ebooks]: [
'epub',
'mobi',
'azw',
@@ -87,10 +152,10 @@ AppConfig.SearchTypeGroups =
'azw8',
'azk',
],
- emails: ['eml', 'msg'],
- folders: ['folders'],
- files: ['files'],
- untagged: ['untagged'],
+ [AppConfig.SearchTypes.emails]: ['eml', 'msg'],
+ [AppConfig.SearchTypes.folders]: ['folders'],
+ [AppConfig.SearchTypes.files]: ['files'],
+ [AppConfig.SearchTypes.untagged]: ['untagged'],
};
AppConfig.autoSaveInterval = 40000;
AppConfig.maxCollectedTag = 500;
diff --git a/src/renderer/components/EditSearchQuery.tsx b/src/renderer/components/EditSearchQuery.tsx
index 182d4cfd0..819351737 100644
--- a/src/renderer/components/EditSearchQuery.tsx
+++ b/src/renderer/components/EditSearchQuery.tsx
@@ -34,13 +34,13 @@ import {
} from '-/components/CommonIcons';
import TagsSelect from '-/components/TagsSelect';
import TooltipTS from '-/components/Tooltip';
-import TsIconButton from '-/components/TsIconButton';
+import TsDatePicker from '-/components/TsDatePicker';
import TsSelect from '-/components/TsSelect';
import TsTextField from '-/components/TsTextField';
import { useLocationIndexContext } from '-/hooks/useLocationIndexContext';
import { useSearchQueryContext } from '-/hooks/useSearchQueryContext';
import { isDesktopMode } from '-/reducers/settings';
-import { Stack } from '@mui/material';
+import { ListItemText, Stack } from '@mui/material';
import Box from '@mui/material/Box';
import FormControl from '@mui/material/FormControl';
import FormHelperText from '@mui/material/FormHelperText';
@@ -49,11 +49,13 @@ import MenuItem from '@mui/material/MenuItem';
import ToggleButton from '@mui/material/ToggleButton';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import Typography from '@mui/material/Typography';
-import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers';
+import { LocalizationProvider } from '@mui/x-date-pickers';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
+import { formatFileSize } from '@tagspaces/tagspaces-common/misc';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
+import TsIconButton from './TsIconButton';
interface Props {
executeSearchOnEnter?: boolean;
@@ -147,12 +149,26 @@ function EditSearchQuery(props: Props) {
const { target } = event;
const { value, name } = target;
- // if (name === 'fileTypes') {
- const types = JSON.parse(value);
+ const types = AppConfig.SearchTypeGroups[value];
setTempSearchQuery({ fileTypes: types });
- // }
};
+ function findPropertiesByValues(searchValues) {
+ if (searchValues) {
+ const array = Object.keys(AppConfig.SearchTypeGroups).filter(
+ (key) =>
+ Array.isArray(AppConfig.SearchTypeGroups[key]) &&
+ searchValues.some((value) =>
+ AppConfig.SearchTypeGroups[key].includes(value),
+ ),
+ );
+ if (array.length > 0) {
+ return array[0];
+ }
+ }
+ return undefined;
+ }
+
return (
<Stack component="form" spacing={2} noValidate autoComplete="off">
<TsTextField
@@ -220,7 +236,7 @@ function EditSearchQuery(props: Props) {
onChange={switchSearchBoxing}
size="small"
exclusive
- style={{ marginBottom: 10, alignSelf: 'center' }}
+ style={{ marginBottom: 0, alignSelf: 'center' }}
value={tempSearchQuery.searchBoxing}
>
<ToggleButton value="location">
@@ -245,7 +261,7 @@ function EditSearchQuery(props: Props) {
onChange={switchSearchType}
size="small"
exclusive
- style={{ marginBottom: 10, alignSelf: 'center' }}
+ style={{ marginBottom: 0, alignSelf: 'center' }}
value={tempSearchQuery.searchType}
>
<ToggleButton value="fuzzy" data-tid="fuzzySearchTID">
@@ -274,7 +290,7 @@ function EditSearchQuery(props: Props) {
}}
size="small"
exclusive
- style={{ marginBottom: 10, alignSelf: 'center' }}
+ style={{ marginBottom: 0, alignSelf: 'center' }}
value={tempSearchQuery.forceIndexing}
>
<ToggleButton value={false}>
@@ -323,180 +339,195 @@ function EditSearchQuery(props: Props) {
/>
</FormControl>
<FormControl disabled={isIndexing !== undefined}>
- <TooltipTS title={t('filterByTypTooltip')}>
- <FormHelperText style={{ marginLeft: 0 }}>
- {t('core:fileType')}
- </FormHelperText>
- <TsSelect
- value={JSON.stringify(tempSearchQuery.fileTypes)}
- onChange={handleFileTypeChange}
+ <FormHelperText style={{ marginLeft: 0 }}></FormHelperText>
+ <TsSelect
+ value={findPropertiesByValues(tempSearchQuery.fileTypes)}
+ onChange={handleFileTypeChange}
+ label={t('core:fileType')}
+ // title={t('filterByTypTooltip')}
+ >
+ <MenuItem value={AppConfig.SearchTypes.any}>
+ <ListItemText primary={t('core:anyType')} />
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTypes.folders}>
+ <TsIconButton size="small">
+ <FolderIcon />
+ </TsIconButton>
+ {t('core:searchFolders')}
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTypes.files}>
+ <TsIconButton size="small">
+ <FileIcon />
+ </TsIconButton>
+ {t('core:searchFiles')}
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTypes.untagged}>
+ <TsIconButton size="small">
+ <UntaggedIcon />
+ </TsIconButton>
+ {t('core:searchUntaggedEntries')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.images.toString()}
+ value={AppConfig.SearchTypes.images}
>
- <MenuItem value={JSON.stringify(AppConfig.SearchTypeGroups.any)}>
- {t('core:anyType')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.folders)}
- >
- <TsIconButton size="small">
- <FolderIcon />
- </TsIconButton>
- {t('core:searchFolders')}
- </MenuItem>
- <MenuItem value={JSON.stringify(AppConfig.SearchTypeGroups.files)}>
- <TsIconButton size="small">
- <FileIcon />
- </TsIconButton>
- {t('core:searchFiles')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.untagged)}
- >
- <TsIconButton size="small">
- <UntaggedIcon />
- </TsIconButton>
- {t('core:searchUntaggedEntries')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.images)}
- title={AppConfig.SearchTypeGroups.images.toString()}
- >
- <TsIconButton size="small">
- <PictureIcon />
- </TsIconButton>
- {t('core:searchPictures')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.documents)}
- title={AppConfig.SearchTypeGroups.documents.toString()}
- >
- <TsIconButton size="small">
- <DocumentIcon />
- </TsIconButton>
- {t('core:searchDocuments')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.notes)}
- title={AppConfig.SearchTypeGroups.notes.toString()}
- >
- <TsIconButton size="small">
- <NoteIcon />
- </TsIconButton>
- {t('core:searchNotes')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.audio)}
- title={AppConfig.SearchTypeGroups.audio.toString()}
- >
- <TsIconButton size="small">
- <AudioIcon />
- </TsIconButton>
- {t('core:searchAudio')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.video)}
- title={AppConfig.SearchTypeGroups.video.toString()}
- >
- <TsIconButton size="small">
- <VideoIcon />
- </TsIconButton>
- {t('core:searchVideoFiles')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.archives)}
- title={AppConfig.SearchTypeGroups.archives.toString()}
- >
- <TsIconButton size="small">
- <ArchiveIcon />
- </TsIconButton>
- {t('core:searchArchives')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.bookmarks)}
- title={AppConfig.SearchTypeGroups.bookmarks.toString()}
- >
- <TsIconButton size="small">
- <BookmarkIcon />
- </TsIconButton>
- {t('core:searchBookmarks')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.ebooks)}
- title={AppConfig.SearchTypeGroups.ebooks.toString()}
- >
- <TsIconButton size="small">
- <BookIcon />
- </TsIconButton>
- {t('core:searchEbooks')}
- </MenuItem>
- <MenuItem
- value={JSON.stringify(AppConfig.SearchTypeGroups.emails)}
- title={AppConfig.SearchTypeGroups.emails.toString()}
- >
- <TsIconButton size="small">
- <EmailIcon />
- </TsIconButton>
- {t('core:searchEmails')}
- </MenuItem>
- </TsSelect>
- </TooltipTS>
+ <TsIconButton size="small">
+ <PictureIcon />
+ </TsIconButton>
+ {t('core:searchPictures')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.documents.toString()}
+ value={AppConfig.SearchTypes.documents}
+ >
+ <TsIconButton size="small">
+ <DocumentIcon />
+ </TsIconButton>
+ {t('core:searchDocuments')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.notes.toString()}
+ value={AppConfig.SearchTypes.notes}
+ >
+ <TsIconButton size="small">
+ <NoteIcon />
+ </TsIconButton>
+ {t('core:searchNotes')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.audio.toString()}
+ value={AppConfig.SearchTypes.audio}
+ >
+ <TsIconButton size="small">
+ <AudioIcon />
+ </TsIconButton>
+ {t('core:searchAudio')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.video.toString()}
+ value={AppConfig.SearchTypes.video}
+ >
+ <TsIconButton size="small">
+ <VideoIcon />
+ </TsIconButton>
+ {t('core:searchVideoFiles')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.archives.toString()}
+ value={AppConfig.SearchTypes.archives}
+ >
+ <TsIconButton size="small">
+ <ArchiveIcon />
+ </TsIconButton>
+ {t('core:searchArchives')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.bookmarks.toString()}
+ value={AppConfig.SearchTypes.bookmarks}
+ >
+ <TsIconButton size="small">
+ <BookmarkIcon />
+ </TsIconButton>
+ {t('core:searchBookmarks')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.ebooks.toString()}
+ value={AppConfig.SearchTypes.ebooks}
+ >
+ <TsIconButton size="small">
+ <BookIcon />
+ </TsIconButton>
+ {t('core:searchEbooks')}
+ </MenuItem>
+ <MenuItem
+ title={AppConfig.SearchTypeGroups.emails.toString()}
+ value={AppConfig.SearchTypes.emails}
+ >
+ <TsIconButton size="small">
+ <EmailIcon />
+ </TsIconButton>
+ {t('core:searchEmails')}
+ </MenuItem>
+ </TsSelect>
</FormControl>
<FormControl disabled={isIndexing !== undefined}>
- <TooltipTS title={t('filterBySizeTooltip')}>
- <FormHelperText style={{ marginLeft: 0 }}>
- {t('core:sizeSearchTitle')}
- </FormHelperText>
- <TsSelect
- value={tempSearchQuery.fileSize}
- onChange={handleFileSizeChange}
- >
- <MenuItem value="">{t('core:sizeAny')}</MenuItem>
- <MenuItem value="sizeEmpty">{t('core:sizeEmpty')}</MenuItem>
- <MenuItem value="sizeTiny">
- {t('core:sizeTiny')}
- &nbsp;(&lt;&nbsp;10KB)
- </MenuItem>
- <MenuItem value="sizeVerySmall">
- {t('core:sizeVerySmall')}
- &nbsp;(&lt;&nbsp;100KB)
- </MenuItem>
- <MenuItem value="sizeSmall">
- {t('core:sizeSmall')}
- &nbsp;(&lt;&nbsp;1MB)
- </MenuItem>
- <MenuItem value="sizeMedium">
- {t('core:sizeMedium')}
- &nbsp;(&lt;&nbsp;50MB)
- </MenuItem>
- <MenuItem value="sizeLarge">
- {t('core:sizeLarge')}
- &nbsp;(&lt;&nbsp;1GB)
- </MenuItem>
- <MenuItem value="sizeHuge">
- {t('core:sizeHuge')}
- &nbsp;(&gt;&nbsp;1GB)
- </MenuItem>
- </TsSelect>
- </TooltipTS>
+ <TsSelect
+ value={tempSearchQuery.fileSize}
+ onChange={handleFileSizeChange}
+ label={t('core:sizeSearchTitle')}
+ title={t('filterBySizeTooltip')}
+ >
+ <MenuItem value="">{t('core:sizeAny')}</MenuItem>
+ <MenuItem value={AppConfig.SearchSizes.empty.key}>
+ {t('core:sizeEmpty')}&nbsp;({formatFileSize(0)})
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchSizes.tiny.key}>
+ {t('core:sizeTiny')}
+ &nbsp;(&lt;&nbsp;
+ {formatFileSize(AppConfig.SearchSizes.tiny.thresholdBytes)})
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchSizes.verySmall.key}>
+ {t('core:sizeVerySmall')}
+ &nbsp;({formatFileSize(AppConfig.SearchSizes.tiny.thresholdBytes)}
+ &nbsp;-&nbsp;
+ {formatFileSize(AppConfig.SearchSizes.verySmall.thresholdBytes)})
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchSizes.small.key}>
+ {t('core:sizeSmall')}
+ &nbsp;(
+ {formatFileSize(AppConfig.SearchSizes.verySmall.thresholdBytes)}
+ &nbsp;-&nbsp;
+ {formatFileSize(AppConfig.SearchSizes.small.thresholdBytes)})
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchSizes.medium.key}>
+ {t('core:sizeMedium')}
+ &nbsp;({formatFileSize(AppConfig.SearchSizes.small.thresholdBytes)}
+ &nbsp;-&nbsp;
+ {formatFileSize(AppConfig.SearchSizes.medium.thresholdBytes)})
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchSizes.large.key}>
+ {t('core:sizeLarge')}
+ &nbsp;({formatFileSize(AppConfig.SearchSizes.medium.thresholdBytes)}
+ &nbsp;-&nbsp;
+ {formatFileSize(AppConfig.SearchSizes.large.thresholdBytes)})
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchSizes.huge.key}>
+ {t('core:sizeHuge')}
+ &nbsp;(&gt;&nbsp;
+ {formatFileSize(AppConfig.SearchSizes.huge.thresholdBytes)})
+ </MenuItem>
+ </TsSelect>
</FormControl>
<FormControl disabled={isIndexing !== undefined}>
- <TooltipTS title={t('filterByLastModifiedDateTooltip')}>
- <FormHelperText style={{ marginLeft: 0 }}>
- {t('core:lastModifiedSearchTitle')}
- </FormHelperText>
- <TsSelect
- value={tempSearchQuery.lastModified}
- onChange={handleLastModifiedChange}
- >
- <MenuItem value="">{t('core:anyTime')}</MenuItem>
- <MenuItem value="today">{t('core:today')}</MenuItem>
- <MenuItem value="yesterday">{t('core:yesterday')}</MenuItem>
- <MenuItem value="past7Days">{t('core:past7Days')}</MenuItem>
- <MenuItem value="past30Days">{t('core:past30Days')}</MenuItem>
- <MenuItem value="past6Months">{t('core:past6Months')}</MenuItem>
- <MenuItem value="pastYear">{t('core:pastYear')}</MenuItem>
- <MenuItem value="moreThanYear">{t('core:moreThanYear')}</MenuItem>
- </TsSelect>
- </TooltipTS>
+ <TsSelect
+ value={tempSearchQuery.lastModified}
+ onChange={handleLastModifiedChange}
+ label={t('core:lastModifiedSearchTitle')}
+ // title={t('filterByLastModifiedDateTooltip')}
+ >
+ <MenuItem value="">{t('core:anyTime')}</MenuItem>
+ <MenuItem value={AppConfig.SearchTimePeriods.today.key}>
+ {t('core:today')}
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTimePeriods.yesterday.key}>
+ {t('core:yesterday')}
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTimePeriods.past7Days.key}>
+ {t('core:past7Days')}
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTimePeriods.past30Days.key}>
+ {t('core:past30Days')}
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTimePeriods.past6Months.key}>
+ {t('core:past6Months')}
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTimePeriods.pastYear.key}>
+ {t('core:pastYear')}
+ </MenuItem>
+ <MenuItem value={AppConfig.SearchTimePeriods.moreThanYear.key}>
+ {t('core:moreThanYear')}
+ </MenuItem>
+ </TsSelect>
</FormControl>
<FormControl>
<TooltipTS title={t('enterTimePeriodTooltip')}>
@@ -506,9 +537,8 @@ function EditSearchQuery(props: Props) {
<FormHelperText style={{ marginLeft: 0, marginTop: 0 }}>
{t('core:enterTagTimePeriodFrom')}
</FormHelperText>
- <DatePicker
+ <TsDatePicker
disabled={isIndexing !== undefined}
- format="yyyy-MM-dd"
value={
tempSearchQuery.tagTimePeriodFrom
? new Date(tempSearchQuery.tagTimePeriodFrom)
@@ -527,9 +557,8 @@ function EditSearchQuery(props: Props) {
<FormHelperText style={{ marginLeft: 0, marginTop: 0 }}>
{t('core:enterTagTimePeriodTo')}
</FormHelperText>
- <DatePicker
+ <TsDatePicker
disabled={isIndexing !== undefined}
- format="yyyy-MM-dd"
value={
tempSearchQuery.tagTimePeriodTo
? new Date(tempSearchQuery.tagTimePeriodTo)
diff --git a/src/renderer/components/RenderHistory.tsx b/src/renderer/components/RenderHistory.tsx
index a7e6cf244..80612baa0 100644
--- a/src/renderer/components/RenderHistory.tsx
+++ b/src/renderer/components/RenderHistory.tsx
@@ -72,8 +72,8 @@ function RenderHistory(props: Props) {
textTransform: 'none',
fontWeight: 'normal',
justifyContent: 'start',
- minWidth: 245,
- maxWidth: 245,
+ minWidth: 255,
+ maxWidth: 255,
}}
onClick={() => openHistoryItem(item as TS.HistoryItem)}
>
@@ -128,7 +128,7 @@ function RenderHistory(props: Props) {
}}
data-tid="deleteHistoryItemTID"
>
- <RemoveIcon />
+ <RemoveIcon fontSize="small" />
</TsIconButton>
)}
</ListItem>
diff --git a/src/renderer/components/SearchPopover.tsx b/src/renderer/components/SearchPopover.tsx
index a80974136..a7c115d2b 100644
--- a/src/renderer/components/SearchPopover.tsx
+++ b/src/renderer/components/SearchPopover.tsx
@@ -168,7 +168,7 @@ function SearchPopover(props: Props) {
</Grid>
<Grid
size={3}
- style={{ display: 'flex', alignSelf: 'center', paddingTop: 40 }}
+ style={{ display: 'flex', alignSelf: 'center', paddingTop: 25 }}
>
<ButtonGroup
style={{
diff --git a/src/renderer/components/StoredSearches.tsx b/src/renderer/components/StoredSearches.tsx
index 0a25a98ff..6ce5ac326 100644
--- a/src/renderer/components/StoredSearches.tsx
+++ b/src/renderer/components/StoredSearches.tsx
@@ -238,6 +238,7 @@ function StoredSearches(props: Props) {
<Grid container direction="row" key={search.uuid}>
<Grid size={10}>
<TsButton
+ tooltip={t('core:searchTitle')}
data-tid={
'StoredSearchTID' +
search.title.trim().replaceAll(/\s+/g, '-')
@@ -266,11 +267,12 @@ function StoredSearches(props: Props) {
</Grid>
<Grid size={2}>
<TsIconButton
+ tooltip={t('core:editSavedSearchTitle')}
aria-label={t('core:searchEditBtn')}
onClick={() => openSaveSearchDialog(search.uuid)}
data-tid="editSearchTID"
>
- <EditIcon />
+ <EditIcon fontSize="small" />
</TsIconButton>
</Grid>
</Grid>
diff --git a/src/renderer/components/TagsSelect.tsx b/src/renderer/components/TagsSelect.tsx
index 657ca9f98..b9b151c57 100644
--- a/src/renderer/components/TagsSelect.tsx
+++ b/src/renderer/components/TagsSelect.tsx
@@ -204,10 +204,9 @@ function TagsSelect(props: Props) {
)}
renderInput={(params) => (
<>
- <FormHelperText style={{ marginLeft: 0 }}>{label}</FormHelperText>
<TsTextField
{...params}
- label={undefined}
+ label={label}
placeholder={placeholderText}
margin="normal"
autoFocus={autoFocus}
diff --git a/src/renderer/components/TsSelect.tsx b/src/renderer/components/TsSelect.tsx
index ca99df630..68f92a604 100644
--- a/src/renderer/components/TsSelect.tsx
+++ b/src/renderer/components/TsSelect.tsx
@@ -36,6 +36,9 @@ function TsSelect(props: TSSelectProps) {
{label}
</FormHelperText>
<TsTextField
+ slotProps={{
+ select: { displayEmpty: true },
+ }}
style={{
cursor: 'context-menu',
marginTop: 0,
diff --git a/src/renderer/components/TsTextField.tsx b/src/renderer/components/TsTextField.tsx
index 19975ef46..833733d8e 100644
--- a/src/renderer/components/TsTextField.tsx
+++ b/src/renderer/components/TsTextField.tsx
@@ -137,14 +137,6 @@ function TsTextField(props: TSTextFieldProps) {
border: `2px solid ${alpha(theme.palette.divider, 0.5)} !important`,
borderRadius: AppConfig.defaultCSSRadius + 'px',
},
- // '& fieldset': {
- // border: '2px solid transparent',
- // borderRadius: AppConfig.defaultCSSRadius + 'px',
- // },
- // '& fieldset:focus': {
- // border: '2px solid red !important',
- // borderRadius: AppConfig.defaultCSSRadius + 'px',
- // },
}}
{...restProps}
label={undefined}
diff --git a/src/renderer/services/search.ts b/src/renderer/services/search.ts
index 9f072830b..2fd9d6369 100644
--- a/src/renderer/services/search.ts
+++ b/src/renderer/services/search.ts
@@ -17,6 +17,7 @@
*
*/
+import AppConfig from '-/AppConfig';
import { getAllTags } from '-/services/utils-io';
import { TS } from '-/tagspaces.namespace';
import { extractTimePeriod } from '-/utils/dates';
@@ -24,7 +25,6 @@ import { parseGeoLocation } from '-/utils/geo';
import jmespath from '@gorillastack/jmespath';
import { isPathStartsWith } from '@tagspaces/tagspaces-common/paths';
import Fuse from 'fuse.js';
-import AppConfig from '-/AppConfig';
export function haveSearchFilters(searchQuery: TS.SearchQuery) {
return (
@@ -428,8 +428,6 @@ export default class Search {
});
}
-//export const searchHistorySize = 15; // Should be moved in the default settings of the PRO
-
function filterIndex(data, searchQuery: TS.SearchQuery) {
console.log('Pro filter ' + JSON.stringify(searchQuery));
let results = data;
@@ -439,66 +437,100 @@ function filterIndex(data, searchQuery: TS.SearchQuery) {
now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getUTCDate(),
);
const msInDay = 1000 * 60 * 60 * 24;
- if (searchQuery.lastModified === 'today') {
+ if (searchQuery.lastModified === AppConfig.SearchTimePeriods.today.key) {
results = results.filter((entry) => entry.lmdt > today.getTime());
- } else if (searchQuery.lastModified === 'yesterday') {
+ } else if (
+ searchQuery.lastModified === AppConfig.SearchTimePeriods.yesterday.key
+ ) {
results = results.filter(
(entry) =>
entry.lmdt > today.getTime() - msInDay && entry.lmdt < today.getTime(),
);
- } else if (searchQuery.lastModified === 'past7Days') {
+ } else if (
+ searchQuery.lastModified === AppConfig.SearchTimePeriods.past7Days.key
+ ) {
results = results.filter(
(entry) =>
entry.lmdt > today.getTime() - msInDay * 7 &&
entry.lmdt < today.getTime(),
);
- } else if (searchQuery.lastModified === 'past30Days') {
+ } else if (
+ searchQuery.lastModified === AppConfig.SearchTimePeriods.past30Days.key
+ ) {
results = results.filter(
(entry) =>
entry.lmdt > today.getTime() - msInDay * 30 &&
entry.lmdt < today.getTime(),
);
- } else if (searchQuery.lastModified === 'past6Months') {
+ } else if (
+ searchQuery.lastModified === AppConfig.SearchTimePeriods.past6Months.key
+ ) {
results = results.filter(
(entry) =>
entry.lmdt > today.getTime() - msInDay * 30 * 6 &&
entry.lmdt < today.getTime(),
);
- } else if (searchQuery.lastModified === 'pastYear') {
+ } else if (
+ searchQuery.lastModified === AppConfig.SearchTimePeriods.pastYear.key
+ ) {
results = results.filter(
(entry) =>
entry.lmdt > today.getTime() - msInDay * 365 &&
entry.lmdt < today.getTime(),
);
- } else if (searchQuery.lastModified === 'moreThanYear') {
+ } else if (
+ searchQuery.lastModified === AppConfig.SearchTimePeriods.moreThanYear.key
+ ) {
results = results.filter(
(entry) => entry.lmdt < today.getTime() - msInDay * 365,
);
}
- if (searchQuery.fileSize === 'sizeEmpty') {
- results = results.filter((entry) => entry.size === 0 && entry.isFile);
- } else if (searchQuery.fileSize === 'sizeTiny') {
- // till 10KB
- results = results.filter((entry) => entry.size <= 10000 && entry.isFile);
- } else if (searchQuery.fileSize === 'sizeVerySmall') {
- // till 100KB
- results = results.filter((entry) => entry.size <= 100000 && entry.isFile);
- } else if (searchQuery.fileSize === 'sizeSmall') {
- // till 1MB
- results = results.filter((entry) => entry.size <= 1000000 && entry.isFile);
- } else if (searchQuery.fileSize === 'sizeMedium') {
- // till 50MB
- results = results.filter((entry) => entry.size <= 50000000 && entry.isFile);
- } else if (searchQuery.fileSize === 'sizeLarge') {
- // till 1GB
+ if (searchQuery.fileSize === AppConfig.SearchSizes.empty.key) {
+ results = results.filter(
+ (entry) =>
+ entry.size === AppConfig.SearchSizes.empty.thresholdBytes &&
+ entry.isFile,
+ );
+ } else if (searchQuery.fileSize === AppConfig.SearchSizes.tiny.key) {
+ results = results.filter(
+ (entry) =>
+ entry.size > AppConfig.SearchSizes.empty.thresholdBytes &&
+ entry.size <= AppConfig.SearchSizes.tiny.thresholdBytes &&
+ entry.isFile,
+ );
+ } else if (searchQuery.fileSize === AppConfig.SearchSizes.verySmall.key) {
+ results = results.filter(
+ (entry) =>
+ entry.size > AppConfig.SearchSizes.tiny.thresholdBytes &&
+ entry.size <= AppConfig.SearchSizes.verySmall.thresholdBytes &&
+ entry.isFile,
+ );
+ } else if (searchQuery.fileSize === AppConfig.SearchSizes.small.key) {
+ results = results.filter(
+ (entry) =>
+ entry.size > AppConfig.SearchSizes.verySmall.thresholdBytes &&
+ entry.size <= AppConfig.SearchSizes.small.thresholdBytes &&
+ entry.isFile,
+ );
+ } else if (searchQuery.fileSize === AppConfig.SearchSizes.medium.key) {
results = results.filter(
- (entry) => entry.size <= 1000000000 && entry.isFile,
+ (entry) =>
+ entry.size > AppConfig.SearchSizes.small.thresholdBytes &&
+ entry.size <= AppConfig.SearchSizes.medium.thresholdBytes &&
+ entry.isFile,
+ );
+ } else if (searchQuery.fileSize === AppConfig.SearchSizes.large.key) {
+ results = results.filter(
+ (entry) =>
+ entry.size > AppConfig.SearchSizes.medium.thresholdBytes &&
+ entry.size <= AppConfig.SearchSizes.large.thresholdBytes &&
+ entry.isFile,
);
- } else if (searchQuery.fileSize === 'sizeHuge') {
- // over 1GB
+ } else if (searchQuery.fileSize === AppConfig.SearchSizes.huge.key) {
results = results.filter(
- (entry) => entry.size > 1000000000 && entry.isFile,
+ (entry) =>
+ entry.size > AppConfig.SearchSizes.huge.thresholdBytes && entry.isFile,
);
}
@@ -518,28 +550,10 @@ function filterIndex(data, searchQuery: TS.SearchQuery) {
);
}
- // results = results.filter(entry => (entry.tags.filter(tag => tag.title === 'done').length > 0));
return results;
- /*
- var tests = Object.keys(criteria).reduce(function(tests, key) {
- var field = criteria[key];
- if ('min' in field) {tests.push(function(item) {
- return item[key] > field.min;
- });}
- if ('max' in field) {tests.push(function(item) {
- return item[key] < field.max;
- });}
- return tests;
- }, []);
- return function(item) {
- return tests.every(function(test) {return test(item);});
- };
- */
}
function constructFileTypeQuery(searchQuery: TS.SearchQuery) {
- // (!isFile)
- // ( extension=='md' || extension=='mdown' || extension=='txt' || extension=='html' )
let extensionQuery = '';
if (searchQuery.fileTypes && searchQuery.fileTypes.length >= 1) {
if (searchQuery.fileTypes[0] === AppConfig.SearchTypeGroups.folders[0]) {
@@ -568,33 +582,3 @@ function constructFileTypeQuery(searchQuery: TS.SearchQuery) {
}
return extensionQuery;
}
-
-/**
- * @deprecated
- * @param searchQuery
- */
-/*export function constructTagQuery(searchQuery: TS.SearchQuery): string {
-
- let tagQuery = '';
- if (searchQuery.tags && searchQuery.tags.length >= 1) {
- let tagConjunction = ' || ';
- if (searchQuery.tagConjunction === 'AND') {
- tagConjunction = ' && ';
- }
- tagQuery = ' ';
- searchQuery.tags.map((tag) => {
- const cleanedTag = tag.trim(); // .toLowerCase();
- if (cleanedTag.length > 0) {
- tagQuery += "tags[? (title=='" + cleanedTag + "' )]" + tagConjunction;
- }
- return true;
- });
- if (tagQuery.endsWith('|| ')) {
- tagQuery = tagQuery.substring(0, tagQuery.length - 3) + ' ';
- }
- if (tagQuery.endsWith('& ')) {
- tagQuery = tagQuery.substring(0, tagQuery.length - 3) + ' ';
- }
- }
- return tagQuery;
-}*/