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

feat: Add Cloud Function execution on Parse Object in data browser #2409

Merged
merged 19 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/components/BrowserCell/BrowserCell.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import React, { Component } from 'react';
import styles from 'components/BrowserCell/BrowserCell.scss';
import baseStyles from 'stylesheets/base.scss';
import * as ColumnPreferences from 'lib/ColumnPreferences';

export default class BrowserCell extends Component {
constructor() {
super();
Expand Down Expand Up @@ -276,6 +275,29 @@ export default class BrowserCell extends Component {
});
}

const validScripts = (this.props.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}}`);
dblythy marked this conversation as resolved.
Show resolved Hide resolved
this.props.onRefresh();
} catch (e) {
this.props.showNote(e.message, true);
console.log(`Could not run ${script.title}: ${e}`);
}
}
}
})
});
}

return contextMenuOptions;
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/BrowserRow/BrowserRow.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ export default class BrowserRow extends Component {
markRequiredFieldRow={markRequiredFieldRow}
setCopyableValue={setCopyableValue}
setContextMenu={setContextMenu}
onEditSelectedRow={onEditSelectedRow} />
onEditSelectedRow={onEditSelectedRow}
showNote={this.props.showNote}
onRefresh={this.props.onRefresh}
scripts={this.props.scripts}
/>
);
})}
</div>
Expand Down
12 changes: 11 additions & 1 deletion src/dashboard/Data/Browser/BrowserTable.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ 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}
scripts={this.context.scripts}
/>
<Button
value="Clone"
Expand Down Expand Up @@ -207,6 +210,9 @@ 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}
scripts={this.context.scripts}
/>
<Button
value="Add"
Expand Down Expand Up @@ -263,7 +269,11 @@ export default class BrowserTable extends React.Component {
setRelation={this.props.setRelation}
setCopyableValue={this.props.setCopyableValue}
setContextMenu={this.props.setContextMenu}
onEditSelectedRow={this.props.onEditSelectedRow} />
onEditSelectedRow={this.props.onEditSelectedRow}
showNote={this.props.showNote}
onRefresh={this.props.onRefresh}
scripts={this.context.scripts}
/>
}

if (this.props.editing) {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/ParseApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export default class ParseApp {
supportedPushLocales,
preventSchemaEdits,
graphQLServerURL,
columnPreference
columnPreference,
scripts
}) {
this.name = appName;
this.createdAt = created_at ? new Date(created_at) : new Date();
Expand All @@ -71,6 +72,7 @@ export default class ParseApp {
this.preventSchemaEdits = preventSchemaEdits || false;
this.graphQLServerURL = graphQLServerURL;
this.columnPreference = columnPreference;
this.scripts = scripts;

if(!supportedPushLocales) {
console.warn('Missing push locales for \'' + appName + '\', see this link for details on setting localizations up. https://github.com/parse-community/parse-dashboard#configuring-localized-push-notifications');
Expand Down