Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: allow .json extension on annotations file #836 #1402

Merged
merged 14 commits into from
Jan 29, 2022

Conversation

mfranzke
Copy link
Contributor

@mfranzke mfranzke commented Jan 2, 2022

Summary of changes:

As the original implementation by @engelfrost (kudos for that!) accidentally got reverted with commit 9c49a09, we should add that nice refactoring again to ensure that annotations JSON files could get used with the correct filetype / file-ending, and even also advocate for that file-ending from now on.

@engelfrost implementation even also ensured backwards compatibility, so this wouldn't be a breaking change.

The resulting implementation could get reviewed on https://deploy-preview-1402--patternlab-handlebars-preview.netlify.app/?p=viewall-molecules-global&view=annotations and https://deploy-preview-1402--patternlab-handlebars-preview.netlify.app/?p=pages-homepage&view=annotations

There's still a problem with displaying the tooltips on the "standalone" view (in our example for the header), as the general styles from pattern-lab.css aren't included in this view.
This problem is unrelated to the fixes in this pull request and I've opened another pull request for that to fix: #1406

@mfranzke mfranzke marked this pull request as ready for review January 2, 2022 14:58
@JosefBredereck
Copy link
Contributor

How do you find stuff like this all the time? That's crazy 😄
One commit with 253 changes, and you know what got removed by that commit.

@mfranzke
Copy link
Contributor Author

mfranzke commented Jan 6, 2022

@JosefBredereck … oh, don't ask … ;-) others read novels, I read git commit history …

Comment on lines +34 to +36
logger.info(
`Please convert ${jsPath} to JSON and rename it annotations.json.`
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit on the fence with that. We should let the user decide if he wants to use JS or JSON, even in the future.
Furthermore, we could check if it is possible to require that .js or .json file so that we do not have to strip comments and anything else in that file. Maybe we can change the way it needs to be written to a module.exports format.

Copy link
Contributor Author

@mfranzke mfranzke Jan 6, 2022

Choose a reason for hiding this comment

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

@JosefBredereck, actually I've realized that we're stripping that var comments part first of all, to add it again on exporting the data:

'var comments = { "comments" : ' + JSON.stringify(annotationsJSON) + '};';

So another solution might be to skip that whole transition to a pure JSON file and only provide the possibility with using JS (the existing format), but remove the JSON file possibility, as we're even already providing another format with the markdown notation as well.
So another task for this ticket could be still to correct the documentation part anyhow: https://patternlab.io/docs/adding-annotations/#heading-json-example

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

No way 😄. In that case, throw away those nasty JSON files 🗑️

Copy link
Contributor Author

@mfranzke mfranzke Jan 6, 2022

Choose a reason for hiding this comment

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

okay, sounds reasonable to me. I've set this ticket on draft again and will proceed by removing these parts as well as the nasty existing transitions in the codebase, as well as correct the documentation page.

Copy link
Contributor

Choose a reason for hiding this comment

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

The whole file you mentioned is a solution, but if we would rework the codebase with today's standards, we would maybe not do it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so does it mean that you want to come up with (or at least describe) a solution ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not for now; it would require a more significant rewrite.
This line shows that we already work with modules somewhere.

'module.exports = { config, ishControls, navItems, patternPaths, viewAllPaths, plugins, defaultShowPatternInfo, defaultPattern };';

But then we also need to adjust the place where we load those annotations again.

What makes me curious. Annotations always have a comments property and no other. Is it possible that they have different properties? If not, this would be another change I would like to implement somehow.

'var comments = { "comments" : ' + JSON.stringify(annotationsJSON) + '};';

Copy link
Contributor Author

@mfranzke mfranzke Jan 23, 2022

Choose a reason for hiding this comment

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

No way 😄. In that case, throw away those nasty JSON files 🗑️

@JosefBredereck, on the other hand, besides the strange way to include the JSON data into the website after a transformation, the positive way of using JSON (even only) would be that this adapts the way other data is being maintained in the pattern lab system (like pattern data).

Copy link
Contributor

Choose a reason for hiding this comment

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

That is correct. Nodejs is so fast in transforming the data that we could use the approach that is already in this PR. In the end, it makes no difference.

@mfranzke mfranzke marked this pull request as draft January 6, 2022 20:46
@JosefBredereck
Copy link
Contributor

Another thing I just discovered and never understood: The annotations are written once and visible on all patterns there are available. Why should I want that?
Would it also be helpful to have a list like useIn: [ <list of pattern names> ]?

@mfranzke
Copy link
Contributor Author

mfranzke commented Jan 6, 2022

Another thing I just discovered and never understood: The annotations are written once and visible on all patterns there are available. Why should I want that?
Would it also be helpful to have a list like useIn: [ <list of pattern names> ]?

well, they are as global as the global data, but there's no "scoped" or "local" annotations, related to a pattern even only. This even also made me wonder. Probably this would be a nice enhancement / future feature ?

@JosefBredereck
Copy link
Contributor

Another thing I just discovered and never understood: The annotations are written once and visible on all patterns there are available. Why should I want that?
Would it also be helpful to have a list like useIn: [ <list of pattern names> ]?

well, they are as global as the global data, but there's no "scoped" or "local" annotations, related to a pattern even only. This even also made me wonder.

Or I'm just blind. There is the el: ... part which defines to which elements these annotations get added. That was not clear to me 🥲

@mfranzke mfranzke marked this pull request as ready for review January 29, 2022 19:55
@JosefBredereck
Copy link
Contributor

Some minor adjustment is standing out after the merge of #1406
https://github.com/pattern-lab/patternlab-node/pull/1406/files#diff-d562b65f94fc7de820db229a45973334e2c8195978fbc7643d1916ed6e63fd19

@mfranzke
Copy link
Contributor Author

Some minor adjustment is standing out after the merge of #1406 https://github.com/pattern-lab/patternlab-node/pull/1406/files#diff-d562b65f94fc7de820db229a45973334e2c8195978fbc7643d1916ed6e63fd19

good catch, thanks. Just checked in the migrated file.

@JosefBredereck JosefBredereck merged commit d303f4d into pattern-lab:dev Jan 29, 2022
@mfranzke mfranzke deleted the rename-annotations-js branch January 29, 2022 20:42
@JosefBredereck
Copy link
Contributor

PR was released with v5.16.0

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants