Skip to content
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

Closed
3 tasks done
mtrezza opened this issue Aug 5, 2023 · 6 comments · Fixed by #2508
Closed
3 tasks done

Execute script for selected rows #2497

mtrezza opened this issue Aug 5, 2023 · 6 comments · Fixed by #2508
Labels
bounty:$50 Bounty applies for fixing this issue (Parse Bounty Program) state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version type:feature New feature or improvement of existing feature

Comments

@mtrezza
Copy link
Member

mtrezza commented Aug 5, 2023

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
Copy link

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

@mtrezza mtrezza added type:feature New feature or improvement of existing feature bounty:$50 Bounty applies for fixing this issue (Parse Bounty Program) labels Aug 5, 2023
@patelmilanun
Copy link
Member

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
Copy link
Member Author

mtrezza commented Oct 18, 2023

I think there are two possible scenarios and uses cases for both:

  • a) Execute multiple server requests, each with a single object.
  • b) Execute a single server requests with all selected rows in the payload.

It's something the developer should be able to decide what they want. Both approaches allow for different features.

For example:

  • (a) allows to implement a progress bar in the dashboard, (b) doesn't.
  • (b) allows to select 2 rows and "connect" the two records in some way, (a) doesn't.

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
Copy link
Contributor

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

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Dec 16, 2023
@parseplatformorg
Copy link
Contributor

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

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label May 16, 2024
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.0.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty:$50 Bounty applies for fixing this issue (Parse Bounty Program) state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants