Skip to content

Commit f74a438

Browse files
author
Yuriy Kurant
authored
DEV: select-kit autoFilterable improvements (#36241)
As a follow-up of #36218. * decrease a threshold number from `>15` to `>=10` for filter to render * add const `FILTER_VISIBILITY_THRESHOLD` as a single source of truth for controlling when filter should be shown * changes hardcoded threshold with imported `FILTER_VISIBILITY_THRESHOLD` in combo-box * consolidate usage of `visible: true` in specs
1 parent d727cb5 commit f74a438

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

frontend/discourse/select-kit/components/category-drop.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import CategoryDropMoreCollection from "discourse/select-kit/components/category
1313
import CategoryRow from "discourse/select-kit/components/category-row";
1414
import ComboBoxComponent from "discourse/select-kit/components/combo-box";
1515
import {
16+
FILTER_VISIBILITY_THRESHOLD,
1617
MAIN_COLLECTION,
1718
pluginApiIdentifiers,
1819
selectKitOptions,
@@ -90,7 +91,10 @@ export default class CategoryDrop extends ComboBoxComponent {
9091

9192
@computed("content.length", "site.lazy_load_categories")
9293
get autoFilterable() {
93-
return this.site.lazy_load_categories || this.content.length >= 10;
94+
return (
95+
this.site.lazy_load_categories ||
96+
this.content.length >= FILTER_VISIBILITY_THRESHOLD
97+
);
9498
}
9599

96100
@computed("value", "selectKit.options.{subCategory,noSubcategories}")

frontend/discourse/select-kit/components/combo-box.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { gte } from "@ember/object/computed";
22
import { classNames } from "@ember-decorators/component";
33
import SingleSelectComponent from "discourse/select-kit/components/single-select";
44
import ComboBoxHeader from "./combo-box/combo-box-header";
5-
import { pluginApiIdentifiers, selectKitOptions } from "./select-kit";
5+
import {
6+
FILTER_VISIBILITY_THRESHOLD,
7+
pluginApiIdentifiers,
8+
selectKitOptions,
9+
} from "./select-kit";
610

711
@classNames("combobox", "combo-box")
812
@pluginApiIdentifiers(["combo-box"])
@@ -15,5 +19,5 @@ import { pluginApiIdentifiers, selectKitOptions } from "./select-kit";
1519
shouldDisplayIcon: false,
1620
})
1721
export default class ComboBox extends SingleSelectComponent {
18-
@gte("content.length", 10) autoFilterable;
22+
@gte("content.length", FILTER_VISIBILITY_THRESHOLD) autoFilterable;
1923
}

frontend/discourse/select-kit/components/select-kit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import SelectedName from "./selected-name";
3636

3737
export const MAIN_COLLECTION = "MAIN_COLLECTION";
3838
export const ERRORS_COLLECTION = "ERRORS_COLLECTION";
39+
export const FILTER_VISIBILITY_THRESHOLD = 10;
3940

4041
function isDocumentRTL() {
4142
return document.documentElement.classList.contains("rtl");
@@ -400,7 +401,7 @@ export default class SelectKit extends Component {
400401
return (
401402
this.selectKit.filter &&
402403
this.options.autoFilterable &&
403-
this.content.length > 15
404+
this.content.length >= FILTER_VISIBILITY_THRESHOLD
404405
);
405406
}
406407

spec/system/page_objects/components/select_kit.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def component
1818
end
1919

2020
def visible?
21-
has_css?(@context)
21+
has_css?(@context, visible: true)
2222
end
2323

2424
def hidden?
@@ -35,7 +35,7 @@ def collapsed_component
3535
end
3636

3737
def expanded?
38-
component.has_css?(".select-kit-body", visible: :visible)
38+
component.has_css?(".select-kit-body", visible: true)
3939
end
4040

4141
def is_collapsed?

spec/system/page_objects/components/welcome_banner.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,24 @@ def has_bg_img?(url)
6363
has_css?(
6464
".welcome-banner.--with-bg-img .custom-search-banner-wrap.welcome-banner__wrap",
6565
style: "background-image:url(#{url});",
66-
visible: :visible,
66+
visible: true,
6767
)
6868
end
6969

7070
def has_custom_text_color?(color)
71-
has_css?(
72-
".welcome-banner .welcome-banner__title",
73-
style: "color:#{color};",
74-
visible: :visible,
75-
)
71+
has_css?(".welcome-banner .welcome-banner__title", style: "color:#{color};", visible: true)
7672
end
7773

7874
def has_no_custom_text_color?(color)
7975
has_no_css?(".welcome-banner .welcome-banner__title", style: "color:#{color};")
8076
end
8177

8278
def above_topic_content?
83-
has_css?("#main-outlet > .--location-above-topic-content", visible: :visible)
79+
has_css?("#main-outlet > .--location-above-topic-content", visible: true)
8480
end
8581

8682
def below_site_header?
87-
has_css?(".discourse-root > .--location-below-site-header", visible: :visible)
83+
has_css?(".discourse-root > .--location-below-site-header", visible: true)
8884
end
8985
end
9086
end

0 commit comments

Comments
 (0)