Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

During domToWorkspace() child block with FieldDropdown is in workspace's topblock #2926

Closed
ArfyFR opened this issue Aug 28, 2019 · 10 comments
Closed
Assignees
Labels
component: fields issue: bug Describes why the code or behaviour is wrong

Comments

@ArfyFR
Copy link

ArfyFR commented Aug 28, 2019

I updated blockly in a project from
1.20190419.0
to "npm": "blockly": "2.20190722.1"

In order to restore a view, I use
Blockly.Xml.domToWorkspace(this.contentData.content, this.workspace);

In our project we only have one top/root block (with childs) by design.
Some child blocks have FieldDropdown, which are filled with a function like

	new Blockly.FieldDropdown(function createSelectedDataTableField_func() {
		let selectedTables = [];
		...
		return selectedTables;

with FieldDropdown values depending on what is set in the root block.

With Blockly 1.20190419.0 => OK

But with Blockly 2.20190722.1 after domToWorkspace, I faced the following. Traces in console like:

Cannot set the dropdown's value to an unavailable option. Block type: dataset_field_table_column, Field name: FIELD_TABLE, Value: mapchartbycust

In the createSelectedDataTableField_func() call, the child block's getRootBlock() is itself O_o
And the workspace has two+ top blocks, the good one and the child(s). So If I call getRootBlock() to do a
let xyz = rootBlock.getFieldValue('SELECTED_TABLE');
call it won't work anymore.

I had to (bad) hack our code with

	if(rootBlock.type == 'dataset_field_table_column') {
	  rootBlock = rootBlock.workspace.getTopBlocks()[0];
	}

to select the "good" root block.

Later, I get the Blockly.Events.BLOCK_CREATE event, and the child(s) block(s) are (back) to root block childs => OK

Expected behavior

Like before

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 76.0.3809.100
@ArfyFR ArfyFR added issue: triage Issues awaiting triage by a Blockly team member issue: bug Describes why the code or behaviour is wrong labels Aug 28, 2019
@rachel-fenichel
Copy link
Collaborator

Thanks for the detailed repro information!

This sounds like a change in the initialization order for fields that broke your blocks. It's not a surprise that blocks are on the workspace when created, and are then attached to the expected parent, but your initialization function must be being called early than it used to be.

@BeksOmega any ideas before I dig in?

@rachel-fenichel rachel-fenichel added component: fields and removed issue: triage Issues awaiting triage by a Blockly team member labels Aug 28, 2019
@rachel-fenichel rachel-fenichel added this to the 2019_q3_release milestone Aug 28, 2019
@BeksOmega
Copy link
Collaborator

@BeksOmega any ideas before I dig in?

The only change I can think of (without digging into it) is that dropdown validators are now called on XML values. This problem doesn't seem to involve validators though, so idk :/

@ArfyFR
Copy link
Author

ArfyFR commented Aug 29, 2019

Hi,

My problem is more: in previous version, the root block DURING Blockly.Xml.domToWorkspace() was the good one ;)
(I noticed I wasn't perhaps clear, I use "Dynamic dropdowns" with a function cf doc )

I also don't know why the function to fill the FieldDropdown is called four time for each child block ?
=> to improve ?

Here are some logs :

  1. first part, the blocks in the toolbox (in flyout) => ok ignored
  2. then the domToWorkspace and the init part (here corrected to switch to real root block id @8H2GG+5_2EcMQ^J[mt=)
  3. at last the events part CREATE, MOVE, ...

workflow log.txt

@ArfyFR
Copy link
Author

ArfyFR commented Aug 29, 2019

The only change I can think of (without digging into it) is that dropdown validators are now called on XML values. This problem doesn't seem to involve validators though, so idk :/

You wrote the validators are NOW called on dropdown for XML values.
If the "Dynamic dropdowns" isn't (well) called to fill the dropdown choices it leads to the error I faced:
Cannot set the dropdown's value to an unavailable option. Block type: dataset_field_table_column, Field name: FIELD_TABLE, Value: mapchartbycust
In my case, not well called because it is linked to a parent block's field value

Hmmm ...

@rachel-fenichel rachel-fenichel self-assigned this Aug 30, 2019
@ArfyFR
Copy link
Author

ArfyFR commented Aug 30, 2019

If other people faced the problem, little "temporary hack" to solve my problem, temporary (during Blockly.Xml.domToWorkspace) bypass the validation for FieldDropdown.

// Save the existing doClassValidation_
let _FieldDropdown_doClassValidation_ = Blockly.FieldDropdown.prototype.doClassValidation_;
// Create a "no validation one"
Blockly.FieldDropdown.prototype.doClassValidation_ = function(newValue) {
  return newValue;
};
Blockly.Xml.domToWorkspace(xml, workspace);
// restore the saved doClassValidation_
Blockly.FieldDropdown.prototype.doClassValidation_ = _FieldDropdown_doClassValidation_;

@RoboErikG
Copy link
Contributor

Possibly fixed. @samelhusseini to confirm.

@samelhusseini
Copy link
Contributor

Yes, we are no longer calling the validation method in the constructor which was the cause of this issue. However, I've also looked into optimizing the number of times we call the dynamic function generator here: #3036

@ArfyFR
Copy link
Author

ArfyFR commented Jan 21, 2020

Hi, we tested with the last Blockly, 3.20191014.4, and we still have the problem with dynamic filled dropdowns

@ArfyFR
Copy link
Author

ArfyFR commented Jan 21, 2020

An example to reproduce the problem with dynamic filled dropdown (in function of another dropdown value)
blockly_dyn_fields.zip

@ArfyFR
Copy link
Author

ArfyFR commented Jan 22, 2020

@samelhusseini , @rachel-fenichel should I open a new issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: fields issue: bug Describes why the code or behaviour is wrong
Projects
None yet
Development

No branches or pull requests

5 participants