Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jsreport/jsreport-scripts

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsreport/jsreport-scripts - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

studio/NewScriptModal.js

12

lib/executeScript.js

@@ -5,7 +5,6 @@ const extend = require('node.extend.without.arrays')

module.exports = async function executeScript (reporter, script, method, req, res) {
module.exports = async function executeScript (reporter, { script, method, onBeforeExecute }, req, res) {
let entityPath
if (script._id) {
entityPath = await reporter.folders.resolveEntityPath(script, 'scripts', req)
entityPath = entityPath.substring(0, entityPath.lastIndexOf('/'))
}

@@ -53,5 +52,14 @@

initialContext.__request.__onBeforeExecute = (topLevelFunctionsNames) => {
onBeforeExecute(script, topLevelFunctionsNames)
}
const sandboxManager = {}
const executionFn = async ({ topLevelFunctions, restore, context }) => {
const onBeforeExecute = context.__request.__onBeforeExecute
delete context.__request.__onBeforeExecute
onBeforeExecute(Object.keys(topLevelFunctions))
try {

@@ -58,0 +66,0 @@ if (method === 'beforeRender' && topLevelFunctions.beforeRender) {

@@ -11,2 +11,3 @@ /*!

name: { type: 'Edm.String' },
scope: { type: 'Edm.String', schema: { enum: ['template', 'global', 'folder'] } },
isGlobal: { type: 'Edm.Boolean' }

@@ -13,0 +14,0 @@ })

@@ -30,21 +30,50 @@ /*!

let scriptsProfilerEvent
if (req.context.scriptsCache.length) {
scriptsProfilerEvent = this.reporter.profiler.emit({
type: 'operationStart',
subtype: 'scriptsBeforeRender',
name: 'scripts beforeRender'
}, req, res)
let generalScriptsProfilerEvent
let currentScriptProfilerEvent
const onBeforeExecute = (script, topLevelFunctionsNames) => {
if (req.context.scriptsCache.length && topLevelFunctionsNames.includes('beforeRender')) {
if (generalScriptsProfilerEvent == null) {
generalScriptsProfilerEvent = this.reporter.profiler.emit({
type: 'operationStart',
subtype: 'scriptsBeforeRender',
name: 'scripts beforeRender'
}, req, res)
}
currentScriptProfilerEvent = this.reporter.profiler.emit({
type: 'operationStart',
subtype: 'script',
name: `scripts ${script.name || 'anonymous'}`,
previousOperationId: generalScriptsProfilerEvent.operationId
}, req, res)
}
}
const onAfterExecute = () => {
if (currentScriptProfilerEvent) {
this.reporter.profiler.emit({
type: 'operationEnd',
operationId: currentScriptProfilerEvent.operationId
}, req, res)
currentScriptProfilerEvent = null
}
}
for (const script of req.context.scriptsCache) {
await this._runScript(req, res, script, 'beforeRender', scriptsProfilerEvent)
await this._runScript(req, res, {
script,
method: 'beforeRender',
onBeforeExecute,
onAfterExecute
})
}
if (scriptsProfilerEvent) {
if (generalScriptsProfilerEvent) {
this.reporter.profiler.emit({
type: 'operationEnd',
operationId: scriptsProfilerEvent.operationId
operationId: generalScriptsProfilerEvent.operationId
}, req, res)
req.context.profiling.lastOperationId = scriptsProfilerEvent.operationId
req.context.profiling.lastOperationId = generalScriptsProfilerEvent.operationId
}

@@ -54,34 +83,56 @@ }

async handleAfterRender (req, res) {
let scriptsProfilerEvent
if (req.context.scriptsCache.find(s => s.shouldRunAfterRender)) {
scriptsProfilerEvent = this.reporter.profiler.emit({
type: 'operationStart',
subtype: 'scriptsAfterRender',
name: 'scripts afterRender'
}, req, res)
let generalScriptsProfilerEvent
let currentScriptProfilerEvent
const onBeforeExecute = (script) => {
if (req.context.scriptsCache.find(s => s.shouldRunAfterRender)) {
if (generalScriptsProfilerEvent == null) {
generalScriptsProfilerEvent = this.reporter.profiler.emit({
type: 'operationStart',
subtype: 'scriptsAfterRender',
name: 'scripts afterRender'
}, req, res)
}
currentScriptProfilerEvent = this.reporter.profiler.emit({
type: 'operationStart',
subtype: 'script',
name: `scripts ${script.name || 'anonymous'}`,
previousOperationId: generalScriptsProfilerEvent.operationId
}, req, res)
}
}
const onAfterExecute = () => {
if (currentScriptProfilerEvent) {
this.reporter.profiler.emit({
type: 'operationEnd',
operationId: currentScriptProfilerEvent.operationId
}, req, res)
currentScriptProfilerEvent = null
}
}
for (const script of req.context.scriptsCache) {
if (script.shouldRunAfterRender) {
await this._runScript(req, res, script, 'afterRender', scriptsProfilerEvent)
await this._runScript(req, res, {
script,
method: 'afterRender',
onBeforeExecute,
onAfterExecute
})
}
}
if (scriptsProfilerEvent) {
if (generalScriptsProfilerEvent) {
this.reporter.profiler.emit({
type: 'operationEnd',
operationId: scriptsProfilerEvent.operationId
operationId: generalScriptsProfilerEvent.operationId
}, req, res)
req.context.profiling.lastOperationId = scriptsProfilerEvent.operationId
req.context.profiling.lastOperationId = generalScriptsProfilerEvent.operationId
}
}
async _runScript (req, res, script, method, scriptsProfilerEvent) {
const scriptProfilerEvent = this.reporter.profiler.emit({
type: 'operationStart',
subtype: 'script',
name: `scripts ${script.name || 'anonymous'}`,
previousOperationId: scriptsProfilerEvent.operationId
}, req, res)
async _runScript (req, res, { script, method, onBeforeExecute, onAfterExecute }) {
this.reporter.logger.debug(`Executing script ${(script.name || script.shortid || 'anonymous')} (${method})`, req)

@@ -91,3 +142,3 @@

const scriptExecResult = await (require('./executeScript')(this.reporter, script, method, req, res))
const scriptExecResult = await (require('./executeScript')(this.reporter, { script, method, onBeforeExecute }, req, res))

@@ -144,6 +195,3 @@ if (scriptExecResult.shouldRunAfterRender) {

this.reporter.profiler.emit({
type: 'operationEnd',
operationId: scriptProfilerEvent.operationId
}, req, res)
onAfterExecute()

@@ -156,2 +204,19 @@ return res

const getSorterByName = () => {
return (a, b) => {
const nameA = a.name.toUpperCase()
const nameB = b.name.toUpperCase()
if (nameA < nameB) {
return -1
}
if (nameA > nameB) {
return 1
}
return 0
}
}
const items = await Promise.all(req.template.scripts.map(async (script) => {

@@ -171,3 +236,6 @@ if (script.content) {

const items = await this.reporter.documentStore.collection('scripts').find(query, req)
let items = await this.reporter.documentStore.collection('scripts').find(query, req)
items = items.filter((s) => s.scope === 'template' || (s.scope == null && !s.isGlobal))
if (items.length < 1) {

@@ -186,5 +254,63 @@ const error = this.reporter.createError(`Script not found or user not authorized to read it (${

const globalItems = await this.reporter.documentStore.collection('scripts').find({ isGlobal: true }, req)
return globalItems.concat(items)
const globalItems = await this.reporter.documentStore.collection('scripts').find({
$or: [
{ isGlobal: true },
{ scope: 'global' }
]
}, req)
// sort alphabetically asc
globalItems.sort(getSorterByName())
const folderItems = []
if (req.context.resolvedTemplate != null) {
let currentEntity = req.context.resolvedTemplate
const scriptsByLevel = []
do {
const folderQuery = currentEntity.folder != null ? { shortid: currentEntity.folder.shortid } : null
const scripts = await this.reporter.documentStore.collection('scripts').find({
scope: 'folder',
folder: folderQuery
}, req)
if (scripts.length > 0) {
scriptsByLevel.push([...scripts])
}
if (currentEntity.folder != null) {
currentEntity = await this.reporter.documentStore.collection('folders').findOne({
shortid: currentEntity.folder.shortid
}, req)
} else {
currentEntity = null
}
} while (currentEntity != null)
scriptsByLevel.reverse()
for (const currentScripts of scriptsByLevel) {
currentScripts.sort(getSorterByName())
folderItems.push(...currentScripts)
}
} else {
// if anonymous request just search for scripts with scope "folder" at the top level
const folders = await this.reporter.documentStore.collection('scripts').find({
scope: 'folder',
folder: null
}, req)
folderItems.push(...folders)
// sort alphabetically asc
folderItems.sort(getSorterByName())
}
return [
...globalItems,
...folderItems,
...items
]
}
}

6

package.json
{
"name": "@jsreport/jsreport-scripts",
"version": "3.1.0",
"version": "3.2.0",
"description": "jsreport extension capable of running custom javascript functions during the rendering process",

@@ -32,4 +32,4 @@ "keywords": [

"devDependencies": {
"@jsreport/jsreport-assets": "3.1.0",
"@jsreport/jsreport-core": "3.2.0",
"@jsreport/jsreport-assets": "3.2.0",
"@jsreport/jsreport-core": "3.3.0",
"@jsreport/jsreport-jsrender": "3.0.0",

@@ -36,0 +36,0 @@ "@jsreport/studio-dev": "3.0.1",

@@ -1,4 +0,5 @@

import ScriptEditor from './ScriptEditor.js'
import TemplateScriptProperties from './TemplateScriptProperties.js'
import ScriptProperties from './ScriptProperties.js'
import NewScriptModal from './NewScriptModal'
import ScriptEditor from './ScriptEditor'
import TemplateScriptProperties from './TemplateScriptProperties'
import ScriptProperties from './ScriptProperties'
import Studio from 'jsreport-studio'

@@ -10,4 +11,5 @@

visibleName: 'script',
onNew: (options) => Studio.openModal(NewScriptModal, options),
helpUrl: 'http://jsreport.net/learn/scripts',
referenceAttributes: ['isGlobal'],
referenceAttributes: ['isGlobal', 'scope'],
entityTreePosition: 800

@@ -53,3 +55,3 @@ })

The script "{entity.name}" doesn't have a function hook defined. This means the script won't do anything. You should define either "beforeRender" or "afterRender" function hooks.
<br />See the <a href='https://jsreport.net/learn/scripts'>scripts docummentation</a> for the details.
<br />See the <a href='https://jsreport.net/learn/scripts'>scripts documentation</a> for the details.
</div>

@@ -60,4 +62,19 @@ ))

Studio.entityTreeIconResolvers.push((entity) => (entity.__entitySet === 'scripts' && entity.isGlobal) ? 'fa-cogs' : null)
Studio.entityTreeIconResolvers.push((entity) => {
if (
entity.__entitySet === 'scripts' &&
(
(
Object.prototype.hasOwnProperty.call(entity, 'scope') &&
(entity.scope === 'global' ||
entity.scope === 'folder')
) || entity.isGlobal
)
) {
return 'fa-cogs'
}
return null
})
function getDefaultScriptContent () {

@@ -64,0 +81,0 @@ return (

@@ -84,3 +84,3 @@ /******/ (function(modules) { // webpackBootstrap

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ return __webpack_require__(__webpack_require__.s = 3);
/******/ })

@@ -107,11 +107,42 @@ /************************************************************************/

var _ScriptEditor = __webpack_require__(3);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = [{
key: 'template',
title: 'template',
value: 'template',
desc: 'script will only run for the templates it is being explicitly attached'
}, {
key: 'global',
title: 'global',
value: 'global',
desc: 'script will run for all templates'
}, {
key: 'folder',
title: 'folder',
value: 'folder',
desc: 'script will run for all templates in the same folder hierarchy'
}];
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _NewScriptModal = __webpack_require__(4);
var _NewScriptModal2 = _interopRequireDefault(_NewScriptModal);
var _ScriptEditor = __webpack_require__(5);
var _ScriptEditor2 = _interopRequireDefault(_ScriptEditor);
var _TemplateScriptProperties = __webpack_require__(4);
var _TemplateScriptProperties = __webpack_require__(6);
var _TemplateScriptProperties2 = _interopRequireDefault(_TemplateScriptProperties);
var _ScriptProperties = __webpack_require__(5);
var _ScriptProperties = __webpack_require__(7);

@@ -130,4 +161,7 @@ var _ScriptProperties2 = _interopRequireDefault(_ScriptProperties);

visibleName: 'script',
onNew: function onNew(options) {
return _jsreportStudio2.default.openModal(_NewScriptModal2.default, options);
},
helpUrl: 'http://jsreport.net/learn/scripts',
referenceAttributes: ['isGlobal'],
referenceAttributes: ['isGlobal', 'scope'],
entityTreePosition: 800

@@ -185,3 +219,3 @@ });

{ href: 'https://jsreport.net/learn/scripts' },
'scripts docummentation'
'scripts documentation'
),

@@ -195,3 +229,7 @@ ' for the details.'

_jsreportStudio2.default.entityTreeIconResolvers.push(function (entity) {
return entity.__entitySet === 'scripts' && entity.isGlobal ? 'fa-cogs' : null;
if (entity.__entitySet === 'scripts' && (Object.prototype.hasOwnProperty.call(entity, 'scope') && (entity.scope === 'global' || entity.scope === 'folder') || entity.isGlobal)) {
return 'fa-cogs';
}
return null;
});

@@ -204,3 +242,3 @@

/***/ }),
/* 3 */
/* 4 */
/***/ (function(module, exports, __webpack_require__) {

@@ -215,2 +253,4 @@

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -222,6 +262,14 @@

var _scopeOptions = __webpack_require__(2);
var _scopeOptions2 = _interopRequireDefault(_scopeOptions);
var _jsreportStudio = __webpack_require__(1);
var _jsreportStudio2 = _interopRequireDefault(_jsreportStudio);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -233,2 +281,263 @@

var NewScriptModal = function (_Component) {
_inherits(NewScriptModal, _Component);
function NewScriptModal(props) {
_classCallCheck(this, NewScriptModal);
var _this = _possibleConstructorReturn(this, (NewScriptModal.__proto__ || Object.getPrototypeOf(NewScriptModal)).call(this, props));
_this.nameInputRef = _react2.default.createRef();
_this.state = {
selectedScope: 'template',
error: null,
processing: false
};
return _this;
}
// the modal component for some reason after open focuses the panel itself
_createClass(NewScriptModal, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _this2 = this;
setTimeout(function () {
return _this2.nameInputRef.current.focus();
}, 0);
}
}, {
key: 'handleKeyPress',
value: function handleKeyPress(e) {
if (e.key === 'Enter') {
this.submit(e.target.value);
}
}
}, {
key: 'submit',
value: function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(val) {
var name, entity;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!this.state.processing) {
_context.next = 2;
break;
}
return _context.abrupt('return');
case 2:
name = val || this.nameInputRef.current.value;
entity = _extends({}, this.props.options.defaults, {
name: name,
scope: this.state.selectedScope,
__entitySet: 'scripts'
});
this.setState({ processing: true });
_context.prev = 5;
_context.next = 8;
return _jsreportStudio2.default.api.post('/studio/validate-entity-name', {
data: {
_id: this.props.options.cloning === true ? undefined : entity._id,
name: name,
entitySet: 'scripts',
folderShortid: entity.folder != null ? entity.folder.shortid : null
}
}, true);
case 8:
_context.next = 14;
break;
case 10:
_context.prev = 10;
_context.t0 = _context['catch'](5);
this.setState({
error: _context.t0.message,
processing: false
});
return _context.abrupt('return');
case 14:
this.setState({
error: null,
processing: false
});
this.props.close();
_jsreportStudio2.default.openNewTab({
entity: entity,
entitySet: 'scripts',
name: name
});
case 17:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[5, 10]]);
}));
function submit(_x) {
return _ref.apply(this, arguments);
}
return submit;
}()
}, {
key: 'render',
value: function render() {
var _this3 = this;
var _state = this.state,
selectedScope = _state.selectedScope,
error = _state.error,
processing = _state.processing;
var currentScopeValue = selectedScope;
var currentScopeOption = _scopeOptions2.default.find(function (opt) {
return opt.value === currentScopeValue;
});
return _react2.default.createElement(
'div',
null,
_react2.default.createElement(
'div',
{ className: 'form-group' },
_react2.default.createElement(
'label',
null,
'New script'
)
),
_react2.default.createElement(
'div',
{ className: 'form-group' },
_react2.default.createElement(
'label',
null,
'name'
),
_react2.default.createElement('input', {
type: 'text',
placeholder: 'name...',
ref: this.nameInputRef,
onKeyPress: function onKeyPress(e) {
return _this3.handleKeyPress(e);
}
})
),
_react2.default.createElement(
'div',
{ className: 'form-group' },
_react2.default.createElement(
'label',
null,
'scope'
),
_react2.default.createElement(
'select',
{
value: currentScopeValue,
onChange: function onChange(v) {
var newScope = v.target.value;
_this3.setState({
selectedScope: newScope
});
}
},
_scopeOptions2.default.map(function (opt) {
return _react2.default.createElement(
'option',
{ key: opt.key, value: opt.value, title: opt.desc },
opt.title
);
})
),
_react2.default.createElement(
'em',
null,
currentScopeOption.desc
)
),
_react2.default.createElement(
'div',
{ className: 'form-group' },
_react2.default.createElement(
'span',
{
style: {
color: 'red',
display: error ? 'block' : 'none',
marginLeft: 'auto',
marginRight: 'auto',
maxWidth: '360px'
}
},
error
)
),
_react2.default.createElement(
'div',
{ className: 'button-bar' },
_react2.default.createElement(
'button',
{ className: 'button confirmation', disabled: processing, onClick: function onClick() {
return _this3.submit();
} },
'Ok'
)
)
);
}
}]);
return NewScriptModal;
}(_react.Component);
exports.default = NewScriptModal;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = __webpack_require__(0);
var _react2 = _interopRequireDefault(_react);
var _jsreportStudio = __webpack_require__(1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ScriptEditor = function (_Component) {

@@ -268,3 +577,3 @@ _inherits(ScriptEditor, _Component);

/***/ }),
/* 4 */
/* 6 */
/***/ (function(module, exports, __webpack_require__) {

@@ -353,3 +662,3 @@

return Object.keys(entities).filter(function (k) {
return entities[k].__entitySet === 'scripts' && entities[k].shortid === s.shortid;
return entities[k].__entitySet === 'scripts' && entities[k].shortid === s.shortid && (entities[k].scope === 'template' || entities[k].scope == null && !entities[k].isGlobal);
}).length;

@@ -381,3 +690,3 @@ });

var scripts = references.scripts.filter(function (e) {
return !e.isGlobal;
return e.scope === 'template' || e.scope == null && !e.isGlobal;
});

@@ -450,3 +759,3 @@ return { scripts: scripts };

/***/ }),
/* 5 */
/* 7 */
/***/ (function(module, exports, __webpack_require__) {

@@ -467,2 +776,6 @@

var _scopeOptions = __webpack_require__(2);
var _scopeOptions2 = _interopRequireDefault(_scopeOptions);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -486,8 +799,38 @@

_createClass(ScriptProperties, [{
key: 'render',
value: function render() {
key: 'componentDidMount',
value: function componentDidMount() {
this.removeOldIsGlobalProperty();
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
this.removeOldIsGlobalProperty();
}
}, {
key: 'removeOldIsGlobalProperty',
value: function removeOldIsGlobalProperty() {
var _props = this.props,
entity = _props.entity,
_onChange = _props.onChange;
onChange = _props.onChange;
if (entity.isGlobal === true) {
onChange({ _id: entity._id, scope: 'global', isGlobal: false });
} else if (entity.scope == null && !entity.isGlobal) {
onChange({ _id: entity._id, scope: 'template', isGlobal: false });
}
}
}, {
key: 'render',
value: function render() {
var _props2 = this.props,
entity = _props2.entity,
_onChange = _props2.onChange;
var currentScopeValue = entity.scope != null ? entity.scope : 'template';
var currentScopeOption = _scopeOptions2.default.find(function (opt) {
return opt.value === currentScopeValue;
});
return _react2.default.createElement(

@@ -502,10 +845,26 @@ 'div',

null,
'run every time'
'scope'
),
_react2.default.createElement('input', {
type: 'checkbox', checked: entity.isGlobal === true,
onChange: function onChange(v) {
return _onChange({ _id: entity._id, isGlobal: v.target.checked });
}
})
_react2.default.createElement(
'select',
{
value: currentScopeValue,
onChange: function onChange(v) {
var newScope = v.target.value;
_onChange({ _id: entity._id, scope: newScope });
}
},
_scopeOptions2.default.map(function (opt) {
return _react2.default.createElement(
'option',
{ key: opt.key, value: opt.value, title: opt.desc },
opt.title
);
})
),
_react2.default.createElement(
'em',
null,
currentScopeOption.desc
)
)

@@ -517,3 +876,7 @@ );

value: function title(entity, entities) {
return 'scripts (global: ' + (entity.isGlobal === true) + ')';
if (entity.scope != null) {
return 'scripts (scope: ' + entity.scope + ')';
}
return 'scripts';
}

@@ -520,0 +883,0 @@ }]);

import React, { Component } from 'react'
import scopeOptions from './scopeOptions'
export default class ScriptProperties extends Component {
class ScriptProperties extends Component {
static title (entity, entities) {
return `scripts (global: ${entity.isGlobal === true})`
if (entity.scope != null) {
return `scripts (scope: ${entity.scope})`
}
return 'scripts'
}
componentDidMount () {
this.removeOldIsGlobalProperty()
}
componentDidUpdate () {
this.removeOldIsGlobalProperty()
}
removeOldIsGlobalProperty () {
const { entity, onChange } = this.props
if (entity.isGlobal === true) {
onChange({ _id: entity._id, scope: 'global', isGlobal: false })
} else if (entity.scope == null && !entity.isGlobal) {
onChange({ _id: entity._id, scope: 'template', isGlobal: false })
}
}
render () {
const { entity, onChange } = this.props
const currentScopeValue = entity.scope != null ? entity.scope : 'template'
const currentScopeOption = scopeOptions.find((opt) => opt.value === currentScopeValue)
return (
<div className='properties-section'>
<div className='form-group'>
<label>run every time</label>
<input
type='checkbox' checked={entity.isGlobal === true}
onChange={(v) => onChange({ _id: entity._id, isGlobal: v.target.checked })}
/>
<label>scope</label>
<select
value={currentScopeValue}
onChange={(v) => {
const newScope = v.target.value
onChange({ _id: entity._id, scope: newScope })
}}
>
{scopeOptions.map((opt) => (
<option key={opt.key} value={opt.value} title={opt.desc}>{opt.title}</option>
))}
</select>
<em>{currentScopeOption.desc}</em>
</div>

@@ -23,1 +58,3 @@ </div>

}
export default ScriptProperties

@@ -52,3 +52,7 @@ import React, { Component } from 'react'

const updatedScripts = entity.scripts.filter((s) => Object.keys(entities).filter((k) => entities[k].__entitySet === 'scripts' && entities[k].shortid === s.shortid).length)
const updatedScripts = entity.scripts.filter((s) => Object.keys(entities).filter((k) => (
entities[k].__entitySet === 'scripts' &&
entities[k].shortid === s.shortid &&
(entities[k].scope === 'template' || (entities[k].scope == null && !entities[k].isGlobal))
)).length)

@@ -70,3 +74,5 @@ if (updatedScripts.length !== entity.scripts.length) {

filter={(references) => {
const scripts = references.scripts.filter((e) => !e.isGlobal)
const scripts = references.scripts.filter((e) => {
return e.scope === 'template' || (e.scope == null && !e.isGlobal)
})
return { scripts: scripts }

@@ -73,0 +79,0 @@ }}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc