From 54883f0a61517c8f293a8b7721c74dc4b42c93e3 Mon Sep 17 00:00:00 2001 From: dblythy Date: Thu, 30 Mar 2023 16:05:09 +1100 Subject: [PATCH 01/13] feat: allow cloud code scripts --- .../BrowserCell/BrowserCell.react.js | 26 ++++++++++++++++++- src/components/BrowserRow/BrowserRow.react.js | 5 +++- .../Data/Browser/BrowserTable.react.js | 9 ++++++- src/lib/ParseApp.js | 4 ++- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/components/BrowserCell/BrowserCell.react.js b/src/components/BrowserCell/BrowserCell.react.js index 96d40b8fcc..f6963bed19 100644 --- a/src/components/BrowserCell/BrowserCell.react.js +++ b/src/components/BrowserCell/BrowserCell.react.js @@ -15,8 +15,9 @@ import React, { Component } from 'react'; import styles from 'components/BrowserCell/BrowserCell.scss'; import baseStyles from 'stylesheets/base.scss'; import * as ColumnPreferences from 'lib/ColumnPreferences'; - +import { CurrentApp } from 'context/currentApp'; export default class BrowserCell extends Component { + static contextType = CurrentApp; constructor() { super(); @@ -276,6 +277,29 @@ export default class BrowserCell extends Component { }); } + const validScripts = (this.context.scripts || []).filter(script => script.classes?.includes(this.props.className)); + if (validScripts.length) { + onEditSelectedRow && contextMenuOptions.push({ + text: 'Scripts', + items: validScripts.map(script => { + return { + text: script.title, + callback: async () => { + try { + const object = Parse.Object.extend(this.props.className).createWithoutData(this.props.objectId); + await Parse.Cloud.run(script.cloudCodeFunction, {object: object.toPointer()}, {useMasterKey: true}); + this.props.showNote(`${script.title} ran with object ${object.id}}`); + this.props.onRefresh(); + } catch (e) { + this.props.showNote(e.message, true); + console.log(`Could not run ${script.title}: ${e}`); + } + } + } + }) + }); + } + return contextMenuOptions; } diff --git a/src/components/BrowserRow/BrowserRow.react.js b/src/components/BrowserRow/BrowserRow.react.js index 5ae4e78ac3..13183f64ac 100644 --- a/src/components/BrowserRow/BrowserRow.react.js +++ b/src/components/BrowserRow/BrowserRow.react.js @@ -100,7 +100,10 @@ export default class BrowserRow extends Component { markRequiredFieldRow={markRequiredFieldRow} setCopyableValue={setCopyableValue} setContextMenu={setContextMenu} - onEditSelectedRow={onEditSelectedRow} /> + onEditSelectedRow={onEditSelectedRow} + showNote={this.props.showNote} + onRefresh={this.props.onRefresh} + /> ); })} diff --git a/src/dashboard/Data/Browser/BrowserTable.react.js b/src/dashboard/Data/Browser/BrowserTable.react.js index dc19d72a54..65819a6294 100644 --- a/src/dashboard/Data/Browser/BrowserTable.react.js +++ b/src/dashboard/Data/Browser/BrowserTable.react.js @@ -155,6 +155,8 @@ export default class BrowserTable extends React.Component { setContextMenu={this.props.setContextMenu} onEditSelectedRow={this.props.onEditSelectedRow} markRequiredFieldRow={this.props.markRequiredFieldRow} + showNote={this.props.showNote} + onRefresh={this.props.onRefresh} />