From fd3d66293cafb37a20e4506d61313bb212dbf2b8 Mon Sep 17 00:00:00 2001 From: Jamil Date: Wed, 12 Jun 2024 09:21:56 -0700 Subject: [PATCH] feat(portal): Enable `address_description` field to provide hint for accessing Resources in Clients (#5273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #5270 - Relaxes the `NOT NULL` constraint because in Clients we already account for empty address descriptions (by showing the address in its place if missing). We may want to simply hide the Resource altogether if the description is missing (based on user feedback). With a blank field, we can differentiate between not entered vs entered an address. - Updates help text a bit ```[tasklist] - [x] Update docs with examples ``` Screenshot 2024-06-06 at 12 01 48 PM --------- Signed-off-by: Jamil --- .../domain/resources/resource/changeset.ex | 4 +- ...ll_constraint_from_address_description.exs | 9 +++++ .../domain/test/domain/resources_test.exs | 6 +-- .../apps/web/lib/web/live/resources/edit.ex | 7 ++-- elixir/apps/web/lib/web/live/resources/new.ex | 35 ++---------------- .../apps/web/lib/web/live/resources/show.ex | 2 +- .../web/test/web/live/resources/new_test.exs | 8 +++- .../deploy/resources/address_description.png | Bin 0 -> 259834 bytes website/src/app/kb/deploy/resources/_page.tsx | 6 +++ website/src/app/kb/deploy/resources/page.tsx | 4 +- .../src/app/kb/deploy/resources/readme.mdx | 27 ++++++++++++++ 11 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 elixir/apps/domain/priv/repo/migrations/20240606182241_remove_null_constraint_from_address_description.exs create mode 100644 website/public/images/kb/deploy/resources/address_description.png create mode 100644 website/src/app/kb/deploy/resources/_page.tsx diff --git a/elixir/apps/domain/lib/domain/resources/resource/changeset.ex b/elixir/apps/domain/lib/domain/resources/resource/changeset.ex index 6f5a0a6e7..20b385338 100644 --- a/elixir/apps/domain/lib/domain/resources/resource/changeset.ex +++ b/elixir/apps/domain/lib/domain/resources/resource/changeset.ex @@ -5,7 +5,7 @@ defmodule Domain.Resources.Resource.Changeset do @fields ~w[address address_description name type]a @update_fields ~w[name address_description]a - @required_fields ~w[name address address_description type]a + @required_fields ~w[name address type]a def create(%Accounts.Account{} = account, attrs, %Auth.Subject{} = subject) do %Resource{connections: []} @@ -152,8 +152,6 @@ defmodule Domain.Resources.Resource.Changeset do changeset |> validate_length(:name, min: 1, max: 255) |> validate_length(:address_description, min: 1, max: 512) - # TODO: remove once address_description is visible again - |> copy_change(:address, :address_description) |> cast_embed(:filters, with: &cast_filter/2) |> unique_constraint(:ipv4, name: :resources_account_id_ipv4_index) |> unique_constraint(:ipv6, name: :resources_account_id_ipv6_index) diff --git a/elixir/apps/domain/priv/repo/migrations/20240606182241_remove_null_constraint_from_address_description.exs b/elixir/apps/domain/priv/repo/migrations/20240606182241_remove_null_constraint_from_address_description.exs new file mode 100644 index 000000000..093979949 --- /dev/null +++ b/elixir/apps/domain/priv/repo/migrations/20240606182241_remove_null_constraint_from_address_description.exs @@ -0,0 +1,9 @@ +defmodule Domain.Repo.Migrations.RemoveNullConstraintFromAddressDescription do + use Ecto.Migration + + def change do + alter table(:resources) do + modify(:address_description, :string, null: true) + end + end +end diff --git a/elixir/apps/domain/test/domain/resources_test.exs b/elixir/apps/domain/test/domain/resources_test.exs index e5323a859..7842247ed 100644 --- a/elixir/apps/domain/test/domain/resources_test.exs +++ b/elixir/apps/domain/test/domain/resources_test.exs @@ -892,7 +892,6 @@ defmodule Domain.ResourcesTest do assert errors_on(changeset) == %{ name: ["can't be blank"], address: ["can't be blank"], - address_description: ["can't be blank"], type: ["can't be blank"], connections: ["can't be blank"] } @@ -987,8 +986,7 @@ defmodule Domain.ResourcesTest do assert {:ok, resource} = create_resource(attrs, subject) assert resource.address == attrs.address - # TODO: uncomment once we show address_description - # assert resource.address_description == attrs.address_description + assert resource.address_description == attrs.address_description assert resource.name == attrs.address assert resource.account_id == account.id @@ -1021,7 +1019,7 @@ defmodule Domain.ResourcesTest do type: :cidr, name: "mycidr", address: "192.168.1.1/28", - address_description: "192.168.1.1/28" + address_description: "https://google.com" ) assert {:ok, resource} = create_resource(attrs, subject) diff --git a/elixir/apps/web/lib/web/live/resources/edit.ex b/elixir/apps/web/lib/web/live/resources/edit.ex index 9fb3b7351..3dbec8f45 100644 --- a/elixir/apps/web/lib/web/live/resources/edit.ex +++ b/elixir/apps/web/lib/web/live/resources/edit.ex @@ -58,16 +58,15 @@ defmodule Web.Resources.Edit do required /> - -