From 81cae9cbe00f11fe6b554e85822c6c64567c3be0 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 18 Sep 2025 18:39:45 +0200 Subject: [PATCH] Fix default handling --- app/assets/stylesheets/filters.css | 2 +- .../controllers/combobox_controller.js | 34 +++++++- .../filters/settings/_assignees.html.erb | 85 ++++++------------- app/views/filters/settings/_closers.html.erb | 55 +++++------- app/views/filters/settings/_controls.html.erb | 8 +- app/views/filters/settings/_creators.html.erb | 55 +++++------- .../filters/settings/_indexed_by.html.erb | 10 ++- .../filters/settings/_sorted_by.html.erb | 11 +-- 8 files changed, 119 insertions(+), 141 deletions(-) diff --git a/app/assets/stylesheets/filters.css b/app/assets/stylesheets/filters.css index a2141bbc6..2b9b9929a 100644 --- a/app/assets/stylesheets/filters.css +++ b/app/assets/stylesheets/filters.css @@ -116,7 +116,7 @@ display: block; } - &:has([aria-checked="true"]) { + &:has([aria-checked="true"]):not(.quick-filter--with-default) { .input--select { --input-background: var(--color-selected); } diff --git a/app/javascript/controllers/combobox_controller.js b/app/javascript/controllers/combobox_controller.js index 92778215a..4764b8ceb 100644 --- a/app/javascript/controllers/combobox_controller.js +++ b/app/javascript/controllers/combobox_controller.js @@ -6,11 +6,13 @@ export default class extends Controller { static targets = [ "label", "item", "hiddenFieldTemplate" ] static values = { selectPropertyName: { type: String, default: "aria-checked" }, - defaultValue: String + defaultValue: String, + defaultLabel: String } + static classes = ["withDefault"] connect() { - this.labelTarget.textContent = this.#selectedLabel + this.#selectedItem = this.#selectedItem } change(event) { @@ -21,6 +23,14 @@ export default class extends Controller { } get #selectedLabel() { + const selectedValue = this.#selectedItemValue() + console.debug("Es ", this.defaultValueValue); + if (this.hasDefaultLabelValue && (selectedValue === this.defaultValueValue || !selectedValue)) { + return this.defaultLabelValue + } + + console.debug("EIN", this.#selectedItem); + return this.#selectedItem?.dataset?.comboboxLabel || "" } @@ -28,11 +38,18 @@ export default class extends Controller { return this.itemTargets.find(item => item.getAttribute(this.selectPropertyNameValue) === "true") } + #selectedItemValue() { + return this.#selectedItem?.dataset?.comboboxValue || "" + } + set #selectedItem(item) { + if (!item) return + this.#clearSelection() item.setAttribute(this.selectPropertyNameValue, "true") this.labelTarget.textContent = this.#selectedLabel this.hiddenField.value = item.dataset.comboboxValue + this.#updateWithDefaultClass() } #clearSelection() { @@ -53,4 +70,17 @@ export default class extends Controller { this.element.appendChild(field) return field } + + #updateWithDefaultClass() { + if (this.hasWithDefaultClass && this.hasDefaultValueValue) { + const selectedValue = this.#selectedItemValue() + const shouldHaveClass = selectedValue === this.defaultValueValue + + if (shouldHaveClass) { + this.element.classList.add(this.withDefaultClass) + } else { + this.element.classList.remove(this.withDefaultClass) + } + } + } } diff --git a/app/views/filters/settings/_assignees.html.erb b/app/views/filters/settings/_assignees.html.erb index 2ea5e389f..7bdc68f40 100644 --- a/app/views/filters/settings/_assignees.html.erb +++ b/app/views/filters/settings/_assignees.html.erb @@ -1,18 +1,19 @@ <% filter = user_filtering.filter %> <%= tag.div class: "quick-filter position-relative", - data: { controller: "dialog", action: "keydown.esc->dialog#close click@document->dialog#closeOnClickOutside", filter_show: user_filtering.show_assignees? } do %> - + + <%= filter_dialog "Assigned to…" do %> Assigned to… @@ -21,55 +22,25 @@ type: "search", autocorrect: "off", autocomplete: "off", data: { "1p-ignore": "true", filter_target: "input", action: "input->filter#filter" } %> <% end %> -