-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Execute script for selected rows #2497
Comments
Thanks for opening this issue!
|
We can't call the cloud function with array of elements it has to be a object meaning our array of selected items must be converted into object. And because of this user should be aware of the cloud function receiving different types of input base on from where it is called i.e. from cell or multi select row. Because accordingly the input will change. If we use this approach. Here is a snippet that demonstrate that. Now the question is do we want to run the function 1-by-1 on each element or just use single object which in actual is array of all the selected elements. In 1-by-1 approach user don't need to worry about the input type anymore but this will be pure overhead in my opinion. @mtrezza guide me senpai async executeSript(script) {
const { selection } = this.props;
try {
const objects = [];
Object.keys(selection).forEach((key) =>
objects.push(
Parse.Object.extend(this.props.currentClass).createWithoutData(key)
)
);
const response = await Parse.Cloud.run(
script.cloudCodeFunction,
{ object: { ...objects.map((object) => object.toPointer()) } },
{ useMasterKey: true }
);
this.props.showNote(
response ||
`Ran script "${script.title}" on "${this.props.currentClass}" object "${object.id}".`
);
this.props.onRefresh();
} catch (e) {
this.props.showNote(e.message, true);
console.log(`Could not run ${script.title}: ${e}`);
}
} This will output in info: Ran cloud function deleteAccount for user undefined with:
Input: {"object":{"0":{"__type":"Pointer","className":"_User","objectId":"fM1mhqXeJ9"},"1":{"__type":"Pointer","className":"_User","objectId":"EiBiG6KFdy"}}}
Result: "Hello world!" {"functionName":"deleteAccount","params":{"object":{"0":{"__type":"Pointer","className":"_User","objectId":"fM1mhqXeJ9"},"1":{"__type":"Pointer","className":"_User","objectId":"EiBiG6KFdy"}}}} As you can see in the output, I have to convert array to object else it won't work. This approach is a bit anti-user. Do you have any suggestion here? |
I think there are two possible scenarios and uses cases for both:
It's something the developer should be able to decide what they want. Both approaches allow for different features. For example:
The developer could choose between (a) and (b) in the script settings. I would however see (b) as a completely new feature and maybe rather start with (a). Which seems simpler. Not sure about the payload the dashboard currently sends, but if we start supporting sending multiple objects with (b), then maybe we should (breaking) change the payload in a way that it works for both, like:
|
🎉 This change has been released in version 5.4.0-alpha.2 |
🎉 This change has been released in version 6.0.0-beta.1 |
🎉 This change has been released in version 6.0.0 |
New Feature / Enhancement Checklist
Current Limitation
A script can currently only be executed per row, as a separate manual step per row. This requires repeated steps when a script should be executed for multiple rows.
Feature / Enhancement Description
Allow to execute a script on all selected rows.
Example Use Case
n/a
Alternatives / Workarounds
None
The text was updated successfully, but these errors were encountered: