feat: Monaco editor with LQL support for search field#3239
feat: Monaco editor with LQL support for search field#3239msmithstubbs wants to merge 22 commits intoLogflare:mainfrom
Conversation
8d09395 to
8d8731d
Compare
|
we can style the new suggested field inputs to look like the monaco inputs but doesn't need to be a monaco editor. |
Yes, can do. What about suggested searches? We use have a |
e2018ce to
6451e20
Compare
d4eea0d to
47fe366
Compare
Ziinc
left a comment
There was a problem hiding this comment.
considering this is a very important flow, lets add an integration test using PhoenixTest that executes a search using this.
would likely need to add postgres lql support for it to run on CI. can be separate PR with this stacked.
assets/js/lql_language.js
Outdated
| { label: "m.", detail: "metadata field", insertText: "m." }, | ||
| { label: "metadata.", detail: "metadata field", insertText: "metadata." }, | ||
| { label: "s:*", detail: "select all fields", insertText: "s:*" }, | ||
| { label: "c:count(*)", detail: "chart count", insertText: "c:count(*)" }, |
There was a problem hiding this comment.
| { label: "c:count(*)", detail: "chart count", insertText: "c:count(*)" }, | |
| { label: "c:count()", detail: "chart count", insertText: "c:count($0)" }, |
There was a problem hiding this comment.
can we get this file's logic covered with tests? using vitest would be great, but whatever works.
There was a problem hiding this comment.
too much chance for breakage for such an important component.
assets/js/lql_editor_wrapper_hook.js
Outdated
|
|
||
| const monaco = window.monaco; | ||
|
|
||
| registerLqlLanguage(monaco); |
There was a problem hiding this comment.
should wrap this in a try/do to prevent mount failure.
There was a problem hiding this comment.
Wrapped registerLqlLanguage to catch failure. Was that where you think we'd get an exception? Or are you concerned monaco might not be loaded at all?
| hook.pushEvent("soft_pause", {}) | ||
| }) | ||
| }, | ||
| pushChartControlsUpdate() { |
There was a problem hiding this comment.
should cover this hook with an integration test as well.
There was a problem hiding this comment.
Will include in the follow up integration test PR.
That should be an integration test with Playwright in test/e2e/features/ ?
| defp schema_fields_json(source), do: source |> lql_schema_fields() |> Jason.encode!() | ||
|
|
||
| defp lql_schema_fields(source) do | ||
| case SourceSchemas.Cache.get_source_schema_by(source_id: source.id) do | ||
| %{schema_flat_map: flat_map} when is_map(flat_map) -> | ||
| Enum.map(flat_map, fn {name, type} -> | ||
| %{name: name, type: format_schema_type(type)} | ||
| end) | ||
|
|
||
| _ -> | ||
| [] | ||
| end | ||
| end |
There was a problem hiding this comment.
can't we pass the flatmap directly? or this needs to be done elixir side?
There was a problem hiding this comment.
We can pass the flatmap as is if we only want the field names. If we'd like the field types, too, we need to encode any tuples (such as {:list, :string}) because they can't currently be JSON encoded.
I've simplified the schema fields helper, and moved it to FormComponents which is a little bit simpler because it reduces passing another assign and attribute. I don't love that a helper in FormComponents is fetching a record which might hit the db, but it's cached so shouldn't be a problem in practice.
There was a problem hiding this comment.
i think would be better to move the fetch out of the template and into the liveview. feels like a code smell, plus we can consolidate the calls (liveview also stores source schema in state)
There was a problem hiding this comment.
Agree with that. I couldn't see anywhere SearchLV stores source schema currently but there would be some refactoring if we stack this on top of #3120
59ffada to
23a9f06
Compare
…onaco query field
6c08e9a to
f97ad82
Compare
f97ad82 to
1855617
Compare

Use the Monaco editor component for the search field
LiveMonacoEditor/1componentlql_language.js)I chose to replace the search
<form>element and have the monaco editor instance communicate using liveview hooks and events. This simplified keeping the editor in sync with a hidden text input.Fixes O11Y-1309
LQL syntax highlighting
Supports aggregate completions
Saved searches are included in autocomplete
Source query and recommended fields adopt similar styling
Same background and text colours, but not Monaco editor.
CleanShot.2026-03-10.at.13.08.47.mp4