From 482c4d1ca4499ae4e80f592176648ee2c03f16b8 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Sat, 7 Jan 2023 01:18:50 +0530 Subject: [PATCH] fix: Fixed issue where the "Attached to" in table view would report an extra number of links --- .../ContentTableView/ContentTableView.tsx | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/packages/web/src/javascripts/Components/ContentTableView/ContentTableView.tsx b/packages/web/src/javascripts/Components/ContentTableView/ContentTableView.tsx index 1b4984a54..cc6cb8bee 100644 --- a/packages/web/src/javascripts/Components/ContentTableView/ContentTableView.tsx +++ b/packages/web/src/javascripts/Components/ContentTableView/ContentTableView.tsx @@ -9,7 +9,6 @@ import { SortableItem, PrefKey, ApplicationEvent, - naturalSort, FileBackupRecord, SystemViewId, DecryptedItemInterface, @@ -25,7 +24,6 @@ import { useTable } from '../Table/useTable' import Menu from '../Menu/Menu' import FileMenuOptions from '../FileContextMenu/FileMenuOptions' import Icon from '../Icon/Icon' -import { createLinkFromItem } from '@/Utils/Items/Search/createLinkFromItem' import LinkedItemBubble from '../LinkedItems/LinkedItemBubble' import LinkedItemsPanel from '../LinkedItems/LinkedItemsPanel' import { LinkingController } from '@/Controllers/LinkingController' @@ -37,6 +35,8 @@ import { getIconAndTintForNoteType } from '@/Utils/Items/Icons/getIconAndTintFor import NotesOptions from '../NotesOptions/NotesOptions' import { NotesController } from '@/Controllers/NotesController/NotesController' import { HistoryModalController } from '@/Controllers/NoteHistory/HistoryModalController' +import { useItemLinks } from '@/Hooks/useItemLinks' +import { ItemLink } from '@/Utils/Items/Search/ItemLink' const ContextMenuCell = ({ items, @@ -218,6 +218,38 @@ const ItemNameCell = ({ item }: { item: DecryptedItemInterface }) => { ) } +const AttachedToCell = ({ item }: { item: DecryptedItemInterface }) => { + const { notesLinkedToItem, notesLinkingToItem, filesLinkedToItem, filesLinkingToItem, tagsLinkedToItem } = + useItemLinks(item) + const application = useApplication() + + const allLinks: ItemLink[] = (notesLinkedToItem as ItemLink[]).concat( + notesLinkingToItem, + filesLinkedToItem, + filesLinkingToItem, + tagsLinkedToItem, + ) + + if (!allLinks.length) { + return null + } + + return ( +
+ { + void application.items.unlinkItems(item, itemToUnlink) + }} + isBidirectional={false} + /> + {allLinks.length - 1 >= 1 && and {allLinks.length - 1} more...} +
+ ) +} + type Props = { application: WebApplication items: DecryptedItemInterface[] @@ -318,39 +350,10 @@ const ContentTableView = ({ { name: 'Attached to', hidden: isSmallBreakpoint || isMediumBreakpoint || isLargeBreakpoint, - cell: (item) => { - const links = [ - ...naturalSort(application.items.referencesForItem(item), 'title').map((item) => - createLinkFromItem(item, 'linked'), - ), - ...naturalSort(application.items.itemsReferencingItem(item), 'title').map((item) => - createLinkFromItem(item, 'linked-by'), - ), - ...application.items.getSortedTagsForItem(item).map((item) => createLinkFromItem(item, 'linked')), - ] - - if (!links.length) { - return null - } - - return ( -
- { - void application.items.unlinkItems(item, itemToUnlink) - }} - isBidirectional={false} - /> - {links.length - 1 > 1 && and {links.length - 1} more...} -
- ) - }, + cell: (item) => , }, ], - [application.items, isLargeBreakpoint, isMediumBreakpoint, isSmallBreakpoint, listHasFiles], + [isLargeBreakpoint, isMediumBreakpoint, isSmallBreakpoint, listHasFiles], ) const getRowId = useCallback((item: DecryptedItemInterface) => item.uuid, [])