From e338537dbf58b8eb9e1a7ca02b1d96ae1aad5fff Mon Sep 17 00:00:00 2001 From: Miguel-Alves Date: Thu, 25 Feb 2021 19:52:46 -0300 Subject: [PATCH 1/8] Correcting dev environment configuration problem Co-authored-by: @AmandaMuniz --- app/src/utils/url_routes.js | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/utils/url_routes.js b/app/src/utils/url_routes.js index 03a9634..362e71e 100644 --- a/app/src/utils/url_routes.js +++ b/app/src/utils/url_routes.js @@ -1,4 +1,4 @@ -export const BASE = process.env.REACT_APP_URL_API + 'api/v1/'; +export const BASE = 'http://localhost:8000/api/v1/'; export const ITEMS_BASE = BASE + 'projects/1/'; export const UTTER_URL = ITEMS_BASE + "utters/"; diff --git a/docker-compose.yml b/docker-compose.yml index f323075..bf71d1e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: ports: - 3000:3000 environment: - REACT_APP_URL_API: http://localhost:8000/ # API + REACT_APP_URL_API: http://localhost:8000/ #API stdin_open: true volumes: - ./app:/botflow/ From 2e4ab956f0d3dc9e9b06d1cbf1481ae8ac873d92 Mon Sep 17 00:00:00 2001 From: Miguel-Alves Date: Tue, 2 Mar 2021 01:14:49 -0300 Subject: [PATCH 2/8] Not saving empty contents and ignoring them on validation --- app/src/components/ToolbarName.js | 12 +++++++++++- app/src/pages/IntentPage.js | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/components/ToolbarName.js b/app/src/components/ToolbarName.js index 3ccb835..0506d84 100644 --- a/app/src/components/ToolbarName.js +++ b/app/src/components/ToolbarName.js @@ -69,7 +69,17 @@ export default class ToolbarName extends Component { } handleClick() { - this.props.saveData(this.props.item); + let realContent = []; + let newIntent = this.props.item; + + this.props.item.samples.forEach(content => { + if (content.trim().length !== 0) { + realContent.push(content); + } + }); + newIntent.samples = realContent; + //console.log("Formatado:", newIntent); + this.props.saveData(newIntent); } handleDelete() { diff --git a/app/src/pages/IntentPage.js b/app/src/pages/IntentPage.js index 28517f0..12e61c7 100644 --- a/app/src/pages/IntentPage.js +++ b/app/src/pages/IntentPage.js @@ -46,15 +46,25 @@ class IntentPage extends Component { } checkEmptyFieldsIntent(samples) { - let changed = true; + let status = true; + let emptyField = false; + let fullfilledIntents = 0; if (samples !== undefined) { samples.forEach(sample => { - if (sample.trim().length === 0) { - changed = false; + if (sample.trim().length === 0) { + emptyField = true; + } else { + fullfilledIntents++; } }); + + if (fullfilledIntents === 0 && emptyField) { + status = false; + } else { + status = true; + } } - return changed; + return status; } isButtonEnabled() { From 8fb36d0fb19cff810477f80e9953384dfd26b697 Mon Sep 17 00:00:00 2001 From: Miguel-Alves Date: Tue, 2 Mar 2021 01:22:44 -0300 Subject: [PATCH 3/8] Not showing empty intent balloongs anymore --- app/src/ducks/intents.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/ducks/intents.js b/app/src/ducks/intents.js index 1eb3ed0..0a3a29a 100644 --- a/app/src/ducks/intents.js +++ b/app/src/ducks/intents.js @@ -59,6 +59,7 @@ export const undoDeleteIntentContent = (state = INITIAL_STATE) => { export const selectIntent = (state = INITIAL_STATE, action) => { let selected_item = action.item; let selected_item_position = action.item_position; + let nonEmptySamples=[]; if (selected_item_position < 0) { state.intents.find((item, index) => { @@ -67,6 +68,14 @@ export const selectIntent = (state = INITIAL_STATE, action) => { }); } + selected_item.samples.forEach(sample => { + if (sample.trim().length !== 0) { + nonEmptySamples.push(sample); + } + }); + + selected_item.samples=nonEmptySamples; + return { ...state, id: selected_item.id, From b1955cb32cbe623bc13c17da8d59c66af038faa5 Mon Sep 17 00:00:00 2001 From: Miguel-Alves Date: Tue, 2 Mar 2021 02:25:22 -0300 Subject: [PATCH 4/8] Removing empty balloons from utter upon loading --- app/src/components/ToolbarName.js | 18 +++++++++++------- app/src/ducks/utters.js | 10 ++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/components/ToolbarName.js b/app/src/components/ToolbarName.js index 0506d84..bed148a 100644 --- a/app/src/components/ToolbarName.js +++ b/app/src/components/ToolbarName.js @@ -72,14 +72,18 @@ export default class ToolbarName extends Component { let realContent = []; let newIntent = this.props.item; - this.props.item.samples.forEach(content => { - if (content.trim().length !== 0) { - realContent.push(content); - } - }); - newIntent.samples = realContent; + if (this.props.item.samples !== undefined) { + this.props.item.samples.forEach(content => { + if (content.trim().length !== 0) { + realContent.push(content); + } + }); + newIntent.samples = realContent; + this.props.saveData(newIntent); + } else { + this.props.saveData(this.props.item); + } //console.log("Formatado:", newIntent); - this.props.saveData(newIntent); } handleDelete() { diff --git a/app/src/ducks/utters.js b/app/src/ducks/utters.js index 1799a34..d339a78 100644 --- a/app/src/ducks/utters.js +++ b/app/src/ducks/utters.js @@ -82,6 +82,16 @@ export const selectUtter = (state = INITIAL_STATE, action) => { }); } + + for (let i=0; i< selected_item.alternatives[0].length; i++) { + if (selected_item.alternatives[0][i].trim().length === 0){ + selected_item.alternatives[0].splice(i, 1); + console.log("ACERTOU!: ", selected_item.alternatives[0]); + }; + } + + + return { ...state, helper_text: "", From b623b2843cf42235c60c45082333d3b537a2cee7 Mon Sep 17 00:00:00 2001 From: Miguel-Alves Date: Thu, 8 Apr 2021 10:52:43 -0300 Subject: [PATCH 5/8] Not saving empty content anymore, removing ballons if present --- app/src/components/ToolbarName.js | 23 ++++++++++++++++++++++- app/src/pages/UtterPage.js | 29 ++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/app/src/components/ToolbarName.js b/app/src/components/ToolbarName.js index bed148a..0be94e4 100644 --- a/app/src/components/ToolbarName.js +++ b/app/src/components/ToolbarName.js @@ -80,7 +80,28 @@ export default class ToolbarName extends Component { }); newIntent.samples = realContent; this.props.saveData(newIntent); - } else { + } + //code above reffers to intents, so we need to treat utters also + else if (this.props.item.alternatives !== undefined) { + if (this.props.item.alternatives.length === 1) { + this.props.item.alternatives[0].forEach(content => { + if (content.trim().length !== 0) { + realContent.push(content); + } + }); + newIntent.alternatives[0] = realContent; + this.props.saveData(newIntent); + } else { + this.props.item.alternatives.forEach(content => { + if (content[0].trim().length !== 0) { + realContent.push(content); + } + }); + newIntent.alternatives = realContent; + this.props.saveData(newIntent); + } + } + else { this.props.saveData(this.props.item); } //console.log("Formatado:", newIntent); diff --git a/app/src/pages/UtterPage.js b/app/src/pages/UtterPage.js index f71a94e..fe5d7d4 100644 --- a/app/src/pages/UtterPage.js +++ b/app/src/pages/UtterPage.js @@ -58,16 +58,27 @@ class UtterPage extends Component { checkEmptyFieldsUtter(alternatives) { let changed = true; + let emptyField = false; + let fullfilledUtters = 0; + if (alternatives !== undefined) { - alternatives.forEach(alternative => { - alternative.forEach(text => { - if (text.trim().length === 0) { - changed = false; - } - }) - }); - } - return changed; + alternatives.forEach(alternative => { + alternative.forEach(content => { + if (content.trim().length === 0) { + emptyField = true; + } else { + fullfilledUtters++; + } + }) + }); + + if (fullfilledUtters === 0 && emptyField) { + changed = false; + } else { + changed = true; + } + } + return changed; } isButtonEnabled() { From e5bc01d3d494ef3844d5eebb080b315c5d3ac3ee Mon Sep 17 00:00:00 2001 From: Miguel-Alves Date: Thu, 8 Apr 2021 11:07:42 -0300 Subject: [PATCH 6/8] Adding confirmation message upon saving, stating empty content was removed --- app/package.json | 2 ++ app/src/components/ToolbarName.js | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/app/package.json b/app/package.json index 2dc7b2f..5058fba 100644 --- a/app/package.json +++ b/app/package.json @@ -8,6 +8,8 @@ "@svgr/cli": "^4.3.2", "axios": "^0.19.0", "react": "^16.8.6", + "react-alert": "^7.0.2", + "react-alert-template-basic": "^1.0.0", "react-beautiful-dnd": "^11.0.5", "react-dom": "^16.8.6", "react-redux": "^7.1.0", diff --git a/app/src/components/ToolbarName.js b/app/src/components/ToolbarName.js index 0be94e4..77ef4e9 100644 --- a/app/src/components/ToolbarName.js +++ b/app/src/components/ToolbarName.js @@ -11,6 +11,8 @@ import MoreVertIcon from '@material-ui/icons/MoreVert'; import InfoIcon from '@material-ui/icons/InfoOutlined'; import Tooltip from '@material-ui/core/Tooltip'; +import { Alert } from 'react-alert'; + const style = { toolbar: { background: "#f6f9f9", @@ -68,10 +70,18 @@ export default class ToolbarName extends Component { } } + sendAlert() { + alert("Balões vazios foram removidos!"); + } + handleClick() { let realContent = []; let newIntent = this.props.item; + this.sendAlert(); + + + if (this.props.item.samples !== undefined) { this.props.item.samples.forEach(content => { if (content.trim().length !== 0) { From c05130aee9bc4cb79392cd94fcc9bd26b9b5d85a Mon Sep 17 00:00:00 2001 From: Miguel-Alves Date: Thu, 8 Apr 2021 12:31:16 -0300 Subject: [PATCH 7/8] Handling API errors on front --- app/src/components/ToolbarName.js | 1 - app/src/ducks/intents.js | 20 +++++++++++++++++++- app/src/ducks/stories.js | 19 +++++++++++++++++++ app/src/ducks/utters.js | 15 +++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/app/src/components/ToolbarName.js b/app/src/components/ToolbarName.js index 77ef4e9..d9feac9 100644 --- a/app/src/components/ToolbarName.js +++ b/app/src/components/ToolbarName.js @@ -11,7 +11,6 @@ import MoreVertIcon from '@material-ui/icons/MoreVert'; import InfoIcon from '@material-ui/icons/InfoOutlined'; import Tooltip from '@material-ui/core/Tooltip'; -import { Alert } from 'react-alert'; const style = { toolbar: { diff --git a/app/src/ducks/intents.js b/app/src/ducks/intents.js index 0a3a29a..6145ee5 100644 --- a/app/src/ducks/intents.js +++ b/app/src/ducks/intents.js @@ -15,6 +15,18 @@ const INITIAL_STATE = { old_content: [''], }; + +function sendAlert(response) { + if (response.status === 404) { + alert("Desculpe, não foi possível encontrar o objeto de pesquisa!"); + } else if (response.status === 400) { + alert("Desculpe, algum caracter inválido foi inserido ou falta alguma informação\nFavor revisar.") + } + else if (response.status === undefined) { + alert("Desculpe, houve um erro de rede.\nFavor verificar a conexão!"); + } +} + export const addIntent = (state = INITIAL_STATE) => { let new_intent = [...state.content]; new_intent.push('') @@ -132,13 +144,14 @@ export const createOrUpdateItem = (mode = 'post', new_item, message = '') => { await axios[mode](mode_url, new_item) .then((resp) => { intent = resp.data; - }) + }); await dispatch(Creators.getIntents()); await dispatch(Creators.selectIntent(intent.id, -1)); dispatch(Creators.notifyAction(message)); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -158,6 +171,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(INTENT_URL + id); await dispatch({ type: Types.SELECT_INTENT, item: response.data, item_position: item_position }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -168,6 +182,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(INTENT_URL); await dispatch({ type: Types.GET_INTENTS, intents: response.data }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -185,11 +200,14 @@ export const { Types, Creators } = createActions({ return async (dispatch) => { try { await axios.delete(INTENT_URL + delete_intent_id); + await dispatch(Creators.getIntents()); await dispatch(Creators.notifyAction(message.intent.deleted)); await dispatch(Creators.createNewIntent()) + } catch (error) { + sendAlert(error.response); throw (error); } } diff --git a/app/src/ducks/stories.js b/app/src/ducks/stories.js index 9c57474..2be84d6 100644 --- a/app/src/ducks/stories.js +++ b/app/src/ducks/stories.js @@ -18,6 +18,17 @@ const INITIAL_STATE = { content_text_validation: "" }; +function sendAlert(response) { + if (response.status === 404) { + alert("Desculpe, não foi possível encontrar o objeto de pesquisa!"); + } else if (response.status === 400) { + alert("Desculpe, algum caracter inválido foi inserido ou falta alguma informação\nFavor revisar.") + } + else if (response.status === undefined) { + alert("Desculpe, houve um erro de rede.\nFavor verificar a conexão!"); + } +} + function createArrayObjCopyOf(samples = []) { return samples.map(text => { return { ...text } }); } @@ -161,6 +172,7 @@ export const createOrUpdateItem = (mode = 'post', new_item, message = "") => { await dispatch(Creators.getStory(response.data.id)); await dispatch(Creators.notifyAction(message)); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -180,6 +192,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(INTENT_URL + intent.id + '/example'); await dispatch({ type: Types.ADD_TO_STORY, item: response.data, mode: "intent" }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -190,6 +203,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(UTTER_URL + utter.id + '/example'); await dispatch({ type: Types.ADD_TO_STORY, item: response.data, mode: "utter" }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -200,6 +214,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(INTENT_URL); await dispatch({ type: Types.GET_INTENTS, intents: response.data }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -210,6 +225,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(UTTER_URL); await dispatch({ type: Types.GET_UTTERS, utters: response.data }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -229,6 +245,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(STORY_URL + '?filter=' + value); await dispatch({ type: Types.GET_STORIES, stories: response.data }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -241,6 +258,7 @@ export const { Types, Creators } = createActions({ await dispatch({ type: Types.GET_STORY, story: response.data }); } } catch (error) { + sendAlert(error.response); throw (error); } } @@ -253,6 +271,7 @@ export const { Types, Creators } = createActions({ await dispatch(Creators.notifyAction(message.story.deleted)); } } catch (error) { + sendAlert(error.response); throw (error); } } diff --git a/app/src/ducks/utters.js b/app/src/ducks/utters.js index d339a78..842bdc2 100644 --- a/app/src/ducks/utters.js +++ b/app/src/ducks/utters.js @@ -15,6 +15,17 @@ const INITIAL_STATE = { multiple_alternatives: false, }; +function sendAlert(response) { + if (response.status === 404) { + alert("Desculpe, não foi possível encontrar o objeto de pesquisa!"); + } else if (response.status === 400) { + alert("Desculpe, algum caracter inválido foi inserido ou falta alguma informação\nFavor revisar.") + } + else if (response.status === undefined) { + alert("Desculpe, houve um erro de rede.\nFavor verificar a conexão!"); + } +} + function createArrayCopyOf(items) { if (items !== undefined) { return items.map(utter => utter.map(text => text)); @@ -178,6 +189,7 @@ export const createOrUpdateItem = (mode = 'post', new_item, message = "") => { await dispatch(Creators.notifyAction(message)); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -198,6 +210,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(UTTER_URL + id); await dispatch({ type: Types.SELECT_UTTER, item: response.data, item_position: item_position }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -208,6 +221,7 @@ export const { Types, Creators } = createActions({ const response = await axios.get(UTTER_URL); await dispatch({ type: Types.GET_UTTERS, utters: response.data }); } catch (error) { + sendAlert(error.response); throw (error); } } @@ -230,6 +244,7 @@ export const { Types, Creators } = createActions({ await dispatch(Creators.createNewUtter()) } catch (error) { + sendAlert(error.response); throw (error); } } From 2b5008e456dfbb95761babf5e4f812272e76186e Mon Sep 17 00:00:00 2001 From: Miguel-Alves Date: Wed, 12 May 2021 20:01:28 -0300 Subject: [PATCH 8/8] Adding verification to the error that was missing --- app/src/ducks/stories.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/ducks/stories.js b/app/src/ducks/stories.js index 2be84d6..c8df368 100644 --- a/app/src/ducks/stories.js +++ b/app/src/ducks/stories.js @@ -19,6 +19,11 @@ const INITIAL_STATE = { }; function sendAlert(response) { + if (response === undefined ) { + alert('Desculpe! Não conseguimos conectar. Verifique sua conexão com a internet ou nossas redes sociais para checar se estamos online!'); + return; + } + if (response.status === 404) { alert("Desculpe, não foi possível encontrar o objeto de pesquisa!"); } else if (response.status === 400) {