diff --git a/src/gui/src/UI/Dashboard/TabFiles.js b/src/gui/src/UI/Dashboard/TabFiles.js index 8a059cbb3..d403cab3c 100644 --- a/src/gui/src/UI/Dashboard/TabFiles.js +++ b/src/gui/src/UI/Dashboard/TabFiles.js @@ -5703,15 +5703,21 @@ const TabFiles = { * Selects the rows for the items a share link names, replacing the * current selection. Matched by uid — the link's `///` * form carries it, and unlike the name it survives a rename. Values that - * aren't shared paths, or items no longer shared, match nothing. + * aren't shared paths, or items no longer shared, match nothing. A + * people filter that hides one of the items gives way to everyone's. * * @param {string[]} sharedPaths - The link's `?shared=` values - * @returns {void} + * @returns {Promise} */ - selectSharedRows (sharedPaths) { + async selectSharedRows (sharedPaths) { const wanted = new Set(shared_uids_from_paths(sharedPaths)); if ( wanted.size === 0 ) return; - this.selectRowsWhere((row) => wanted.has(String(row.getAttribute('data-uid') ?? '').toLowerCase())); + const uidOf = (row) => String(row.getAttribute('data-uid') ?? '').toLowerCase(); + if ( this.sharerFilter && this.currentPath === window.shared_path ) { + const shown = new Set(this.$el_window.find('.files-tab .files .row').map((_, row) => uidOf(row)).get()); + if ( [...wanted].some((uid) => ! shown.has(uid)) ) await this.setSharerFilter(null); + } + this.selectRowsWhere((row) => wanted.has(uidOf(row))); }, /** diff --git a/src/gui/src/UI/Dashboard/TabFiles.test.js b/src/gui/src/UI/Dashboard/TabFiles.test.js index f4769f6a6..4cd0bc06f 100644 --- a/src/gui/src/UI/Dashboard/TabFiles.test.js +++ b/src/gui/src/UI/Dashboard/TabFiles.test.js @@ -598,6 +598,8 @@ describe('TabFiles people filter across navigation', () => { TabFiles.renderingDirectory = false; TabFiles.trashedNames ??= new Map(); TabFiles.sharerFilter = null; + // jsdom has no layout to scroll. + Element.prototype.scrollIntoView ??= () => {}; vi.spyOn(TabFiles, 'listSharedView').mockImplementation(async () => [share('a', 'ann'), share('b', 'bob')]); vi.spyOn(TabFiles, 'applyColumnWidths').mockImplementation(() => {}); vi.spyOn(TabFiles, 'renderItem').mockImplementation(async (file) => { @@ -620,6 +622,31 @@ describe('TabFiles people filter across navigation', () => { expect($('.sharer-chip.active').attr('data-sharer')).toBe('bob'); }); + it('gives way to show an item a share link or notification names', async () => { + const uid = '5298098f-d8a2-41da-828f-867b9a7f0cce'; + TabFiles.listSharedView.mockImplementation(async () => [{ ...share('a', 'ann'), uid }, share('b', 'bob')]); + await TabFiles.renderDirectory(SHARED); + await TabFiles.setSharerFilter('bob'); + + await TabFiles.selectSharedRows([`/ann/${uid}/a`]); + + expect(TabFiles.sharerFilter).toBeNull(); + expect(listed()).toEqual(['a', 'b']); + expect($('.files .row.selected').attr('data-name')).toBe('a'); + }); + + it('stays put when the named item is already shown', async () => { + const uid = '5298098f-d8a2-41da-828f-867b9a7f0cce'; + TabFiles.listSharedView.mockImplementation(async () => [share('a', 'ann'), { ...share('b', 'bob'), uid }]); + await TabFiles.renderDirectory(SHARED); + await TabFiles.setSharerFilter('bob'); + + await TabFiles.selectSharedRows([`/bob/${uid}/b`]); + + expect(TabFiles.sharerFilter).toBe('bob'); + expect($('.files .row.selected').attr('data-name')).toBe('b'); + }); + it("clears once the user goes back to their own files", async () => { await TabFiles.renderDirectory(SHARED); await TabFiles.setSharerFilter('bob');