mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 13:27:52 +08:00
FIX: IconPicker option to display only available icons (#20235)
Not all icons are shipped by default. Sidebar section icon picker should only display available icons.
This commit is contained in:
parent
d84d38cbe7
commit
85fbe3f628
@ -26,6 +26,7 @@
|
||||
@value={{link.icon}}
|
||||
@options={{hash maximum=1}}
|
||||
class={{link.iconCssClass}}
|
||||
@onlyAvailable={{true}}
|
||||
@onChange={{action (mut link.icon)}}
|
||||
/>
|
||||
</div>
|
||||
|
@ -36,7 +36,10 @@ export default MultiSelectComponent.extend({
|
||||
return this._cachedIconsList;
|
||||
} else {
|
||||
return ajax("/svg-sprite/picker-search", {
|
||||
data: { filter },
|
||||
data: {
|
||||
filter,
|
||||
only_available: this.onlyAvailable,
|
||||
},
|
||||
}).then((icons) => {
|
||||
icons = icons.map(this._processIcon);
|
||||
if (filter === "") {
|
||||
|
@ -46,10 +46,11 @@ class SvgSpriteController < ApplicationController
|
||||
|
||||
def icon_picker_search
|
||||
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do
|
||||
params.permit(:filter)
|
||||
params.permit(:filter, :only_available)
|
||||
filter = params[:filter] || ""
|
||||
only_available = params[:only_available]
|
||||
|
||||
icons = SvgSprite.icon_picker_search(filter)
|
||||
icons = SvgSprite.icon_picker_search(filter, only_available)
|
||||
render json: icons.take(200), root: false
|
||||
end
|
||||
end
|
||||
|
@ -426,7 +426,8 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
||||
false
|
||||
end
|
||||
|
||||
def self.icon_picker_search(keyword)
|
||||
def self.icon_picker_search(keyword, only_available = false)
|
||||
icons = all_icons(SiteSetting.default_theme_id) if only_available
|
||||
results = Set.new
|
||||
|
||||
sprite_sources(SiteSetting.default_theme_id).each do |item|
|
||||
@ -436,6 +437,7 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
||||
.css("symbol")
|
||||
.each do |sym|
|
||||
icon_id = prepare_symbol(sym, item[:filename])
|
||||
next if only_available && !icons.include?(icon_id)
|
||||
if keyword.empty? || icon_id.include?(keyword)
|
||||
sym.attributes["id"].value = icon_id
|
||||
sym.css("title").each(&:remove)
|
||||
|
@ -99,6 +99,21 @@ RSpec.describe SvgSpriteController do
|
||||
expect(data.length).to eq(1)
|
||||
expect(data[0]["id"]).to eq("fab-500px")
|
||||
end
|
||||
|
||||
it "should display only available" do
|
||||
sign_in(Fabricate(:user))
|
||||
|
||||
get "/svg-sprite/picker-search"
|
||||
data = response.parsed_body
|
||||
beer_icon = response.parsed_body.find { |i| i["id"] == "beer" }
|
||||
expect(beer_icon).to be_present
|
||||
|
||||
get "/svg-sprite/picker-search", params: { only_available: "true" }
|
||||
data = response.parsed_body
|
||||
beer_icon = response.parsed_body.find { |i| i["id"] == "beer" }
|
||||
expect(beer_icon).to be nil
|
||||
expect(data.length).to eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#svg_icon" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user