remove prefix, use status in controller
This commit is contained in:
parent
b4ed393a55
commit
a0671a1321
5 changed files with 22 additions and 28 deletions
|
@ -14,7 +14,7 @@ class Instructeurs::ColumnFilterComponent < ApplicationComponent
|
|||
{
|
||||
selected_key: column.present? ? column.id : '',
|
||||
items: filterable_columns_options,
|
||||
name: "#{prefix}[id]",
|
||||
name: "filters[][id]",
|
||||
id: 'search-filter',
|
||||
'aria-describedby': 'instructeur-filter-combo-label',
|
||||
form: 'filter-component',
|
||||
|
@ -29,11 +29,9 @@ class Instructeurs::ColumnFilterComponent < ApplicationComponent
|
|||
def current_filter_tags
|
||||
@procedure_presentation.filters_for(@statut).flat_map do
|
||||
[
|
||||
hidden_field_tag("#{prefix}[id]", _1.column.id, id: nil),
|
||||
hidden_field_tag("#{prefix}[filter]", _1.filter, id: nil)
|
||||
hidden_field_tag("filters[][id]", _1.column.id, id: nil),
|
||||
hidden_field_tag("filters[][filter]", _1.filter, id: nil)
|
||||
]
|
||||
end.reduce(&:concat)
|
||||
end
|
||||
|
||||
def prefix = "#{procedure_presentation.filters_name_for(@statut)}[]"
|
||||
end
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
}
|
||||
|
||||
= label_tag :value, t('.value'), for: 'value', class: 'fr-label'
|
||||
= render Instructeurs::ColumnFilterValueComponent.new(column:, prefix:)
|
||||
= render Instructeurs::ColumnFilterValueComponent.new(column:)
|
||||
|
||||
= hidden_field_tag :statut, statut
|
||||
= hidden_field_tag :prefix, prefix
|
||||
= submit_tag t('.add_filter'), class: 'fr-btn fr-btn--secondary fr-mt-2w'
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
class Instructeurs::ColumnFilterValueComponent < ApplicationComponent
|
||||
attr_reader :column
|
||||
|
||||
def initialize(column:, prefix:)
|
||||
def initialize(column:)
|
||||
@column = column
|
||||
@prefix = prefix
|
||||
end
|
||||
|
||||
def column_type = column.present? ? column.type : :text
|
||||
|
@ -15,15 +14,15 @@ class Instructeurs::ColumnFilterValueComponent < ApplicationComponent
|
|||
select_tag :filter,
|
||||
options_for_select(options_for_select_of_column),
|
||||
id: 'value',
|
||||
name: "#{@prefix}[filter]",
|
||||
name: "filters[][filter]",
|
||||
class: 'fr-select',
|
||||
data: { no_autosubmit: true }
|
||||
else
|
||||
tag.input(
|
||||
class: 'fr-input',
|
||||
id: 'value',
|
||||
type: html_column_type,
|
||||
name: "#{@prefix}[filter]",
|
||||
type:,
|
||||
name: "filters[][filter]",
|
||||
maxlength: FilteredColumn::FILTERS_VALUE_MAX_LENGTH,
|
||||
disabled: column.nil? ? true : false,
|
||||
data: { no_autosubmit: true },
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
module Instructeurs
|
||||
class ProcedurePresentationController < InstructeurController
|
||||
before_action :set_procedure_presentation
|
||||
before_action :set_procedure_presentation, only: [:update]
|
||||
|
||||
def update
|
||||
if !@procedure_presentation.update(procedure_presentation_params)
|
||||
|
@ -15,11 +15,9 @@ module Instructeurs
|
|||
end
|
||||
|
||||
def refresh_column_filter
|
||||
prefix = params[:prefix]
|
||||
key = prefix.gsub('[]', '')
|
||||
column = ColumnType.new.cast(params[key].last['id'])
|
||||
|
||||
component = Instructeurs::ColumnFilterValueComponent.new(column:, prefix:)
|
||||
# According to the html, the selected filters is the last one
|
||||
column = ColumnType.new.cast(params['filters'].last['id'])
|
||||
component = Instructeurs::ColumnFilterValueComponent.new(column:)
|
||||
|
||||
render turbo_stream: turbo_stream.replace('value', component)
|
||||
end
|
||||
|
@ -29,15 +27,12 @@ module Instructeurs
|
|||
def procedure = @procedure_presentation.procedure
|
||||
|
||||
def procedure_presentation_params
|
||||
# TODO: peut etre simplifier en transformer un parametre filter -> tous_filter, suivant le params statut
|
||||
h = params.permit(displayed_columns: [], sorted_column: [:order, :id], filters: [:id, :filter]).to_h
|
||||
|
||||
|
||||
filters = [
|
||||
:tous_filters, :a_suivre_filters, :suivis_filters, :traites_filters,
|
||||
:expirant_filters, :archives_filters, :supprimes_filters
|
||||
].index_with { [:id, :filter] }
|
||||
|
||||
h = params.permit(displayed_columns: [], sorted_column: [:order, :id], **filters).to_h
|
||||
if params[:statut].present?
|
||||
filter_name = @procedure_presentation.filters_name_for(params[:statut])
|
||||
h[filter_name] = h.delete("filters") # move filters to the right key, ex: tous_filters
|
||||
end
|
||||
|
||||
# React ComboBox/MultiComboBox return [''] when no value is selected
|
||||
# We need to remove them
|
||||
|
|
|
@ -22,7 +22,8 @@ describe Instructeurs::ProcedurePresentationController, type: :controller do
|
|||
{
|
||||
displayed_columns: [state_column.id],
|
||||
sorted_column: { order: 'asc', id: state_column.id },
|
||||
tous_filters: [{ id: state_column.id, filter: 'en_construction' }]
|
||||
filters: [{ id: state_column.id, filter: 'en_construction' }],
|
||||
statut: 'tous'
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -71,7 +72,9 @@ describe Instructeurs::ProcedurePresentationController, type: :controller do
|
|||
context 'with an error in filters' do
|
||||
before { sign_in(instructeur.user) }
|
||||
|
||||
let(:presentation_params) { { tous_filters: [{ id: state_column.id, filter: '' }] } }
|
||||
let(:presentation_params) do
|
||||
{ filters: [{ id: state_column.id, filter: '' }], statut: 'tous' }
|
||||
end
|
||||
|
||||
it 'does not update the procedure_presentation' do
|
||||
subject
|
||||
|
|
Loading…
Reference in a new issue