diff --git a/lib/components/state-resources/awaiting-human-input/index.js b/lib/components/state-resources/awaiting-human-input/index.js index b251f71..f11da36 100644 --- a/lib/components/state-resources/awaiting-human-input/index.js +++ b/lib/components/state-resources/awaiting-human-input/index.js @@ -1,5 +1,6 @@ const jp = require('jsonpath') const _ = require('lodash') +const resolveInputPaths = require('@wmfs/json-path-input-resolver') const getFromObject = (obj, path, defaultValue) => { const result = String.prototype.split.call(path, /[,[\].]+?/) @@ -15,6 +16,7 @@ class AwaitingHumanInput { this.uiName = resourceConfig.uiName this.uiType = resourceConfig.uiType this.uiRefresh = resourceConfig.uiRefresh + this.uiListener = resourceConfig.uiListener this.dataPath = resourceConfig.dataPath this.defaults = resourceConfig.defaults @@ -50,6 +52,7 @@ class AwaitingHumanInput { uiName: this.uiName, uiType: this.uiType, uiRefresh: this.uiRefresh, + uiListener: resolveUiListener(event, this.uiListener), data } @@ -91,4 +94,9 @@ class AwaitingHumanInput { } // run } // class AwaitingHumanInput +function resolveUiListener (data, config) { + if (!Array.isArray(config)) return [] + return config.map(c => resolveInputPaths(data, c)) +} + module.exports = AwaitingHumanInput diff --git a/lib/components/state-resources/awaiting-human-input/schema.json b/lib/components/state-resources/awaiting-human-input/schema.json index fc3e5a0..ffd984c 100644 --- a/lib/components/state-resources/awaiting-human-input/schema.json +++ b/lib/components/state-resources/awaiting-human-input/schema.json @@ -13,6 +13,10 @@ "type": "integer", "description": "If the uiType is progress, the suggest refresh time in seconds" }, + "uiListener": { + "type": "string", + "description": "Key value of event to listen for" + }, "dataPath": { "type": "string", "description": "Path to data" diff --git a/package.json b/package.json index 468c9cf..d3dc57b 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "main": "./lib/index.js", "dependencies": { + "@wmfs/json-path-input-resolver": "1.1.0", "@wmfs/form-maker": "1.9.0", "jsonfile": "6.1.0", "jsonpath": "1.1.1",