-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Execute scripts via right-click on info panel header column #3068
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/components/ScriptConfirmationModal/ScriptConfirmationModal.react.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright (c) 2016-present, Parse, LLC | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the license found in the LICENSE file in | ||
| * the root directory of this source tree. | ||
| */ | ||
| import React from 'react'; | ||
| import Modal from 'components/Modal/Modal.react'; | ||
| import labelStyles from 'components/Label/Label.scss'; | ||
| import browserCellStyles from 'components/BrowserCell/BrowserCell.scss'; | ||
|
|
||
| /** | ||
| * Confirmation dialog for executing scripts | ||
| */ | ||
| export default function ScriptConfirmationModal({ script, onConfirm, onCancel }) { | ||
| if (!script) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Modal | ||
| type={script.confirmationDialogStyle === 'critical' ? Modal.Types.DANGER : Modal.Types.INFO} | ||
| icon="warn-outline" | ||
| title={script.title} | ||
| confirmText="Continue" | ||
| cancelText="Cancel" | ||
| onCancel={onCancel} | ||
| onConfirm={onConfirm} | ||
| > | ||
| <div className={[labelStyles.label, labelStyles.text, browserCellStyles.action].join(' ')}> | ||
| {`Do you want to run script "${script.title}" on "${script.className}" object "${script.objectId}"?`} | ||
| </div> | ||
| </Modal> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Copyright (c) 2016-present, Parse, LLC | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the license found in the LICENSE file in | ||
| * the root directory of this source tree. | ||
| */ | ||
| import Parse from 'parse'; | ||
|
|
||
| /** | ||
| * Filters scripts to only those valid for the given className and field | ||
| * @param {Array} scripts - Array of script configurations | ||
| * @param {string} className - The Parse class name | ||
| * @param {string} field - The field name | ||
| * @returns {Object} - { validScripts: Array, validator: Function|null } | ||
| */ | ||
| export function getValidScripts(scripts, className, field) { | ||
| let validator = null; | ||
| const validScripts = (scripts || []).filter(script => { | ||
| if (script.classes?.includes(className)) { | ||
| return true; | ||
| } | ||
| for (const scriptClass of script?.classes || []) { | ||
| if (scriptClass?.name !== className) { | ||
| continue; | ||
| } | ||
| const fields = scriptClass?.fields || []; | ||
| if (scriptClass?.fields.includes(field) || scriptClass?.fields.includes('*')) { | ||
| return true; | ||
| } | ||
| for (const currentField of fields) { | ||
| if (Object.prototype.toString.call(currentField) === '[object Object]') { | ||
| if (currentField.name === field) { | ||
| if (typeof currentField.validator === 'string') { | ||
| // SAFETY: eval() is used here on validator strings from trusted admin-controlled | ||
| // dashboard configuration only (not user input). These validators are used solely | ||
| // for UI validation logic to enable/disable script menu items. This is an accepted | ||
| // tradeoff in this trusted admin context. If requirements change, consider replacing | ||
| // with Function constructor or a safer expression parser. | ||
| validator = eval(currentField.validator); | ||
| } else { | ||
| validator = currentField.validator; | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| }); | ||
|
|
||
| return { validScripts, validator }; | ||
| } | ||
|
|
||
| /** | ||
| * Executes a Parse Cloud Code script | ||
| * @param {Object} script - The script configuration | ||
| * @param {string} className - The Parse class name | ||
| * @param {string} objectId - The object ID | ||
| * @param {Function} showNote - Callback to show notification | ||
| * @param {Function} onRefresh - Callback to refresh data | ||
| */ | ||
| export async function executeScript(script, className, objectId, showNote, onRefresh) { | ||
| try { | ||
| const object = Parse.Object.extend(className).createWithoutData(objectId); | ||
| const response = await Parse.Cloud.run( | ||
| script.cloudCodeFunction, | ||
| { object: object.toPointer() }, | ||
| { useMasterKey: true } | ||
| ); | ||
| showNote?.( | ||
| response || `Ran script "${script.title}" on "${className}" object "${object.id}".` | ||
| ); | ||
| onRefresh?.(); | ||
| } catch (e) { | ||
| showNote?.(e.message, true); | ||
| console.error(`Could not run ${script.title}:`, e); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add defensive check for context access.
Line 977 destructures
scriptsfromthis.contextwithout verifying thatthis.contextis not null. If the component is used outside aCurrentAppprovider, this will throw an error.Apply this diff:
handlePanelHeaderContextMenu(event, objectId) { - const { scripts = [] } = this.context || {}; + const { scripts = [] } = this.context ?? {}; const className = this.props.className; const field = 'objectId';Note: The
??operator provides the same protection but is more idiomatic for null/undefined checks.🤖 Prompt for AI Agents