Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix #247 comment patch and delete addressed #347

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

Gerald1614
Copy link

I removed v-on:input=“editorText” from commentForm.vue and comment.vue as I do not think they are useful.
I just used an existing action to trigger a mutation after comment update to get the field being updated just after the submission of the updated comment.
then i discovered that the same process happened when the comment update was cancelled.
i then added a .prevent on the cancel button
@click.prevent=“cancelEdit"

for delete I added a new mutation called removeComment

removeComment (state, id) {
const cmt = state.comments[state.comments.findIndex(comment => comment._id === id)]
console.log(cmt)
cmt.deleted = true
},

which is called by this action

remove ({commit}, id) {
commit('removeComment', id)
return this.app.$api.service('comments').remove(id)
// .then(() => {
// commit('removeComment', id)
// })
}

definitive code should be
remove```
({commit}, id) {
return this.app.$api.service('comments').remove(id)
.then(() => {
commit('removeComment', id)
})
}

but the API was sending me an error message ('item not found', which is weird as I did not touch the code to call the API) that prevented the mutation to happen. 
It would be greta if someone could test the code with the .then so mutation is done only if the change happened in the backend.

thanks for your feedback
Gerald

Copy link
Contributor

@roschaefer roschaefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gerald1614 thank you so much for your contribution!

I haven't tested this code but I think it is very strange that there is no need for editorText. I thought, without it, you cannot enter text input anymore.

In the meantime, until sb. gives it a check, you can already improve these two things here.

Also: You can improve the description of your PR if you markup your code listing with triple backticks `

store/comments.js Outdated Show resolved Hide resolved
components/Comments/Comment.vue Outdated Show resolved Hide resolved
@roschaefer
Copy link
Contributor

Some more things:

  • If possible, rebase your feature branch like this:
    git remote add origin [email protected]:Human-Connection/WebApp.git
    git fetch origin
    git rebase origin/master
  • Add fix NUMBER_OF_ISSUE to your description of the PR. That will link your PR with the issue you are trying to fix.
  • Edit the PR title in a way, that would help a non-developer to understand the problem and the fix. We will use the PR titles for a changelog

@Gerald1614
Copy link
Author

ok I will do it later thanks

@Gerald1614
Copy link
Author

HI @roschaefer, I did commit a new version that removes all comments. I also created a mutation for the update so the code is clean for both delete and update of comment. i do not know why there is a conflict with yarn.lock. i thought those kind of files would be ignored. i dod not touched it. maybe you can just igmore the changes on this file and try the rest.

@Gerald1614
Copy link
Author

i just made another commit with an updated version of sanitize-html and now the only discripency is the integrity check from yarn.

@Lulalaby Lulalaby self-requested a review November 9, 2018 20:21
Lulalaby
Lulalaby previously approved these changes Nov 9, 2018
Copy link
Contributor

@Lulalaby Lulalaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets try

@Lulalaby
Copy link
Contributor

Lulalaby commented Nov 9, 2018

@Gerald1614 can i remove WIP?

@Gerald1614
Copy link
Author

for me the code is working so yes, you can remove the WIP

Copy link
Contributor

@roschaefer roschaefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gerald1614 thank you so much for making a stab at issue #247. If your PR is related to an issue, you can add fix #247 to the description of the pull request. It will automagically close the respective issue when this PR is merged, see Github's autoclosing feature.

Also, it would be great to add software-tests to your PR. I will try to scaffold them for you.

@@ -111,10 +118,14 @@ export const actions = {
create ({dispatch}, data) {
return this.app.$api.service('comments').create(data)
},
patch ({dispatch}, data) {
patch ({dispatch, commit}, data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove obsolete argument dispatch if possible

@@ -26,6 +26,14 @@ export const mutations = {
clear (state) {
state.comments = []
},

updateComment (state, data) {
state.comments[state.comments.findIndex(comment => comment._id === data._id)].contentExcerpt = data.content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why only contentExerpt and why contentExcerpt = data.content? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it is the field used to store the text of the comment. so here, once the comment has been updated on the backend, i update the state of the store through a mutation. in previous code, there was no mutation so the value of the state to which the computed property was bind did not trigger a change of value, this is why a refresh was required (all comments were loaded from the backend) with the mutation, the change of state will trigger a change in the computed property and vuejs will update teh UI accordingly. Another nice effect is to limit requests to the backend. if the store is updated when we update, delete or create a comment, there is no reason to send a request to the back end to access the data, we should trust the state of the store.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but why is contentExcerptoverwritten with 'content`? Is only content given? If you don't want to wait for the API response, feel free to change or remove the Tests I wrote yesterday.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually, calls to APIs are done in actions. this is what we do here:
patch ({commit}, data) {
return this.app.$api.service('comments').patch(data._id, data)
.then(() => {
commit('updateComment', data)
})
},
I Do not know what the API is doing but I guess it takes all the data. but for my store, I am changing only ContentExcerpt because it is the only thing a user can modify.
I am waiting for the API to make the change before initiating the mutation. if the API answers with a promise I then call the mutation. No need to go back to the API at the mutation level. does it make sense ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roschaefer , now i understand why you asked why i was updating contentExcerpt only. i guess your ask is why i do not update Content object ? it is because the comment API is not returning content. when i look at the comment object, the API returns comment objects with content Excerpt but no content. and I guess this is why I receive an error message on my promise. on the API when you try to delete a comment in fact you allocate the comment.deleted object to true and change the comment.content = "DELETED" but this field does not exist. so the API sends back an error message to the front end, just because you try to patch a filed that does not exist. I think it is clearly a bug. I am not familiar enough with Feather to make further investigations but as you said i may create a bug so that somebody could look at this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: the 'content' field exists on the backend side but is omitted (https://github.com/Human-Connection/API/blob/develop/server/services/comments/comments.hooks.js#L122) when using find(). That is why it is not in the store when the page is loaded as it uses the find method. I presume this was done to preserve bandwidth as by default only the excerpts of the comments are shown. The content field is then loaded when the comment is expanded or edited (https://github.com/Human-Connection/WebApp/blob/develop/components/Comments/Comment.vue#L187-L221). In that regard, I think you need to fetch the comment with get() before you do any mutation on it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ionphractal not sure doing two fetch reduce the bandwidth. I do not know if there are other reasons behind that but I saw that at several places. so in fact we do a lot of back and forth with the backend as we fetch data a first time, do another one to fetch the comment and then a request to delete the comment. if we could get the full object to the backend it could perform the update of the comment.content and return a 200 message so i can proceed to the mutation of the state. we save a fetch

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ionphractal, in fact, returning the content is just one way we could leverage more the store instead of fetching data agin, but to solve my fix on deletion. can you check why the deletion of comment call is not returning a 200 message? it is is the only thing that is missing to close this issue. my understanding is that we are moving the backend so no need to chnage no the way of dealign with the backend bu tthis 404 message is preventing the promise to be solved.

@@ -170,9 +169,7 @@
remove: 'comments/remove',
patch: 'comments/patch'
}),
editorText (newText) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, the editorText method was used to show the confirmation dialog, when a user accidently or intentionally clicked a button to leave the current page. So your latest changes would not be lost. @ionphractal could you confirm?

Actually I would love to see you @Gerald1614 pair-program with a community member. @Gerald1614 did you join our Discord Server already? You can organize a pair-programming with e.g. @ionphractal. He speaks perfect English as far as I know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's the invitation link to our public Discord Server: https://discord.gg/6ub73U3

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am on discord. i have a very busy week but i will use discord to contact @ionphractal. I will be happy to spend time with him. it will be easier than playign ping pong with chat messages. thanks, Gerald

@@ -1,18 +0,0 @@
# WEBAPP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was .env.example removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my mistake, in the documentation (https://docs.human-connection.org/documentation/web-app/installation) it mentions .env file so when i first installed the product i changed .env.example by .env

@@ -5,10 +5,12 @@
"@ava/babel-plugin-throws-helper@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@ava/babel-plugin-throws-helper/-/babel-plugin-throws-helper-2.0.0.tgz#2fc1fe3c211a71071a4eca7b8f7af5842cd1ae7c"
integrity sha1-L8H+PCEacQcaTsp7j3r1hCzRrnw=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gerald1614 your yarn version is between v1.10.0 and v1.12.0 see yarn's release notes here. 😆 try to avoid unrelated changes in your PR. You can e.g. git checkout origin/master -- yarn.lock.

If you want, you can create a new PR called "Add integrity-sha to yarn.lock". It doesn't seem to hurt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was my adding with the integrity. i resolved it via the jnternal github resolver on this page. so there was no commit msg to ad

store/comments.js Outdated Show resolved Hide resolved
@roschaefer
Copy link
Contributor

@Gerald1614 I worked on your branch and added a couple of tests that expose bugs in the current implementation. You can run those tests with yarn run test.

I hope these tests give you some guidelines for testing. The vue-test-utils api docs are a great read!

Please contact @ionphractal for the changes related to the confirmation dialog.

@roschaefer
Copy link
Contributor

Great! The build server has failed. That's what we want.

@roschaefer
Copy link
Contributor

roschaefer commented Nov 12, 2018

Ah, one more thing. Usually, we should use https://feathers-plus.github.io/v1/feathers-vuex/ instead of re-implementing this behaviour. We already use it for another pull request. I don't ask you @Gerald1614 to refactor the store/comments.js with feathers-vuex, but I just want to make you aware of that library.

Human connection is transitioning to GraphQL+Express+Neo4j instead of REST+FeathersJS+MongoDB and we will replace FeathersJS, so it's not worth to spend time on feathers-vuex anymore.

@Gerald1614
Copy link
Author

@roschaefer , I just looked quickly at your commit with async await utilisation. You are using a const that is then not used and it makes the test failed. if we look at the vuex doc here is how async await needs to be used differnetly
actions: {
async actionA ({ commit }) {
commit('gotData', await getData())
},
async actionB ({ dispatch, commit }) {
await dispatch('actionA') // wait for actionA to finish
commit('gotOtherData', await getOtherData())
}
}
the other issue we are facing is that the API removes the comment but returns a bad request message that prevents the promise to then get resolved. I know that becasue initially i tried to implement the following code that never got executed
remove ({commit}, id) {
return this.app.$api.service('comments').remove(id)
.then(()=> {
commit('removeComment', id)
}
}
I am not familiar with the APi but it would be good somebody would check the code i added is not affected the request so the bug was there before. I agree with you we should not commit the transaction before knowing the API did execute the removal.

@roschaefer
Copy link
Contributor

@Gerald1614 could you please format the inline code with backticks? That makes it much easier to read. See Github help.

I know that I added constants that are not used. I wanted to give you a hint, how to make the tests pass 😉

If the backend always responds with bad message upon removal, that is a serious bug and is worth a bug report.

@roschaefer
Copy link
Contributor

@Gerald1614 I mentioned you in our video blog! https://youtu.be/LiD3BmH09z8

What's the status on this PR? The build server crashed, I see

The command "eval git clone --depth=50 --branch=no-refresh-after-comment-update-or-delete https://github.com/Human-Connection/WebApp.git Human-Connection/WebApp " failed. Retrying, 2 of 3.

What the heck? https://travis-ci.org/Human-Connection/WebApp/jobs/454177158#L423

@Gerald1614
Copy link
Author

@roschaefer since a few days, the app is crashing and I do not know why as i did nto touch anything. it looks like it is going back and forward with the backend. I also discuss with @ionphractal and i need anyway to bring back the code used for dialog box in case people are leaving the page. i am thinking about creating a new branch from scratch and reduce modifications to address the refresh aspects. the PR can not anyway be used as the promise returned by the backend sends a 404 message so i can not chain with a mutation. it is being addressed.

@Gerald1614
Copy link
Author

@roschaefer I just cloned the repository and when i run it I am facing the same issue as i had with my code. i do not =know if somebody else made same changes recently but while the app is workign fine, i receive tons of logs that repeat eternally ### refreshJWT auth/init true false

API: find categories

data undefined

API: get users

data undefined

API: get users

data undefined

API: find settings

data undefined

API: find status

data undefined
I thought I may have done something but it is not the case, i am using current API and current WebApp and i have same message as on my fork.

@ionphractal
Copy link

@Gerald1614 When I checked out your repo/branch, the app didn't crash on me. What's the error message? Maybe try deleting node_modules and executing yarn again. Regarding the messages you posted in your last comment: that's "normal" for me to get.

Yes, things got quite messy, which is why they started developing the app from scratch, see 'nitro' repos.

Regarding the 404, I opened a PR yesterday: Human-Connection/API#182

@Gerald1614
Copy link
Author

Hi @ionphractal , @roschaefer, because of those messages I thought there was something corrupted so i restarted all my repository from scratch to provide you a clean code, instead of creating a new branch i just deleted all i did in the past. i just made a new PR (#361) that addresses this issue. Please proceed with the other PR instead of this one. thanks to the PR made on teh backend, the frontend behaves now as expected which mean I receive a success message from the API which allows me to solve my promise when I delete a comment and the comment is deleted without having to refresh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants