-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathstreams_table.ex
More file actions
73 lines (64 loc) · 1.8 KB
/
streams_table.ex
File metadata and controls
73 lines (64 loc) · 1.8 KB
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
defmodule EventStore.Dashboard.Components.StreamsTable do
alias EventStore.Page
import Phoenix.LiveDashboard.PageBuilder
import EventStore.Dashboard.Helpers
# See: https://hexdocs.pm/phoenix_live_dashboard/Phoenix.LiveDashboard.PageBuilder.html
def render(event_store, _assigns) do
live_table(
columns: table_columns(),
default_sort_by: :stream_id,
id: :event_store_streams_table,
row_attrs: &row_attrs/1,
row_fetcher: &paginate_streams(event_store, &1, &2),
title: "Streams"
)
end
defp paginate_streams(event_store, params, node) do
%{search: search, sort_by: sort_by, sort_dir: sort_dir, limit: limit} = params
{:ok, %Page{entries: entries, total_entries: total_entries}} =
rpc_event_store(node, event_store, :paginate_streams, [
[page_size: limit, search: search, sort_by: sort_by, sort_dir: sort_dir]
])
entries = Enum.map(entries, &Map.from_struct/1)
{entries, total_entries}
end
defp table_columns do
[
%{
field: :stream_id,
header: "Id",
header_attrs: [class: "pl-4"],
cell_attrs: [class: "tabular-column-id pl-4"],
sortable: :asc
},
%{
field: :stream_uuid,
header: "Stream identity",
cell_attrs: [class: "tabular-column-name pl-4"],
sortable: :asc
},
%{
field: :stream_version,
header: "Version",
sortable: :asc
},
%{
field: :created_at,
header: "Created at",
sortable: :asc
},
%{
field: :deleted_at,
header: "Deleted at",
sortable: :asc
}
]
end
defp row_attrs(table) do
[
{"phx-click", "show_stream"},
{"phx-value-stream", table[:stream_uuid]},
{"phx-page-loading", true}
]
end
end