Current section

Files

Jump to
dumper lib dumper components table_records.html.heex
Raw

lib/dumper/components/table_records.html.heex

<%!--
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
--%>
<p :if={Enum.empty?(@records)} class="italic">
No records
</p>
<div :if={!Enum.empty?(@records)} class="card tabular-card">
<% first_record = List.first(@records) %>
<% module = Map.get(first_record, :__struct__) %>
<% fields = if module, do: fields(module, @config_module), else: Map.keys(first_record) %>
<% embeds = if module, do: embeds(module), else: [] %>
<% redacted_fields = if module, do: redacted_fields(module), else: [] %>
<div class="card-body p-0">
<div class="dash-table-wrapper">
<table
:if={!Enum.empty?(@records)}
class="table table-sm table-hover table-bordered mt-0 dash-table"
>
<thead class="">
<tr>
<th :for={field <- fields} :if={field not in embeds} class="">
{field}
</th>
</tr>
</thead>
<tbody>
<tr :for={record <- @records}>
<td :for={field <- fields} :if={field not in embeds} data-field={field}>
<%= if field == :id do %>
<.link navigate={"#{@dumper_home}?module=#{module}&id=#{record.id}"}>
{record.id}
</.link>
<% else %>
<.value
module={module}
field={field}
resource={record}
value={Map.get(record, field)}
type={if module, do: module.__schema__(:type, field), else: nil}
redacted={field in redacted_fields}
config_module={@config_module}
dumper_home={@dumper_home}
/>
<% end %>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>