mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-13 22:33:19 +00:00
Bring the buttonsEnabled stuff into here
This commit is contained in:
+2
-2
@@ -49,10 +49,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn" [class]="cancelBtnClass" (click)="cancel()" [disabled]="!buttonsEnabled">
|
||||
<button type="button" class="btn" [class]="cancelBtnClass" (click)="cancel()" [disabled]="!buttonsEnabled()">
|
||||
<span class="d-inline-block" style="padding-bottom: 1px;">{{cancelBtnCaption}}</span>
|
||||
</button>
|
||||
<button type="button" class="btn" [class]="btnClass" (click)="confirm()" [disabled]="!confirmButtonEnabled || !buttonsEnabled">
|
||||
<button type="button" class="btn" [class]="btnClass" (click)="confirm()" [disabled]="!confirmButtonEnabled || !buttonsEnabled()">
|
||||
{{btnCaption}}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
+2
-2
@@ -13,6 +13,6 @@
|
||||
<div class="form-text mt-2" i18n>Select one document to add as a version.</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-outline-secondary" (click)="cancel()" [disabled]="!buttonsEnabled" i18n>Cancel</button>
|
||||
<button type="button" class="btn btn-primary" (click)="confirm()" [disabled]="!buttonsEnabled || selectedDocumentIDs.length !== 1" i18n>Add version</button>
|
||||
<button type="button" class="btn btn-outline-secondary" (click)="cancel()" [disabled]="!buttonsEnabled()" i18n>Cancel</button>
|
||||
<button type="button" class="btn btn-primary" (click)="confirm()" [disabled]="!buttonsEnabled() || selectedDocumentIDs.length !== 1" i18n>Add version</button>
|
||||
</div>
|
||||
|
||||
+17
@@ -53,4 +53,21 @@ describe('AddExistingDocumentVersionDialogComponent', () => {
|
||||
|
||||
expect(activeModal.dismiss).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should re-render the buttons when they are toggled from outside', async () => {
|
||||
const cancelButton: HTMLButtonElement = fixture.nativeElement.querySelector(
|
||||
'.modal-footer button'
|
||||
)
|
||||
expect(cancelButton.disabled).toBeFalsy()
|
||||
|
||||
// No detectChanges: the dropdown toggling this from a request callback is
|
||||
// all that happens, and nothing else schedules a render for the modal
|
||||
component.buttonsEnabled.set(false)
|
||||
await fixture.whenStable()
|
||||
expect(cancelButton.disabled).toBeTruthy()
|
||||
|
||||
component.buttonsEnabled.set(true)
|
||||
await fixture.whenStable()
|
||||
expect(cancelButton.disabled).toBeFalsy()
|
||||
})
|
||||
})
|
||||
|
||||
+9
-2
@@ -1,4 +1,11 @@
|
||||
import { Component, EventEmitter, Input, Output, inject } from '@angular/core'
|
||||
import {
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
Output,
|
||||
inject,
|
||||
signal,
|
||||
} from '@angular/core'
|
||||
import { FormsModule } from '@angular/forms'
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { DocumentLinkComponent } from 'src/app/components/common/input/document-link/document-link.component'
|
||||
@@ -15,7 +22,7 @@ export class AddExistingDocumentVersionDialogComponent {
|
||||
@Output() confirmClicked = new EventEmitter<number>()
|
||||
|
||||
selectedDocumentIDs: number[] = []
|
||||
buttonsEnabled = true
|
||||
readonly buttonsEnabled = signal(true)
|
||||
|
||||
confirm(): void {
|
||||
if (this.selectedDocumentIDs.length !== 1) return
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { DatePipe } from '@angular/common'
|
||||
import { SimpleChange } from '@angular/core'
|
||||
import { SimpleChange, signal } from '@angular/core'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||
@@ -342,7 +342,7 @@ describe('DocumentVersionDropdownComponent', () => {
|
||||
const modal = {
|
||||
componentInstance: {
|
||||
rootDocumentID: null,
|
||||
buttonsEnabled: true,
|
||||
buttonsEnabled: signal(true),
|
||||
confirmClicked,
|
||||
},
|
||||
close: jest.fn(),
|
||||
|
||||
+2
-2
@@ -290,7 +290,7 @@ export class DocumentVersionDropdownComponent implements OnChanges, OnDestroy {
|
||||
dialog.confirmClicked
|
||||
.pipe(takeUntil(this.destroy$), takeUntil(this.documentChange$))
|
||||
.subscribe((existingDocumentID) => {
|
||||
dialog.buttonsEnabled = false
|
||||
dialog.buttonsEnabled.set(false)
|
||||
const versionLabel = this.newVersionLabel?.trim()
|
||||
this.documentsService
|
||||
.mergeDocumentsAsVersions(
|
||||
@@ -301,7 +301,7 @@ export class DocumentVersionDropdownComponent implements OnChanges, OnDestroy {
|
||||
.pipe(
|
||||
switchMap(() => this.documentsService.getVersions(this.documentId)),
|
||||
first(),
|
||||
finalize(() => (dialog.buttonsEnabled = true)),
|
||||
finalize(() => dialog.buttonsEnabled.set(true)),
|
||||
takeUntil(this.destroy$),
|
||||
takeUntil(this.documentChange$)
|
||||
)
|
||||
|
||||
@@ -1012,7 +1012,6 @@ export class BulkEditorComponent
|
||||
mergeDialog.confirmClicked
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
mergeDialog.buttonsEnabled = false
|
||||
this.executeDocumentAction(
|
||||
modal,
|
||||
this.documentService.mergeDocumentsAsVersions(
|
||||
|
||||
Reference in New Issue
Block a user