Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix: only show create when there is text, hide set values if no fields in cf bulk edit dropdown (#13688)

shamoondb15c8280459
diff --git a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.html b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.html
index f03895662..4355fcca1 100644
--- a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.html
+++ b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.html
@@ -49,7 +49,7 @@
</cdk-virtual-scroll-viewport>
}
@if (editing) {
- @if (filteredItems.length === 0 && createRef !== undefined) {
+ @if (filteredItems.length === 0 && createRef !== undefined && filterText?.length > 0) {
<button class="list-group-item list-group-item-action bg-light" (click)="createClicked()" [disabled]="disabled">
<small class="ms-2"><ng-container i18n>Create</ng-container> "{{filterText}}"</small>
<i-bs width="1.5em" height="1em" name="plus"></i-bs>
@@ -62,7 +62,7 @@
</button>
}
}
- @if (extraButtonTitle) {
+ @if (extraButtonTitle && (showExtraButtonIfEmpty || filteredItems?.length > 0)) {
<button class="list-group-item list-group-item-action bg-light d-flex align-items-center" (click)="extraButtonClicked($event)" [disabled]="disabled">
<small class="ms-2 fw-bold">{{extraButtonTitle}}</small>
<i-bs width="1.5em" height="1em" name="arrow-right"></i-bs>
diff --git a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts
index b3ba7b8e7..95b1dd1fc 100644
--- a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts
+++ b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.spec.ts
@@ -911,6 +911,25 @@ describe('FilterableDropdownComponent & FilterableDropdownSelectionModel', () =>
expect(createSpy).toHaveBeenCalled()
})
+ it('should only show create when a non-empty filter has no matches', () => {
+ component.selectionModel.items = []
+ component.icon = 'tag-fill'
+ component.editing = true
+ component.createRef = jest.fn()
+
+ fixture.detectChanges()
+ expect(fixture.nativeElement.textContent).not.toContain('Create')
+ component.listFilterEnter()
+ expect(component.createRef).not.toHaveBeenCalled()
+
+ const filterInput: HTMLInputElement =
+ fixture.nativeElement.querySelector('input[type="text"]')
+ filterInput.value = 'FooBar'
+ filterInput.dispatchEvent(new Event('input'))
+ fixture.detectChanges()
+ expect(fixture.nativeElement.textContent).toContain('Create "FooBar"')
+ })
+
it('should exclude item and trigger change event', () => {
const id = 1
const state = ToggleableItemState.Selected
@@ -970,4 +989,18 @@ describe('FilterableDropdownComponent & FilterableDropdownSelectionModel', () =>
expect(extraButtonClicked).toBeTruthy()
expect(applied).toBeFalsy()
})
+
+ it('should only show the extra button for an empty result when enabled', () => {
+ component.selectionModel.items = items
+ component.icon = 'tag-fill'
+ component.extraButtonTitle = 'Extra'
+ component.filterText = 'FooBar'
+
+ fixture.detectChanges()
+ expect(fixture.nativeElement.textContent).not.toContain('Extra')
+
+ fixture.componentRef.setInput('showExtraButtonIfEmpty', true)
+ fixture.detectChanges()
+ expect(fixture.nativeElement.textContent).toContain('Extra')
+ })
})
diff --git a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts
index 5b4ff0d12..6db19fa00 100644
--- a/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts
+++ b/src-ui/src/app/components/common/filterable-dropdown/filterable-dropdown.component.ts
@@ -774,6 +774,9 @@ export class FilterableDropdownComponent
@Input()
extraButtonTitle: string
+ @Input()
+ showExtraButtonIfEmpty: boolean = false
+
creating: boolean = false
@Output()
@@ -892,7 +895,11 @@ export class FilterableDropdownComponent
this.dropdown.close()
}
}, 200)
- } else if (filtered.length == 0 && this.createRef) {
+ } else if (
+ filtered.length == 0 &&
+ this.createRef &&
+ this.filterText?.length > 0
+ ) {
this.createClicked()
}
}