-
Notifications
You must be signed in to change notification settings - Fork 0
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
#161776762 Edit articles #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @samuelbwambale.
There is a bug that should be easily fixed:
When I click on Read more
it shows the article briefly before returning to the dashboard
src/actions/types.js
Outdated
export const CREATE_ARTICLE_SUCCESS = 'CREATE_ARTICLE_SUCCESS'; | ||
export const CREATE_ARTICLE_INITIATED = 'CREATE_ARTICLE_INITIATED'; | ||
export const CREATE_ARTICLE_ERROR = 'CREATE_ARTICLE_ERROR'; | ||
export const LOGOUT_USER = 'LOGOUT_USER'; | ||
export const SEND_RESET_LINK_SUCCESS = 'SEND_RESET_LINK_SUCCESS'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these reset password changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RonKbS Reset-password changes have been removed after rebasing develop branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelbwambale these particular action_types should also be removed since the updated PR for them has not yet been merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RonKbS The action_types have been removed
src/actions/articleActions.js
Outdated
response.data.message, | ||
{ autoClose: 3500, hideProgressBar: true }, | ||
{ | ||
position: toast.POSITION.TOP_CENTER, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelbwambale , please remove this line, the toast position was already set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MuhanguziDavid Line removed to take the default toast settings
7912c35
to
81f206e
Compare
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove redundant line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MuhanguziDavid Line removed
const { title, description, body } = this.state; | ||
const { loading } = this.props; | ||
const { articlePayload, articlePayload: { article } } = this.props; | ||
const { isEditing } = this.state; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 92 and 95 can be put on the same line,
i.e. const { title, description, body, isEditing } = this.state;
Lines 93 and 94 can also be put on the same line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MuhanguziDavid code refactored as advised
); | ||
}); | ||
|
||
// it('should not update an article if not the author', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the commented block of code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MuhanguziDavid Commented code has been removed from the PR
81f206e
to
7047ed0
Compare
@RonKbS the bug causing an article not to be loaded was fixed |
Pull Request Test Coverage Report for Build 513
💛 - Coveralls |
f43385c
to
a419314
Compare
b1847bc
to
2f0f051
Compare
src/actions/articleActions.js
Outdated
errorMessage = 'Re-login and try again'; | ||
} | ||
if (error.response.status === 404) { | ||
errorMessage = 'Please enter valid data'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelbwambale I think we may need a more user-friendly message here. Developers might feel at home when they see this message but the same probably can't be said for other types of authors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the response to Please enter a valid text
. Let me know if this suffices
@@ -185,6 +188,13 @@ describe('likeDislikeAction', () => { | |||
localStorage.setItem('auth_token', 'token'); | |||
const payload = { reaction: 'Like' }; | |||
const slug = 'testing-1-2-3'; | |||
const article_data = { | |||
article: { | |||
body: '<p>The first you’ll want tr, they may have already done this, so components!</p>', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some spelling mistakes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RonKbS This was random text but has been updated to correct spellings
503ef0c
to
f930662
Compare
expect(handleChange).toBeCalled(); | ||
}); | ||
|
||
it('should call handleEditorChange when the there is an input in text editor', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing when the there
on line 47 and 52 to make the test more meaningful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kakaemma lines 47 and 52 have been updated with more descriptive comment
import ReactQuill from 'react-quill'; | ||
import 'react-quill/dist/quill.snow.css'; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kindly consider removing this redundant line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kakaemma Redundant line has been removed
loading={loading} | ||
/>); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line too should be removed and all the other redundant lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kakaemma Redundant line 31 has been removed. Please note that there are some other blank lines left for easy readability of code.
}); | ||
}; | ||
|
||
toggleEdit() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making this an arrow function which binds automatically to the class. Then remove line 21
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @kakaemma toggleEdit()
has been redefined as an arrow function and line 21
deleted.
f930662
to
eed17cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelbwambale I was able to edit an article!
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
eed17cb
to
265c750
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor
src/actions/articleActions.js
Outdated
@@ -62,16 +65,15 @@ export const fetchComments = article => dispatch => { | |||
|
|||
export const fetchArticles = () => dispatch => { | |||
dispatch(getArticlesInitiated(true)); | |||
return axiosInstance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove the return statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return statement has been replaced.
src/actions/articleActions.js
Outdated
.get('/api/article/') | ||
.then((response) => { | ||
dispatch(getAllArticles(response.data.article)); | ||
}); | ||
}; | ||
|
||
export const fetchSpecificArticle = slug => dispatch => { | ||
dispatch(getArticlesInitiated(true)); | ||
return axiosInstance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove both lines of code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getArticlesInitiated(true)
was not adding anything to the app. Instead it was disabling the loading of the list of articles. This was removed. Without any other statement in the arrow function, ESLint suggests that the return statement be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you fetch a new article and it takes longer, what does the user see while that happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a loader to show as the article is being fetched
src/actions/articleActions.js
Outdated
export const updateArticle = (slug, newData) => dispatch => { | ||
toast.dismiss(); | ||
dispatch(editArticleInititated(true)); | ||
axiosInstance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a return statement. updateArticle
should return a promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return statement has been added to return the promise
errorMessage = 'Please enter valid text'; | ||
} | ||
dispatch(editArticleError(errorMessage)); | ||
toast.error(errorMessage, { autoClose: false, hideProgressBar: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are notifying the user of this error, why add it to state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dispatch handles change in state for other state variables such as loading
besides adding the error to the state
const { article: { title, body, description } } = articlePayload; | ||
this.setState({ title }); | ||
this.setState({ body }); | ||
this.setState({ description }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use one setState
statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This piece of code has been refactored as advised
addArticle={addArticle} | ||
resetForm={resetForm} | ||
handleEditorChange={handleEditorChange} | ||
handleChange={handleChange} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add all these props to the props const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constants have been added into a single object const props {}
const title = ''; | ||
const description = ''; | ||
const body = ''; | ||
const loading = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a props object for all these props and pass its spread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constants have been added into a single object const props {}
|
||
it('should call handleSubmit when the form is submitted', () => { | ||
wrapper.find('#add-article-form').simulate('submit'); | ||
expect(handleSubmit).toBeCalled(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test showing what describe handleSubmit
does. Same goes for the rest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was handled in the file NewArticle.test.js
which has the tests for the main component
|
||
it('should call resetForm when the clear button is clicked', () => { | ||
wrapper.find('#clear-button').simulate('click', { preventDefault() {} }); | ||
expect(resetForm).toBeCalled(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test showing what describe resetForm
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was handled in the file NewArticle.test.js
which has the tests for the main component
1bce059
to
7316f39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor
|
||
componentWillReceiveProps(nextProps) { | ||
const { articlePayload } = nextProps; | ||
if (nextProps.articlePayload !== this.props.articlePayload) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intentionally ignore this linting error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was skipped accidentally. It has been restructured.
const { loading, articlePayload, articlePayload: { article } } = this.props; | ||
if (isEditing) { | ||
return ( | ||
<CreateArticleForm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to ArticleForm
. Create
does not sound right in Edit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreateArticleForm
has been renamed to ArticleForm
src/actions/articleActions.js
Outdated
errorMessage = 'Re-login and try again'; | ||
} | ||
if (error.response.status === 404) { | ||
errorMessage = 'Please enter valid text'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does valid text
help the user determine whether its the title, body or description
with the issue? Is there an error message that returns with this error response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The front-end already caters for validation of title
and description
fields. I have updated the message to point to the article body specifically.
payload: true, | ||
}; | ||
const currentState = articlesReducer(initialState, action); | ||
expect(currentState).toEqual({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everyone seems to be doing this which is making this file ambiguous. How about this:
expect(...).toEqual({
...initialState,
loading: action.payload,
});
@samuelbwambale . If it works, advise the next victims.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have refactored this and shared with the team
7316f39
to
a7d006b
Compare
- Enable users to edit articles they authored [Delivers #161776762]
a7d006b
to
8a21670
Compare
What does this PR do?
Enables users to edit articles which they authored
Description of Task to be completed?
Currently, the users are unable to update articles.
This feature enables users to edit articles. Users can only edit the articles they authored.
How should this be manually tested?
Pull the changes on a new branch and run
npm install
run
npm start
to start the serverLog into the app using a registered email and password
Click on profile and select
New Article
to add a new articleSelect the created article from the list of articles by clicking on
Read more
linkOn loading the article, click on edit button and change any of the fields
Click on save button and see the updated article on the profile
What are the relevant pivotal tracker stories?
Screenshots (if appropriate)
Checklist: I completed these to help reviewers
My IDE is configured to follow the ESlint Conventions
I have added tests to cover my changes.
All new and existing tests passed.
My pull request is based on the latest changes of the develop branch.