Skip to content

Commit bee5779

Browse files
authored
feat: display select fields in search results (#2988)
* ui: add select field example to error message * refactor * refactor: use HEEx components for logs search UI * feat: display selected fields in log search results * style: tidy up formatting * refactor: replace live_modal_show_link references with <.modal_link /> component * consolidate SearchLive components * test: integration test for logs search with selected field * include selected fields in copy to clipboard * use last field of the path * bump ci * test: LogEventComponentsTest async * ci: fix merge by removing empty file * chore: merge with main, consolidate log_event_components_test.exs
1 parent 550a1f4 commit bee5779

File tree

17 files changed

+820
-561
lines changed

17 files changed

+820
-561
lines changed

lib/logflare/lql/parser/helpers.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ defmodule Logflare.Lql.Parser.Helpers do
333333
Keyword.t() | {atom(), any()} | no_return()
334334
def check_for_invalid_blank_select_alias({:invalid_blank_select_alias, "@"}) do
335335
throw(
336-
"Error while parsing select clause: select alias cannot be blank, expected alias name after @"
336+
"Error while parsing select clause: select alias cannot be blank, expected alias name after @. For example, s:my_field@my_alias"
337337
)
338338
end
339339

lib/logflare_web/live/lql/lql_form_lvc.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="form-group">
22
<%= label @f, :lql_string do %>
3-
Use {LqlHelpers.lql_help_modal_link()} and source {LqlHelpers.bq_source_schema_modal_link()} to configure log event routing to sinks.
3+
Use <LqlHelpers.lql_help_modal_link /> and source <LqlHelpers.bq_source_schema_modal_link /> to configure log event routing to sinks.
44
<% end %>
55
{text_input(@f, :lql_string, value: @lql_string, class: "form-control", disabled: @loading)}
66
{error_tag(@f, :lql_string)}
Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
defmodule LogflareWeb.LqlHelpers do
22
@moduledoc false
3-
use LogflareWeb, :view
3+
use Phoenix.Component
44

55
import LogflareWeb.ModalLiveHelpers
66

77
alias LogflareWeb.SharedView
88

9-
def lql_help_modal_link do
10-
live_modal_show_link(
11-
template: "lql_help.html",
12-
view: SharedView,
13-
modal_id: :lql_help_link,
14-
title: "Logflare Query Language"
15-
) do
16-
assigns = %{}
17-
18-
~H"""
9+
def lql_help_modal_link(assigns) do
10+
~H"""
11+
<.modal_link template="lql_help.html" view={SharedView} modal_id={:lql_help_link} title="Logflare Query Language">
1912
<i class="fas fa-code"></i><span class="hide-on-mobile"> LQL </span>
20-
"""
21-
end
13+
</.modal_link>
14+
"""
2215
end
2316

24-
def bq_source_schema_modal_link do
25-
live_modal_show_link(
26-
component: LogflareWeb.SourceBqSchemaComponent,
27-
modal_id: :bq_schema_link,
28-
title: "Source Schema"
29-
) do
30-
assigns = %{}
31-
32-
~H"""
17+
@doc """
18+
Renders a link to open the BigQuery source schema modal.
19+
"""
20+
def bq_source_schema_modal_link(assigns) do
21+
~H"""
22+
<.modal_link component={LogflareWeb.SourceBqSchemaComponent} modal_id={:bq_schema_link} title="Source Schema">
3323
<i class="fas fa-database"></i><span class="hide-on-mobile"> schema </span>
34-
"""
35-
end
24+
</.modal_link>
25+
"""
3626
end
3727
end

lib/logflare_web/live/modal_live_helpers.ex

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ defmodule LogflareWeb.ModalLiveHelpers do
22
@moduledoc """
33
Modal helpers to be imported where modals may be called
44
"""
5-
import Phoenix.Component, only: [assign: 3]
6-
import Phoenix.HTML.Link, only: [link: 2]
5+
use Phoenix.Component
76

87
alias Phoenix.LiveView.JS
98

@@ -57,57 +56,6 @@ defmodule LogflareWeb.ModalLiveHelpers do
5756
end
5857
end
5958

60-
@doc """
61-
Creates a link to show a modal when clicked.
62-
63-
# Customize click behaviour
64-
You can optionally assign a custom JS command to `click` which will be executed before showing the modal.
65-
66-
```
67-
<%= live_modal_show_link(component: LogflareWeb.MyComponent, click: JS.push("some_event"), ...) %>
68-
```
69-
"""
70-
def live_modal_show_link(content \\ [], opts)
71-
72-
def live_modal_show_link(opts, do: block) when is_list(opts) do
73-
live_modal_show_link(block, opts)
74-
end
75-
76-
def live_modal_show_link(contents, opts) when is_list(opts) do
77-
{type, module_or_template} =
78-
Enum.find(opts, &match?({k, _} when k in [:component, :live_view, :template], &1))
79-
80-
id = Keyword.fetch!(opts, :modal_id)
81-
title = Keyword.fetch!(opts, :title)
82-
view = Keyword.get(opts, :view)
83-
return_to = Keyword.get(opts, :return_to)
84-
85-
click =
86-
case Keyword.get(opts, :click) do
87-
nil ->
88-
:show_live_modal
89-
90-
js_command when is_struct(js_command, JS) ->
91-
js_command
92-
|> JS.push("show_live_modal")
93-
end
94-
95-
opts =
96-
[
97-
to: "#",
98-
phx_click: click,
99-
phx_value_close: Keyword.get(opts, :close),
100-
phx_value_module_or_template: module_or_template,
101-
phx_value_type: type,
102-
phx_value_id: id,
103-
phx_value_title: title,
104-
phx_value_return_to: return_to,
105-
phx_value_view: view
106-
] ++ opts
107-
108-
link(contents, opts)
109-
end
110-
11159
def live_modal(template, opts)
11260
when is_binary(template) do
11361
path = Keyword.fetch!(opts, :return_to)
@@ -144,4 +92,59 @@ defmodule LogflareWeb.ModalLiveHelpers do
14492

14593
Phoenix.Component.live_component(modal_opts)
14694
end
95+
96+
@doc """
97+
Creates a link to show a modal when clicked.
98+
99+
Only supports component modals.
100+
101+
## Customize click behaviour
102+
You can optionally assign a custom JS command to `click` which will be executed before showing the modal.
103+
104+
## Example
105+
106+
<.modal_link component={LogflareWeb.MyComponent} modal_id={:my_modal} title="My Modal">
107+
<span>Open Modal</span>
108+
</.modal_link>
109+
"""
110+
attr :component, :atom, default: nil
111+
attr :live_view, :atom, default: nil
112+
attr :template, :string, default: nil
113+
attr :modal_id, :atom, required: true
114+
attr :title, :string, required: true
115+
attr :view, :atom, default: nil
116+
attr :return_to, :string, default: nil
117+
attr :click, JS, default: nil
118+
attr :close, JS, default: nil
119+
attr :class, :string, default: nil
120+
attr :rest, :global
121+
slot :inner_block, required: true
122+
123+
def modal_link(assigns) do
124+
{type, module_or_template} =
125+
cond do
126+
assigns.component -> {:component, assigns.component}
127+
assigns.live_view -> {:live_view, assigns.live_view}
128+
assigns.template -> {:template, assigns.template}
129+
true -> raise "Must provide one of :component, :live_view, or :template"
130+
end
131+
132+
click =
133+
case assigns.click do
134+
nil -> "show_live_modal"
135+
js_command when is_struct(js_command, JS) -> JS.push(js_command, "show_live_modal")
136+
end
137+
138+
assigns =
139+
assigns
140+
|> assign(:module_or_template, module_or_template)
141+
|> assign(:phx_click, click)
142+
|> assign(:type, type)
143+
144+
~H"""
145+
<.link href="#" class={@class} phx-click={@phx_click} phx-value-close={@close} phx-value-module-or-template={@module_or_template} phx-value-type={@type} phx-value-id={@modal_id} phx-value-title={@title} phx-value-return-to={@return_to} phx-value-view={@view} {@rest}>
146+
{render_slot(@inner_block)}
147+
</.link>
148+
"""
149+
end
147150
end

0 commit comments

Comments
 (0)