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

Use case visualization with Mermaid.js #37

Closed
dalssoft opened this issue Apr 16, 2022 · 17 comments
Closed

Use case visualization with Mermaid.js #37

dalssoft opened this issue Apr 16, 2022 · 17 comments
Assignees
Labels
enhancement New feature or request hacktoberfest ready-to-work Item is ready to work on it

Comments

@dalssoft
Copy link
Member

It would be interesting to understand a use case not only in code but also having a more "visual" approach and have this information as part of Shelf experience.

For that we could extract metadata from Herbs usecase and export to MermaidJS:

graph TD
    A([Update User Account])
    B(Validate given User Account information)
    C(Is User expired?)
    D{If User is expired}
    E(Then Activate User)
    F(Else Do nothing)
    G(Save User Account)
    A --> B
    B --> C
    C --> D
    D --> E
    D --> F
    E --> G
    F --> G

Generated graph (by github / mermaid):

graph TD
    A([Update User Account])
    B(Validate given User Account information)
    C(Is User expired?)
    D{If User is expired}
    E(Then Activate User)
    F(Else Do nothing)
    G(Save User Account)
    A --> B
    B --> C
    C --> D
    D --> E
    D --> F
    E --> G
    F --> G
Loading
@dalssoft dalssoft added the enhancement New feature or request label Apr 16, 2022
@italojs italojs added the ready-to-work Item is ready to work on it label May 4, 2022
@dalssoft dalssoft moved this to More discussion is needed in Herbs - 3rd Anniversary Edition May 25, 2022
@maikmb
Copy link
Contributor

maikmb commented Jul 5, 2022

I will work on this issue.

@maikvortx
Copy link
Contributor

Guys, where do you think this diagram should be on the shelf? I think to put it on the bottom of usecase details.

Image

@dalssoft
Copy link
Member Author

dalssoft commented Jul 6, 2022

My suggestion is to have a switch buttons to view steps as text or as workflow, something like this:

image

maikmb pushed a commit to maikmb/herbsshelf that referenced this issue Jul 6, 2022
include usecase flow chat to readme and refactor some methods to reder mermaid to support usecase
and entities

re herbsjs#37
maikmb pushed a commit to maikmb/herbsshelf that referenced this issue Jul 15, 2022
maikmb pushed a commit to maikmb/herbsshelf that referenced this issue Jul 16, 2022
maikmb pushed a commit to maikmb/herbsshelf that referenced this issue Jul 17, 2022
@maikmb
Copy link
Contributor

maikmb commented Jul 18, 2022

Hello! What do you think about this example?

screenshot-localhost_4000-2022 07 18-18_57_28

screenshot-localhost_4000-2022 07 18-18_55_45

maikmb pushed a commit to maikmb/herbsshelf that referenced this issue Jul 18, 2022
@dalssoft
Copy link
Member Author

Wow! great job @maikmb!

(1) is it possible to change the color of the graph? this blue/purple doesn't match the current visual identity.

(2) have you tested with complex UCs (many IFs and/or multi-level steps)?

@jhomarolo
Copy link
Contributor

Well done @maikmb!

For me, we just need to change the colors, nothing more.

@maikmb
Copy link
Contributor

maikmb commented Jul 25, 2022

Hey guys!

This is an example with Herbs primary color and complex UCs like many Ifs or multi-level-steps. Any more suggestions?

screenshot-localhost_4000-2022 07 24-21_13_37

@jhomarolo
Copy link
Contributor

Awesome!

@jhomarolo
Copy link
Contributor

Please open the PR

@dalssoft
Copy link
Member Author

Wow! its getting very cool!!

One thing that I didn't understand was this part:
image

Could you post here the code for this use case?

@maikvortx
Copy link
Contributor

Please open the PR

Hi @jhomarolo, I will implement unit tests to open PR. I need one more day to implement it.

@maikmb
Copy link
Contributor

maikmb commented Jul 25, 2022

Could you post here the code for this use case?

Hi @dalssoft ! This part refers to Multi-Level Steps.

Step example:

    'Send real time events': step({

      'Update mobile push notifications': step(async (ctx) => {
        return Ok()
      }),

      'Update payment cart': step(async (ctx) => {
        return Ok()
      }),     

    }),

@maikmb
Copy link
Contributor

maikmb commented Jul 27, 2022

Hey guys, here's the full example with complex Multi-Level Steps.

Flow Chart

screenshot-localhost_4000-2022 07 26-22_32_40

Usecase

const updateItem = (injection) =>
  usecase('Update Item', {
    request: {
      id: Number,
      description: String,
      isDone: Boolean,
      position: Number
    },

    response: Item,

    'Validate request': step(async (ctx) => {
      return Ok()
    }),

    'Check if is necessary to update': ifElse({
      'If position has changed ': step((ctx) => {
        return Ok(true)
      }),

      'Save itens': step(async (ctx) => {
        return Ok()
      }),

      'Updated item': step(async (ctx) => {
        return Ok()
      }),
    }),

    'Notify update item': step(async (ctx) => {
      return Ok()
    }),

    'Calculate stock': step(async (ctx) => {
      return Ok()
    }),

    'Send real time events': step({

      'Update mobile push notifications': step(async (ctx) => {
        return Ok()
      }),

      'Update payment cart': step(async (ctx) => {
        return Ok()
      }),     

    }),

    'Check if has product': ifElse({
      'If has product ': step((ctx) => {
        return Ok(true)
      }),

      'Update product item': step(async (ctx) => {
       return Ok()
      }),

      'Create product item': step(async (ctx) => {
        return Ok() 
      }),
     
    }), 

    'Update cart dashboard': step(async (ctx) => {
      return Ok()
    }),
    
    'Save product': step({

      'Update database': step(async (ctx) => {
        return Ok()
      }),

      'Update cache database': step(async (ctx) => {
        return Ok()
      }),     

    }),

  })


maikmb pushed a commit to maikmb/herbsshelf that referenced this issue Jul 30, 2022
@dalssoft
Copy link
Member Author

dalssoft commented Aug 7, 2022

Is there a PR for this issue? I couldn't find.

@maikvortx
Copy link
Contributor

Hi @dalssoft,

I will open a PR for this feature. I created a new glue, herbs2mermaid, and configure it for my project to test with shelf.

@jhomarolo
Copy link
Contributor

@maikmb when you finish, please put the pr link here

@dalssoft
Copy link
Member Author

dalssoft commented Sep 5, 2022

since we have /~https://github.com/herbsjs/herbs2mermaid now, can we move on with this feature?

maikmb pushed a commit to maikmb/herbsshelf that referenced this issue Sep 11, 2022
github-actions bot pushed a commit that referenced this issue Oct 10, 2022
# [4.1.0](v4.0.1...v4.1.0) (2022-10-10)

### Features

* **herbs2mermaid:** install herbs2mermaid and configure darkmode to mermaid render ([6281f72](6281f72)), closes [#37](#37)
* **mermaid-usecase:** implement basic ifelse workfow ([f613dde](f613dde)), closes [#37](#37)
* **mermaid-usecase:** implement basic usecase class diagram ([bb5614e](bb5614e)), closes [#37](#37)
* **mermaid-usecase:** implement flow chart tab to shelf ([bc52c9e](bc52c9e)), closes [#37](#37)
* **mermaid-usecase:** implement ifelse complex relationship ([bea52d0](bea52d0)), closes [#37](#37)
* **mermaid-usecase:** include usecase flow chat ([dbf0790](dbf0790)), closes [#37](#37)
@github-project-automation github-project-automation bot moved this from More discussion is needed to Done in Herbs - 3rd Anniversary Edition Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest ready-to-work Item is ready to work on it
Projects
Development

No branches or pull requests

5 participants