Skip to content

Commit de8d7ab

Browse files
taylordowns2000elias-bamidigofrank
authored
Added logos & case-insensitive sorting of credential types (#3107)
* square images if they exist * images on if they're present * remove humanize, fix oauth-2 path * run formatter * changelog * try static path * Manifest from envs instead of static path * No parenthesis for functions with no params * Few tests for coverage * allow failed image path * use object to avoid showing non-existent images * run formatter * fix failing test --------- Co-authored-by: Elias W. BA <[email protected]> Co-authored-by: Frank Midigo <[email protected]>
1 parent 338919e commit de8d7ab

File tree

5 files changed

+36
-69
lines changed

5 files changed

+36
-69
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ and this project adheres to
4444
- `phoenix` from 1.7.20 to 1.7.21
4545
- `phoenix_live_view` from 1.0.5 to 1.0.9
4646
- `petal_components` from 2.9.0 to 3.0.1
47+
- Added logos & case-insensitive sorting of credential types
48+
[#3107](https://github.com/OpenFn/lightning/pull/3107)
4749
- Added a "BETA" label to the Kafka trigger type
4850
[#3098](https://github.com/OpenFn/lightning/pull/3098)
4951

lib/lightning_web/live/components/form.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ defmodule LightningWeb.Components.Form do
384384
<%= PhoenixHTMLHelpers.Form.label(@form, @field, @opts) do %>
385385
<div class="flex items-center">
386386
{@title}
387-
<img :if={@logo} src={@logo} class="w-3 h-3 ml-1" />
387+
<object :if={@logo} data={@logo} type="image/png" class="w-3 h-3 ml-1" />
388388
</div>
389389
<% end %>
390390
<LightningWeb.Components.Common.tooltip
@@ -396,7 +396,7 @@ defmodule LightningWeb.Components.Form do
396396
<%= PhoenixHTMLHelpers.Form.label(@form, @field, @opts) do %>
397397
<div class="flex items-center">
398398
{@title}
399-
<img :if={@logo} src={@logo} class="w-3 h-3 ml-1" />
399+
<object :if={@logo} data={@logo} type="image/png" class="w-3 h-3 ml-1" />
400400
</div>
401401
<% end %>
402402
<% end %>

lib/lightning_web/live/credential_live/credential_form_component.ex

+11-4
Original file line numberDiff line numberDiff line change
@@ -532,15 +532,22 @@ defmodule LightningWeb.CredentialLive.CredentialFormComponent do
532532
Path.wildcard("#{schemas_path}/*.json")
533533
|> Enum.map(fn p ->
534534
name = p |> Path.basename() |> String.replace(".json", "")
535-
{Phoenix.Naming.humanize(name), name, nil, nil}
535+
536+
image_path =
537+
Routes.static_path(
538+
LightningWeb.Endpoint,
539+
"/images/adaptors/#{name}-square.png"
540+
)
541+
542+
{name, name, image_path, nil}
536543
end)
537544

538545
schemas_options
539546
|> Enum.reject(fn {_, name, _, _} ->
540547
name in ["googlesheets", "gmail", "collections"]
541548
end)
542549
|> Enum.concat([{"Raw JSON", "raw", nil, nil}])
543-
|> Enum.sort_by(& &1, :asc)
550+
|> Enum.sort_by(&String.downcase(elem(&1, 0)), :asc)
544551
end
545552

546553
defp list_users do
@@ -673,10 +680,10 @@ defmodule LightningWeb.CredentialLive.CredentialFormComponent do
673680
get_type_options(schemas_path)
674681
|> Enum.concat(
675682
Enum.map(oauth_clients, fn client ->
676-
{client.name, client.id, nil, "oauth"}
683+
{client.name, client.id, "/images/oauth-2.png", "oauth"}
677684
end)
678685
)
679-
|> Enum.sort()
686+
|> Enum.sort_by(&String.downcase(elem(&1, 0)), :asc)
680687
else
681688
[]
682689
end

priv/static/images/oauth-2.png

63.3 KB
Loading

test/lightning_web/live/credential_live_test.exs

+21-63
Original file line numberDiff line numberDiff line change
@@ -986,69 +986,6 @@ defmodule LightningWeb.CredentialLiveTest do
986986
{_path, flash} = assert_redirect(index_live)
987987
assert flash == %{"info" => "Credential updated successfully"}
988988
end
989-
990-
# test "blocks credential transfer to invalid owner; allows to valid owner", %{
991-
# conn: conn,
992-
# user: first_owner,
993-
# credential: credential_1
994-
# } do
995-
# user_2 = insert(:user)
996-
# user_3 = insert(:user)
997-
998-
# project =
999-
# insert(:project,
1000-
# name: "myproject",
1001-
# project_users: [%{user_id: first_owner.id}, %{user_id: user_2.id}]
1002-
# )
1003-
1004-
# credential =
1005-
# insert(:credential,
1006-
# user: first_owner,
1007-
# name: "the one for giving away",
1008-
# project_credentials: [
1009-
# %{project: project, credential: nil}
1010-
# ]
1011-
# )
1012-
1013-
# {:ok, index_live, html} = live(conn, ~p"/credentials")
1014-
1015-
# # both credentials appear in the list
1016-
# assert html =~ credential_1.name
1017-
# assert html =~ credential.name
1018-
1019-
# assert html =~ first_owner.id
1020-
# assert html =~ user_2.id
1021-
# assert html =~ user_3.id
1022-
1023-
# assert index_live
1024-
# |> form("#credential-form-#{credential.id}",
1025-
# credential: Map.put(@update_attrs, :user_id, user_3.id)
1026-
# )
1027-
# |> render_change() =~ "Invalid owner"
1028-
1029-
# # Can't transfer to user who doesn't have access to right projects
1030-
# assert index_live |> submit_disabled()
1031-
1032-
# {:ok, _index_live, html} =
1033-
# index_live
1034-
# |> form("#credential-form-#{credential.id}",
1035-
# credential: %{
1036-
# body: "{\"a\":\"new_secret\"}",
1037-
# user_id: user_2.id
1038-
# }
1039-
# )
1040-
# |> render_submit()
1041-
# |> follow_redirect(
1042-
# conn,
1043-
# ~p"/credentials"
1044-
# )
1045-
1046-
# # Once the transfer is made, the credential should not show up in the list
1047-
1048-
# assert html =~ "Credential updated successfully"
1049-
# assert html =~ credential_1.name
1050-
# refute html =~ "the one for giving away"
1051-
# end
1052989
end
1053990

1054991
describe "Authorizing an oauth credential" do
@@ -3152,6 +3089,27 @@ defmodule LightningWeb.CredentialLiveTest do
31523089
end
31533090
end
31543091

3092+
describe "credential type picker modal" do
3093+
test "displays credential type modal with icons", %{conn: conn} do
3094+
{:ok, _view, html} = live(conn, ~p"/credentials")
3095+
3096+
html_tree = Floki.parse_document!(html)
3097+
3098+
for adaptor <- ["postgresql", "dhis2", "http"] do
3099+
adaptor_label =
3100+
Floki.find(
3101+
html_tree,
3102+
"label[for='credential-schema-picker_selected_#{adaptor}']"
3103+
)
3104+
3105+
adaptor_icon = Floki.find(adaptor_label, "object")
3106+
assert length(adaptor_icon) > 0
3107+
img_src = adaptor_icon |> Floki.attribute("data") |> List.first()
3108+
assert img_src =~ "/images/adaptors/#{adaptor}-square.png"
3109+
end
3110+
end
3111+
end
3112+
31553113
defp wait_for_assigns(live, key, id) do
31563114
Enum.reduce_while(1..10, nil, fn n, _ ->
31573115
{_mod, assigns} =

0 commit comments

Comments
 (0)