Skip to content

Commit a9cc24f

Browse files
committed
Use view action in resource toolbar
1 parent df3fe05 commit a9cc24f

File tree

6 files changed

+39
-13
lines changed

6 files changed

+39
-13
lines changed

app/views/shared/_resource_toolbar.html.erb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Locals:
33
edit_path: path for edit action (optional)
44
edit_aria_label: aria-label for edit button (defaults to t('globals.edit'))
5-
preview_path: path for preview action (optional)
6-
preview_aria_label: aria-label for preview button (defaults to t('globals.preview'))
5+
view_path: path for view action (optional)
6+
view_aria_label: aria-label for view button (defaults to t('globals.view'))
77
destroy_path: path for destroy action (optional)
88
destroy_confirm: confirmation message (defaults to t('globals.confirm_delete'))
99
destroy_aria_label: aria-label for destroy button (defaults to t('globals.delete'))
@@ -14,9 +14,9 @@
1414
<i class="fas fa-edit"></i> <%= t('globals.edit') %>
1515
<% end %>
1616
<% end %>
17-
<% if local_assigns[:preview_path] %>
18-
<%= link_to preview_path, class: 'btn btn-outline-secondary btn-sm me-2', 'aria-label' => (local_assigns[:preview_aria_label] || t('globals.preview')) do %>
19-
<i class="fas fa-eye"></i> <%= t('globals.preview') %>
17+
<% if local_assigns[:view_path] %>
18+
<%= link_to view_path, class: 'btn btn-outline-secondary btn-sm me-2', 'aria-label' => (local_assigns[:view_aria_label] || t('globals.view')) do %>
19+
<i class="fas fa-eye"></i> <%= t('globals.view') %>
2020
<% end %>
2121
<% end %>
2222
<% if local_assigns[:destroy_path] %>

config/locales/en.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,6 @@ en:
12731273
destroy: Destroy
12741274
draft: Draft
12751275
edit: Edit
1276-
preview: Preview
12771276
'false': 'No'
12781277
forms:
12791278
save: Save

config/locales/es.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,6 @@ es:
12591259
destroy: Destruir
12601260
draft: Borrador
12611261
edit: Editar
1262-
preview: Vista previa
12631262
'false': 'No'
12641263
forms:
12651264
save: Guardar

config/locales/fr.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,6 @@ fr:
12861286
destroy: Détruire
12871287
draft: Brouillon
12881288
edit: Modifier
1289-
preview: Aperçu
12901289
'false': Non
12911290
forms:
12921291
save: Enregistrer

docs/resource_toolbar.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
# Resource Toolbar
22

3-
A shared partial for rendering edit, preview, and destroy buttons for a resource.
3+
A shared partial for rendering edit, view, and destroy buttons for a resource.
44

55
## Usage
66

77
```
88
<%= render 'shared/resource_toolbar',
99
edit_path: edit_post_path(@post),
10-
preview_path: preview_post_path(@post),
10+
view_path: post_path(@post),
1111
destroy_path: post_path(@post),
1212
destroy_confirm: t('globals.confirm_delete'),
1313
edit_aria_label: 'Edit Post',
14-
preview_aria_label: 'Preview Post',
14+
view_aria_label: 'View Post',
1515
destroy_aria_label: 'Delete Post' %>
1616
```
1717

1818
## Locals
1919

2020
- `edit_path` – link for the edit action (optional)
21-
- `preview_path` – link for the preview action (optional)
21+
- `view_path` – link for the view action (optional)
2222
- `destroy_path` – link for the destroy action (optional)
2323
- `destroy_confirm` – confirmation text for destroy (defaults to `t('globals.confirm_delete')`)
24-
- `edit_aria_label`, `preview_aria_label`, `destroy_aria_label` – ARIA labels for accessibility.
24+
- `edit_aria_label`, `view_aria_label`, `destroy_aria_label` – ARIA labels for accessibility.
2525

2626
Buttons render only when the corresponding path is provided. Defaults use the global translations for button text and ARIA labels.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe 'shared/resource_toolbar', type: :view do
6+
it 'renders provided action buttons' do
7+
render partial: 'shared/resource_toolbar', locals: {
8+
edit_path: '/edit',
9+
view_path: '/view',
10+
destroy_path: '/destroy',
11+
destroy_confirm: 'Are you sure?'
12+
}
13+
14+
expect(rendered).to include(t('globals.edit'))
15+
expect(rendered).to include(t('globals.view'))
16+
expect(rendered).to include(t('globals.delete'))
17+
expect(rendered).to include('href="/edit"')
18+
expect(rendered).to include('href="/view"')
19+
expect(rendered).to include('href="/destroy"')
20+
end
21+
22+
it 'omits buttons when paths are missing' do
23+
render partial: 'shared/resource_toolbar'
24+
25+
expect(rendered).not_to include(t('globals.edit'))
26+
expect(rendered).not_to include(t('globals.view'))
27+
expect(rendered).not_to include(t('globals.delete'))
28+
end
29+
end

0 commit comments

Comments
 (0)