feed dropdown extension uses replace options mixin

This commit is contained in:
Loren Norman 2025-03-04 13:45:44 -05:00
parent 39722d2786
commit 56c3f13544
4 changed files with 5 additions and 30 deletions

View file

@ -10,6 +10,7 @@ export default {
tooltip: "The last value of this feed or component, always a String"
},
mixins: ['replaceDropdownOptions'],
extensions: ['populateFeedDropdown'],
lines: [

View file

@ -10,6 +10,7 @@ export default {
colour: 300
},
mixins: ['replaceDropdownOptions'],
extensions: ['populateFeedDropdown'],
connections: {

View file

@ -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

View file

@ -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
}