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

fixes #24380 - load bookmarks on demand #5872

Merged
merged 1 commit into from
Aug 6, 2018

Conversation

ohadlevy
Copy link
Member

This commits change that bookmarks are fetched (on every index action)
only once the bookmarks dropdown is opneded, this avoids extra API
call on most index pages when users don't use bookmarks.

This commits change that bookmarks are fetched (on every index action)
only once the bookmarks dropdown is opneded, this avoids extra API
call on most index pages when users don't use bookmarks.
@theforeman-bot
Copy link
Member

Issues: #24380

@ohadlevy
Copy link
Member Author

ping @theforeman/ui-ux for a quick review. /cc @LaViro

Copy link
Member

@amirfefer amirfefer left a comment

Choose a reason for hiding this comment

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

Thanks, Works well !
Could you just add PropTypes ?

@ohadlevy
Copy link
Member Author

@amirfefer adding prop type, changing directory structure (to align to best practices etc) imho is out of scope for this PR and should be done for all existing components?

@sharvit
Copy link
Contributor

sharvit commented Jul 25, 2018

@ohadlevy You can add propTypes without changing the folder structure and we will still get benefits from it.
Later, it will be easier to migrate the folder structure because we will understand the props flow better.

@ohadlevy
Copy link
Member Author

@tstrachota got a minute for a quick review? @sharvit @amirfefer and I agreed that refactoring for all components should be in another PR...

componentDidMount() {
const { url, controller, getBookmarks } = this.props;
loadBookmarks() {
if (this.props.bookmarks.length === 0 && this.props.status !== STATUS.PENDING) {
Copy link
Member

Choose a reason for hiding this comment

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

I am afraid the logic under if will grow.
what about:

const {bookmarks, status, url, controller, getBookmarks} = this.props;
if (bookmarks.length > 0 || status === STATUS.PENDING) {
  // do nothing: bookmarks are being loaded or already loaded earlier
  return ;
}
getBookmarks(url, controller)

In addition, should we add tests?

Other than that LGTM 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

a. I agree the statement might grow, but if it does, we will change as needed?
b. I didnt extract the values just to reduce the amount of const extractions in case its a noop - don't mind changing but ymmv
c. regarding tests, whats the best way to test (now that I'm a bit pushed away from the code)? I can see test that onclick calls the function, and that the condition are tested (e.g. if the action is fired or not)?

Copy link
Member

Choose a reason for hiding this comment

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

I tried to write a test to BookmarksContainer but I realized that the class itself isn't exported and thus getting access to getBookmarks/loadBookmarks is not trivial as I though. 😮

Regarding a and b - you're probably right. 😃

Copy link
Member

Choose a reason for hiding this comment

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

Um, interesting, I actually got access to them but it feels like it's not responding to my click event. I will try to investigate more.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ripcurld any suggestions ?

Copy link
Member

Choose a reason for hiding this comment

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

nope but don't want to block this either. I tested it manually and it works 👍 .

If I figure a way to test it, I will send a pull request.

Copy link
Member

Choose a reason for hiding this comment

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

@ohadlevy I think I worked it out. See here.

Let me know what you think.

Copy link
Contributor

@sharvit sharvit left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @ohadlevy 👍

Copy link
Member

@dLobatog dLobatog left a comment

Choose a reason for hiding this comment

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

Seems to work pretty well, thanks @ohadlevy , I had no idea about this API call on every index page. Thanks @ripcurld & @sharvit for reviewing too

@dLobatog dLobatog merged commit 825acd6 into theforeman:develop Aug 6, 2018
@ohadlevy
Copy link
Member Author

ohadlevy commented Aug 6, 2018 via email

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

Successfully merging this pull request may close these issues.

6 participants