Skip to content

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

fix search options for not Pro and tests

sytolk44a1688e4091
diff --git a/app/components/SearchAutocomplete.tsx b/app/components/SearchAutocomplete.tsx
index db66bafc8..54e47e49d 100644
--- a/app/components/SearchAutocomplete.tsx
+++ b/app/components/SearchAutocomplete.tsx
@@ -62,7 +62,6 @@ import {
scope,
ScopeType,
SearchActions,
- SearchOptions,
SearchOptionType,
SearchQueryComposition
} from '-/components/SearchOptions';
@@ -70,6 +69,7 @@ import { getCurrentLocation, getLocations } from '-/reducers/locations';
import CloseIcon from '@mui/icons-material/Close';
import { getTagLibrary } from '-/services/taglibrary-utils';
import { getSearches } from '-/reducers/searches';
+import { getSearchOptions } from '-/components/SearchOptionsMenu';
interface Props {
style?: any;
@@ -121,7 +121,7 @@ function SearchAutocomplete(props: Props) {
openSavedSearches,
setOpenSavedSearches
] = useState<null | HTMLElement>(null);
- const searchOptions = useRef<Array<SearchOptionType>>(SearchOptions);
+ const searchOptions = useRef<Array<SearchOptionType>>(getSearchOptions());
const currentOptions = useRef<string>(undefined);
// const textQuery = useRef<string>(props.searchQuery.textQuery || ''); // rethink to use inputValue instead
// const textQueryMask = useRef<string>('');
@@ -931,12 +931,12 @@ function SearchAutocomplete(props: Props) {
currentOptions.current = action;
const execActionsArr = Object.values(ExecActions);
if (execActionsArr.includes(action)) {
- searchOptions.current = SearchOptions.filter(
+ searchOptions.current = getSearchOptions().filter(
option => option.group === 'query'
);
optionsChanged = true;
} else {
- searchOptions.current = SearchOptions;
+ searchOptions.current = getSearchOptions();
}
}
@@ -997,7 +997,7 @@ function SearchAutocomplete(props: Props) {
} else if (option.action === ExecActions.OPEN_LOCATION) {
props.exitSearchMode();
// isOpen.current = false;
- searchOptions.current = SearchOptions;
+ searchOptions.current = getSearchOptions();
currentOptions.current = undefined;
props.openLocationById(option.id);
return [];
@@ -1056,7 +1056,7 @@ function SearchAutocomplete(props: Props) {
props.openFsEntry
);
}
- searchOptions.current = SearchOptions;
+ searchOptions.current = getSearchOptions();
currentOptions.current = undefined;
isOpen.current = false;
return [];
@@ -1076,13 +1076,13 @@ function SearchAutocomplete(props: Props) {
props.openFsEntry
);
}
- searchOptions.current = SearchOptions;
+ searchOptions.current = getSearchOptions();
currentOptions.current = undefined;
isOpen.current = false;
return [];
} else if (option.action === ExecActions.OPEN_SAVED_SEARCHES) {
props.setSearchQuery(JSON.parse(option.fullName));
- searchOptions.current = SearchOptions;
+ searchOptions.current = getSearchOptions();
currentOptions.current = undefined;
isOpen.current = false;
return [];
@@ -1336,12 +1336,12 @@ function SearchAutocomplete(props: Props) {
function resetActions(actions: Array<SearchOptionType>) {
resetValues(actions);
if (actions.length === 0) {
- searchOptions.current = SearchOptions;
+ searchOptions.current = getSearchOptions();
currentOptions.current = undefined;
// textQuery.current = ''; todo remove tagsAnd from search query
} else {
actionValues.current = execActions(actions, [], false);
- searchOptions.current = SearchOptions.filter(
+ searchOptions.current = getSearchOptions().filter(
option => option.group === 'query'
);
currentOptions.current = undefined;
diff --git a/app/components/SearchOptions.ts b/app/components/SearchOptions.ts
index 9f2d50102..6b8d33fbb 100644
--- a/app/components/SearchOptions.ts
+++ b/app/components/SearchOptions.ts
@@ -177,118 +177,3 @@ export function findAction(option: string, equal = false): string {
}
return undefined;
}
-
-export const SearchOptions: Array<SearchOptionType> = [
- {
- id: SearchActions.LOCATION.shortName,
- label: SearchActions.LOCATION.shortName,
- fullName: SearchActions.LOCATION.fullName,
- action: SearchActions.LOCATION.shortName,
- descr: 'find and open a location',
- group: 'actions'
- },
- {
- id: SearchActions.FILTER.shortName,
- label: SearchActions.FILTER.shortName,
- fullName: SearchActions.FILTER.fullName,
- action: SearchActions.FILTER.shortName,
- descr: 'filter the entries from the current folder',
- group: 'actions'
- },
- {
- id: SearchActions.HISTORY.shortName,
- label: SearchActions.HISTORY.shortName,
- fullName: SearchActions.HISTORY.fullName,
- action: SearchActions.HISTORY.shortName,
- descr: 'find recently used files and folders',
- group: 'actions'
- },
- {
- id: SearchActions.BOOK.shortName,
- label: SearchActions.BOOK.shortName,
- fullName: SearchActions.BOOK.fullName,
- action: SearchActions.BOOK.shortName,
- descr: 'find bookmarks',
- group: 'actions'
- },
- {
- id: SearchActions.SEARCH.shortName,
- label: SearchActions.SEARCH.shortName,
- fullName: SearchActions.SEARCH.fullName,
- action: SearchActions.SEARCH.shortName,
- descr: 'find and execute saved search queries',
- group: 'actions'
- },
- {
- id: SearchActions.SEARCH_HISTORY.shortName,
- label: SearchActions.SEARCH_HISTORY.shortName,
- fullName: SearchActions.SEARCH_HISTORY.fullName,
- action: SearchActions.SEARCH_HISTORY.shortName,
- descr: 'Execute search queries from history',
- group: 'actions'
- },
- {
- id: SearchQueryComposition.TAG_AND.shortName,
- label: SearchQueryComposition.TAG_AND.shortName,
- action: SearchQueryComposition.TAG_AND.shortName,
- descr:
- 'entries should have this tag to be included in the results (logical AND)',
- group: 'query'
- },
- {
- id: SearchQueryComposition.TAG_NOT.shortName,
- label: SearchQueryComposition.TAG_NOT.shortName,
- action: SearchQueryComposition.TAG_NOT.shortName,
- descr:
- 'entries should not have this tag to be included in the results (logical NOT)',
- group: 'query'
- },
- {
- id: SearchQueryComposition.TAG_OR.shortName,
- label: SearchQueryComposition.TAG_OR.shortName,
- action: SearchQueryComposition.TAG_OR.shortName,
- descr:
- 'allows searching for entries having one tag or another (logical 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/SearchOptionsMenu.ts b/app/components/SearchOptionsMenu.ts
new file mode 100644
index 000000000..528dab6c6
--- /dev/null
+++ b/app/components/SearchOptionsMenu.ts
@@ -0,0 +1,138 @@
+import { Pro } from '-/pro';
+import { SearchActions, SearchOptionType, SearchQueryComposition } from "-/components/SearchOptions";
+
+export function getSearchOptions(): Array<SearchOptionType> {
+ const options = [];
+
+ options.push({
+ id: SearchActions.LOCATION.shortName,
+ label: SearchActions.LOCATION.shortName,
+ fullName: SearchActions.LOCATION.fullName,
+ action: SearchActions.LOCATION.shortName,
+ descr: 'find and open a location',
+ group: 'actions'
+ });
+ options.push({
+ id: SearchActions.FILTER.shortName,
+ label: SearchActions.FILTER.shortName,
+ fullName: SearchActions.FILTER.fullName,
+ action: SearchActions.FILTER.shortName,
+ descr: 'filter the entries from the current folder',
+ group: 'actions'
+ });
+ if (Pro) {
+ options.push({
+ id: SearchActions.HISTORY.shortName,
+ label: SearchActions.HISTORY.shortName,
+ fullName: SearchActions.HISTORY.fullName,
+ action: SearchActions.HISTORY.shortName,
+ descr: 'find recently used files and folders',
+ group: 'actions'
+ });
+ }
+ if (Pro) {
+ options.push({
+ id: SearchActions.BOOK.shortName,
+ label: SearchActions.BOOK.shortName,
+ fullName: SearchActions.BOOK.fullName,
+ action: SearchActions.BOOK.shortName,
+ descr: 'find bookmarks',
+ group: 'actions'
+ });
+ }
+
+ if (Pro) {
+ options.push({
+ id: SearchActions.SEARCH.shortName,
+ label: SearchActions.SEARCH.shortName,
+ fullName: SearchActions.SEARCH.fullName,
+ action: SearchActions.SEARCH.shortName,
+ descr: 'find and execute saved search queries',
+ group: 'actions'
+ });
+ }
+ if (Pro) {
+ options.push({
+ id: SearchActions.SEARCH_HISTORY.shortName,
+ label: SearchActions.SEARCH_HISTORY.shortName,
+ fullName: SearchActions.SEARCH_HISTORY.fullName,
+ action: SearchActions.SEARCH_HISTORY.shortName,
+ descr: 'Execute search queries from history',
+ group: 'actions'
+ });
+ }
+ options.push({
+ id: SearchQueryComposition.TAG_AND.shortName,
+ label: SearchQueryComposition.TAG_AND.shortName,
+ action: SearchQueryComposition.TAG_AND.shortName,
+ descr:
+ 'entries should have this tag to be included in the results (logical AND)',
+ group: 'query'
+ });
+ options.push({
+ id: SearchQueryComposition.TAG_NOT.shortName,
+ label: SearchQueryComposition.TAG_NOT.shortName,
+ action: SearchQueryComposition.TAG_NOT.shortName,
+ descr:
+ 'entries should not have this tag to be included in the results (logical NOT)',
+ group: 'query'
+ });
+ options.push({
+ id: SearchQueryComposition.TAG_OR.shortName,
+ label: SearchQueryComposition.TAG_OR.shortName,
+ action: SearchQueryComposition.TAG_OR.shortName,
+ descr:
+ 'allows searching for entries having one tag or another (logical OR)',
+ group: 'query'
+ });
+ if (Pro) {
+ options.push({
+ 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'
+ });
+ }
+
+ if (Pro) {
+ options.push({
+ id: SearchQueryComposition.SIZE.shortName,
+ label: SearchQueryComposition.SIZE.shortName,
+ fullName: SearchQueryComposition.SIZE.fullName,
+ action: SearchQueryComposition.SIZE.shortName,
+ descr: 'list sizes from advanced search',
+ group: 'query'
+ });
+ }
+
+ if (Pro) {
+ options.push({
+ 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'
+ });
+ }
+
+ options.push({
+ 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'
+ });
+ options.push({
+ id: SearchQueryComposition.ACCURACY.shortName,
+ label: SearchQueryComposition.ACCURACY.shortName,
+ fullName: SearchQueryComposition.ACCURACY.fullName,
+ action: SearchQueryComposition.ACCURACY.shortName,
+ descr: 'accuracy: fuzzy, semi strict, strict',
+ group: 'query'
+ });
+ return options;
+}
diff --git a/tests/e2e/search.pw.e2e.js b/tests/e2e/search.pw.e2e.js
index d12952918..076283502 100644
--- a/tests/e2e/search.pw.e2e.js
+++ b/tests/e2e/search.pw.e2e.js
@@ -40,6 +40,7 @@ import { AddRemoveTagsToSelectedFiles } from './perspective-grid.helpers';
test.beforeAll(async () => {
await startTestingApp('extconfig.js'); //'extconfig-with-welcome.js');
// await clearDataStorage();
+ await createEmptyFile();
});
test.afterAll(async () => {
@@ -151,7 +152,7 @@ test.describe('TST06 - Test Search in file structure:', () => {
expect(file).toContain('txt');
});
- test('TST0623 - Search actions - history [web,electron]', async () => {
+ test('TST0623 - Search actions - history [web,electron,_pro]', async () => {
const file = 'sample.txt';
// add file to history
await openContextEntryMenu(
@@ -168,7 +169,7 @@ test.describe('TST06 - Test Search in file structure:', () => {
);
});
- test('TST0624 - Search actions - bookmarks [web,electron]', async () => {
+ test('TST0624 - Search actions - bookmarks [web,electron,_pro]', async () => {
const bookmarkFileTitle = 'sample.txt';
await openContextEntryMenu(
'[data-tid="fsEntryName_' + bookmarkFileTitle + '"]',
@@ -187,7 +188,7 @@ test.describe('TST06 - Test Search in file structure:', () => {
);
});
- test('TST0625 - Search actions - execute query from stored searches [web,electron]', async () => {
+ test('TST0625 - Search actions - execute query from stored searches [web,electron,_pro]', async () => {
const storedSearchTitle = 'jpgSearch';
await createSavedSearch({ title: storedSearchTitle, textQuery: 'jpg' });
@@ -197,7 +198,7 @@ test.describe('TST06 - Test Search in file structure:', () => {
await expectElementExist(getGridFileSelector('sample.pdf'), false, 5000);
});
- test('TST0626 - Search actions - execute query from search history [web,electron]', async () => {
+ test('TST0626 - Search actions - execute query from search history [web,electron,_pro]', async () => {
await searchEngine('txt');
await clickOn('#clearSearchID');
@@ -259,10 +260,15 @@ test.describe('TST06 - Test Search in file structure:', () => {
await expectElementExist(getFileName(file3, tags3), false, 5000);
});
- test('TST0629 - Search q. comp - file size [web,electron]', async () => {
- await createEmptyFile();
- await openLocationMenu(defaultLocationName);
- await clickOn('[data-tid=indexLocation]');
+ test('TST0629 - Search q. comp - file size [web,electron,_pro]', async () => {
+ await global.client.dblclick('[data-tid=fsEntryName_empty_folder]');
+ await expectElementExist(
+ getGridFileSelector('empty_file.html'),
+ true,
+ 5000
+ );
+ //await openLocationMenu(defaultLocationName);
+ //await clickOn('[data-tid=indexLocation]');
await addSearchCommand('si:', false);
await clickOn('#textQuery-option-0');
@@ -275,7 +281,7 @@ test.describe('TST06 - Test Search in file structure:', () => {
);
});
- test('TST0630 - Search q. comp - type [web,electron]', async () => {
+ test('TST0630 - Search q. comp - type [web,electron,_pro]', async () => {
await addSearchCommand('t:', false);
// choose image file type
await clickOn('#textQuery-option-1');
@@ -285,7 +291,7 @@ test.describe('TST06 - Test Search in file structure:', () => {
await expectElementExist(getGridFileSelector('sample.csv'), false, 5000);
});
- test('TST0631 - Search q. comp - last modified [web,electron]', async () => {
+ test('TST0631 - Search q. comp - last modified [web,electron,_pro]', async () => {
await addSearchCommand('lm:', false);
// choose option Today
await clickOn('#textQuery-option-0');