Skip to content

Commit

Permalink
Format <%= %> into {...} in HEEX. Fix issues with GraphQL queries
Browse files Browse the repository at this point in the history
GraphQL queries are like {query { field } } which is processed as
interpolation. Replace { and } with &lbrace; and &rbrace; to avoid
syntax errors
  • Loading branch information
IvanIvanoff committed Jan 3, 2025
1 parent 52683f4 commit c9c50cd
Show file tree
Hide file tree
Showing 31 changed files with 245 additions and 242 deletions.
28 changes: 14 additions & 14 deletions lib/sanbase_web/components/admin/admin_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule SanbaseWeb.AdminComponents do
<%= for {attr, message} <- Ecto.Changeset.traverse_errors(@changeset, &translate_error/1) do %>
<li class="text-red-500">
<.icon name="hero-exclamation-circle-mini" class="mr-2" />
<%= humanize(attr) %>: <%= Enum.join(message, ", ") %>
{humanize(attr)}: {Enum.join(message, ", ")}
</li>
<% end %>
</ul>
Expand Down Expand Up @@ -263,7 +263,7 @@ defmodule SanbaseWeb.AdminComponents do
~H"""
<div class="mt-4">
<h3 class="text-2xl font-medium text-gray-700 mb-2">
Show <%= Inflex.singularize(@resource) %>
Show {Inflex.singularize(@resource)}
</h3>
<div class="relative shadow-md sm:rounded-lg">
<div class="overflow-x-auto">
Expand All @@ -272,7 +272,7 @@ defmodule SanbaseWeb.AdminComponents do
<%= for field <- @fields do %>
<tr class="hover:bg-gray-50 dark:hover:bg-gray-600">
<th class="text-xs px-2 py-1 text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400 border-b border-gray-200 whitespace-nowrap w-1/4">
<%= to_string(field) %>
{to_string(field)}
</th>
<.td_show
class="px-3 py-2 border-b border-gray-200 whitespace-pre-wrap break-words"
Expand Down Expand Up @@ -348,7 +348,7 @@ defmodule SanbaseWeb.AdminComponents do
~H"""
<div class="table-responsive">
<div class="m-4 flex flex-col gap-x-10">
<h3 class="text-3xl font-medium text-gray-700 mb-2"><%= @resource_name %></h3>
<h3 class="text-3xl font-medium text-gray-700 mb-2">{@resource_name}</h3>
<%= if @create_link_kv != [] do %>
<.new_resource_button resource={@resource} create_link_kv={@create_link_kv} />
<% end %>
Expand Down Expand Up @@ -466,7 +466,7 @@ defmodule SanbaseWeb.AdminComponents do
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400 sticky top-0">
<tr>
<%= for field <- @fields do %>
<th scope="col" class="px-2 py-1 whitespace-nowrap min-w-[120px]"><%= field %></th>
<th scope="col" class="px-2 py-1 whitespace-nowrap min-w-[120px]">{field}</th>
<% end %>
<%= if @actions do %>
<th scope="col" class="px-2 py-1 whitespace-nowrap w-[140px] min-w-[140px]">Actions</th>
Expand Down Expand Up @@ -564,7 +564,7 @@ defmodule SanbaseWeb.AdminComponents do
classes[@color][@size]
}
>
<%= @label %>
{@label}
</button>
</.link>
"""
Expand Down Expand Up @@ -599,7 +599,7 @@ defmodule SanbaseWeb.AdminComponents do
Keyword.merge([resource: @resource], @create_link_kv)
)
}>
<.icon name="hero-plus-circle" /> Add new <%= Inflex.singularize(@resource) %>
<.icon name="hero-plus-circle" /> Add new {Inflex.singularize(@resource)}
</.link>
</button>
"""
Expand Down Expand Up @@ -683,7 +683,7 @@ defmodule SanbaseWeb.AdminComponents do
def td_index(assigns) do
~H"""
<td class="px-3 py-2 whitespace-nowrap overflow-hidden text-ellipsis min-w-[120px]">
<%= @value %>
{@value}
</td>
"""
end
Expand All @@ -694,7 +694,7 @@ defmodule SanbaseWeb.AdminComponents do
def td_show(assigns) do
~H"""
<td class={@class}>
<%= @value %>
{@value}
</td>
"""
end
Expand All @@ -710,7 +710,7 @@ defmodule SanbaseWeb.AdminComponents do
href={Routes.generic_admin_path(SanbaseWeb.Endpoint, @action, @row, resource: @resource)}
class="underline"
>
<%= @label %>
{@label}
</.link>
"""
end
Expand Down Expand Up @@ -758,10 +758,10 @@ defmodule SanbaseWeb.AdminComponents do
search={@search}
/>
<span class="text-xs text-gray-700">
Showing <%= @current_page * @page_size + 1 %> to <%= Enum.min([
Showing {@current_page * @page_size + 1} to {Enum.min([
(@current_page + 1) * @page_size,
@rows_count
]) %> of <%= @rows_count %> entries
])} of {@rows_count} entries
</span>
</div>
"""
Expand Down Expand Up @@ -884,7 +884,7 @@ defmodule SanbaseWeb.AdminComponents do
type="button"
class="inline-flex w-full px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
>
<%= field %>
{field}
</button>
</li>
<% end %>
Expand Down Expand Up @@ -976,7 +976,7 @@ defmodule SanbaseWeb.AdminComponents do
def resource_title(assigns) do
~H"""
<h1 class="text-3xl font-bold mb-6">
<%= Inflex.camelize(@resource) %>
{Inflex.camelize(@resource)}
</h1>
"""
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sanbase_web/components/admin/live_search.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule SanbaseWeb.LiveSearch do
>
<li :for={{name, path} <- @routes}>
<a href={path} class="block p-4 hover:bg-gray-100 text-sm font-semibold">
<%= name %>
{name}
</a>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion lib/sanbase_web/components/admin/live_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule SanbaseWeb.LiveSelect do
/>
<datalist id={"matches_" <> to_string(@session["field"])}>
<%= for {id, match} <- @matches do %>
<option value={id}><%= match %></option>
<option value={id}>{match}</option>
<% end %>
</datalist>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule SanbaseWeb.AdminFormsComponents do
def status(assigns) do
~H"""
<p class={status_to_color(@status)}>
<%= @status |> String.replace("_", " ") |> String.upcase() %>
{@status |> String.replace("_", " ") |> String.upcase()}
</p>
"""
end
Expand All @@ -36,7 +36,7 @@ defmodule SanbaseWeb.AdminFormsComponents do
]}
disabled={@disabled}
>
<%= @display_text %>
{@display_text}
</button>
"""
end
Expand All @@ -46,7 +46,7 @@ defmodule SanbaseWeb.AdminFormsComponents do
def forms_list_container(assigns) do
~H"""
<div class="flex flex-col border border-gray-100 mx-auto max-w-3xl p-6 rounded-xl shadow-sm divide-y divide-solid">
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</div>
"""
end
Expand All @@ -56,7 +56,7 @@ defmodule SanbaseWeb.AdminFormsComponents do
def forms_list_title(assigns) do
~H"""
<h1 class="py-6 text-3xl font-extrabold leading-none tracking-tight text-gray-900">
<%= @title %>
{@title}
</h1>
"""
end
Expand All @@ -70,14 +70,14 @@ defmodule SanbaseWeb.AdminFormsComponents do
<div class="flex flex-col md:flex-row py-8 items-center justify-between">
<!-- Title and description -->
<div class="w-3/4">
<span class="text-2xl mb-6"><%= @title %></span>
<p class="text-sm text-gray-500"><%= @description %></p>
<span class="text-2xl mb-6">{@title}</span>
<p class="text-sm text-gray-500">{@description}</p>
</div>
<!-- Link to form -->
<div class="flex flex-col space-y-2 ">
<.link :for={button <- @buttons} href={button.url} target="_blank">
<button class="bg-blue-600 w-full px-6 hover:bg-blue-900 rounded-xl text-white py-2">
<%= button.text %>
{button.text}
</button>
</.link>
</div>
Expand Down
14 changes: 7 additions & 7 deletions lib/sanbase_web/components/available_metrics_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule SanbaseWeb.AvailableMetricsComponents do
class="text-gray-900 bg-white hover:bg-gray-100 border border-gray-200 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center gap-x-2"
>
<CoreComponents.icon :if={@icon} name={@icon} class="text-gray-500" />
<%= @text %>
{@text}
</.link>
"""
end
Expand All @@ -41,7 +41,7 @@ defmodule SanbaseWeb.AvailableMetricsComponents do
data-popover-placement={@popover_placement}
>
<span class="border-b border-dotted border-gray-500 hover:cursor-help hover:text-blue-500 hover:border-blue-500">
<%= @display_text %>
{@display_text}
</span>
</div>
Expand All @@ -53,7 +53,7 @@ defmodule SanbaseWeb.AvailableMetricsComponents do
@popover_class
]}
>
<span class="[&>pre]:font-sans"><%= @popover_target_text %></span>
<span class="[&>pre]:font-sans">{@popover_target_text}</span>
</div>
</div>
"""
Expand Down Expand Up @@ -125,7 +125,7 @@ defmodule SanbaseWeb.AvailableMetricsComponents do
<div class="block py-4 pr-6">
<span class="absolute -inset-y-px right-0 -left-4 group-hover:bg-zinc-50 sm:rounded-l-xl" />
<span class={["relative", i == 0 && "text-zinc-900"]}>
<%= render_slot(col, @row_item.(row)) %>
{render_slot(col, @row_item.(row))}
</span>
</div>
</td>
Expand All @@ -136,7 +136,7 @@ defmodule SanbaseWeb.AvailableMetricsComponents do
:for={action <- @action}
class="relative ml-4 font-semibold leading-6 text-zinc-900 hover:text-zinc-700"
>
<%= render_slot(action, @row_item.(row)) %>
{render_slot(action, @row_item.(row))}
</span>
</div>
</td>
Expand All @@ -150,14 +150,14 @@ defmodule SanbaseWeb.AvailableMetricsComponents do
def th(assigns) do
~H"""
<th class="px-5 py-3 text-xs font-semibold tracking-wider text-left text-gray-600 uppercase bg-gray-100 border-b-2 border-gray-200">
<%= @field %>
{@field}
</th>
"""
end

def td(assigns) do
~H"""
<td class="px-5 py-5 text-sm bg-white border-b border-gray-200"><%= @value %></td>
<td class="px-5 py-5 text-sm bg-white border-b border-gray-200">{@value}</td>
"""
end
end
Loading

0 comments on commit c9c50cd

Please sign in to comment.