Skip to content

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

fix: global search with mix of local and cloud locations

Ilian Sapundshievd97de03da364
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 166dba736..fa85d7ed4 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -17,7 +17,7 @@
*/
import uuidv1 from 'uuid';
-import { Location, locationType } from './locations';
+import { Location, getLocation, locationType } from './locations';
import PlatformIO from '../services/platform-io';
import AppConfig from '../config';
import {
@@ -697,7 +697,13 @@ export const actions = {
dispatch(actions.showNotification(i18n.t('core:loading'), 'info', false));
PlatformIO.listDirectoryPromise(directoryPath, false)
.then(results => {
- prepareDirectoryContent(results, directoryPath, settings, dispatch);
+ prepareDirectoryContent(
+ results,
+ directoryPath,
+ settings,
+ dispatch,
+ getState
+ );
return true;
})
.catch(error => {
@@ -1127,7 +1133,13 @@ export const actions = {
entryPath,
isFile
);
- entryForOpening.url = PlatformIO.getURLforPath(entryPath); // Needed for the s3 support
+ const { currentDirectoryEntries } = getState().app;
+ const currentEntry = currentDirectoryEntries.find(
+ entry => entry.path === entryPath
+ );
+ if (currentEntry && currentEntry.url) {
+ entryForOpening.url = currentEntry.url;
+ }
if (
editMode &&
entryForOpening.editingExtensionId &&
@@ -1419,16 +1431,28 @@ function prepareDirectoryContent(
dirEntries,
directoryPath,
settings,
- dispatch
+ dispatch,
+ getState
) {
const directoryContent = [];
const tmbGenerationPromises = [];
const tmbGenerationList = [];
const isWorkerAvailable = PlatformIO.isWorkerAvailable();
+ const currentLocation: Location = getLocation(
+ getState(),
+ getState().app.currentLocationId
+ );
+ const isCloudLocation = currentLocation.type === locationType.TYPE_CLOUD;
+
dirEntries.map(entry => {
if (!settings.showUnixHiddenEntries && entry.name.startsWith('.')) {
return true;
}
+
+ if (isCloudLocation) {
+ entry.url = PlatformIO.getURLforPath(entry.path);
+ }
+
const enhancedEntry = enhanceEntry(entry);
directoryContent.push(enhancedEntry);
if (
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index ac4568514..a08f11c31 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -17,7 +17,7 @@
*/
import { Location, getLocation, getLocations, locationType } from './locations';
-import { createDirectoryIndex } from '../services/utils-io';
+import { createDirectoryIndex, FileSystemEntry } from '../services/utils-io';
import { Pro } from '../pro';
import {
extractFileExtension,
@@ -175,12 +175,7 @@ export const actions = {
directoryPath: string,
extractText: boolean,
isCurrentLocation: boolean = true
- ) => (dispatch: (actions: Object) => void, getState: () => any) => {
- const state = getState();
- const currentLocation: Location = getLocation(
- state,
- state.app.currentLocationId
- );
+ ) => (dispatch: (actions: Object) => void) => {
dispatch(actions.startDirectoryIndexing());
createDirectoryIndex(directoryPath, extractText)
.then(directoryIndex => {
@@ -190,7 +185,6 @@ export const actions = {
}
dispatch(actions.indexDirectorySuccess());
if (Pro && Pro.Indexer) {
- // && (currentLocation.persistIndex || PlatformIO.haveObjectStoreSupport())) { // always persist on s3 stores
Pro.Indexer.persistIndex(
directoryPath,
directoryIndex,
@@ -208,10 +202,6 @@ export const actions = {
getState: () => any
) => {
const state = getState();
- const currentLocation: Location = getLocation(
- state,
- state.app.currentLocationId
- );
dispatch(actions.startDirectoryIndexing());
const allLocations = getLocations(state);
const locationPaths = [];
@@ -252,12 +242,7 @@ export const actions = {
loadDirectoryIndex: (
directoryPath: string,
isCurrentLocation: boolean = true
- ) => (dispatch: (actions: Object) => void, getState: () => any) => {
- const state = getState();
- const currentLocation: Location = getLocation(
- state,
- state.app.currentLocationId
- );
+ ) => (dispatch: (actions: Object) => void) => {
dispatch(actions.startDirectoryIndexing());
dispatch(
AppActions.showNotification(i18n.t('core:loadingIndex'), 'default', true)
@@ -331,6 +316,11 @@ export const actions = {
}
Search.searchLocationIndex(GlobalSearch.index, searchQuery)
.then(searchResults => {
+ if (currentLocation.type === locationType.TYPE_CLOUD) {
+ searchResults.forEach((entry: FileSystemEntry) => {
+ entry.url = PlatformIO.getURLforPath(entry.path);
+ });
+ }
dispatch(AppActions.setSearchResults(searchResults));
dispatch(AppActions.hideNotifications());
return true;
@@ -421,8 +411,21 @@ export const actions = {
}
return Search.searchLocationIndex(directoryIndex, searchQuery)
.then(searchResults => {
- searchResultCount += searchResults.length;
- dispatch(AppActions.appendSearchResults(searchResults));
+ let enhancedSearchResult = searchResults;
+ if (isCloudLocation) {
+ enhancedSearchResult = searchResults.filter(
+ (entry: FileSystemEntry) => {
+ // Excluding s3 folders from global search
+ if (entry && entry.isFile) {
+ entry.url = PlatformIO.getURLforPath(entry.path);
+ return entry;
+ }
+ }
+ );
+ }
+
+ searchResultCount += enhancedSearchResult.length;
+ dispatch(AppActions.appendSearchResults(enhancedSearchResult));
dispatch(AppActions.hideNotifications());
if (isCloudLocation) {
PlatformIO.disableObjectStoreSupport();