-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#10788] In instructeur view add a autocomplete select to navigate to…
… a procedure
- Loading branch information
Showing
11 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/components/instructeurs/select_procedure_drop_down_list_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class Instructeurs::SelectProcedureDropDownListComponent < Dsfr::InputComponent | ||
def initialize(procedures:) | ||
@procedures = procedures | ||
end | ||
|
||
def react_props | ||
{ | ||
items:, | ||
placeholder: t('.placeholder'), | ||
name: "procedure_id", | ||
id: 'select-procedure-drop-down-list', | ||
'aria-describedby': 'select-procedure-drop-down-list-label', | ||
form: 'select-procedure-drop-down-list-component', | ||
data: { no_autosubmit: 'input blur', no_autosubmit_on_empty: 'true', autosubmit_target: 'input' } | ||
} | ||
end | ||
|
||
def items | ||
@procedures.map { ["n°#{_1.id} - #{_1.libelle}", _1.id] } | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
...elect_procedure_drop_down_list_component/select_procedure_drop_down_list_component.en.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
en: | ||
label: Direct access | ||
placeholder: Select a procedure |
4 changes: 4 additions & 0 deletions
4
...elect_procedure_drop_down_list_component/select_procedure_drop_down_list_component.fr.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
fr: | ||
label: Accès direct | ||
placeholder: Sélectionner une démarche |
17 changes: 17 additions & 0 deletions
17
...ct_procedure_drop_down_list_component/select_procedure_drop_down_list_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
= form_with url: url_for([:select_procedure, :instructeur, :procedures]), | ||
class: 'ml-auto', | ||
id: 'select-procedure-drop-down-list-component', | ||
data: { turbo: true, controller: 'autosubmit' } do | ||
|
||
.flex.align-center | ||
= label_tag :procedure_id, t('.label'), class: 'fr-label font-weight-bold fr-mr-2w', id: 'select-procedure-drop-down-list-label', for: 'select-procedure-drop-down-list' | ||
%react-fragment | ||
= render ReactComponent.new "ComboBox/SingleComboBox", **react_props | ||
|
||
%input.hidden{ | ||
type: 'submit', | ||
formmethod: 'get', | ||
formaction: url_for([:select_procedure, :instructeur, :procedures]), | ||
formnovalidate: 'true', | ||
data: { autosubmit_target: 'submitter' } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -464,6 +464,7 @@ | |
collection do | ||
get 'order_positions' | ||
patch 'update_order_positions' | ||
get 'select_procedure' | ||
end | ||
end | ||
|
||
|
33 changes: 33 additions & 0 deletions
33
spec/components/instructeurs/select_procedure_drop_down_list_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Instructeurs::SelectProcedureDropDownListComponent, type: :component do | ||
subject do | ||
render_inline(described_class.new(procedures:)) | ||
end | ||
|
||
let(:procedures) { | ||
[ | ||
create(:procedure, libelle: "Procedure importante", id: 1001), | ||
create(:procedure, libelle: "Procedure facile", id: 1002), | ||
create(:procedure, libelle: "Procedure terminée", id: 1003) | ||
] | ||
} | ||
|
||
it "renders the label" do | ||
expect(subject).to have_text("Accès direct") | ||
end | ||
|
||
let(:react_component) { page.find('react-component') } | ||
let(:react_props_items) { JSON.parse(react_component['props']) } | ||
|
||
it "renders the procedures" do | ||
subject | ||
expect(react_props_items["items"]).to eq([ | ||
["n°1001 - Procedure importante", 1001], | ||
["n°1002 - Procedure facile", 1002], | ||
["n°1003 - Procedure terminée", 1003] | ||
]) | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/components/previews/instructeurs/select_procedure_drop_down_list_component_preview.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class Instructeurs::SelectProcedureDropDownListComponentPreview < ViewComponent::Preview | ||
def default | ||
@procedures = Procedure.limit(10) | ||
render(Instructeurs::SelectProcedureDropDownListComponent.new(procedures: @procedures)) | ||
end | ||
end |