Pass arguments to react-admin dataProvider getList - react-admin

How can I pass additional arguments from the List component to the dataProvider I am building?
For example:
<List filter={myFilters} perPage={10} myArgs={someArgs} {...props} >
I do receive the filter argument, but I don't receive myArgs.

You can't. dataProvider.getList() only accepts filter, sort, and pagination parameters (see documentation).
You can add code in your dataProvider to transform a specific filter into a special argument, or use another resource name that triggers a special piece of logic.
But the question is: why do you need to pass additional parameters for?

Related

Can I use filters in Intellij structural search to reference variable counts?

I am trying to create a custom inspection in IntelliJ using structural search. The idea is to find all methods that have one or more parameters, of which at least one is not annotated. Bonus: Only hit non-primitive types of parameters.
So far, I have created the following Search Template:
$MethodType$ $Method$(#$ParamAnnotation$ $ParameterType$ $Parameter$);
using these filters and the search target "complete match":
$Parameters$: count[1,∞]
$ParamAnnotation$: count[0,0]
However, this only hits methods without any parameters annotated. I want it to also match methods where only some parameters have an annotation but others don't.
Is it possible to reference the count of one variable in the filter of another, e.g. by using script filters? If so, how?
You can do this by creating a Search Template like this:
$MethodType$ $Method$($TypeBefore$ $before$,
#$ParamAnnotation$ $ParameterType$ $Parameter$,
$TypeAfter$ $after$);
Filters:
$Parameters$: count=[1,1] // i.e. no filter
$ParamAnnotation$: count=[0,0]
$before$: count=[0,∞]
$after$: count=[0,∞]
This will find all method with at least one parameter without annotation.

'OR' with GET url parameters

I have a GET API url something like: /api/countries.
I want to search from it using multiple parameters like name& code... For that, I will do /api/countries?name=pak&code=92
But what if I want to use OR in url params e.g. /api/countries?name=pakORcode=92
If you use OR as you have shown in your question then it will not work (name will contain the value pakORcode=92). If this is something that you would consider doing then you could use explode to split into key-value pairs around each OR.
You could maybe also have a third variable, method. You could set this to either AND or OR, then you'd know what method to use?
Hope this helps
What you describe is not a regular API call.
you can solve this in 2 ways
Create the logic in your controller where you implement the or statement
Implement the ODATA REST protocol.
I would prefer ODATA. Entity framework has support for this and you can even implement this on your own created lists.
In ODATA you can use filter expressions:
filter=name eq 610 or code eq 615
https://msdn.microsoft.com/en-us/library/hh169248(v=nav.90).aspx

Vue 2 arguments in inline (in-template) event handler

Is it possible to access arguments/parameters passed to an emitted event within an inline / in-template handler? Something like:
<component #some-event="someObject.field = $arguments[0]"></component
What I'm trying to do exactly is assign a value to an object in the scope. I know I can create a method to do that and use it as a handler for the event but I was wondering if this could work as an inline statement.
It is not $arguments[0], but just arguments[0] (without the $). I am surprised that it actually works in the inline handler. So the following code is valid and will work:
<component #some-event="someObject.field = arguments[0]"></component>
The docs for Methods in Inline Handlers specifies $event as a special variable that gets the first parameter passed via event. I have always used it till now.
After reading your question, a bit more research led me to this reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
It seems every javascript function has a local variable called arguments, which is used when a function is expected to get variable number of arguments.
Using arguments[] as inline statements is definitely possible, but not documented anywhere in the context of vue.js framework. On the other hand, if you use $event in inline handler for events, it feels safer as it is documented clearly and will not break in a future version of Vue.js
Sample usage for $event:
<component #some-event="someObject.field = $event"></component>
There is something that not many people know.
Inline handler besides the $event has access to arguments.
For example I was using v-dropzone which is passing many arguments (e.g. file, response).
By using
<v-dropzone #some-event="callMethod($event, 'some other arg')" >
will catch only the first argument.
So the solution was:
<v-dropzone #some-event="callMethod(arguments, 'some other arg')" >

Question mark in callback

static setItem(key: string, value: string, callback?: ?(error: ?Error) => void)
This is the declaration of setitem in AsyncStorage. the third parameter is a callback. Could some one explain the use of question marks here. I am familiar with how to use promise but couldn't get a handle of question mark.
AsyncStorage uses flow - Facebook's open-sourced static type checker. You will find #flow at the beginning of the file and it marks flow-enabled source. Flow does a lot of checking on the variable types (including automated type inference) but it also lets you specify the types for variables and parameters. In the example above 'key: string' for example indicates that key should be string type (it's not a valid javascript construct - you cannot specify type in javascript). React has built in transformers that transform it to pure javascript (so all the types are stripped) but before that flow checks if types are passed around properly and find things like passing null or undefined and using it later as object and many other checks. You can read the specs in http://flowtype.org/.
So answering your detailed questionmark question:
'?Error' indicates that error parameter is a "Maybe" type - i.e. it CAN be null and flow will not complain if null or undefined is passed here elsewhere in the code callback (http://flowtype.org/docs/nullable-types.html#type-annotating-null)
'callback?' indicates an optional parameter - so it might be skipped http://flowtype.org/docs/functions.html#function-based-type-annotations
'?(error...)' is another "Maybe" type - it simply indicates that the callback function might take one parameter ('error') or no parameters at all.

how to pass an external property into a hive udf

I am writing a hive UDF in which I have to call an REST API and return an array of String. I have written the function with hardcoded REST API url. But now to make the endpoint configurable I want to take the host property out and put it in a config. Is it possible? If yes, then how can pass this?
Can you do change your UDF to take the host as part of its input, and then use variable substitution in Hive:
SET host=todayshosturl
SELECT TRANSFORM ${hiveconf:host}, line
USING 'python myudf.py' AS (line)
FROM
yourtable;