Skip to content

Commit 43a0155

Browse files
authored
Merge pull request #13306 from demarche-numerique/auto/haml-migration/batch-d0e305e4
Tech: migrer CopyButtonComponent de HAML vers ERB
2 parents 173a68b + eac2ab9 commit 43a0155

9 files changed

Lines changed: 182 additions & 72 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
en:
3+
copy_confirmation: Link copied
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<span data-controller="clipboard" data-clipboard-text-value="<%= @text %>">
2+
<button
3+
class="
4+
fr-btn fr-icon-clipboard-line fr-btn--sm fr-btn--tertiary-no-outline
5+
align-middle
6+
"
7+
data-action="clipboard#copy"
8+
title="<%= @title %>"
9+
>
10+
<%= @title %>
11+
</button>
12+
13+
<span class="fr-text--sm hidden" data-clipboard-target="success">
14+
<%= @success || t('.copy_confirmation') %>
15+
</span>
16+
</span>

app/components/dsfr/copy_button_component/copy_button_component.html.haml

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<div class="fr-download">
2+
<%= link_to url, {class: "fr-download__link", download: name} do %>
3+
<% if !has_name -%>
4+
<span class="fr-sr-only"><%= t('.action') %></span>
5+
<% end -%>
6+
7+
<%= truncate ? name.truncate(20) : name %>
8+
9+
<span class="fr-download__detail">
10+
<%= helpers.download_details(attachment) %>
11+
</span>
12+
<% end %>
13+
14+
<% if ephemeral_link -%>
15+
<span class="fr-ml-2w fr-text--xs fr-text-mention--grey">
16+
<span class="fr-icon-questionnaire-line" aria-hidden="true"></span>
17+
<%= t('.ephemeral_link') %>
18+
</span>
19+
<% end -%>
20+
21+
<% if virus_not_analyzed -%>
22+
<div class="fr-text--xs fr-text-mention--grey">
23+
<%= t('.virus_not_analyzed') %>
24+
</div>
25+
<% end -%>
26+
</div>

app/components/dsfr/download_component/download_component.html.haml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<%= content_tag(:div, input_group_opts) do %>
2+
<%= @form.label @attribute, label_opts do %>
3+
<% capture do %>
4+
<%= label %>
5+
6+
<% if required? %>
7+
<%= render EditableChamp::AsteriskMandatoryComponent.new %>
8+
<% end %>
9+
10+
<% if hint_renderable? %>
11+
<span class="fr-hint-text"><%= hint %></span>
12+
<% end %>
13+
<% end %>
14+
<% end %>
15+
16+
<% if button.present? %>
17+
<div class="fr-input-wrap fr-input-wrap--addon">
18+
<%= @form.public_send(@input_type, @attribute, input_opts) %>
19+
<%= button %>
20+
</div>
21+
<% else %>
22+
<%= @form.public_send(@input_type, @attribute, input_opts) %>
23+
<% end %>
24+
25+
<% if errors_on_attribute? %>
26+
<% if error_messages.size == 1 %>
27+
<p class="fr-error-text" id="<%= error_id %>">
28+
<%= error_messages.first %>
29+
</p>
30+
<% else %>
31+
<div class="fr-error-text" id="<%= error_id %>">
32+
<ul class="list-style-type-none fr-pl-0">
33+
<% error_messages.each do |error_message| %>
34+
<li><%= error_message %></li>
35+
<% end %>
36+
</ul>
37+
</div>
38+
<% end %>
39+
<% elsif describedby.present? %>
40+
<%= describedby %>
41+
<% end %>
42+
43+
<% if password? %>
44+
<div class="fr-password__checkbox fr-checkbox-group fr-checkbox-group--sm">
45+
<input
46+
id="<%= show_password_id %>"
47+
aria-label="<%= aria_label_show_confirmation %>"
48+
type="checkbox"
49+
>
50+
51+
<label
52+
class="fr--password__checkbox fr-label"
53+
for="<%= show_password_id %>"
54+
>
55+
<%= t('.show_password.label') %>
56+
</label>
57+
</div>
58+
<% end %>
59+
60+
<% if email? %>
61+
<div
62+
class="suspect-email hidden"
63+
data-email-input-target="ariaRegion"
64+
tabindex="-1"
65+
>
66+
<%= render Dsfr::AlertComponent.new(title: t('.email_suggest.mistake'), state: '', extra_class_names: 'fr-alert--info') do |c| %>
67+
<% c.with_body do %>
68+
<p>
69+
<%= t('.email_suggest.wanna_say') %>
70+
<span data-email-input-target="suggestion">exemple@gmail.com</span>
71+
<%= "?" %>
72+
</p>
73+
74+
<p>
75+
<%= button_tag type: 'button', class: 'fr-btn fr-btn--sm fr-mr-3w', data: { action: 'click->email-input#accept' } do %>
76+
<%= t('utils.yes') %>
77+
<% end %>
78+
79+
<%= button_tag type: 'button', class: 'fr-btn fr-btn--sm', data: { action: 'click->email-input#discard' } do %>
80+
<%= t('utils.no') %>
81+
<% end %>
82+
</p>
83+
<% end %>
84+
<% end %>
85+
</div>
86+
<% end %>
87+
<% end %>

app/components/dsfr/input_component/input_component.html.haml

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
class Dsfr::DownloadComponentPreview < ViewComponent::Preview
4+
def default
5+
attachment = Struct.new(:filename, :byte_size).new(
6+
Struct.new(:extension).new('pdf'),
7+
12_345
8+
)
9+
render Dsfr::DownloadComponent.new(attachment:, url: '/rails/view_components/download_sample.pdf')
10+
end
11+
12+
def with_name
13+
attachment = Struct.new(:filename, :byte_size).new(
14+
Struct.new(:extension).new('pdf'),
15+
12_345
16+
)
17+
render Dsfr::DownloadComponent.new(attachment:, name: 'Mon fichier', has_name: true,
18+
url: '/rails/view_components/download_sample.pdf')
19+
end
20+
21+
def with_ephemeral_link
22+
attachment = Struct.new(:filename, :byte_size).new(
23+
Struct.new(:extension).new('pdf'),
24+
12_345
25+
)
26+
render Dsfr::DownloadComponent.new(attachment:, ephemeral_link: true,
27+
url: '/rails/view_components/download_sample.pdf')
28+
end
29+
30+
def with_virus_not_analyzed
31+
attachment = Struct.new(:filename, :byte_size).new(
32+
Struct.new(:extension).new('pdf'),
33+
12_345
34+
)
35+
render Dsfr::DownloadComponent.new(attachment:, virus_not_analyzed: true,
36+
url: '/rails/view_components/download_sample.pdf')
37+
end
38+
39+
def full
40+
attachment = Struct.new(:filename, :byte_size).new(
41+
Struct.new(:extension).new('pdf'),
42+
12_345
43+
)
44+
render Dsfr::DownloadComponent.new(attachment:, name: 'Mon fichier', has_name: true,
45+
ephemeral_link: true, virus_not_analyzed: true, url: '/rails/view_components/download_sample.pdf')
46+
end
47+
end

spec/controllers/instructeurs/dossiers_controller_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,9 +2123,9 @@
21232123
end
21242124

21252125
it 'returns pieces jointes from champs, messagerie and avis' do
2126-
expect(response.body).to have_text("Télécharger le fichier \ntoto.txt")
2127-
expect(response.body).to have_text("Télécharger le fichier \nlogo_test_procedu...")
2128-
expect(response.body).to have_text("Télécharger le fichier \nRIB.pdf")
2126+
expect(response.body).to have_text("Télécharger le fichier toto.txt", normalize_ws: true)
2127+
expect(response.body).to have_text("Télécharger le fichier logo_test_procedu...", normalize_ws: true)
2128+
expect(response.body).to have_text("Télécharger le fichier RIB.pdf", normalize_ws: true)
21292129
expect(response.body).to include('Visualiser')
21302130
expect(response.body).to include('Pièce jointe au message')
21312131
expect(response.body).to include('Pièce jointe à l’avis')

0 commit comments

Comments
 (0)