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

Default Tool arguments #4421

Open
TomasPetrauskas opened this issue Oct 4, 2022 · 5 comments
Open

Default Tool arguments #4421

TomasPetrauskas opened this issue Oct 4, 2022 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@TomasPetrauskas
Copy link

Describe the bug
By passing an array of default tool arguments to IModelApp.toolAdmin.defaultToolArgs the arguments do not get parsed correctly. In the async run function line 821 of the tool.js file, the array does not get spread with the spread operator and instead becomes an array of an array. You will receive an error that the tool's viewport is not setup correctly as the viewport is at that point set as an array with the arguments.

To Reproduce
Steps to reproduce the behaviour:

  1. Add default tool arg array
  2. Attempt to run the default tool
  3. You will receive an error once trying to use the tool that the tool's viewport does not contain some function.

Expected behavior
The arguments should be parsed separately not enclosed into another array.

Desktop (please complete the applicable information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: 106.0.5249.91
  • iTwin.js Version: 3.3.0

Additional context
This should be an easy fix as the variables being passed in the function should not contain the spread operator (...args) as this is what breaks it.
This issue can simply be recreated by running this piece of code:

let defaultToolArgs = [1,2,3];
function hej(a, b, c) { console.log({a,b,c}) }
function test(a, ...b) { hej(...b) }
test("hej", defaultToolArgs)

If this code is run:

let defaultToolArgs = [1,2,3];
function hej(a, b, c) { console.log({a,b,c}) }
function test(a, b) { hej(...b) }
test("hej", defaultToolArgs)

We receive the expected behaviour.

@pmconne pmconne added the bug Something isn't working label Oct 4, 2022
@TomasPetrauskas
Copy link
Author

TomasPetrauskas commented Oct 4, 2022

Example code being run:
example-code

Debugging the tool.js code:
issue-debug

Attaching some screenshots for more reference.

@bbastings
Copy link
Contributor

bbastings commented Oct 4, 2022

I think this would let you do what you want without making public api changes (below)?

public async startDefaultTool(): Promise {
(remove) if (!await IModelApp.tools.run(this.defaultToolId, this.defaultToolArgs))
(add) if (!await IModelApp.tools.run(this.defaultToolId, ...(this.defaultToolArgs || [])))
return this.startPrimitiveTool(undefined);
}

@TomasPetrauskas Agree? Not sure whether there is a prettier way to deal with defaultToolArgs allowing undefined...

@TomasPetrauskas
Copy link
Author

Yes we can try this solution.

@aruniverse
Copy link
Member

@TomasPetrauskas was @bbastings 's suggestion helpful? Can we close this issue?

@bbastings
Copy link
Contributor

I was actually suggesting that Tomas could create a PR to make this change if it was sufficient for their needs...I don't think what is there now for default args is very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants