Skip to content

Commit 979bc27

Browse files
authored
Merge branch 'master' into new-upgrade-page
2 parents c9f25bb + 18907ae commit 979bc27

File tree

34 files changed

+1641
-108
lines changed

34 files changed

+1641
-108
lines changed

assets/js/liveview/live_socket.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import 'phoenix_html'
77
import { Socket } from 'phoenix'
88
import { LiveSocket } from 'phoenix_live_view'
9+
import topbar from 'topbar'
910
/* eslint-enable import/no-unresolved */
1011

1112
import Alpine from 'alpinejs'
@@ -66,6 +67,14 @@ if (csrfToken && websocketUrl) {
6667
}
6768
})
6869

70+
topbar.config({
71+
barColors: { 0: '#303f9f' },
72+
shadowColor: 'rgba(0, 0, 0, .3)',
73+
barThickness: 4
74+
})
75+
window.addEventListener('phx:page-loading-start', (_info) => topbar.show())
76+
window.addEventListener('phx:page-loading-stop', (_info) => topbar.hide())
77+
6978
liveSocket.connect()
7079
window.liveSocket = liveSocket
7180
}

assets/package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"react-popper": "^2.3.0",
3939
"react-router-dom": "^6.25.1",
4040
"react-transition-group": "^4.4.2",
41+
"topbar": "^3.0.0",
4142
"topojson-client": "^3.1.0",
4243
"url-search-params-polyfill": "^8.2.5",
4344
"visionscarto-world-atlas": "^1.0.0"
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
defmodule Plausible.CustomerSupport.Resource do
2+
@moduledoc """
3+
Generic behaviour for CS resources and their components
4+
"""
5+
defstruct [:id, :type, :module, :object]
6+
7+
@type schema() :: map()
8+
9+
@type t() :: %__MODULE__{
10+
id: pos_integer(),
11+
module: atom(),
12+
object: schema(),
13+
type: String.t()
14+
}
15+
16+
@callback search(String.t(), pos_integer()) :: list(schema())
17+
@callback get(pos_integer()) :: schema()
18+
@callback component() :: module()
19+
@callback type() :: String.t()
20+
@callback dump(schema()) :: t()
21+
22+
defmodule Component do
23+
@moduledoc false
24+
@callback render_result(assigns :: Phoenix.LiveView.Socket.assigns()) ::
25+
Phoenix.LiveView.Rendered.t()
26+
end
27+
28+
defmacro __using__(:component) do
29+
quote do
30+
use PlausibleWeb, :live_component
31+
alias Plausible.CustomerSupport.Resource
32+
import PlausibleWeb.CustomerSupport.Live.Shared
33+
34+
@behaviour Plausible.CustomerSupport.Resource.Component
35+
36+
def success(socket, msg) do
37+
send(socket.root_pid, {:success, msg})
38+
socket
39+
end
40+
41+
def failure(socket, msg) do
42+
send(socket.root_pid, {:failure, msg})
43+
socket
44+
end
45+
end
46+
end
47+
48+
defmacro __using__(component: component) do
49+
quote do
50+
@behaviour Plausible.CustomerSupport.Resource
51+
alias Plausible.CustomerSupport.Resource
52+
53+
import Ecto.Query
54+
alias Plausible.Repo
55+
56+
@impl true
57+
def dump(schema) do
58+
Resource.new(__MODULE__, schema)
59+
end
60+
61+
defoverridable dump: 1
62+
63+
@impl true
64+
def type do
65+
__MODULE__
66+
|> Module.split()
67+
|> Enum.reverse()
68+
|> hd()
69+
|> String.downcase()
70+
end
71+
72+
defoverridable type: 0
73+
74+
@impl true
75+
def component, do: unquote(component)
76+
77+
defoverridable component: 0
78+
end
79+
end
80+
81+
def new(module, schema) do
82+
%__MODULE__{
83+
id: schema.id,
84+
type: module.type(),
85+
module: module,
86+
object: schema
87+
}
88+
end
89+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
defmodule Plausible.CustomerSupport.Resource.Site do
2+
@moduledoc false
3+
use Plausible.CustomerSupport.Resource, component: PlausibleWeb.CustomerSupport.Live.Site
4+
5+
@impl true
6+
def search("", limit) do
7+
q =
8+
from s in Plausible.Site,
9+
inner_join: t in assoc(s, :team),
10+
inner_join: o in assoc(t, :owners),
11+
order_by: [
12+
desc: :id
13+
],
14+
limit: ^limit,
15+
preload: [team: {t, owners: o}]
16+
17+
Plausible.Repo.all(q)
18+
end
19+
20+
def search(input, limit) do
21+
q =
22+
from s in Plausible.Site,
23+
inner_join: t in assoc(s, :team),
24+
inner_join: o in assoc(t, :owners),
25+
where:
26+
ilike(s.domain, ^"%#{input}%") or ilike(t.name, ^"%#{input}%") or
27+
ilike(o.name, ^"%#{input}%"),
28+
order_by: [
29+
desc: fragment("?.domain = ?", s, ^input),
30+
desc: fragment("?.name = ?", t, ^input),
31+
desc: fragment("?.name = ?", o, ^input),
32+
asc: s.domain
33+
],
34+
limit: ^limit,
35+
preload: [team: {t, owners: o}]
36+
37+
Plausible.Repo.all(q)
38+
end
39+
40+
@impl true
41+
def get(id) do
42+
Plausible.Site
43+
|> Plausible.Repo.get(id)
44+
|> Plausible.Repo.preload(:team)
45+
end
46+
end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
defmodule Plausible.CustomerSupport.Resource.Team do
2+
@moduledoc false
3+
use Plausible.CustomerSupport.Resource, component: PlausibleWeb.CustomerSupport.Live.Team
4+
5+
@impl true
6+
def search("", limit) do
7+
q =
8+
from t in Plausible.Teams.Team,
9+
inner_join: o in assoc(t, :owners),
10+
limit: ^limit,
11+
where: not is_nil(t.trial_expiry_date),
12+
order_by: [desc: :id],
13+
preload: [owners: o]
14+
15+
Plausible.Repo.all(q)
16+
end
17+
18+
def search(input, limit) do
19+
q =
20+
from t in Plausible.Teams.Team,
21+
inner_join: o in assoc(t, :owners),
22+
where: ilike(t.name, ^"%#{input}%") or ilike(o.name, ^"%#{input}%"),
23+
limit: ^limit,
24+
order_by: [
25+
desc: fragment("?.name = ?", t, ^input),
26+
desc: fragment("?.name = ?", o, ^input),
27+
asc: t.name
28+
],
29+
preload: [owners: o]
30+
31+
Plausible.Repo.all(q)
32+
end
33+
34+
@impl true
35+
def get(id) do
36+
Plausible.Teams.Team
37+
|> Repo.get(id)
38+
|> Plausible.Teams.with_subscription()
39+
|> Repo.preload(:owners)
40+
end
41+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
defmodule Plausible.CustomerSupport.Resource.User do
2+
@moduledoc false
3+
use Plausible.CustomerSupport.Resource, component: PlausibleWeb.CustomerSupport.Live.User
4+
5+
@impl true
6+
def get(id) do
7+
Plausible.Repo.get!(Plausible.Auth.User, id)
8+
|> Plausible.Repo.preload(team_memberships: :team)
9+
end
10+
11+
@impl true
12+
def search("", limit) do
13+
q =
14+
from u in Plausible.Auth.User,
15+
order_by: [
16+
desc: :id
17+
],
18+
preload: [:owned_teams],
19+
limit: ^limit
20+
21+
Plausible.Repo.all(q)
22+
end
23+
24+
def search(input, limit) do
25+
q =
26+
from u in Plausible.Auth.User,
27+
where: ilike(u.email, ^"%#{input}%") or ilike(u.name, ^"%#{input}%"),
28+
order_by: [
29+
desc: fragment("?.name = ?", u, ^input),
30+
desc: fragment("?.email = ?", u, ^input),
31+
asc: u.name
32+
],
33+
preload: [:owned_teams],
34+
limit: ^limit
35+
36+
Plausible.Repo.all(q)
37+
end
38+
end

extra/lib/plausible/help_scout.ex

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ defmodule Plausible.HelpScout do
105105
}
106106
end)
107107

108-
user_link = Routes.kaffy_resource_url(PlausibleWeb.Endpoint, :show, :auth, :user, user.id)
108+
user_link =
109+
Routes.customer_support_resource_url(
110+
PlausibleWeb.Endpoint,
111+
:details,
112+
:users,
113+
:user,
114+
user.id
115+
)
109116

110117
{:ok,
111118
%{
@@ -129,19 +136,20 @@ defmodule Plausible.HelpScout do
129136

130137
status_link =
131138
if team do
132-
Routes.kaffy_resource_url(PlausibleWeb.Endpoint, :show, :teams, :team, team.id)
133-
else
134-
Routes.kaffy_resource_url(PlausibleWeb.Endpoint, :show, :auth, :user, user.id)
135-
end
136-
137-
sites_link =
138-
if team do
139-
Routes.kaffy_resource_url(PlausibleWeb.Endpoint, :index, :sites, :site,
140-
custom_search: team.identifier
139+
Routes.customer_support_resource_url(
140+
PlausibleWeb.Endpoint,
141+
:details,
142+
:teams,
143+
:team,
144+
team.id
141145
)
142146
else
143-
Routes.kaffy_resource_url(PlausibleWeb.Endpoint, :index, :sites, :site,
144-
custom_search: user.email
147+
Routes.customer_support_resource_url(
148+
PlausibleWeb.Endpoint,
149+
:details,
150+
:users,
151+
:user,
152+
user.id
145153
)
146154
end
147155

@@ -156,8 +164,7 @@ defmodule Plausible.HelpScout do
156164
status_link: status_link,
157165
plan_label: plan_label(subscription, plan),
158166
plan_link: plan_link(subscription),
159-
sites_count: Teams.owned_sites_count(team),
160-
sites_link: sites_link
167+
sites_count: Teams.owned_sites_count(team)
161168
}}
162169
end
163170
end

0 commit comments

Comments
 (0)