Skip to content

Commit

Permalink
nebulab/rainerd/admin/live-product-listing-search: [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Jul 28, 2023
1 parent 8a6e494 commit fb073cd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 39 deletions.
11 changes: 7 additions & 4 deletions admin/app/components/solidus_admin/ui/table/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
<%= form_with(
url: @base_search_url,
method: :get,
class: 'flex-grow',
"data-#{stimulus_id}-target": "searchForm",
"data-turbo-frame": table_frame_id,
html: {
class: 'flex-grow',
"data-#{stimulus_id}-target": "searchForm",
"data-turbo-frame": table_frame_id,
},
) do |form| %>
<label class="bg-white rounded border border-gray-300 items-center gap-1 px-3 py-1.5 inline-flex w-full justify-start">
<%= render component('ui/icon').new(name: 'search-line', class: "w-[1.4em] h-[1.4em] fill-gray-500") %>
<input
name="q[<%= @search_key %>]"
type="search"
placeholder="<%= t('.search_placeholder', resources: resource_plural_name) %>"
class="w-full placeholder:text-gray-400"
class="w-full placeholder:text-gray-400 appearance-none"
data-<%= stimulus_id %>-target="searchField"
data-action="<%= stimulus_id %>#search"
>
<button type="reset">
<%= render component('ui/icon').new(name: 'close-circle-fill', class: "w-[1.4em] h-[1.4em] fill-gray-500") %>
Expand Down
4 changes: 3 additions & 1 deletion admin/app/components/solidus_admin/ui/table/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class extends Controller {
"scopesToolbar",
"searchToolbar",
"searchField",
"searchForm",
"defaultHeader",
"batchHeader",
"selectedRowsCount",
Expand All @@ -29,7 +30,6 @@ export default class extends Controller {

connect() {
if (this.searchFieldTarget.value !== "") this.modeValue = "search"

this.render()
}

Expand Down Expand Up @@ -74,8 +74,10 @@ export default class extends Controller {
const selectedRows = this.checkboxTargets.filter((checkbox) => checkbox.checked)

this.searchToolbarTarget.toggleAttribute("hidden", this.modeValue !== "search")

this.batchToolbarTarget.toggleAttribute("hidden", this.modeValue !== "batch")
this.batchHeaderTarget.toggleAttribute("hidden", this.modeValue !== "batch")

this.scopesToolbarTarget.toggleAttribute("hidden", this.modeValue !== "scopes")
this.defaultHeaderTarget.toggleAttribute("hidden", this.modeValue !== "scopes")

Expand Down
2 changes: 1 addition & 1 deletion admin/app/components/solidus_admin/ui/table/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def batch_actions_form_id
end

def table_frame_id
@table_frame_id ||= "#{stimulus_id}--table-#{SecureRandom.hex}"
@table_frame_id ||= "#{stimulus_id}--table-frame"
end

def render_batch_action_button(batch_action)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<nav aria-label="pagination" class="flex items-center" data-controller="<%= stimulus_id %>">
<nav aria-label="pagination" class="flex items-center">
<%= render @button_component.new(
icon: 'arrow-left-s-line',
class: 'rounded-tr-none rounded-br-none border-r-0',
Expand Down

This file was deleted.

18 changes: 3 additions & 15 deletions admin/app/controllers/solidus_admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
module SolidusAdmin
class ProductsController < SolidusAdmin::BaseController
def index
@search_key = search_key
@query_params = product_params[:q]
@q = Spree::Product.ransack(@query_params)

@products = @q.result(distinct: true).order(created_at: :desc, id: :desc)
@search_key = :name_or_variants_including_master_sku_cont
@query_params = params[:q].permit!
@products = Spree::Product.ransack(@query_params).result(distinct: true).order(created_at: :desc, id: :desc)

set_page_and_extract_portion_from(
@products,
Expand Down Expand Up @@ -55,15 +53,5 @@ def activate
flash[:notice] = t('.success')
redirect_to products_path, status: :see_other
end

private

def product_params
params.permit(:page, q: [search_key])
end

def search_key
:name_or_variants_including_master_sku_cont
end
end
end

0 comments on commit fb073cd

Please sign in to comment.