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

#161776762 Edit articles #28

Merged
merged 1 commit into from
Nov 22, 2018
Merged

#161776762 Edit articles #28

merged 1 commit into from
Nov 22, 2018

Conversation

samuelbwambale
Copy link
Collaborator

@samuelbwambale samuelbwambale commented Nov 15, 2018

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 server
Log into the app using a registered email and password
Click on profile and select New Article to add a new article
Select the created article from the list of articles by clicking on Read more link
On 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.

Copy link
Contributor

@RonKbS RonKbS left a 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

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';
Copy link
Contributor

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

Copy link
Collaborator Author

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

Copy link
Contributor

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.

Copy link
Collaborator Author

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

response.data.message,
{ autoClose: 3500, hideProgressBar: true },
{
position: toast.POSITION.TOP_CENTER,
Copy link
Contributor

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.

Copy link
Collaborator Author

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

}
}


Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove redundant line

Copy link
Collaborator Author

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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 () => {
Copy link
Contributor

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

Copy link
Collaborator Author

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

@samuelbwambale
Copy link
Collaborator Author

@RonKbS the bug causing an article not to be loaded was fixed

@coveralls
Copy link

coveralls commented Nov 17, 2018

Pull Request Test Coverage Report for Build 513

  • 94 of 95 (98.95%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 97.789%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/Articles/EditArticle.js 39 40 97.5%
Totals Coverage Status
Change from base Build 500: 0.2%
Covered Lines: 474
Relevant Lines: 479

💛 - Coveralls

@samuelbwambale samuelbwambale force-pushed the ft-edit-article-161776762 branch 3 times, most recently from f43385c to a419314 Compare November 19, 2018 10:00
@samuelbwambale samuelbwambale force-pushed the ft-edit-article-161776762 branch 2 times, most recently from b1847bc to 2f0f051 Compare November 19, 2018 14:26
errorMessage = 'Re-login and try again';
}
if (error.response.status === 404) {
errorMessage = 'Please enter valid data';
Copy link
Contributor

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.

Copy link
Collaborator Author

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>',
Copy link
Contributor

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.

Copy link
Collaborator Author

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

@samuelbwambale samuelbwambale force-pushed the ft-edit-article-161776762 branch 3 times, most recently from 503ef0c to f930662 Compare November 19, 2018 17:12
expect(handleChange).toBeCalled();
});

it('should call handleEditorChange when the there is an input in text editor', () => {
Copy link
Contributor

@kakaemma kakaemma Nov 19, 2018

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.

Copy link
Collaborator Author

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';


Copy link
Contributor

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.

Copy link
Collaborator Author

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}
/>);
});

Copy link
Contributor

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.

Copy link
Collaborator Author

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() {
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

Copy link
Contributor

@MuhanguziDavid MuhanguziDavid left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@mendozabree mendozabree left a 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

Copy link
Contributor

@RonKbS RonKbS left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@dondrzzy dondrzzy left a comment

Choose a reason for hiding this comment

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

Please refactor

@@ -62,16 +65,15 @@ export const fetchComments = article => dispatch => {

export const fetchArticles = () => dispatch => {
dispatch(getArticlesInitiated(true));
return axiosInstance
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

.get('/api/article/')
.then((response) => {
dispatch(getAllArticles(response.data.article));
});
};

export const fetchSpecificArticle = slug => dispatch => {
dispatch(getArticlesInitiated(true));
return axiosInstance
Copy link
Contributor

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?

Copy link
Collaborator Author

@samuelbwambale samuelbwambale Nov 20, 2018

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

Copy link
Contributor

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?

Copy link
Collaborator Author

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

export const updateArticle = (slug, newData) => dispatch => {
toast.dismiss();
dispatch(editArticleInititated(true));
axiosInstance
Copy link
Contributor

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.

Copy link
Collaborator Author

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 });
Copy link
Contributor

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?

Copy link
Collaborator Author

@samuelbwambale samuelbwambale Nov 20, 2018

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 });
Copy link
Contributor

Choose a reason for hiding this comment

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

Use one setState statement.

Copy link
Collaborator Author

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}
Copy link
Contributor

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.

Copy link
Collaborator Author

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

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();
Copy link
Contributor

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

Copy link
Collaborator Author

@samuelbwambale samuelbwambale Nov 20, 2018

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();
Copy link
Contributor

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.

Copy link
Collaborator Author

@samuelbwambale samuelbwambale Nov 20, 2018

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

@samuelbwambale samuelbwambale force-pushed the ft-edit-article-161776762 branch 3 times, most recently from 1bce059 to 7316f39 Compare November 21, 2018 10:12
Copy link
Contributor

@dondrzzy dondrzzy left a 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) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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
Copy link
Contributor

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.

Copy link
Collaborator Author

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

errorMessage = 'Re-login and try again';
}
if (error.response.status === 404) {
errorMessage = 'Please enter valid text';
Copy link
Contributor

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?

Copy link
Collaborator Author

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({
Copy link
Contributor

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.

Copy link
Collaborator Author

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

- Enable users to edit articles they authored

[Delivers #161776762]
@dondrzzy dondrzzy merged commit 1c3190b into develop Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants