Skip to content

Commit

Permalink
Fix command argument types when importing from history (#159)
Browse files Browse the repository at this point in the history
* Convert cmd args to strings before setting cmd in parent

* Fix for complex commanding
  • Loading branch information
thomas-bc committed Jan 31, 2024
1 parent 15ebba5 commit a4077c2
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/fprime_gds/flask/static/addons/commanding/command-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,29 @@ Vue.component("command-history", {
cmd.full_name = template.full_name;
// Can only set command if it is a child of a command input
if (this.$parent.selectCmd) {
this.$parent.selectCmd(cmd.full_name, cmd.args);
// command-input expects an array of strings as arguments
this.$parent.selectCmd(cmd.full_name, this.preprocess_args(cmd.args));
}
},
/**
* Process the arguments for a command. If the argument is (or contains) a number, it
* is converted to a string. Other types that should be pre-processed can be added here.
*
* @param {*} args
* @returns args processed for command input (numbers converted to strings)
*/
preprocess_args(args) {
if (Array.isArray(args)) {
return args.map(el => this.preprocess_args(el));
} else if (typeof args === 'object' && args !== null) {
return Object.fromEntries(
Object.entries(args).map(([key, value]) => [key, this.preprocess_args(value)])
);
} else if (typeof args === 'number') {
return args.toString();
} else {
return args;
}
}
}
});
});

0 comments on commit a4077c2

Please sign in to comment.