From a365103087296cdba5e2e3b6cece92415e5e04df Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Mon, 17 Oct 2022 10:18:47 -0500 Subject: [PATCH] clean up livebook/mermaid diagrams --- lib/ash/api/info/diagram.ex | 7 +++--- lib/ash/api/info/livebook.ex | 25 +++++++++++++------- lib/ash/resource/actions/destroy.ex | 1 + test/api/diagram_test.exs | 8 +++---- test/api/livebook_test.exs | 36 ++++++++++++++--------------- 5 files changed, 44 insertions(+), 33 deletions(-) diff --git a/lib/ash/api/info/diagram.ex b/lib/ash/api/info/diagram.ex index 2cc2bd6f..90dfb767 100644 --- a/lib/ash/api/info/diagram.ex +++ b/lib/ash/api/info/diagram.ex @@ -130,9 +130,10 @@ defmodule Ash.Api.Info.Diagram do arguments = action.arguments attributes = - case action.type do - :read -> [] - _ -> action.accept |> Enum.map(&Ash.Resource.Info.attribute(resource, &1)) + case action do + %{type: :read} -> [] + %{type: :destroy, soft?: false} -> [] + %{accept: accept} -> accept |> Enum.map(&Ash.Resource.Info.attribute(resource, &1)) end list_arguments(arguments ++ attributes) diff --git a/lib/ash/api/info/livebook.ex b/lib/ash/api/info/livebook.ex index 52dc6773..f3391531 100644 --- a/lib/ash/api/info/livebook.ex +++ b/lib/ash/api/info/livebook.ex @@ -79,7 +79,7 @@ defmodule Ash.Api.Info.Livebook do #{action_header() |> String.trim()} #{for action <- Ash.Resource.Info.actions(resource) do - action_section(action) + action_section(resource, action) end |> Enum.join("\n")} """ end @@ -97,18 +97,27 @@ defmodule Ash.Api.Info.Livebook do def action_header do """ - | Name | Type | Description | Args | - | ---- | ---- | ----------- | ---- | + | Name | Type | Input | Description | + | ---- | ---- | ----- | ----------- | """ end - def action_section(action) do - "| **#{action.name}** | _#{action.type}_ | #{action.description} | |" + def action_section(resource, action) do + "| **#{action.name}** | _#{action.type}_ | | #{action.description} |" end - def action_arg_section(action) do - for arg <- action.arguments do - "
  • #{arg.name} #{class_short_type(arg.type)} #{arg.description}
  • " + def action_input_section(resource, action) do + attributes = + if action.type == :destroy && !action.soft? do + [] + else + action + |> Map.get(:accept, []) + |> Enum.map(&Ash.Resource.Info.attribute(resource, &1)) + end + + for input <- action.arguments ++ attributes do + "
  • #{input.name} #{class_short_type(input.type)} #{input.description}
  • " end end end diff --git a/lib/ash/resource/actions/destroy.ex b/lib/ash/resource/actions/destroy.ex index 06436371..c46bff55 100644 --- a/lib/ash/resource/actions/destroy.ex +++ b/lib/ash/resource/actions/destroy.ex @@ -36,6 +36,7 @@ defmodule Ash.Resource.Actions.Destroy do soft?: [ type: :atom, doc: "If specified, the destroy action behaves as an update internally", + default: false, links: [] ] ] diff --git a/test/api/diagram_test.exs b/test/api/diagram_test.exs index 90348142..3b005cb7 100644 --- a/test/api/diagram_test.exs +++ b/test/api/diagram_test.exs @@ -29,7 +29,7 @@ defmodule Ash.Test.Api.Info.DiagramTest do String last_name String email Org org - destroy(UUID id, String first_name, String last_name, String email) + destroy() read() for_org(UUID org) create(UUID org, UUID id, String first_name, String last_name, ...) @@ -41,7 +41,7 @@ defmodule Ash.Test.Api.Info.DiagramTest do UUID id String name User[] users - destroy(UUID id, String name) + destroy() update(UUID id, String name) read() create(UUID id, String name) @@ -86,7 +86,7 @@ defmodule Ash.Test.Api.Info.DiagramTest do Boolean approved UUID org_id Org org - destroy(UUID id, String first_name, String last_name, String email) + destroy() read() for_org(UUID org) create(UUID org, UUID id, String first_name, String last_name, ...) @@ -98,7 +98,7 @@ defmodule Ash.Test.Api.Info.DiagramTest do UUID id String name User[] users - destroy(UUID id, String name) + destroy() update(UUID id, String name) read() create(UUID id, String name) diff --git a/test/api/livebook_test.exs b/test/api/livebook_test.exs index 1e06be51..ef0b4373 100644 --- a/test/api/livebook_test.exs +++ b/test/api/livebook_test.exs @@ -17,7 +17,7 @@ defmodule Ash.Test.Api.Info.LivebookTest do String last_name String email Org org - destroy(UUID id, String first_name, String last_name, String email) + destroy() read() for_org(UUID org) create(UUID org, UUID id, String first_name, String last_name, ...) @@ -29,7 +29,7 @@ defmodule Ash.Test.Api.Info.LivebookTest do UUID id String name User[] users - destroy(UUID id, String name) + destroy() update(UUID id, String name) read() create(UUID id, String name) @@ -79,15 +79,15 @@ defmodule Ash.Test.Api.Info.LivebookTest do ### Actions - | Name | Type | Description | Args | - | ---- | ---- | ----------- | ---- | - | **destroy** | _destroy_ | | | - | **read** | _read_ | | | - | **for_org** | _read_ | | | - | **create** | _create_ | | | - | **update** | _update_ | | | - | **approve** | _update_ | | | - | **unapprove** | _update_ | | | + | Name | Type | Input | Description | + | ---- | ---- | ----- | ----------- | + | **destroy** | _destroy_ | | | + | **read** | _read_ | | | + | **for_org** | _read_ | | | + | **create** | _create_ | | | + | **update** | _update_ | | | + | **approve** | _update_ | | | + | **unapprove** | _update_ | | | ## Org @@ -102,13 +102,13 @@ defmodule Ash.Test.Api.Info.LivebookTest do ### Actions - | Name | Type | Description | Args | - | ---- | ---- | ----------- | ---- | - | **destroy** | _destroy_ | | | - | **update** | _update_ | | | - | **read** | _read_ | | | - | **create** | _create_ | | | - | **by_name** | _read_ | | | + | Name | Type | Input | Description | + | ---- | ---- | ----- | ----------- | + | **destroy** | _destroy_ | | | + | **update** | _update_ | | | + | **read** | _read_ | | | + | **create** | _create_ | | | + | **by_name** | _read_ | | | """ end