Skip to content

Commit

Permalink
Adding new test block for dynamic dropdown (#493)
Browse files Browse the repository at this point in the history
* Adding new test block for dynamic dropdown

* Change options

* update

* Add block to toolbox category

* Add fix
  • Loading branch information
Monica Kozbial authored Nov 20, 2020
1 parent 75eb453 commit 5f1e21d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions plugins/block-test/src/fields/dropdowns.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,35 @@ Blockly.Blocks['test_dropdowns_dynamic_random'] = {
},
};

Blockly.Blocks['test_dropdowns_dynamic_connect_dependant'] = {
init: function() {
const dropdown = new Blockly.FieldDropdown(this.dynamicOptions);
this.appendDummyInput()
.appendField('dynamic connect-dependant')
.appendField(dropdown, 'OPTIONS');
this.setNextStatement(true);
this.setPreviousStatement(true);
},

dynamicOptions: function() {
if (this.sourceBlock_ && this.sourceBlock_.getSurroundParent()) {
const parent = this.sourceBlock_.getSurroundParent();
const options = [
['connected', 'CONNECTED_KEY'],
[`surroundParent: ${parent.type}`, `${parent.id}_type_key`],
[`surroundParent: ${parent.id}`, `${parent.id}_key`]];
const top = this.sourceBlock_.getTopStackBlock();
if (top.id !== parent.id) {
options.push([`topStack: ${top.type}`, `${top.id}_type_key`]);
options.push([`topStack: ${top.id}`, `${top.id}_key`]);
}
return options;
} else {
return [['unconnected', 'UNCONNECTED_KEY']];
}
},
};

/**
* Mutator methods added to the test_dropdowns_in_mutator block.
* @mixin
Expand Down Expand Up @@ -515,6 +544,10 @@ export const category = {
'kind': 'BLOCK',
'type': 'test_dropdowns_dynamic_random',
},
{
'kind': 'BLOCK',
'type': 'test_dropdowns_dynamic_connect_dependant',
},
{
'kind': 'LABEL',
'text': 'Other',
Expand Down
3 changes: 2 additions & 1 deletion plugins/block-test/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import * as Blockly from 'blockly';
import {createPlayground, toolboxCategories,
toolboxSimple} from '@blockly/dev-tools';
import {toolbox, onInit} from '../src/index';
import {toolboxTestBlocks as toolbox,
toolboxTestBlocksInit as onInit} from '../src/index';


/**
Expand Down

0 comments on commit 5f1e21d

Please sign in to comment.