parse-community / parse-dashboard

A dashboard for managing Parse Server
https://parseplatform.org
Other
3.74k stars 1.39k forks source link

Execute script for selected rows #2497

Closed mtrezza closed 9 months ago

mtrezza commented 1 year ago

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

parse-github-assistant[bot] commented 1 year ago

Thanks for opening this issue!

patelmilanun commented 11 months ago

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?

mtrezza commented 11 months ago

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:

{
  objects: [...]
}
parseplatformorg commented 9 months ago

🎉 This change has been released in version 5.4.0-alpha.2

parseplatformorg commented 4 months ago

🎉 This change has been released in version 6.0.0-beta.1