diff --git a/app/blocks/feed/get_value.js b/app/blocks/feed/get_value.js index 7c80c3b..952816d 100644 --- a/app/blocks/feed/get_value.js +++ b/app/blocks/feed/get_value.js @@ -10,6 +10,7 @@ export default { tooltip: "The last value of this feed or component, always a String" }, + mixins: ['replaceDropdownOptions'], extensions: ['populateFeedDropdown'], lines: [ diff --git a/app/blocks/feed/set_value.js b/app/blocks/feed/set_value.js index 8c61f5d..99bdd72 100644 --- a/app/blocks/feed/set_value.js +++ b/app/blocks/feed/set_value.js @@ -10,6 +10,7 @@ export default { colour: 300 }, + mixins: ['replaceDropdownOptions'], extensions: ['populateFeedDropdown'], connections: { diff --git a/app/extensions/populate_feed_dropdown.js b/app/extensions/populate_feed_dropdown.js index c56b5b6..3fe7c4f 100644 --- a/app/extensions/populate_feed_dropdown.js +++ b/app/extensions/populate_feed_dropdown.js @@ -1,41 +1,14 @@ // Populates Feed dropdowns with name FEED_KEY to contain the user's feeds // that are viable for Actions. Provided by the backend at runtime. export const populateFeedDropdown = ({ block, data, Blockly }) => { - const - { feedOptions } = data, - FIELD_KEY = "FEED_KEY" + const { feedOptions } = data if(!feedOptions) { console.error(`[extensions.populateFeedDropdown] No feedOptions found in extension data.`) return } - // search this block's inputs... - let input, foundFieldAt - for (let i = 0; i < block.inputList.length;i++) { - input = block.inputList[i] - - // ...and the input's fields... - for (let j = 0; j < input.fieldRow.length;j++) { - // ...for a field with the right name... - if(input.fieldRow[j].name == FIELD_KEY) { - // ...and record its index - foundFieldAt = j - break - } - } - - // stop iterating inputs when field is found - if(foundFieldAt) { break } - } - - if(!foundFieldAt) { - console.error(`[extensions.populateFeedDropdown] No field named "${FIELD_KEY}" found in ${block.type} block.`) - return - } - - input.removeField(FIELD_KEY) - input.insertFieldAt(foundFieldAt, new Blockly.FieldDropdown(feedOptions), FIELD_KEY) + block.replaceDropdownOptions("FEED_KEY", feedOptions) } // also export as default diff --git a/app/mixins/replace_dropdown_options.js b/app/mixins/replace_dropdown_options.js index 28a4a35..608ff72 100644 --- a/app/mixins/replace_dropdown_options.js +++ b/app/mixins/replace_dropdown_options.js @@ -21,7 +21,7 @@ export const replaceDropdownOptions = function(fieldKey, newOptions) { } if(!foundFieldAt) { - console.error(`[mixins.relaceDropdown] No field named "${fieldKey}" found in ${this.type} block.`) + console.error(`[mixins.relaceDropdownOptions] No field named "${fieldKey}" found in ${this.type} block.`) return }