Skip to content

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

fix: correcting the algorithm for finding incoming links

Ilian Sapundshievb605a1e7e6fd
diff --git a/src/renderer/components/LinksTab.tsx b/src/renderer/components/LinksTab.tsx
index e444c8a7c..5c17cd6fb 100644
--- a/src/renderer/components/LinksTab.tsx
+++ b/src/renderer/components/LinksTab.tsx
@@ -17,7 +17,7 @@
*/
import AppConfig from '-/AppConfig';
-import { LinkIcon } from '-/components/CommonIcons';
+import { LinkIcon, ReloadIcon } from '-/components/CommonIcons';
import TsButton from '-/components/TsButton';
import { TabNames } from '-/hooks/EntryPropsTabsContextProvider';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
@@ -28,6 +28,7 @@ import { TS } from '-/tagspaces.namespace';
import { getURLParameter } from '-/utils/dom';
import { Box, Typography } from '@mui/material';
import { extractLinks } from '@tagspaces/tagspaces-common/misc';
+import { generateSharingLink } from '@tagspaces/tagspaces-common/paths';
import { useEffect, useReducer, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
@@ -38,7 +39,7 @@ interface Props {}
function LinksTab(props: Props) {
const { t } = useTranslation();
const { findLocation } = useCurrentLocationContext();
- const { openedEntry, sharingLink, openLink } = useOpenedEntryContext();
+ const { openedEntry, openLink } = useOpenedEntryContext();
const { findLinks, checkIndexExist, isIndexing, createLocationIndex } =
useLocationIndexContext();
const selectedTabName = useSelector(getEntryContainerTab);
@@ -90,14 +91,15 @@ function LinksTab(props: Props) {
}
function setInboundLinks() {
- findLinks(sharingLink, location.uuid).then((entries) => {
+ const entryID = openedEntry.uuid;
+ findLinks(entryID, location.uuid).then((entries) => {
inboundLinks.current = entries;
indexExist.current = true;
forceUpdate();
});
}
- const linkButton = (link: TS.Link) => {
+ const outgoingLinkButton = (link: TS.Link) => {
let url = link.value ? link.value : link.href;
url = url.split('\\').join(''); // tmp fix for milkdown issue
let buttonTitle = url;
@@ -147,35 +149,70 @@ function LinksTab(props: Props) {
);
};
+ const incomingLinkButton = (fsEntry: TS.FileSystemEntry) => {
+ let buttonTitle = fsEntry.name;
+ const sharingLink = generateSharingLink(
+ fsEntry.locationID,
+ undefined,
+ fsEntry.path,
+ fsEntry.uuid,
+ );
+ return (
+ <>
+ <TsButton
+ data-tid={'linkTID' + fsEntry.uuid}
+ tooltip={fsEntry.path}
+ onClick={() => openLink(sharingLink)}
+ variant="text"
+ startIcon={
+ <TooltipTS title={sharingLink}>
+ <LinkIcon />
+ </TooltipTS>
+ }
+ style={{
+ marginRight: AppConfig.defaultSpaceBetweenButtons,
+ textTransform: 'none',
+ fontWeight: 'normal',
+ whiteSpace: 'nowrap',
+ overflow: 'hidden',
+ }}
+ >
+ {buttonTitle}
+ </TsButton>
+ <br />
+ </>
+ );
+ };
+
const findInboundButton = (title) => (
<TsButton
loading={isIndexing !== undefined}
data-tid={'generateInboundTID'}
- variant="text"
onClick={() =>
title === 'reGenerateInbound'
? refreshInboundLinks()
: setInboundLinks()
}
- style={{
- marginRight: AppConfig.defaultSpaceBetweenButtons,
- whiteSpace: 'nowrap',
- overflow: 'hidden',
- }}
+ startIcon={<ReloadIcon />}
>
{t('core:' + title)}
</TsButton>
);
return (
- <Box display="block">
- {links.current && links.current.length > 0 && (
- <>
- <Typography variant="caption">{t('core:outgoingLinks')}:</Typography>
- <br />
- {links.current.map((link) => linkButton(link))}
- </>
- )}
+ <>
+ <Box display="block">
+ {links.current && links.current.length > 0 && (
+ <>
+ <Typography variant="caption">
+ {t('core:outgoingLinks')} (
+ {t('found in the file content and/or its description')}):
+ </Typography>
+ <br />
+ {links.current?.map((link) => outgoingLinkButton(link))}
+ </>
+ )}
+ </Box>
<Box display="block">
<Typography variant="caption">
{t('core:incomingLinks')} (
@@ -184,21 +221,16 @@ function LinksTab(props: Props) {
<br />
{indexExist.current ? (
<>
- {inboundLinks.current &&
- inboundLinks.current.length > 0 &&
- inboundLinks.current.map((entry) => (
- <div>
- {entry.name}: {entry.links.map((link) => linkButton(link))}
- <br />
- </div>
- ))}{' '}
+ {inboundLinks.current?.map((entry) => {
+ return incomingLinkButton(entry);
+ })}
{findInboundButton('reGenerateInbound')}
</>
) : (
findInboundButton('generateInbound')
)}
</Box>
- </Box>
+ </>
);
}
diff --git a/src/renderer/hooks/LocationIndexContextProvider.tsx b/src/renderer/hooks/LocationIndexContextProvider.tsx
index 0d09a490f..74afdbd98 100644
--- a/src/renderer/hooks/LocationIndexContextProvider.tsx
+++ b/src/renderer/hooks/LocationIndexContextProvider.tsx
@@ -16,41 +16,35 @@
*
*/
-import React, {
- createContext,
- useEffect,
- useMemo,
- useReducer,
- useRef,
-} from 'react';
-import { useSelector } from 'react-redux';
-import { useTranslation } from 'react-i18next';
-import { TS } from '-/tagspaces.namespace';
-import { executePromisesInBatches } from '-/services/utils-io';
-import { getEnableWS } from '-/reducers/settings';
-import { loadJSONString } from '@tagspaces/tagspaces-common/utils-io';
-import { locationType } from '@tagspaces/tagspaces-common/misc';
-import {
- getMetaIndexFilePath,
- createIndex,
-} from '@tagspaces/tagspaces-indexer';
-import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
import AppConfig from '-/AppConfig';
+import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
+import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
+import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';
+import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';
+import { useNotificationContext } from '-/hooks/useNotificationContext';
+import { Pro } from '-/pro';
+import { getEnableWS } from '-/reducers/settings';
import Search from '-/services/search';
+import { executePromisesInBatches } from '-/services/utils-io';
+import { TS } from '-/tagspaces.namespace';
+import { CommonLocation } from '-/utils/CommonLocation';
+import useFirstRender from '-/utils/useFirstRender';
+import { locationType } from '@tagspaces/tagspaces-common/misc';
import {
+ cleanTrailingDirSeparator,
+ getMetaDirectoryPath,
getThumbFileLocationForDirectory,
getThumbFileLocationForFile,
- getMetaDirectoryPath,
joinPaths,
- cleanTrailingDirSeparator,
} from '@tagspaces/tagspaces-common/paths';
-import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
-import { useNotificationContext } from '-/hooks/useNotificationContext';
-import { useEditedEntryContext } from '-/hooks/useEditedEntryContext';
-import { useFSWatcherContext } from '-/hooks/useFSWatcherContext';
-import { CommonLocation } from '-/utils/CommonLocation';
-import { Pro } from '-/pro';
-import useFirstRender from '-/utils/useFirstRender';
+import { loadJSONString } from '@tagspaces/tagspaces-common/utils-io';
+import {
+ createIndex,
+ getMetaIndexFilePath,
+} from '@tagspaces/tagspaces-indexer';
+import React, { createContext, useEffect, useReducer, useRef } from 'react';
+import { useTranslation } from 'react-i18next';
+import { useSelector } from 'react-redux';
type LocationIndexContextData = {
//index: TS.FileSystemEntry[];
@@ -264,16 +258,24 @@ export const LocationIndexContextProvider = ({
}
async function findLinks(
- link: string,
+ entryID: string,
locationId: string,
): Promise<TS.FileSystemEntry[]> {
const lastIndex = await getLastIndex(locationId);
+ const foundEntriesLinkingToId = [];
if (!lastIndex || lastIndex.length < 1) {
- return undefined;
+ return foundEntriesLinkingToId;
}
- return lastIndex.filter(
- (i) => i.links && i.links.some((l) => l.href === link),
+ lastIndex.forEach((entry) =>
+ entry.links?.some((link) => {
+ if (link.type === 'tslink' && link.tseid) {
+ if (entryID === link.tseid) {
+ foundEntriesLinkingToId.push(entry);
+ }
+ }
+ }),
);
+ return foundEntriesLinkingToId;
}
/*function indexUpdateSidecarTags(path: string, tags: Array<TS.Tag>) {
diff --git a/src/renderer/tagspaces.namespace.d.ts b/src/renderer/tagspaces.namespace.d.ts
index 189dd94c5..9af96fe1b 100644
--- a/src/renderer/tagspaces.namespace.d.ts
+++ b/src/renderer/tagspaces.namespace.d.ts
@@ -212,6 +212,10 @@ export namespace TS {
* Should be the value of this links `href` attribute.
*/
href: string;
+ /**
+ * Entry id if link from type tslink and id is available
+ */
+ tseid: string;
/**
* The original entity substring.
*/