fix(web): [OCISDEV-1581] fix copy link in EPUB library book details (#13270)
fix(web): [OCISDEV-1581] fix copy link in EPUB library book details (#13239) Signed-off-by: Matteo <matteo.sonnenholzner@kiteworks.com>
This commit is contained in:
1 parent
01a1774b9b
commit
4624bcca86
3 files changed
+33
-2
No files matched your search
@@ -0,0 +1,11 @@
|
||||
Bugfix: fixed copy link failing in the EPUB library book details
|
||||
|
||||
Clicking "Copy link" in the details of a book in the EPUB library showed
|
||||
a "The link could not be copied" error whenever the book had been found
|
||||
through the server-side search, because those search results carry no
|
||||
link to the file.
|
||||
|
||||
The link is now built from the id of the file when the search result does
|
||||
not provide one, so copying the link works for all books.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/13239
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
useCapabilityStore,
|
||||
useClientService,
|
||||
useClipboard,
|
||||
useConfigStore,
|
||||
useDownloadFile,
|
||||
useFolderLink,
|
||||
useMessages,
|
||||
@@ -34,6 +35,7 @@ export function useLibrary() {
|
||||
const { showErrorMessage } = useMessages()
|
||||
const clientService = useClientService()
|
||||
const capabilityStore = useCapabilityStore()
|
||||
const configStore = useConfigStore()
|
||||
const spacesStore = useSpacesStore()
|
||||
const router = useRouter()
|
||||
const { downloadFile } = useDownloadFile()
|
||||
@@ -253,7 +255,10 @@ export function useLibrary() {
|
||||
}
|
||||
|
||||
async function copyBookLink(book: LibraryBook): Promise<boolean> {
|
||||
const privateLink = book.resource.privateLink
|
||||
// search REPORT results don't carry oc:privatelink, so build it from the file id
|
||||
const fileId = book.resource.fileId || book.resource.id
|
||||
const privateLink =
|
||||
book.resource.privateLink || (fileId ? `${configStore.serverUrl}f/${fileId}` : '')
|
||||
if (!privateLink) {
|
||||
showErrorMessage({ title: $gettext('The link could not be copied') })
|
||||
return false
|
||||
|
||||
@@ -216,7 +216,7 @@ describe('useLibrary', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('reports an error when no private link is available', async () => {
|
||||
it('builds the link from the file id when the resource has no private link', async () => {
|
||||
await withLibrary({ searchAvailable: true }, async ({ library }) => {
|
||||
const book = {
|
||||
resource: epubResource({ privateLink: undefined }),
|
||||
@@ -225,6 +225,21 @@ describe('useLibrary', () => {
|
||||
|
||||
const success = await library.copyBookLink(book)
|
||||
|
||||
expect(success).toBe(true)
|
||||
expect(copyToClipboard).toHaveBeenCalledWith(expect.stringMatching(/\/f\/file-1$/))
|
||||
expect(showErrorMessage).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
it('reports an error when no link can be built', async () => {
|
||||
await withLibrary({ searchAvailable: true }, async ({ library }) => {
|
||||
const book = {
|
||||
resource: epubResource({ privateLink: undefined, fileId: undefined, id: undefined }),
|
||||
space: personalSpace
|
||||
} as never
|
||||
|
||||
const success = await library.copyBookLink(book)
|
||||
|
||||
expect(success).toBe(false)
|
||||
expect(copyToClipboard).not.toHaveBeenCalled()
|
||||
expect(showErrorMessage).toHaveBeenCalled()
|
||||
|
||||
Reference in new issue
Block a user