I am currently working on implementing a plugin using react.
Therefore i want to make use of the useIndicoAxios Hook.
To achieve this I have already dealt with the Indico plugins which are based on react.
So I already added a rule to the blueprint of the plugin which points to a method of the controller.
According to Indico Axios, the hook needs a URL, which I believe is structured as follows:
“import chatURL from ‘indico-url:blueprintname.rulename’;”.
Unfortunately, however, I get a Flask error when I compile it
indico-url imports must reference a valid flask endpoint.
Therefore, the question arises for me how a valid URL must be built?
Thanks in advance
Try prefixing the blueprint name with plugin_
(you can find some examples in the burotel plugins in the indico-cern-plugins repo).
Also make sure to restart the build-assets script (in case you use --watch
mode) after adding a new endpoint to your blueprint since the url rules are only collected when the script is started.
Thank you. That worked in some way but resulted in a new error.
When executing the axios hook the client sends a get request to a url which looks like the following:
http://localhost:8080/event/16/plugin_conf/206/function()%20{%20%20%20%20[native%20code]}.
So the hook basically appends a javascript function to the url which of course results in a 404 error.
Do you know a solution to that problem?
You need to call the thing you import from indico-url:...
; it’s a function that builds the URL, it looks like you used it directly.
Okay that makes sense.
But when calling it, it returns the following error:
Error: Could not build URL for endpoint ‘plugin_plugin_conf.chat’ ({})
Uh somehow you ended up with plugin_
there twice… Did you by any chance put it twice in the import?
no its just the name of the plugin
I think posting more of your JS code and blueprint would make it easier to help here
So the blueprint looks like the following:
blueprint = IndicoPluginBlueprint('plugin_conf', __name__, url_prefix='/event/<int:event_id>')
....
blueprint.add_url_rule('/conference/api/chat_messages', 'chat', RHConfContributionChat)
And the controller class is just a test class with a print to see if it worked:
class RHConfContributionChat(RH):
"""Return the chat for the contribution view."""
def _process(self):
print("in function")
return ''
or could the error depend on the parameter Rh?
And the JS Code Hook Call looks like the following
import chatURL from ‘indico-url:plugin_plugin_conf.chat’;
const {data: _data, loading} = useIndicoAxios({
url: chatURL(),
trigger: contributionId,
camelize: true,
unhandledErrors: [404],
});
Remove the plugin_
from the blueprint name. This is implicitly added by IndicoPluginBlueprint
.
PS: I’ve edited your posts to fix the code formatting; please use triple-backtick fences to format code as monospace, otherwise it’s not very easy to read.
For example:
```js
code here
```
Okay so i changed plugin_conf to conf in all files but it still results in the same errors
Did you restart the build script?
Yes i did.
The code looks like the following now:
import chatURL from 'indico-url:plugin_conf.chat';
...
const {data: _data, loading} = useIndicoAxios({
url: chatURL({}),
trigger: contributionId,
camelize: true,
unhandledErrors: [404],
});
blueprint.py:
blueprint = IndicoPluginBlueprint('conf', __name__, url_prefix='/event/<int:event_id>')
...
blueprint.add_url_rule('/conf/api/chat_messages', 'chat', RHConfContributionChat)
controllers.py:
class RHConfContributionChat(RH):
"""Return the chat for the contribution view."""
def _process(self):
print("in function")
return ''
Search for plugin_conf
in url_map.json
in your plugin folder to see what you have there… this is the data used to resolve the indico-url
imports. Most of the file’s content is just indico urls but your plugin urls should be there as well.
Searching for plugin_conf resulted in 0 matches. But i found an entry regarding the url:
"plugin_conf.chat": {
"endpoint": "plugin_conf.chat",
"rules": [
{
"args": [
"event_id"
],
"converters": {
"event_id": "IntegerConverter"
},
"defaults": {},
"trace": [
{
"data": "|",
"isDynamic": false
},
{
"data": "/",
"isDynamic": false
},
{
"data": "event",
"isDynamic": false
},
{
"data": "/",
"isDynamic": false
},
{
"data": "event_id",
"isDynamic": true
},
{
"data": "/",
"isDynamic": false
},
{
"data": "conf",
"isDynamic": false
},
{
"data": "/",
"isDynamic": false
},
{
"data": "api",
"isDynamic": false
},
{
"data": "/",
"isDynamic": false
},
{
"data": "chat_messages",
"isDynamic": false
}
]
}
]
},
So that looks fine. But I just noticed the problem in your code: chatURL({})
- you are passing an empty list of params here. But your endpoint requires an event_id
param to build a URL for it…
Thank you that fixed the problem!