Skip to content

Commit

Permalink
fix(studio): fix error when renaming node (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebburon committed Nov 1, 2021
1 parent 60825f3 commit 0183dfa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/studio-ui/src/web/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@
"add": "add",
"addAction": "Add new action",
"cantSeeActions": "Can't see your action?",
"nameAlreadyExists": "Can't rename node (this name already exists)",
"emptyName": "Node name cannot be empty",
"confirmOverwriteParameters": "Do you want to overwrite existing parameters?",
"contentPaste": "content_paste",
"couldNotRetrieveActionServer": "Could not retrieve action servers",
Expand Down
2 changes: 2 additions & 0 deletions packages/studio-ui/src/web/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@
"add": "Añadir",
"addAction": "Añadir nueva acción",
"cantSeeActions": "No puedes ver tu acción?",
"nameAlreadyExists": "No puedo cambiar el nodo (Nombre ya existe)",
"emptyName": "Nodo nombre no puede estar vacío",
"confirmOverwriteParameters": "¿Desea sobrescribir los parámetros existentes?",
"contentPaste": "content_paste",
"couldNotRetrieveActionServer": "No se pudieron recuperar servidores de acción",
Expand Down
2 changes: 2 additions & 0 deletions packages/studio-ui/src/web/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@
"add": "ajouter",
"addAction": "Ajouter une nouvelle action",
"cantSeeActions": "Vous ne voyez pas votre action?",
"nameAlreadyExists": "Impossible de renommer le noeud (Ce nom existe déjà)",
"emptyName": "Le nom du noeud ne peut être vide",
"chatbotExecutes": "L'assistant virtuel exécute",
"chatbotSays": "L'assistant virtuel dit",
"triggeredBy": "Le workflow est is déclenché par",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lang } from 'botpress/shared'
import { lang, toast } from 'botpress/shared'
import React, { Component, Fragment } from 'react'

import { Tabs, Tab, Badge, Panel } from 'react-bootstrap'
Expand All @@ -11,12 +11,18 @@ import TransitionSection from './TransitionSection'
const style = require('./style.scss')

export default class StandardNodePropertiesPanel extends Component {
renameNode = text => {
onChange = text => {
if (text) {
const alreadyExists = this.props.flow.nodes.find(x => x.name === text)
if (!alreadyExists) {
this.props.updateNode({ name: text })
if (text !== this.props.node.name) {
const alreadyExists = this.props.flow.nodes.find(x => x.name === text)
if (alreadyExists) {
toast.failure(lang.tr('studio.flow.node.nameAlreadyExists'))
} else {
this.props.updateNode({ name: text })
}
}
} else {
toast.failure(lang.tr('studio.flow.node.emptyName'))
}
}

Expand All @@ -38,7 +44,7 @@ export default class StandardNodePropertiesPanel extends Component {
readOnly={readOnly}
value={node.name}
className={style.name}
onChanged={this.renameNode}
onChanged={this.onChange}
transform={this.transformText}
/>
</Panel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dropdown, lang, MoreOptions, MoreOptionsItems } from 'botpress/shared'
import { Dropdown, lang, MoreOptions, MoreOptionsItems, toast } from 'botpress/shared'
import _ from 'lodash'
import React, { FC, Fragment, useEffect, useRef, useState } from 'react'
import { connect } from 'react-redux'
Expand Down Expand Up @@ -52,13 +52,18 @@ const SaySomethingForm: FC<Props> = props => {
}
}, [props.currentFlowNode.id])

const renameNode = text => {
const onChange = text => {
if (text) {
const alreadyExists = props.currentFlow.nodes.find(x => x.name === text)

if (!alreadyExists) {
props.updateNode({ name: text })
if (text !== props.currentFlowNode.nodeName) {
const alreadyExists = props.currentFlow.nodes.find(x => x.name === text)
if (alreadyExists) {
toast.failure(lang.tr('studio.flow.node.nameAlreadyExists'))
} else {
props.updateNode({ name: text })
}
}
} else {
toast.failure(lang.tr('studio.flow.node.emptyName'))
}
}

Expand Down Expand Up @@ -158,7 +163,7 @@ const SaySomethingForm: FC<Props> = props => {
readOnly={readOnly}
value={currentFlowNode.name}
className={style.textInput}
onChanged={renameNode}
onChanged={onChange}
transform={transformText}
/>
</label>
Expand Down

0 comments on commit 0183dfa

Please sign in to comment.