Skip to content

Commit

Permalink
Remove Phoenix.View and use the new Phoenix.Component structure (#3055)
Browse files Browse the repository at this point in the history
* Replace Phoenix.View from config

* Update json rendering to 1.7 standards

* Update VIEW test to JSON tests

* Remove old views

* Update html structure without Phoenix.View

* Fix suse_manager_json rendering

* Clean up code

* Apply suggestions

* Refactor function
  • Loading branch information
EMaksy authored Oct 10, 2024
1 parent ceb259d commit 9d6ac21
Show file tree
Hide file tree
Showing 84 changed files with 775 additions and 909 deletions.
5 changes: 4 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ config :trento,
# Configures the endpoint
config :trento, TrentoWeb.Endpoint,
url: [host: "localhost"],
render_errors: [view: TrentoWeb.ErrorView, accepts: ~w(json)],
render_errors: [
formats: [json: TrentoWeb.ErrorJSON],
layout: false
],
pubsub_server: Trento.PubSub,
live_view: [signing_salt: "4tNZ+tm7"]

Expand Down
11 changes: 6 additions & 5 deletions lib/trento/clusters/projections/cluster_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Trento.Clusters.Projections.ClusterProjector do
repo: Trento.Repo,
name: "cluster_projector"

alias TrentoWeb.V2.ClusterView
alias TrentoWeb.V2.ClusterJSON

alias Trento.Clusters.Events.{
ChecksSelected,
Expand Down Expand Up @@ -158,7 +158,7 @@ defmodule Trento.Clusters.Projections.ClusterProjector do
TrentoWeb.Endpoint.broadcast(
"monitoring:clusters",
"cluster_registered",
ClusterView.render("cluster_registered.json", cluster: registered_cluster)
ClusterJSON.cluster_registered(%{cluster: registered_cluster})
)
end

Expand All @@ -168,7 +168,8 @@ defmodule Trento.Clusters.Projections.ClusterProjector do
_,
_
) do
message = ClusterView.render("cluster_details_updated.json", data: updated_details)
message =
ClusterJSON.cluster_details_updated(%{data: updated_details})

TrentoWeb.Endpoint.broadcast(
"monitoring:clusters",
Expand All @@ -185,7 +186,7 @@ defmodule Trento.Clusters.Projections.ClusterProjector do
end

def after_update(%ClusterHealthChanged{}, _, %{cluster: %ClusterReadModel{} = cluster}) do
message = ClusterView.render("cluster_health_changed.json", %{cluster: cluster})
message = ClusterJSON.cluster_health_changed(%{cluster: cluster})

TrentoWeb.Endpoint.broadcast("monitoring:clusters", "cluster_health_changed", message)
end
Expand All @@ -212,7 +213,7 @@ defmodule Trento.Clusters.Projections.ClusterProjector do
TrentoWeb.Endpoint.broadcast(
"monitoring:clusters",
"cluster_restored",
ClusterView.render("cluster_restored.json", cluster: restored_cluster)
ClusterJSON.cluster_restored(%{cluster: restored_cluster})
)
end

Expand Down
50 changes: 22 additions & 28 deletions lib/trento/databases/projections/database_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
DatabaseReadModel
}

alias TrentoWeb.V1.DatabaseView
alias TrentoWeb.V1.DatabaseJSON

alias Trento.Databases.Events.{
DatabaseDeregistered,
Expand Down Expand Up @@ -261,7 +261,7 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_registered",
DatabaseView.render("database_registered.json", database: database)
DatabaseJSON.database_registered(%{database: database})
)
end

Expand All @@ -274,12 +274,12 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_health_changed",
DatabaseView.render("database_health_changed.json",
DatabaseJSON.database_health_changed(%{
health: %{
id: id,
health: health
}
)
})
)
end

Expand All @@ -298,13 +298,10 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_instance_registered",
DatabaseView.render(
"database_instance_with_sr_status.json",
%{
instance: instance,
database_instances: database_instances
}
)
DatabaseJSON.database_instance_with_sr_status(%{
instance: instance,
database_instances: database_instances
})
)
end

Expand All @@ -324,14 +321,14 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_instance_health_changed",
DatabaseView.render("database_instance_health_changed.json",
DatabaseJSON.database_instance_health_changed(%{
instance: %{
database_id: database_id,
host_id: host_id,
instance_number: instance_number,
health: health
}
)
})
)
end

Expand All @@ -352,15 +349,15 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_instance_system_replication_changed",
DatabaseView.render("database_instance_system_replication_changed.json",
DatabaseJSON.database_instance_system_replication_changed(%{
instance: %{
database_id: database_id,
host_id: host_id,
instance_number: instance_number,
system_replication: system_replication,
system_replication_status: system_replication_status
}
)
})
)
end

Expand All @@ -378,15 +375,15 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_instance_absent_at_changed",
DatabaseView.render("database_instance_absent_at_changed.json",
DatabaseJSON.database_instance_absent_at_changed(%{
instance: %{
instance_number: instance_number,
host_id: host_id,
database_id: database_id,
sid: sid,
absent_at: absent_at
}
)
})
)
end

Expand All @@ -403,15 +400,15 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_instance_absent_at_changed",
DatabaseView.render("database_instance_absent_at_changed.json",
DatabaseJSON.database_instance_absent_at_changed(%{
instance: %{
instance_number: instance_number,
host_id: host_id,
database_id: database_id,
sid: sid,
absent_at: nil
}
)
})
)
end

Expand All @@ -429,7 +426,7 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_restored",
DatabaseView.render("database_restored.json", database: database)
DatabaseJSON.database_restored(%{database: database})
)
end

Expand All @@ -448,10 +445,10 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_deregistered",
DatabaseView.render("database_deregistered.json",
DatabaseJSON.database_deregistered(%{
id: database_id,
sid: sid
)
})
)
end

Expand All @@ -472,12 +469,12 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_instance_deregistered",
DatabaseView.render("database_instance_deregistered.json",
DatabaseJSON.database_instance_deregistered(%{
database_id: database_id,
instance_number: instance_number,
host_id: host_id,
sid: sid
)
})
)
end

Expand All @@ -496,10 +493,7 @@ defmodule Trento.Databases.Projections.DatabaseProjector do
TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_tenants_updated",
DatabaseView.render("database_tenants_updated.json",
tenants: tenants,
database_id: database_id
)
DatabaseJSON.database_tenants_updated(%{tenants: tenants, database_id: database_id})
)
end

Expand Down
29 changes: 11 additions & 18 deletions lib/trento/hosts/projections/host_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Trento.Hosts.Projections.HostProjector do
repo: Trento.Repo,
name: "host_projector"

alias TrentoWeb.V1.HostView
alias TrentoWeb.V1.HostJSON

alias Trento.Repo

Expand Down Expand Up @@ -265,7 +265,7 @@ defmodule Trento.Hosts.Projections.HostProjector do
TrentoWeb.Endpoint.broadcast(
"monitoring:hosts",
"host_registered",
HostView.render("host_registered.json", host: host)
HostJSON.host_registered(%{host: host})
)
end

Expand All @@ -282,7 +282,7 @@ defmodule Trento.Hosts.Projections.HostProjector do
TrentoWeb.Endpoint.broadcast(
"monitoring:hosts",
"host_restored",
HostView.render("host_restored.json", host: host)
HostJSON.host_restored(%{host: host})
)
end

Expand Down Expand Up @@ -340,7 +340,7 @@ defmodule Trento.Hosts.Projections.HostProjector do
TrentoWeb.Endpoint.broadcast(
"monitoring:hosts",
"host_details_updated",
HostView.render("host_details_updated.json", host: host)
HostJSON.host_details_updated(%{host: host})
)
end

Expand All @@ -352,12 +352,12 @@ defmodule Trento.Hosts.Projections.HostProjector do
TrentoWeb.Endpoint.broadcast(
"monitoring:hosts",
"heartbeat_succeded",
HostView.render("heartbeat_result.json",
HostJSON.heartbeat_result(%{
host: %{
id: id,
hostname: hostname
}
)
})
)
end

Expand All @@ -369,12 +369,12 @@ defmodule Trento.Hosts.Projections.HostProjector do
TrentoWeb.Endpoint.broadcast(
"monitoring:hosts",
"heartbeat_failed",
HostView.render("heartbeat_result.json",
HostJSON.heartbeat_result(%{
host: %{
id: id,
hostname: hostname
}
)
})
)
end

Expand All @@ -396,10 +396,7 @@ defmodule Trento.Hosts.Projections.HostProjector do
%{host: %HostReadModel{selected_checks: checks} = host}
) do
message =
HostView.render(
"host_details_updated.json",
%{host: host}
)
HostJSON.host_details_updated(%{host: host})

TrentoWeb.Endpoint.broadcast("monitoring:hosts", "host_details_updated", message)
end
Expand All @@ -409,11 +406,7 @@ defmodule Trento.Hosts.Projections.HostProjector do
_,
%{host: %HostReadModel{} = host}
) do
message =
HostView.render(
"saptune_status_updated.json",
%{host: host}
)
message = HostJSON.saptune_status_updated(%{host: host})

TrentoWeb.Endpoint.broadcast("monitoring:hosts", "saptune_status_updated", message)
end
Expand All @@ -423,7 +416,7 @@ defmodule Trento.Hosts.Projections.HostProjector do
_,
%{host: %HostReadModel{} = host}
) do
message = HostView.render("host_health_changed.json", %{host: host})
message = HostJSON.host_health_changed(%{host: host})

TrentoWeb.Endpoint.broadcast("monitoring:hosts", "host_health_changed", message)
end
Expand Down
Loading

0 comments on commit 9d6ac21

Please sign in to comment.