Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"scripts": {
"build": "vue-cli-service build",
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build-bundle": "vue-cli-service build --target lib --name flow-builder src/lib.ts",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-service lint",
Expand Down Expand Up @@ -44,6 +43,7 @@
"plain-draggable": "^2.5.12",
"pointer-event": "^1.0.0",
"popper.js": "^1.16.1",
"scanf": "^1.1.2",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3",
"vue-focus": "^2.1.0",
Expand Down
8 changes: 8 additions & 0 deletions src/assets/messages.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"en.flow-builder": {
"scanf-format-string-invalid": "Format String Invalid. Please refer to the documentation for scanf: https://www.php.net/manual/en/function.sscanf.php",
"edit-variable": "Enter Variable Name",
"format-string": "Format String",
"enter-format-string": "Enter Format String",
"flow-name": "Flow name",
"flow-label": "Flow label",
"flow-importer": "Flow importer",
Expand Down Expand Up @@ -1539,6 +1543,10 @@
"youre-using-floip-expressions": "It looks like you're using FLOIP expressions, nice!"
},
"fr.flow-builder": {
"scanf-format-string-invalid": "Chaîne de format non valide. Veuillez vous référer à la documentation: https://www.php.net/manual/en/function.sscanf.php",
"edit-variable": "Modifier le nom de la variable",
"format-string": "Chaîne de format",
"enter-format-string": "Entrez la chaîne de format",
"flow-name": "Nom du flux",
"flow-label": "Libélé du flux",
"flow-importer": "importateur de flux",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
<div>
<text-editor v-model="formatString"
:label="'flow-builder.format-string' | trans"
:placeholder="'flow-builder.enter-format-string' | trans"/>
:placeholder="'flow-builder.enter-format-string' | trans">
<small class="text-danger" v-if="!isScanfSelectorValid">
{{'flow-builder.scanf-format-string-invalid' | trans}}
</small>
</text-editor>
</div>
</template>

<script>
import TextEditor from '@/components/common/TextEditor'
import lang from '@/lib/filters/lang'
import { sscanf } from 'scanf'

export default {
components: {
Expand All @@ -21,13 +26,24 @@ export default {
required: true,
},
},
data() {
return {
isScanfSelectorValid: true,
}
},
computed: {
formatString: {
get() {
return this.block.config.format_string
},
set(value) {
this.$emit('commitFormatStringChange', value)
set(newFormatString) {
try {
sscanf('any string', newFormatString)
this.isScanfSelectorValid = true
} catch (error) {
this.isScanfSelectorValid = false
}
this.$emit('commitFormatStringChange', newFormatString)
},
},
},
Expand Down
13 changes: 11 additions & 2 deletions src/store/flow/block-types/ConsoleIO_ReadBlockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ import { IdGeneratorUuidV4 } from '@floip/flow-runner/dist/domain/IdGeneratorUui
import { IRunFlowBlock } from '@floip/flow-runner/src/model/block/IRunFlowBlock'
import { defaults, split } from 'lodash'
import { IFlowsState } from '../index'
import { sscanf } from 'scanf'

export const BLOCK_TYPE = 'ConsoleIO\\Read'

export const getters: GetterTree<IFlowsState, IRootState> = {
destinationVariablesFields: (state, getters, rootState, rootGetters): string[] => {
const activeBlock = rootGetters['builder/activeBlock']
// TODO: correct the destination variables array according to scanf library we're using, and think about consecutive % or other error we should avoid
return new Array(split(activeBlock.config.format_string || '', '%').length - 1)
try {
//We don't care what string we use to test the format string
//...we just want to know how many scanf variables we will read.
//When we would only read a single variable the library only gives back one value
//...rather than an array so we have to force it into an array.
const destinationVariables = sscanf('any string', activeBlock.config.format_string || '')
return (typeof destinationVariables === 'object') ? destinationVariables : [destinationVariables]
} catch (error) {
return []
}
},
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14166,6 +14166,11 @@ saxes@^5.0.0:
dependencies:
xmlchars "^2.2.0"

scanf@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/scanf/-/scanf-1.1.2.tgz#1a11912f50f6773e0c9e1e26145b9895fdd69c07"
integrity sha512-AjyDCF9jrLcGl+wbH2OO0vfpMUNmv6skJuuLL/vgDUmG/0YXCT6SVBTOvZXOPAD5raJLtDtUU7v0yF79JDuAqA==

scheduler@^0.19.1:
version "0.19.1"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196"
Expand Down