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

feat: Add getConfigValue #5251

Closed
wants to merge 1 commit into from
Closed

feat: Add getConfigValue #5251

wants to merge 1 commit into from

Conversation

sidharthv96
Copy link
Member

No description provided.

@github-actions github-actions bot added the Type: Enhancement New feature or request label Jan 30, 2024
Copy link

codecov bot commented Jan 30, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (80c20a7) 80.08% compared to head (8b0399e) 43.25%.

Additional details and impacted files

Impacted file tree graph

@@                  Coverage Diff                  @@
##           sidv/mindmapToTs    #5251       +/-   ##
=====================================================
- Coverage             80.08%   43.25%   -36.84%     
=====================================================
  Files                   167       23      -144     
  Lines                 13867     5056     -8811     
  Branches                741       23      -718     
=====================================================
- Hits                  11106     2187     -8919     
- Misses                 2594     2868      +274     
+ Partials                167        1      -166     
Flag Coverage Δ
e2e ?
unit 43.25% <52.63%> (+0.02%) ⬆️

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

Files Coverage Δ
packages/mermaid/src/config.ts 52.25% <52.63%> (-16.70%) ⬇️

... and 162 files with indirect coverage changes

Copy link
Member

@Yokozuna59 Yokozuna59 left a comment

Choose a reason for hiding this comment

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

I wouldn't really recommend this approach. The path approach isn't type-safe since it's being used as a string. It's kind of complicating the object destructuring.

@sidharthv96
Copy link
Member Author

It is typesafe though, both the path and the return value will be properly typed.

image image

@@ -47,7 +47,7 @@ const addNode = (level: number, id: string, descr: string, type: number) => {
descr: sanitizeText(descr, conf),
type,
children: [],
width: conf.mindmap?.maxNodeWidth ?? defaultConfig.mindmap.maxNodeWidth,
width: getConfigValue(conf, 'mindmap.maxNodeWidth'),
Copy link
Member

Choose a reason for hiding this comment

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

I'm also not a big fan of this syntax, since it makes things more complicated.

Ideally, we'd instead change getConfig() to return RequiredDeep<MermaidConfig>.

The only reason I haven't yet is that some of the config values don't have default values, because undefined is a valid value for them. Ideally, I'd go through the config and change every value that currently accepts undefined to instead use null, that way we can safely do RequiredDeep<MermaidConfig> and still keep the null types.

Then we could just do: conf.mindmap.maxNodeWidth.

path: Path
): Get<RequiredDeep<MermaidConfig>, Path> => {
let value = lodashGet(config, path) as Get<RequiredDeep<MermaidConfig>, Path>;
if (!value) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't work for values that valid but falsy, false, 0, or "".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants