Skip to content

Commit

Permalink
Upgrade deps, add storybook (#4947)
Browse files Browse the repository at this point in the history
* Add `<.dropdown_item>`

* Make the ellipsis menu functional again

* Upgrade deps so that storybook can be added

* Add storybook and dropdown story

* Remove lingering warnings/errors

* Add color mode to storybook

* Use new liveview used_input? function

* Alpine improvements

* Add select input to storybook

* Bring back `render_form` for CRM

* Configure eslint so it can see deps

* Remove LiveViewTest patch

* Fix test for phoenix liveview 1.0

* Build assets in prod

* Fix tests

* Attempt to fix lint error

* Add explicit text color to input

* mix format

* Format after merge master

* Add moduledocs

* Only run storybook in production

* Update storybook dependency

* Mix format
  • Loading branch information
ukutaht authored Jan 13, 2025
1 parent 32d1783 commit 6c30f62
Show file tree
Hide file tree
Showing 148 changed files with 683 additions and 587 deletions.
7 changes: 6 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
plugins: [Phoenix.LiveView.HTMLFormatter],
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
inputs: ["*.{heex,ex,exs}", "{config,lib,test,extra}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
inputs: [
"*.{heex,ex,exs}",
"{config,lib,test,extra}/**/*.{heex,ex,exs}",
"priv/*/seeds.exs",
"storybook/**/*.exs"
]
]
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ COPY tracker ./tracker
COPY priv ./priv
COPY lib ./lib
COPY extra ./extra
COPY storybook ./storybook

RUN npm run deploy --prefix ./tracker && \
mix assets.deploy && \
Expand Down
3 changes: 3 additions & 0 deletions assets/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"import/resolver": {
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
},
"node": {
"moduleDirectory": ["node_modules", "../deps"]
}
},
"react": {
Expand Down
14 changes: 14 additions & 0 deletions assets/css/storybook.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/*
* Put your component styling within the Tailwind utilities layer.
* See the https://hexdocs.pm/phoenix_storybook/sandboxing.html guide for more info.
*/

@layer utilities {
* {
font-family: system-ui;
}
}
6 changes: 5 additions & 1 deletion assets/js/liveview/live_socket.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// eslint-disable-next-line import/no-unresolved
import "phoenix_html"
import Alpine from 'alpinejs'
// eslint-disable-next-line import/no-unresolved
import { Socket } from "phoenix"
// eslint-disable-next-line import/no-unresolved
import { LiveSocket } from "phoenix_live_view"
// eslint-disable-next-line import/no-unresolved
import Alpine from 'alpinejs'

let csrfToken = document.querySelector("meta[name='csrf-token']")
let websocketUrl = document.querySelector("meta[name='websocket-url']")
Expand Down
39 changes: 39 additions & 0 deletions assets/js/storybook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Alpine from 'alpinejs'
import dropdown from "./liveview/dropdown"

// If your components require any hooks or custom uploaders, or if your pages
// require connect parameters, uncomment the following lines and declare them as
// such:
//
// import * as Hooks from "./hooks";
// import * as Params from "./params";
// import * as Uploaders from "./uploaders";

// (function () {
// window.storybook = { Hooks, Params, Uploaders };
// })();


window.Alpine = Alpine
document.addEventListener('DOMContentLoaded', () => {
window.Alpine.start();
});

document.addEventListener('alpine:init', () => {
window.Alpine.data('dropdown', dropdown)
});


(function () {
window.storybook = {
LiveSocketOptions: {
dom: {
onBeforeElUpdated(from, to) {
if (from._x_dataStack) {
window.Alpine.clone(from, to)
}
}
}
}
};
})();
14 changes: 0 additions & 14 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
"d3": "^7.9.0",
"dayjs": "^1.11.7",
"iframe-resizer": "^4.3.2",
"phoenix": "^1.7.2",
"phoenix_html": "^3.3.1",
"phoenix_live_view": "^0.18.18",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-flatpickr": "3.10.5",
Expand Down
2 changes: 1 addition & 1 deletion assets/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
"max-w-screen-xl"
],
darkMode: 'class',
important: '.plausible',
theme: {
container: {
center: true,
Expand Down Expand Up @@ -51,7 +52,6 @@ module.exports = {
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/aspect-ratio'),
plugin(({ addVariant }) => addVariant("phx-no-feedback", [".phx-no-feedback&", ".phx-no-feedback &"])),
plugin(({ addVariant }) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])),
plugin(({ addVariant }) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])),
plugin(({ addVariant }) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])),
Expand Down
10 changes: 9 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ config :esbuild,
version: "0.17.11",
default: [
args:
~w(js/app.js js/dashboard.tsx js/embed.host.js js/embed.content.js --bundle --target=es2017 --loader:.js=jsx --outdir=../priv/static/js --define:BUILD_EXTRA=true),
~w(js/app.js js/storybook.js js/dashboard.tsx js/embed.host.js js/embed.content.js --bundle --target=es2017 --loader:.js=jsx --outdir=../priv/static/js --define:BUILD_EXTRA=true),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]
Expand All @@ -34,6 +34,14 @@ config :tailwind,
--output=../priv/static/css/app.css
),
cd: Path.expand("../assets", __DIR__)
],
storybook: [
args: ~w(
--config=tailwind.config.js
--input=css/storybook.css
--output=../priv/static/css/storybook.css
),
cd: Path.expand("../assets", __DIR__)
]

config :ua_inspector,
Expand Down
4 changes: 3 additions & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config :plausible, PlausibleWeb.Endpoint,
watchers: [
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]},
storybook_tailwind: {Tailwind, :install_and_run, [:storybook, ~w(--watch)]},
npm: ["--prefix", "assets", "run", "typecheck", "--", "--watch", "--preserveWatchOutput"],
npm: [
"run",
Expand All @@ -21,7 +22,8 @@ config :plausible, PlausibleWeb.Endpoint,
],
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r"lib/plausible_web/(controllers|live|components|templates|views|plugs)/.*(ex|heex)$"
~r"lib/plausible_web/(controllers|live|components|templates|views|plugs)/.*(ex|heex)$",
~r"storybook/.*(exs)$"
]
]

Expand Down
2 changes: 2 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,5 @@ unless s3_disabled? do
exports_bucket: s3_env_value.("S3_EXPORTS_BUCKET"),
imports_bucket: s3_env_value.("S3_IMPORTS_BUCKET")
end

config :phoenix_storybook, enabled: env !== "prod"
4 changes: 2 additions & 2 deletions extra/lib/plausible_web/live/funnel_settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ defmodule PlausibleWeb.Live.FunnelSettings do
<.flash_messages flash={@flash} />
<%= if @setup_funnel? do %>
<%= live_render(
{live_render(
@socket,
PlausibleWeb.Live.FunnelSettings.Form,
id: "funnels-form",
session: %{
"domain" => @domain,
"funnel_id" => @funnel_id
}
) %>
)}
<% end %>
<div :if={@goal_count >= Funnel.min_steps()}>
<.live_component
Expand Down
4 changes: 2 additions & 2 deletions extra/lib/plausible_web/live/funnel_settings/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form do
class="bg-white dark:bg-gray-800 shadow-md rounded px-8 pt-6 pb-8 mb-4 mt-8"
>
<.title class="mb-6">
<%= if @funnel, do: "Edit", else: "Add" %> Funnel
{if @funnel, do: "Edit", else: "Add"} Funnel
</.title>
<.input
Expand Down Expand Up @@ -136,7 +136,7 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form do
length(@step_ids) > map_size(@selections_made)
}
>
<span><%= if @funnel, do: "Update", else: "Add" %> Funnel</span>
<span>{if @funnel, do: "Update", else: "Add"} Funnel</span>
</.button>
</div>
</.form>
Expand Down
4 changes: 2 additions & 2 deletions extra/lib/plausible_web/live/funnel_settings/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ defmodule PlausibleWeb.Live.FunnelSettings.List do
<.table rows={@funnels}>
<:tbody :let={funnel}>
<.td truncate>
<span class="font-medium"><%= funnel.name %></span>
<span class="font-medium">{funnel.name}</span>
</.td>
<.td hide_on_mobile>
<span class="text-gray-500 dark:text-gray-400">
<%= funnel.steps_count %>-step funnel
{funnel.steps_count}-step funnel
</span>
</.td>
<.td actions>
Expand Down
16 changes: 8 additions & 8 deletions extra/lib/plausible_web/views/help_scout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ defmodule PlausibleWeb.HelpScoutView do
<%= if @conn.assigns[:error] do %>
<p>
Failed to get details: <%= @error %>
Failed to get details: {@error}
</p>
<% else %>
<div class="status">
<p class="label">
Status
</p>
<p class="value">
<a href={@status_link} target="_blank"><%= @status_label %></a>
<a href={@status_link} target="_blank">{@status_label}</a>
</p>
</div>
Expand All @@ -34,13 +34,13 @@ defmodule PlausibleWeb.HelpScoutView do
Plan
</p>
<p class="value">
<a href={@plan_link} target="_blank"><%= @plan_label %></a>
<a href={@plan_link} target="_blank">{@plan_label}</a>
</p>
</div>
<div class="sites">
<p class="label">
Owner of <b><a href={@sites_link} target="_blank"><%= @sites_count %> sites</a></b>
Owner of <b><a href={@sites_link} target="_blank">{@sites_count} sites</a></b>
</p>
<p class="value"></p>
</div>
Expand All @@ -51,7 +51,7 @@ defmodule PlausibleWeb.HelpScoutView do
</p>
<div class="value">
<%= Phoenix.HTML.Format.text_to_html(@notes, escape: true) %>
{PhoenixHTMLHelpers.Format.text_to_html(@notes, escape: true)}
</div>
</div>
<% end %>
Expand All @@ -64,7 +64,7 @@ defmodule PlausibleWeb.HelpScoutView do
<.layout>
<%= if @conn.assigns[:error] do %>
<p>
Failed to run search: <%= @error %>
Failed to run search: {@error}
</p>
<% else %>
<div class="search">
Expand All @@ -82,7 +82,7 @@ defmodule PlausibleWeb.HelpScoutView do
onclick={"loadContent('/helpscout/show?#{URI.encode_query(email: user.email, conversation_id: @conversation_id, customer_id: @customer_id)}')"}
href="#"
>
<%= user.email %> (<%= user.sites_count %> sites)
{user.email} ({user.sites_count} sites)
</a>
</li>
</ul>
Expand Down Expand Up @@ -160,7 +160,7 @@ defmodule PlausibleWeb.HelpScoutView do
<body>
<div id="content">
<%= render_slot(@inner_block) %>
{render_slot(@inner_block)}
</div>
<script type="text/javascript">
Expand Down
15 changes: 4 additions & 11 deletions lib/plausible/billing/ecto/feature.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end

defmodule Plausible.Billing.Ecto.FeatureList do
@moduledoc """
Ecto type representing a list of features. This is a proxy for
Ecto type representing a list of features. This is a proxy for
`{:array, Plausible.Billing.Ecto.Feature}` and is required for Kaffy to
render the HTML input correctly.
"""
Expand All @@ -52,23 +52,16 @@ defmodule Plausible.Billing.Ecto.FeatureList do
for mod <- Plausible.Billing.Feature.list(), not mod.free?() do
[
{:safe, ~s(<label style="padding-right: 15px;">)},
Phoenix.HTML.Tag.tag(
:input,
name: Phoenix.HTML.Form.input_name(form, field) <> "[]",
id: Phoenix.HTML.Form.input_id(form, field, mod.name()),
type: "checkbox",
value: mod.name(),
style: "margin-right: 3px;",
checked: mod in features
),
{:safe,
~s(<input type="checkbox" name="#{form.name}[#{field}][]" "#{form.name}_#{field}_#{mod.name()}" value="#{mod.name()}" style="margin-right: 3px;" #{if mod in features, do: "checked", else: ""}>)},
mod.display_name(),
{:safe, ~s(</label>)}
]
end

[
{:safe, ~s(<div class="form-group">)},
Phoenix.HTML.Form.label(form, field),
{:safe, ~s(<label for="#{form.name}_#{field}">#{Phoenix.Naming.humanize(field)}</label>)},
{:safe, ~s(<div class="form-control">)},
checkboxes,
{:safe, ~s(</div>)},
Expand Down
11 changes: 3 additions & 8 deletions lib/plausible/billing/ecto/limit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ defmodule Plausible.Billing.Ecto.Limit do

[
{:safe, ~s(<div class="form-group">)},
Phoenix.HTML.Form.label(form, field),
Phoenix.HTML.Form.number_input(form, field,
class: "form-control",
name: "#{form.name}[#{field}]",
id: "#{form.name}_#{field}",
value: value,
min: -1
),
{:safe, ~s(<label for="#{form.name}_#{field}">#{Phoenix.Naming.humanize(field)}</label>)},
{:safe,
~s(<input id="#{form.name}_#{field}" name="#{form.name}[#{field}]" class="form-control" value="#{value}" min="-1" type="number" />)},
{:safe, ~s(<p class="help_text">Use -1 for unlimited.</p>)},
{:safe, ~s(</div>)}
]
Expand Down
1 change: 0 additions & 1 deletion lib/plausible_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ defmodule PlausibleWeb do

use Phoenix.Component

import PlausibleWeb.ErrorHelpers
import PlausibleWeb.Components.Generic
import PlausibleWeb.Live.Components.Form
alias PlausibleWeb.Router.Helpers, as: Routes
Expand Down
Loading

0 comments on commit 6c30f62

Please sign in to comment.