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

Issue with including part query in macro #423

Closed
poi33 opened this issue Sep 27, 2022 · 4 comments
Closed

Issue with including part query in macro #423

poi33 opened this issue Sep 27, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@poi33
Copy link
Contributor

poi33 commented Sep 27, 2022

I have a TextArea in a part configuration.
This textArea can have macroes inside it.

Lets say the field is text

Then the query for the part needs to include:

text (processHtml:{}) {
    processedHtml
    macros {
                    ref
                    name
                    descriptor
                    <Insert the config for every macro in the system>
                }
    }
}

Now this will be too much to handle manually. Especially since the system can have any macro number of TextArea s or macroes.

Luckely the src\_enonicAdapter\guillotine\getMetaData.ts includes a function for getting them: RichTextQuery.

Now the does not work to include it a part query? It looks like the ComponentRegistry (defined in _mapping) is not include the macroes at the same stage?
So the RichTextQuery cant be used inside querys that get registered to the ComponentRegistry?
I would assume the ComponentRegistry was available when the macroes are defined higher up then the parts, but they don't seem to be registred at all?

@poi33 poi33 added the bug Something isn't working label Sep 27, 2022
@pmi
Copy link
Member

pmi commented Sep 28, 2022

To make sure that macros are available in the queries 2 things need to be satisfied:

  • Macros need to be registered first (There is a comment about that in _mappings.ts)
  • queries that use use richTextQuery need to be converted to functions to control when they are invoked (There is a comment about that in getMetaData.ts next to richTextQuery). It may actually work without that, but it's safer this way.

So to use macros in part config you need to register your macros first and then use richTextQuery:

ComponentRegistry.addMacro(`${APP_NAME}:panel2`, macroPanelConfig);

const childListConfig = () => `{
        sorting 
        ${richTextQuery('desc')}
    }`

ComponentRegistry.addPart(`${APP_NAME}:child-list`, {
    query: getChildList,
    processor: childListProcessor,
    view: ChildList,
    configQuery: childListConfig()
});

@poi33
Copy link
Contributor Author

poi33 commented Sep 28, 2022

@pmi I did this, but i thought it was a hacky way of doing it.
And when applying a change to the part config they show up as missing components.

@pmi
Copy link
Member

pmi commented Sep 28, 2022

@poi33 Those are not hacks, those are foundations of javascript 😆

The change showed missing because of lacking mappings import in _component.ts file that I fixed today, so that should not be an issue any more !

@poi33
Copy link
Contributor Author

poi33 commented Sep 29, 2022

Nice, I'll check if it works today 🎉

@pmi pmi closed this as completed Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants