Skip to content
37 changes: 33 additions & 4 deletions src/components/BrowserCell/BrowserCell.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,49 @@ export default class BrowserCell extends Component {
});
}

const { className, objectId } = this.props;
const validScripts = (this.props.scripts || []).filter(script => script.classes?.includes(this.props.className));
const { className, objectId,field, scripts = [], rowValue } = this.props;
let validator = null;
const validScripts = (scripts || []).filter(script => {
if (script.classes?.includes(className)) {
return true;
}
for (const script of script?.classes || []) {
if (script?.name !== className) {
continue;
}
const fields = script?.fields || [];
if (script?.fields.includes(field) || script?.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') {
validator = eval(currentField.validator);
} else {
validator = currentField.validator;
}
return true;
}
}
}
}
});
if (validScripts.length) {
onEditSelectedRow && contextMenuOptions.push({
text: 'Scripts',
items: validScripts.map(script => {
return {
text: script.title,
disabled: validator?.(this.props.rowValue, field) === false,
callback: () => {
this.selectedScript = { ...script, className, objectId };
if(script.showConfirmationDialog)
if (script.showConfirmationDialog) {
this.toggleConfirmationDialog();
else
}
else {
this.executeSript(script);
}
}
}
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/BrowserRow/BrowserRow.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class BrowserRow extends Component {
}

render() {
const { className, columns, currentCol, isUnique, obj, onPointerClick, onPointerCmdClick, order, readOnlyFields, row, rowWidth, selection, selectRow, setCopyableValue, setCurrent, setEditing, setRelation, onEditSelectedRow, setContextMenu, onFilterChange, markRequiredFieldRow } = this.props;
const { className, columns, currentCol, isUnique, obj, onPointerClick, onPointerCmdClick, order, readOnlyFields, row, rowValue, rowWidth, selection, selectRow, setCopyableValue, setCurrent, setEditing, setRelation, onEditSelectedRow, setContextMenu, onFilterChange, markRequiredFieldRow } = this.props;
let attributes = obj.attributes;
let requiredCols = [];
Object.entries(columns).reduce((acc, cur) => {
Expand Down Expand Up @@ -82,6 +82,7 @@ export default class BrowserRow extends Component {
className={className}
field={name}
row={row}
rowValue={rowValue}
col={j}
type={type}
readonly={isUnique || readOnlyFields.indexOf(name) > -1}
Expand Down
4 changes: 4 additions & 0 deletions src/components/ContextMenu/ContextMenu.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ const MenuSection = ({ level, items, path, setPath, hide }) => {
<li
key={`menu-section-${level}-${index}`}
className={styles.option}
style={item.disabled ? {'opacity': 0.5, cursor: 'not-allowed'} : {}}
onClick={() => {
if (item.disabled === true) {
return;
}
item.callback && item.callback();
hide();
}}
Expand Down
2 changes: 2 additions & 0 deletions src/dashboard/Data/Browser/BrowserTable.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export default class BrowserTable extends React.Component {
order={this.props.order}
readOnlyFields={READ_ONLY}
row={index}
rowValue={this.props.data[index]}
rowWidth={rowWidth}
selection={this.props.selection}
selectRow={this.props.selectRow}
Expand Down Expand Up @@ -265,6 +266,7 @@ export default class BrowserTable extends React.Component {
order={this.props.order}
readOnlyFields={READ_ONLY}
row={i}
rowValue={this.props.data[i]}
rowWidth={rowWidth}
selection={this.props.selection}
selectRow={this.props.selectRow}
Expand Down