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

fix: glossary recursion #857

Closed
wants to merge 5 commits into from
Closed

fix: glossary recursion #857

wants to merge 5 commits into from

Conversation

jeeyyy
Copy link
Collaborator

@jeeyyy jeeyyy commented Aug 29, 2019

  • Identifies other glossary terms that may have been referred with in a glossary and enumerates them in the glossary definitions for a rule.
  • Add tests to verify glossary terms internally referred within a glossary exists.

Closes issue(s):


Pull Request Etiquette

When creating PR:

  • Make sure you requesting to pull a branch (right side) to the develop branch (left side).

After creating PR:

  • Add yourself (and co-authors) as "Assignees" for PR.
  • Add label to indicate if it's a Rule, Definition or Chore.
  • Close the issue that the PR resolves (and make sure the issue is referenced in the top of this comment)
  • Optionally request feedback from anyone in particular by assigning them as "Reviewers".

How to Review And Approve

  • Go to the “Files changed” tab
  • Here you will have the option to leave comments on different lines.
  • Once the review is completed, find the “Review changes” button in the top right, select “Approve” (if you are really confident in the rule) or "Request changes" and click “Submit review”.

@jeeyyy jeeyyy self-assigned this Aug 29, 2019
@jeeyyy jeeyyy requested a review from Jym77 August 29, 2019 12:05
@jeeyyy jeeyyy changed the title Glossary recursion fix fix: glossary recursion Aug 29, 2019
Copy link
Member

@WilcoFiers WilcoFiers left a comment

Choose a reason for hiding this comment

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

I can't really tell if this code works or not. There aren't enough tests, and things aren't properly abstracted for me to be able to tell if this works. This "glossaries-in-glossaries.json" file seems unnecessary though.

* @param {String} type key denoting type/ grouping of markdown data, to help parse frontmatter
* @returns {Object|null}
*/
const getUsageMetaData = (frontmatter, type) => {
Copy link
Member

Choose a reason for hiding this comment

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

This function does two things. Should be two functions (or none).

@@ -153,13 +148,29 @@ export const getGlossaryUsedLink = (slug, allGlossary) => {

export const getGlossaryItemsUsedInRule = slug => {
const keys = []
Copy link
Member

Choose a reason for hiding this comment

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

What are keys and slugs? Please give these meaningful names.

* @param {String} type key denoting type/ grouping of markdown data, to help parse frontmatter
* @returns {Array<Object>}
*/
const getGlossaryUsagesInMarkdownData = (markdownData, type = 'rule') => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please stop using "glossary" as a synonym for "definition". The glossary is a list of definitions. Each rule has one glossary, containing one or more definitions. There are no glossaries inside of other glossaries. Some definitions have references to other definitions.

* @returns {Array<Object>}
*/
const getGlossaryUsagesInMarkdownData = (markdownData, type = 'rule') => {
const usages = {}
Copy link
Member

Choose a reason for hiding this comment

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

That's not a meaningful variable name.

@@ -153,13 +148,29 @@ export const getGlossaryUsedLink = (slug, allGlossary) => {

export const getGlossaryItemsUsedInRule = slug => {
Copy link
Member

Choose a reason for hiding this comment

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

The logic for coming up with the glossary for a rule should not live in a render method. That stuff needs to be isolated. Quite possibly this glossaries-in-glossaries.json file shouldn't even exist, and all that info should be rolled up into a simple function that, you pass it the rule ID, and it returns an array of definitions IDs used in that rule.

* Iterate through references in rules
*/
Object.keys(glossariesInRules).forEach(key => {
glossariesInRules[key].forEach(({ slug: s }) => {
Copy link
Member

Choose a reason for hiding this comment

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

What is "s"? Please give this a meaningful name.

*/
Object.keys(glossariesInGlossaries).forEach(key => {
glossariesInGlossaries[key].forEach(({ glossarykey }) => {
if (!keys.includes(glossarykey)) {
Copy link
Member

Choose a reason for hiding this comment

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

It's hard to tell (because the code is hard to read), but it looks like this is including everything. Definitely this isn't recursively looking up definitions inside of other definitions.

@jeeyyy
Copy link
Collaborator Author

jeeyyy commented Sep 10, 2019

I have worked out a POC to reduce this step into a gatsby preBootstrap script. That will be a refactor exercise. I will close this PR and re-open the relevant issues.

@jeeyyy jeeyyy closed this Sep 10, 2019
@jeeyyy jeeyyy deleted the glossary-recursion-fix branch October 8, 2019 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants