-
Notifications
You must be signed in to change notification settings - Fork 3
/
table_component.html.erb
218 lines (217 loc) · 9 KB
/
table_component.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<% if @has_samples && @pagy.vars[:size].positive? %>
<%= render Viral::BaseComponent.new(**wrapper_arguments) do %>
<%= render Viral::BaseComponent.new(**system_arguments) do %>
<table
class='
w-full text-sm text-left rtl:text-right text-slate-500 dark:text-slate-400
whitespace-nowrap
'
>
<thead
class='
sticky top-0 z-10 text-xs uppercase text-slate-700 bg-slate-50 dark:bg-slate-700
dark:text-slate-300
'
>
<tr>
<% @columns.each_with_index do |column, index| %>
<%= render_cell(
tag: 'th',
scope: 'col',
classes: class_names('px-3 py-3', 'sticky left-0 min-w-56 max-w-56 z-10 bg-slate-50 dark:bg-slate-700': index.zero?, 'sticky left-56 z-10 bg-slate-50 dark:bg-slate-700': index == 1)
) do %>
<% if index.zero? and @abilities[:select_samples] %>
<%= check_box_tag "select-page",
title: t(:".select_page"),
"aria-label": t(:".select_page"),
data: {
action: "input->selection#togglePage",
controller: "filters",
selection_target: "selectPage",
},
class:
"w-4 h-4 mr-2.5 text-primary-600 bg-slate-100 border-slate-300 rounded focus:ring-primary-500 dark:focus:ring-primary-600 dark:ring-offset-slate-800 focus:ring-2 dark:bg-slate-700 dark:border-slate-600" %>
<% end %>
<%= render SortComponent.new(
sort: @search_params[:sort],
label: t(".#{column}"),
url: sort_url(column),
field: column,
data: {
turbo_action: "replace",
},
) %>
<% end %>
<% end %>
<% @metadata_fields.each do |field| %>
<%= render_cell(
tag: 'th',
scope: 'col',
classes: class_names('px-3 py-3')
) do %>
<%= render SortComponent.new(
sort: @search_params[:sort],
label: field,
url: sort_url("metadata_#{field}"),
field: "metadata_#{field}",
data: {
turbo_action: "replace",
},
) %>
<% end %>
<% end %>
<% if @renders_row_actions %>
<%= render_cell(
tag: 'th',
scope: 'col',
classes: class_names('px-3 py-3 bg-slate-50 dark:bg-slate-700 sticky right-0')
) do %>
<%= t(".action") %>
<% end %>
<% end %>
</tr>
</thead>
<tbody
class='
overflow-y-auto bg-white divide-y divide-slate-200 dark:bg-slate-800
dark:divide-slate-700
'
>
<% @samples.each do |sample| %>
<%= render Viral::BaseComponent.new(**row_arguments(sample)) do %>
<% @columns.each_with_index do |column, index| %>
<%= render_cell(
tag: index.zero? ? 'th' :'td',
scope: index.zero? ? 'row' : nil,
classes: class_names('px-3 py-3', 'sticky left-0 min-w-56 max-w-56 bg-slate-50 dark:bg-slate-700': index.zero?, 'sticky left-56 bg-slate-50 dark:bg-slate-700': index == 1)
) do %>
<% if index.zero? && @abilities[:select_samples] %>
<%= check_box_tag "sample_ids[]",
sample.id,
nil,
id: dom_id(sample),
"aria-label": sample.name,
data: {
action: "input->selection#toggle",
selection_target: "rowSelection",
},
class:
"w-4 h-4 mr-2.5 text-primary-600 bg-slate-100 border-slate-300 rounded focus:ring-primary-500 dark:focus:ring-primary-600 dark:ring-offset-slate-800 focus:ring-2 dark:bg-slate-700 dark:border-slate-600" %>
<% end %>
<% if column == :puid || column == :name %>
<%= link_to(
namespace_project_sample_path(sample.project.namespace.parent, sample.project, sample),
data: { turbo: false },
class: "text-slate-700 dark:text-slate-300 font-semibold hover:underline"
) do %>
<span class="font-semibold">
<%= highlight(
sample[column],
defined?(@search_params[:name_or_puid_cont]) &&
@search_params[:name_or_puid_cont],
highlighter: '<mark class="bg-primary-300 dark:bg-primary-600">\1</mark>',
) %>
</span>
<% end %>
<% elsif column == :project_id %>
<%= link_to sample.project.puid,
namespace_project_samples_path(sample.project.namespace.parent, sample.project),
data: {
turbo: false,
},
class: "font-semibold hover:underline" %>
<% elsif column == :created_at %>
<%= helpers.local_time(sample[column], :full_date) %>
<% elsif column == :updated_at || column == :attachments_updated_at %>
<% if sample[column].present? %>
<%= helpers.local_time_ago(sample[column]) %>
<% end %>
<% else %>
<%= sample[column.to_sym] %>
<% end %>
<% end %>
<% end %>
<% @metadata_fields.each do |field| %>
<%= render_cell(
tag: 'td',
classes: class_names('px-3 py-3')
) do %>
<%= sample.metadata[field] %>
<% end %>
<% end %>
<% if @renders_row_actions %>
<%= render_cell(
tag: 'td',
classes: class_names('px-3 py-3 sticky right-0 bg-white dark:bg-slate-800 z-5 space-x-2')
) do %>
<% if @row_actions[:edit] %>
<%= link_to(
t(:"projects.samples.index.edit_button"),
edit_project_sample_path(sample.project, sample),
data: {
turbo: false,
},
class:
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer",
) %>
<% end %>
<% if @row_actions[:destroy] %>
<%= link_to(
t(:"projects.samples.index.remove_button"),
new_namespace_project_samples_deletion_path(
sample_id: sample.id,
deletion_type: "single",
),
data: {
"turbo-stream": true,
},
class:
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer",
) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</tbody>
<% if @abilities[:select_samples] && @has_samples %>
<tfoot class="sticky bottom-0 z-10">
<tr class="border-t dark:border-slate-700 border-slate-200">
<td
class="
sticky left-0 z-10 px-6 py-3 text-slate-700 dark:text-slate-300 bg-slate-50
dark:bg-slate-700
"
colspan="3"
>
<span>
<%= t(".counts.samples") %>:
<strong data-action="turbo:morph-element->selection#idempotentConnect"><%= @pagy.count %></strong>
</span>
<span>
<%= t(".counts.selected") %>:
<strong
data-selection-target="selected"
data-action="
turbo:morph-element->selection#idempotentConnect
"
>0</strong>
</span>
</td>
<td colspan="100%" class="px-3 py-3 bg-slate-50 dark:bg-slate-700"></td>
</tr>
</tfoot>
<% end %>
</table>
<% end %>
<%= render Viral::Pagy::FullComponent.new(@pagy, item: t(".limit.item")) %>
<% end %>
<% else %>
<div class="empty_state_message">
<%= viral_empty(
title: @empty[:title],
description: @empty[:description],
icon_name: :beaker,
) %>
</div>
<% end %>