Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update shape timestamp field type #985

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4e65dbc
fix: commit CoreComponents from a phoenix 7 new app
meagharty Jun 5, 2024
88f441f
fix: update arrow_web.ex to match new phoenix app, use CoreComponents
meagharty Jun 5, 2024
91222d0
chore: commit cosmetic npm lockfile change
meagharty Jun 5, 2024
a7ee6f2
feat: hook up phoenix 1.7 verified_routes to endpoint.ex
meagharty Jun 5, 2024
0b47d5f
fix: fix icons by adding to static path list
meagharty Jun 5, 2024
73f7d4a
feat: add tailwind css & hero icons for CoreComponents 1.7
meagharty Jun 5, 2024
3eb2ada
fix: format tailwind.config.js with prettier
meagharty Jun 5, 2024
3976c72
fix: add phx.digest output to .gitignore
meagharty Jun 7, 2024
9bb6d02
fix: add tailwind to mix assets.build, assets.deploy
meagharty Jun 6, 2024
e07c972
fix: fix dev config name for watching tailwind changes
meagharty Jun 6, 2024
41e35df
fix: have phoenix serve static files like images, fonts, icons
meagharty Jun 6, 2024
b72717f
fix: remove asset tagged versions of icons
meagharty Jun 7, 2024
926208f
fix: fix path for checkbox.css image
meagharty Jun 7, 2024
9d35758
fix: separate out css from js build, remove tailwind.css separate file
meagharty Jun 6, 2024
ee79d7b
fix: remove @tailwind/base to prevent collision with bootstrap
meagharty Jun 6, 2024
cf7ee90
fix: update esbuild, remove css refs and add empty loader
meagharty Jun 6, 2024
4823396
fix: fix Dockerfile to work with tailwind with Phoenix .heex
meagharty Jun 6, 2024
64d2bc4
feat: commit mix phx.gen.html output
meagharty Jun 5, 2024
c1abdec
feat: commit result of ecto migration
meagharty Jun 5, 2024
4bbb742
fix: rename Shape -> ShapeView, add auth
meagharty Jun 5, 2024
2acaa83
tests: add authentication to controller tests
meagharty Jun 5, 2024
20dba1e
fix: fix credo issues
meagharty Jun 5, 2024
e40d27d
feat: add file upload input, mark required
meagharty Jun 7, 2024
9de3398
tests: add test with upload params set
meagharty Jun 7, 2024
9a6afcd
fix: shapes schema use :timestamptz (default is naive_datetime)
meagharty Jun 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ npm-debug.log
# Ignore assets that are produced by build tools.
/priv/static/assets

# Ignore digested assets cache.
/priv/static/cache_manifest.json

# Code coverage from React tests
/assets/coverage/

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ RUN mix deps.compile

COPY assets assets
RUN npm ci --prefix assets
RUN mix assets.deploy

COPY lib lib
RUN mix assets.deploy

COPY priv priv

RUN mix phx.digest
Expand Down
4 changes: 4 additions & 0 deletions assets/css/app.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* This file is for your main application css. */
@import "tailwindcss/components";
@import "tailwindcss/utilities";

@import "./variables.css";
@import "./bootstrap.css";
@import "../node_modules/react-datepicker/dist/react-datepicker.css";
@import "../node_modules/@fullcalendar/daygrid/main.css";
@import "../node_modules/@fullcalendar/common/main.css";

@import "./base.css";
@import "./checkbox.css";
Expand Down
1 change: 1 addition & 0 deletions assets/package-lock.json

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

6 changes: 0 additions & 6 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
"jest": {
"testEnvironment": "jsdom",
"clearMocks": true,
"transformIgnorePatterns": [
"node_modules/(?!@fullcalendar).+"
],
"transform": {
"^.+\\.(j|t)sx?$": "ts-jest"
},
Expand All @@ -63,9 +60,6 @@
"json",
"node"
],
"moduleNameMapper": {
"\\.(css)$": "identity-obj-proxy"
},
"setupFilesAfterEnv": [
"<rootDir>/jest-setup.ts"
],
Expand Down
8 changes: 0 additions & 8 deletions assets/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
// We need to import the CSS so that webpack will load it.
// The MiniCssExtractPlugin is used to separate it out into
// its own CSS file.
declare function require(name: string): string

// tslint:disable-next-line
require("../css/app.css")

import "phoenix_html"

import ReactPhoenix from "./ReactPhoenix"
Expand Down
94 changes: 94 additions & 0 deletions assets/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// See the Tailwind configuration guide for advanced usage
// https://tailwindcss.com/docs/configuration

const plugin = require("tailwindcss/plugin")
const fs = require("fs")
const path = require("path")

module.exports = {
content: ["./js/**/*.js", "../lib/arrow_web.ex", "../lib/arrow_web/**/*.*ex"],
theme: {
extend: {
colors: {
brand: "#FD4F00",
},
},
},
plugins: [
require("@tailwindcss/forms"),
// Allows prefixing tailwind classes with LiveView classes to add rules
// only when LiveView classes are applied, for example:
//
// <div class="phx-click-loading:animate-ping">
//
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 &",
])
),

// Embeds Heroicons (https://heroicons.com) into your app.css bundle
// See your `CoreComponents.icon/1` for more information.
//
plugin(function ({ matchComponents, theme }) {
let iconsDir = path.join(__dirname, "../deps/heroicons/optimized")
let values = {}
let icons = [
["", "/24/outline"],
["-solid", "/24/solid"],
["-mini", "/20/solid"],
["-micro", "/16/solid"],
]
icons.forEach(([suffix, dir]) => {
fs.readdirSync(path.join(iconsDir, dir)).forEach((file) => {
let name = path.basename(file, ".svg") + suffix
values[name] = { name, fullPath: path.join(iconsDir, dir, file) }
})
})
matchComponents(
{
hero: ({ name, fullPath }) => {
let content = fs
.readFileSync(fullPath)
.toString()
.replace(/\r?\n|\r/g, "")
let size = theme("spacing.6")
if (name.endsWith("-mini")) {
size = theme("spacing.5")
} else if (name.endsWith("-micro")) {
size = theme("spacing.4")
}
return {
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
"-webkit-mask": `var(--hero-${name})`,
mask: `var(--hero-${name})`,
"mask-repeat": "no-repeat",
"background-color": "currentColor",
"vertical-align": "middle",
display: "inline-block",
width: size,
height: size,
}
},
},
{ values }
)
}),
],
}
2 changes: 1 addition & 1 deletion assets/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src", "tests", "node_modules/@fullcalendar", "jest-setup.ts"],
"include": ["src", "tests", "jest-setup.ts"],
"exclude": ["node_modules"],
"compilerOptions": {
/* Basic Options */
Expand Down
22 changes: 18 additions & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,35 @@ config :arrow, ArrowWeb.Endpoint,
pubsub_server: Arrow.PubSub

config :esbuild,
version: "0.12.18",
version: "0.17.11",
default: [
args: ~w(
src/app.tsx
--bundle
--target=es2015
--loader:.png=file
--loader:.woff=file
--loader:.css=empty
--outdir=../priv/static/assets
--external:/fonts/*
--external:/images/*
--external:/css/*
#{if(Mix.env() == :test, do: "--define:__REACT_DEVTOOLS_GLOBAL_HOOK__={'isDisabled':true}")}
),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
]

# Configure tailwind (the version is required)
config :tailwind,
version: "3.4.0",
default: [
args: ~w(
--config=tailwind.config.js
--input=css/app.css
--output=../priv/static/assets/app.css
),
cd: Path.expand("../assets", __DIR__)
]

config :arrow, ArrowWeb.AuthManager, issuer: "arrow"

config :ueberauth, Ueberauth,
Expand Down Expand Up @@ -98,4 +112,4 @@ config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
import_config "#{config_env()}.exs"
17 changes: 14 additions & 3 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ config :arrow, ArrowWeb.Endpoint,
secret_key_base: "local_secret_key_base_at_least_64_bytes_________________________________",
watchers: [
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
node: ~w(assets/node_modules/.bin/tsc --project assets --noEmit --watch --preserveWatchOutput)
node:
~w(assets/node_modules/.bin/tsc --project assets --noEmit --watch --preserveWatchOutput),
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
]

config :arrow, ArrowWeb.AuthManager, secret_key: "test key"
Expand Down Expand Up @@ -58,8 +60,7 @@ config :arrow, ArrowWeb.Endpoint,
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/gettext/.*(po)$",
~r"lib/arrow_web/{live,views}/.*(ex)$",
~r"lib/arrow_web/templates/.*(eex)$"
~r"lib/arrow_web/(controllers|live|components)/.*(ex|heex)$"
]
]

Expand All @@ -70,6 +71,9 @@ config :ueberauth, Ueberauth,

config :arrow, :redirect_http?, false

# Enable dev routes for dashboard and mailbox
config :arrow, dev_routes: true

# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"

Expand All @@ -79,3 +83,10 @@ config :phoenix, :stacktrace_depth, 20

# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime

config :phoenix_live_view,
# Include HEEx debug annotations as HTML comments in rendered markup
debug_heex_annotations: true

# Enable helpful, but potentially expensive runtime checks
# enable_expensive_runtime_checks: true
104 changes: 104 additions & 0 deletions lib/arrow/shuttle.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
defmodule Arrow.Shuttle do
@moduledoc """
The Shuttle context.
"""

import Ecto.Query, warn: false
alias Arrow.Repo

alias Arrow.Shuttle.Shape

@doc """
Returns the list of shapes.

## Examples

iex> list_shapes()
[%Shape{}, ...]

"""
def list_shapes do
Repo.all(Shape)
end

@doc """
Gets a single shape.

Raises `Ecto.NoResultsError` if the Shape does not exist.

## Examples

iex> get_shape!(123)
%Shape{}

iex> get_shape!(456)
** (Ecto.NoResultsError)

"""
def get_shape!(id), do: Repo.get!(Shape, id)

@doc """
Creates a shape.

## Examples

iex> create_shape(%{field: value})
{:ok, %Shape{}}

iex> create_shape(%{field: bad_value})
{:error, %Ecto.Changeset{}}

"""
def create_shape(attrs \\ %{}) do
%Shape{}
|> Shape.changeset(attrs)
|> Repo.insert()
end

@doc """
Updates a shape.

## Examples

iex> update_shape(shape, %{field: new_value})
{:ok, %Shape{}}

iex> update_shape(shape, %{field: bad_value})
{:error, %Ecto.Changeset{}}

"""
def update_shape(%Shape{} = shape, attrs) do
shape
|> Shape.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a shape.

## Examples

iex> delete_shape(shape)
{:ok, %Shape{}}

iex> delete_shape(shape)
{:error, %Ecto.Changeset{}}

"""
def delete_shape(%Shape{} = shape) do
Repo.delete(shape)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking shape changes.

## Examples

iex> change_shape(shape)
%Ecto.Changeset{data: %Shape{}}

"""
def change_shape(%Shape{} = shape, attrs \\ %{}) do
Shape.changeset(shape, attrs)
end
end
19 changes: 19 additions & 0 deletions lib/arrow/shuttle/shape.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Arrow.Shuttle.Shape do
@moduledoc "schema for shuttle shapes"
use Ecto.Schema
import Ecto.Changeset

schema "shapes" do
field :name, :string

timestamps(type: :utc_datetime)
end

@doc false
def changeset(shape, attrs) do
shape
|> cast(attrs, [:name])
|> validate_required([:name])
|> unique_constraint(:name)
end
end
Loading
Loading