FIX: bump the number of svg icons we return to first 500 (#29286)
instead of the first 200 which would "hide" some icons from the list when picking an icon for a badge or a sidebar link. Internal ref - t/119652
This commit is contained in:
parent
6bdb6650a2
commit
97ba39e60f
|
@ -48,8 +48,9 @@ class SvgSpriteController < ApplicationController
|
||||||
filter = params[:filter] || ""
|
filter = params[:filter] || ""
|
||||||
only_available = params[:only_available]
|
only_available = params[:only_available]
|
||||||
|
|
||||||
icons = SvgSprite.icon_picker_search(filter, only_available)
|
icons = SvgSprite.icon_picker_search(filter, only_available).take(500)
|
||||||
render json: icons.take(200), root: false
|
|
||||||
|
render json: icons, root: false
|
||||||
end
|
end
|
||||||
|
|
||||||
def svg_icon
|
def svg_icon
|
||||||
|
|
|
@ -426,12 +426,10 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.icon_picker_search(keyword, only_available = false)
|
def self.icon_picker_search(keyword, only_available = false)
|
||||||
icons = all_icons(SiteSetting.default_theme_id) if only_available
|
|
||||||
|
|
||||||
symbols = svgs_for(SiteSetting.default_theme_id)
|
symbols = svgs_for(SiteSetting.default_theme_id)
|
||||||
symbols.slice!(*icons) if only_available
|
symbols.slice!(*all_icons(SiteSetting.default_theme_id)) if only_available
|
||||||
symbols.reject! { |icon_id, sym| !icon_id.include?(keyword) } unless keyword.empty?
|
symbols.reject! { |icon_id, _sym| !icon_id.include?(keyword) } if keyword.present?
|
||||||
symbols.sort_by(&:first).map { |icon_id, symbol| { id: icon_id, symbol: symbol } }
|
symbols.sort_by(&:first).map { |id, symbol| { id:, symbol: } }
|
||||||
end
|
end
|
||||||
|
|
||||||
# For use in no_ember .html.erb layouts
|
# For use in no_ember .html.erb layouts
|
||||||
|
|
|
@ -85,14 +85,14 @@ RSpec.describe SvgSpriteController do
|
||||||
expect(response.status).to eq(403)
|
expect(response.status).to eq(403)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with no filter and max out at 200 results" do
|
it "should work with no filter and max out at 500 results" do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
get "/svg-sprite/picker-search"
|
get "/svg-sprite/picker-search"
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
|
||||||
data = response.parsed_body
|
data = response.parsed_body
|
||||||
expect(data.length).to eq(200)
|
expect(data.length).to be <= 500
|
||||||
expect(data[0]["id"]).to eq("0")
|
expect(data[0]["id"]).to eq("0")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ RSpec.describe SvgSpriteController do
|
||||||
data = response.parsed_body
|
data = response.parsed_body
|
||||||
beer_icon = response.parsed_body.find { |i| i["id"] == "beer-mug-empty" }
|
beer_icon = response.parsed_body.find { |i| i["id"] == "beer-mug-empty" }
|
||||||
expect(beer_icon).to be nil
|
expect(beer_icon).to be nil
|
||||||
expect(data.length).to eq(200)
|
expect(data.length).to eq(250)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue