Fix: disable toggle for share link creation without archive version, fix auto-copy in Safari (#4885)

* Fix: disable share link archive switch if archive version doesnt exist

* Fix: Add brief timeout before copy after share link creation for Safari, only show if succeeded

* Update messages.xlf
This commit is contained in:
shamoon
2023-12-07 13:48:33 -08:00
committed by GitHub
parent 5cd17e71e2
commit 5942cd6cd2
6 changed files with 65 additions and 39 deletions

View File

@@ -38,7 +38,7 @@
<li class="list-group-item pt-3 pb-2">
<div class="input-group input-group-sm w-100">
<div class="form-check form-switch ms-auto">
<input class="form-check-input" type="checkbox" role="switch" id="versionSwitch" [(ngModel)]="archiveVersion">
<input class="form-check-input" type="checkbox" role="switch" id="versionSwitch" [disabled]="!hasArchiveVersion" [(ngModel)]="useArchiveVersion">
<label class="form-check-label small" for="versionSwitch" i18n>Share archive version</label>
</div>
</div>

View File

@@ -19,6 +19,7 @@ import { ToastService } from 'src/app/services/toast.service'
import { environment } from 'src/environments/environment'
import { ShareLinksDropdownComponent } from './share-links-dropdown.component'
import { Clipboard } from '@angular/cdk/clipboard'
import { By } from '@angular/platform-browser'
describe('ShareLinksDropdownComponent', () => {
let component: ShareLinksDropdownComponent
@@ -88,7 +89,7 @@ describe('ShareLinksDropdownComponent', () => {
.mockReturnValueOnce(throwError(() => new Error('Unable to get links')))
component.documentId = 99
component.refresh()
component.ngOnInit()
fixture.detectChanges()
expect(toastSpy).toHaveBeenCalled()
})
@@ -97,12 +98,13 @@ describe('ShareLinksDropdownComponent', () => {
const createSpy = jest.spyOn(shareLinkService, 'createLinkForDocument')
component.documentId = 99
component.expirationDays = 7
component.archiveVersion = false
component.useArchiveVersion = false
const expiration = new Date()
expiration.setDate(expiration.getDate() + 7)
const copySpy = jest.spyOn(clipboard, 'copy')
copySpy.mockReturnValue(true)
const refreshSpy = jest.spyOn(component, 'refresh')
component.createLink()
@@ -117,8 +119,10 @@ describe('ShareLinksDropdownComponent', () => {
fixture.detectChanges()
tick(3000)
expect(copySpy).toHaveBeenCalled()
expect(refreshSpy).toHaveBeenCalled()
expect(copySpy).toHaveBeenCalled()
expect(component.copied).toEqual(1)
tick(100) // copy timeout
}))
it('should show error on link creation if needed', () => {
@@ -212,4 +216,16 @@ describe('ShareLinksDropdownComponent', () => {
'http://example.domainwithapiinit.com:1234/subpath/share/123abc123'
)
})
it('should disable archive switch & option if no archive available', () => {
component.hasArchiveVersion = false
component.ngOnInit()
fixture.detectChanges()
expect(component.useArchiveVersion).toBeFalsy()
expect(
fixture.debugElement.query(By.css("input[type='checkbox']")).attributes[
'ng-reflect-is-disabled'
]
).toBeTruthy()
})
})

View File

@@ -38,6 +38,9 @@ export class ShareLinksDropdownComponent implements OnInit {
@Input()
disabled: boolean = false
@Input()
hasArchiveVersion: boolean = true
shareLinks: PaperlessShareLink[]
loading: boolean = false
@@ -46,7 +49,7 @@ export class ShareLinksDropdownComponent implements OnInit {
expirationDays: number = 7
archiveVersion: boolean = true
useArchiveVersion: boolean = true
constructor(
private shareLinkService: ShareLinkService,
@@ -56,6 +59,7 @@ export class ShareLinksDropdownComponent implements OnInit {
ngOnInit(): void {
if (this._documentId !== undefined) this.refresh()
this.useArchiveVersion = this.hasArchiveVersion
}
refresh() {
@@ -94,11 +98,13 @@ export class ShareLinksDropdownComponent implements OnInit {
}
copy(link: PaperlessShareLink) {
this.clipboard.copy(this.getShareUrl(link))
this.copied = link.id
setTimeout(() => {
this.copied = null
}, 3000)
const success = this.clipboard.copy(this.getShareUrl(link))
if (success) {
this.copied = link.id
setTimeout(() => {
this.copied = null
}, 3000)
}
}
canShare(link: PaperlessShareLink): boolean {
@@ -132,7 +138,7 @@ export class ShareLinksDropdownComponent implements OnInit {
this.shareLinkService
.createLinkForDocument(
this._documentId,
this.archiveVersion
this.useArchiveVersion
? PaperlessFileVersion.Archive
: PaperlessFileVersion.Original,
expiration
@@ -140,7 +146,9 @@ export class ShareLinksDropdownComponent implements OnInit {
.subscribe({
next: (result) => {
this.loading = false
this.copy(result)
setTimeout(() => {
this.copy(result)
}, 10)
this.refresh()
},
error: (e) => {