react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Syntax error: Unexpected token ... (105:49)

Open Dr8g0n opened this issue 9 years ago • 4 comments

I am using the custom key per this FAQ https://marmelab.com/admin-on-rest/FAQ.html#can-i-have-custom-identifiers-primary-keys-for-my-resources

./src/restClient.js Syntax error: Unexpected token ... (105:49)

103 | return { 104 | //data: json.map(x => x),

105 | data: json.map(resource => { ...resource, id: resource.userName } ), | ^ 106 | total: parseInt(headers.get('x-total-count').split('/').pop(), 10), 107 | };

Dr8g0n avatar Jun 05 '17 21:06 Dr8g0n

@Dr8g0n This line should be:

data: json.map(resource => {{ ...resource, id: resource._id }} ),

An extra set of {} is necessary to return an object in this form of arrow function.

wesley6j avatar Jun 05 '17 22:06 wesley6j

@wesley6j Thank you for your reply, I tried it but still same error. Please see below

https://babeljs.io/repl/#?babili=false&evaluate=false&lineWrap=true&presets=es2015%2Creact%2Cstage-0&targets=&browsers=&builtIns=false&debug=false&code=let%20%7B%20x%2C%20y%2C%20...z%20%7D%20%3D%20%7B%20x%3A%201%2C%20y%3A%202%2C%20a%3A%203%2C%20b%3A%204%20%7D%3B%0Aconsole.log(x)%3B%20%2F%2F%201%0Aconsole.log(y)%3B%20%2F%2F%202%0Aconsole.log(z)%3B%20%2F%2F%20%7B%20a%3A%203%2C%20b%3A%204%20%7D%0A%0A%0Aconst%20convertHTTPResponseToREST%20%3D%20(response%2C%20type%2C%20resource%2C%20params)%20%3D%3E%20%7B%0A%20%20%20%20const%20%7B%20headers%2C%20json%20%7D%20%3D%20response%3B%0A%20%20%20%20switch%20(type)%20%7B%0A%20%20%20%20case%20GET_LIST%3A%0A%20%20%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20data%3A%20json.map(resource%20%3D%3E%20%7B%7B%20...resource%2C%20id%3A%20resource._id%20%7D%7D%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20total%3A%20parseInt(headers.get('content-range').split('%2F').pop()%2C%2010)%2C%0A%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20case%20UPDATE%3A%0A%20%20%20%20case%20DELETE%3A%0A%20%20%20%20case%20GET_ONE%3A%0A%20%20%20%20%20%20%20%20return%20%7B%20...json%2C%20id%3A%20json._id%20%7D%3B%20%0A%20%20%20%20case%20CREATE%3A%0A%20%20%20%20%20%20%20%20return%20%7B%20...params.data%2C%20id%3A%20json._id%20%7D%3B%0A%20%20%20%20default%3A%0A%20%20%20%20%20%20%20%20return%20json%3B%0A%20%20%20%20%7D%0A%7D%3B

Dr8g0n avatar Jun 05 '17 22:06 Dr8g0n

This works:

data: json.map(resource => resource= { ...resource, id: resource._id })

Dr8g0n avatar Jun 05 '17 22:06 Dr8g0n

data: json.map(resource => ({ ...resource, id: resource._id }))

We don't provide support through GitHub issues. If you need advice on using or debugging your own project based on admin-on-rest, please use StackOverflow.

djhi avatar Jun 06 '17 07:06 djhi