-
Notifications
You must be signed in to change notification settings - Fork 15
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: support action queries with prefixed resource names #19
Conversation
Related: dhis2/ui-widgets#53 |
Implementing an action resource type will avoid this hack which currently (sometimes) works : https://github.com/dhis2/ui-widgets/blob/master/src/HeaderBar/index.js#L30 |
I'm OK with this API, it doesn't squat a key we might want to use in the feature in the query object. |
It also applies to the CJS build. Humourously enough, this works: import { Query } from './components/Query'
import { Provider } from './components/Provider'
import { CustomProvider } from './components/CustomProvider'
import { Context } from './components/Context'
import { useQuery } from './hooks/useQuery'
export { Query }
export { Provider }
export { CustomProvider }
export { Context }
export { useQuery } EditFound the issue, fixed in v7.5.2 of @babel/plugin-transform-typescript: |
fix: use internal function for joining path, update deps for babel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, any second thoughts on this PR or should we go ahead with it?
Setting to ready for review as the build issue is resolved. |
If we want to add features like abort/cancel (and possibly other stuff), it'd be confusing to me if we added that on the same level as the "resource" property, so how about this: const query = {
apps: {
resource: ['menu/getModules', { isAction: true }]
}
}
|
@varl thanks for fixing my silly mistake! @Mohammer5 That's an interesting idea, I like the cleanliness of the API. I considered something like this as well (also just a Let's take const query = {
me: {
resource: 'me'
},
identifiers: {
resource: 'identifiers'
}
}
const { error, loading, data, abort } = useDataQuery(query)
....
abort() // This cancels all requests spawned by the query Note that there's nothing stopping the user from specifying separate queries if they want finer-grained abort control. For something like Finally, we get to the one that I think might make sense with a formal parameterized Sorry for the long rant, but this is why I avoided making a formal API for this legacy support case. I could still see an argument for formalizing it, but not if we're going to keep it "undocumented". Here are the options as I see them, very open to votes for what we think makes the most sense as the long-term API:
const query = {
idents: {
resource: 'identifiers',
args: {
limit: 10
}
},
// OR MAYBE
idents: {
resource: {
name: 'identifiers',
limit: 10
}
},
apps: {
resource: 'menu/getModules'
isAction: true
},
// OR
apps: {
action: 'menu/getModules'
}
} Are there other options I missed? This is all a bit out-of-scope for this change which I hoped would be minimally disruptive. |
I agree with your concerns! I think it doesn't really matter what we do to support actions, which we're trying to get rid of anyways, so I wouldn't mind the There's one options, which is a mix of the first and second one: const query = {
idents: {
resource: 'identifiers',
args: {
limit: 10
},
},
apps: {
resource: 'menu/getModules'
isAction: true
},
} To me this seams to be the cleanest solution in terms of api, it allows to fully customize every single resource individually (headers? external? request method?) while making the request args clearly visible |
@Mohammer5 great, yeah I like that one as well and think it's the cleanest. The reason I didn't want to do it here is that it's technically a breaking change, but maybe we're early enough that it's worth it to change all current app-runtime consumers as well? @varl thoughts? One additional downside is that it makes simple queries a little more complex. What do you think about the field name I think it's important to realize that the user shouldn't need to care that this is actually a network request behind the scenes, but rather only care about describing the data they are requesting. Eventually there might not be any direct HTTP requests. As such I think headers and request method ( I realize those were only a few examples you threw out there, but I really haven't seen a compelling use-case yet. It's also important to point out since the With this design in mind, does |
Here is a use case for a non-option parameter other than const query = {
idents: {
resource: 'identifiers',
// This could be automatically memoized by the engine
selector: vals => vals.filter(v => v.answer === 42)
options: {
// In this case, limit might not be passed on in the query string
// since it would limit the output of the selector.
limit: 10
},
}
} Looking at this use case, I'm not sure what the distinction is between an |
I think
The indicator's, validationRule's and predictor's endpoint for validating expressions needs a header |
I think pulling out the long-term API design into a separate discussion with executable use cases would be good. I vote for this to be the scope of this PR:
If we are going to do a breaking API change in the future anyway, then we can just remove this undocumented feature when we do so. |
I don't think
On the contrary, I think that absolutely needs to be part of the data provider. But the data provider should do that automatically for expression validation, so the user of the Validation might be an edge case here, since it's not really a "data request", so maybe the engine needs a different interface for those kinds of request, but I 100% think they need to be included. An app should never have to make direct HTTP requests to the server if we build this API right. |
@varl agreed |
@amcgee since everyone agrees that this is an ok solution for now, shall we merge? |
Merged |
# [1.3.0](v1.2.0...v1.3.0) (2019-07-09) ### Features * support action queries with prefixed resource names ([#19](#19)) ([c5c5dc7](c5c5dc7))
🎉 This PR is included in version 1.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This adds first-class support for action resource types. These are legacy resources which are deprecated and should be avoided when an alternative exists, so this will not be a documented feature.
To fetch from an action endpoint such as
dhis-web-commons/menu/getModules.action
use the following query (note theaction::
resource prefix):I don't love this string-parsing API, but it's less disruptive than adding a sibling
action
property to the Query type. An alternative, if we don't like this, would be to do something likeresource: { action: 'menu/getModules' }
NOTE there's a weird babel error that seems to have been introduced by a dependency upgrade (?) which causes the build to fail (the output in
services/data/build/es/index.js
is empty when it should contain all the re-exports) so I'm leaving this as a draft for now, but open to API or implementation feedback.