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

Update classId generation to use generic type #5223

Closed

Conversation

jgreywolf
Copy link
Contributor

📑 Summary

In order to allow class diagrams where there are multiple generic classes with the same name, only different type parameter, updated the classId generation logic to append -TYPE to the end of class name to get the id.

However, this means that any later referrals to that class needs to either be in the format class~T~ or class-T to ensure that the correct class is utilized.

  • Updated documentation
  • added tests

Resolves #4762

📏 Design Decisions

📋 Tasks

Make sure you

Copy link

netlify bot commented Jan 22, 2024

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 234a2cc
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/65ffcfa1867cc50008bc85c0
😎 Deploy Preview https://deploy-preview-5223--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the Type: Bug / Error Something isn't working or is incorrect label Jan 22, 2024
Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This should help out a lot of people.

Is this a breaking change though? (Or did the previous implementation not support this at all?)
Should we fall back to previous behavior, so existing diagrams don't break?

If the diagram refers class without type, we could pick whichever class was defined first (or whatever the current behaviour is)?

We need rendering tests as well.

cc @knsv

packages/mermaid/src/diagrams/class/classDb.ts Outdated Show resolved Hide resolved
packages/mermaid/src/docs/syntax/classDiagram.md Outdated Show resolved Hide resolved
@jgreywolf
Copy link
Contributor Author

Nice! This should help out a lot of people.

Is this a breaking change though? (Or did the previous implementation not support this at all?) Should we fall back to previous behavior, so existing diagrams don't break?

If the diagram refers class without type, we could pick whichever class was defined first (or whatever the current behaviour is)?

We need rendering tests as well.

cc @knsv

The previous implemetation did not support this at all. This should not be a breaking change, any existing class diagrams will still parse the same as they did before

@jgreywolf jgreywolf mentioned this pull request Jan 28, 2024
4 tasks
Copy link

codecov bot commented Jan 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 48 lines in your changes missing coverage. Please review.

Project coverage is 5.72%. Comparing base (c00bf26) to head (234a2cc).
Report is 1720 commits behind head on develop.

Files with missing lines Patch % Lines
packages/mermaid/src/diagrams/class/classDb.ts 0.00% 47 Missing ⚠️
packages/mermaid/src/diagrams/class/classTypes.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #5223      +/-   ##
==========================================
- Coverage     5.72%   5.72%   -0.01%     
==========================================
  Files          277     277              
  Lines        41896   41902       +6     
  Branches        27      27              
==========================================
  Hits          2400    2400              
- Misses       39495   39501       +6     
  Partials         1       1              
Flag Coverage Δ
unit 5.72% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/mermaid/src/diagrams/class/classTypes.ts 0.00% <0.00%> (ø)
packages/mermaid/src/diagrams/class/classDb.ts 0.00% <0.00%> (ø)

@jgreywolf
Copy link
Contributor Author

We need rendering tests as well.

There are already rendering tests that cover use of generic in class name

@jgreywolf
Copy link
Contributor Author

@sidharthv96
FYI - in reviewing the failing rendering tests, these are actually expected, since this is fixing a bug and the previous renders were actually not showing the correct data

This is assuming that the test result images are showing the old (expected) on the left, and the new (received) is on the left

@sidharthv96
Copy link
Member

That's fine. Yes it's like you mentioned.

…in-class-name

* develop: (501 commits)
  Add extra test
  Add visual test
  Wait for image to be rendered
  Update docs
  Linting
  chore:  temp fix for eslint OOM
  chore: Update error snapshots
  Fix ESLint
  chore: Prettier
  chore: YOLO `pnpm --recursive update`
  chore: Remove commitlint
  Fix flowchart-elk render test
  chore: Add example page link in index
  Fix flowchart-elk render test
  chore: Add example page link in index
  fix: Remove space which caused extra newline on diagrams
  fix: Remove repeated config calls
  fix: ELK diagram remove re-parsing
  chore: Minor fixes #4856
  chore: Increase ESLint memory limit
  ...
Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous implemetation did not support this at all. This should not be a breaking change, any existing class diagrams will still parse the same as they did before

Consider this diagram

classDiagram
    class Class01~T~
      Class01 : size()
      Class01 : int chimp
      Class01 : int gorilla
      Class08 <--> C2: Cool label
      class Class10~T~ {
        &lt;&lt;service&gt;&gt;
        int id
        test()
      }

In mermaid.live
image

In branch preview
image

So this infact breaks existing diagrams. So we should add a fallback so the diagram will render the same.

@jgreywolf
Copy link
Contributor Author

FYI - I am redoing this slightly as part of a separate PR (too many conflicts). Im not sure this is the best solution anymore either. I mentioned to someone else recently, that I totally regret using ~~ to denote types.

@jgreywolf jgreywolf closed this Nov 8, 2024
@jgreywolf jgreywolf deleted the bug/4762_class-diagram-generic-type-info-in-class-name branch November 8, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

a generic class with different type arguments is rendered as the same class symbol
2 participants