clean up livebook/mermaid diagrams

This commit is contained in:
Zach Daniel 2022-10-17 10:18:47 -05:00
parent 3f572c65a2
commit a365103087
5 changed files with 44 additions and 33 deletions

View file

@ -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)

View file

@ -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} | <ul>#{action_arg_section(action)}</ul> |"
def action_section(resource, action) do
"| **#{action.name}** | _#{action.type}_ | <ul>#{action_input_section(resource, action)}</ul> | #{action.description} |"
end
def action_arg_section(action) do
for arg <- action.arguments do
"<li><b>#{arg.name}</b> <i>#{class_short_type(arg.type)}</i> #{arg.description}</li>"
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
"<li><b>#{input.name}</b> <i>#{class_short_type(input.type)}</i> #{input.description}</li>"
end
end
end

View file

@ -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: []
]
]

View file

@ -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)

View file

@ -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_ | | <ul></ul> |
| **read** | _read_ | | <ul></ul> |
| **for_org** | _read_ | | <ul><li><b>org</b> <i>UUID</i> </li></ul> |
| **create** | _create_ | | <ul><li><b>org</b> <i>UUID</i> </li></ul> |
| **update** | _update_ | | <ul></ul> |
| **approve** | _update_ | | <ul></ul> |
| **unapprove** | _update_ | | <ul></ul> |
| Name | Type | Input | Description |
| ---- | ---- | ----- | ----------- |
| **destroy** | _destroy_ | <ul></ul> | |
| **read** | _read_ | <ul></ul> | |
| **for_org** | _read_ | <ul><li><b>org</b> <i>UUID</i> </li></ul> | |
| **create** | _create_ | <ul><li><b>org</b> <i>UUID</i> </li><li><b>id</b> <i>UUID</i> PK</li><li><b>first_name</b> <i>String</i> User's first name</li><li><b>last_name</b> <i>String</i> User's last name</li><li><b>email</b> <i>String</i> User's email address</li></ul> | |
| **update** | _update_ | <ul><li><b>id</b> <i>UUID</i> PK</li><li><b>first_name</b> <i>String</i> User's first name</li><li><b>last_name</b> <i>String</i> User's last name</li><li><b>email</b> <i>String</i> User's email address</li></ul> | |
| **approve** | _update_ | <ul></ul> | |
| **unapprove** | _update_ | <ul></ul> | |
## Org
@ -102,13 +102,13 @@ defmodule Ash.Test.Api.Info.LivebookTest do
### Actions
| Name | Type | Description | Args |
| ---- | ---- | ----------- | ---- |
| **destroy** | _destroy_ | | <ul></ul> |
| **update** | _update_ | | <ul></ul> |
| **read** | _read_ | | <ul></ul> |
| **create** | _create_ | | <ul></ul> |
| **by_name** | _read_ | | <ul><li><b>name</b> <i>String</i> </li></ul> |
| Name | Type | Input | Description |
| ---- | ---- | ----- | ----------- |
| **destroy** | _destroy_ | <ul></ul> | |
| **update** | _update_ | <ul><li><b>id</b> <i>UUID</i> </li><li><b>name</b> <i>String</i> </li></ul> | |
| **read** | _read_ | <ul></ul> | |
| **create** | _create_ | <ul><li><b>id</b> <i>UUID</i> </li><li><b>name</b> <i>String</i> </li></ul> | |
| **by_name** | _read_ | <ul><li><b>name</b> <i>String</i> </li></ul> | |
"""
end