Skip to content

Commit

Permalink
fix(editor): allow using decimal numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Apr 11, 2022
1 parent 29e1407 commit 92e581c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
13 changes: 0 additions & 13 deletions src/components/EditorOperatorArgument.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
>
<el-input
:ref="argument.selected.arguments[0].id"
:type="inputType(argument.selected.arguments[0])"
class="input-operator"
data-test="argument-input"
:placeholder="argument.selected.arguments[0].label"
Expand Down Expand Up @@ -231,18 +230,6 @@ export default {
}
},
methods: {
inputType(input) {
if (input.value.chartAt(0) === '$') {
return 'text'
}
if (input.type.toLowerCase() === 'number') {
return 'number'
}
if (input.type.toLowerCase() === 'boolean') {
return 'boolean'
}
return 'text'
},
scrollToCurrentFocus() {
this.$refs[this.currentFocus].$el.scrollIntoView()
this.$store.commit('clearCurrentFocus')
Expand Down
4 changes: 1 addition & 3 deletions src/components/EditorToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ export default {
this.clearHistory()
},
getJsFile() {
this.template.usedVariables.forEach(variable => {
const id = variable.id
const value = variable.value
this.template.usedVariables.forEach(({ value, id }) => {
this.updateTemplate({ id, value, keepRecord: false })
})
this.jsFile = this.radRequest.getJs()
Expand Down
9 changes: 5 additions & 4 deletions src/components/RadonOperator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
standardizeOperatorName,
standardizeOutputType,
selectInnerError,
getNativeValueFromMarkupArgumentType,
} from '@/utils'
import {
UPDATE_TEMPLATE,
Expand Down Expand Up @@ -258,7 +259,7 @@ export default {
},
updateArgumentsAndVariables(input) {
const id = input.id
let value = input.value
const value = input.value
const type = input.type
this.variableName = value
this.toggleVariables({ hasVariables: true })
Expand All @@ -283,20 +284,20 @@ export default {
this.toggleVariables({ hasVariables: false })
this.updateTemplate({
id,
value: value,
value: getNativeValueFromMarkupArgumentType(value, type),
})
}
},
updateOperatorAndVariables(id, value, type) {
this.selected = {
id: id,
primaryText: value,
value: value,
value,
secondaryText: 'boolean',
}
this.updateTemplate({
id,
value: value,
value,
})
},
scrollToCurrentFocus() {
Expand Down
6 changes: 1 addition & 5 deletions src/store/rad.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ export default {
})
},
[DELETE_USED_VARIABLE](state, { index }) {
if (index === 0) {
state.currentTemplate.usedVariables.shift()
} else {
state.currentTemplate.usedVariables.splice(index, 1)
}
state.currentTemplate.usedVariables.splice(index, 1)
this.dispatch('saveTemplate')
},
[USED_VARIABLES](state, { id, variable, value, type }) {
Expand Down
16 changes: 11 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,17 @@ export function copyToClipboard(str) {
// Get the native javascript type from the radon markup argument type
// Map types are handled by witnet-radon-js library
export function getNativeValueFromMarkupArgumentType(value, type) {
if (type.toLowerCase() === 'number') {
return Number(value)
}
if (type.toLowerCase() === 'boolean') {
return value === 'true'
if (type) {
if (
type.toLowerCase() === 'number' &&
Number(value) &&
value.slice(-1) !== '.'
) {
return Number(value)
}
if (type.toLowerCase() === 'boolean') {
return value === 'true'
}
}
return value
}
Expand Down

0 comments on commit 92e581c

Please sign in to comment.