mui / toolpad

Toolpad: Full stack components and low-code builder for dashboards and internal apps.
https://mui.com/toolpad/
MIT License
964 stars 243 forks source link

Transforming query results in error #1855

Closed cherniavskii closed 1 year ago

cherniavskii commented 1 year ago

Duplicates

Latest version

Steps to reproduce πŸ•Ή

I've been following https://mui.com/toolpad/getting-started/quickstart/ and noticed that query transformation doesn't work

Steps:

  1. Add a query and try to transform it as shown in the screenshot:
Screenshot 2023-04-04 at 17 21 16

Current behavior 😯

Error in the query preview

Expected behavior πŸ€”

No errors in the query preview

Context πŸ”¦

I looked into it quickly and the error seems to be coming from

https://github.com/mui/mui-toolpad/blob/217a17e7dc6f581210a175422cf86839a627fa21/packages/toolpad-app/src/toolpadDataSources/applyTransform.ts#L10

Given the transform function (data) => { return data.message }, the evaluated code looks like:

(data) => { return data.message }(/** data **/)

Shouldn't the transform function be wrapped in parenthesis?

-`${transformFn}(${JSON.stringify(data)})`,
+`(${transformFn})(${JSON.stringify(data)})`,

This seems to fix the issue. I can submit a PR

Your environment 🌎

No response

Janpot commented 1 year ago

This seems to fix the issue. I can submit a PR

Yep, good catch. This is a regression so we're going to add an integration test. We'll deal with, unless you feel particularly compelled to dig into the test suite πŸ™‚

cherniavskii commented 1 year ago

We'll deal with

Sure, thanks!

bharatkashyap commented 1 year ago

We'll deal with

Sure, thanks!

Thanks for the catch, Andrew πŸ‘