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 #24041 - Move HW Models Table to pf-react #5755

Merged
merged 1 commit into from
Feb 21, 2019
Merged

Fixes #24041 - Move HW Models Table to pf-react #5755

merged 1 commit into from
Feb 21, 2019

Conversation

boaz0
Copy link
Member

@boaz0 boaz0 commented Jun 29, 2018

This is almost ready -

  • Need to add tests to Rails. I will be working on it. In addition, I will add integration tests to ModelsTable.

  • I did the best I can to make the table look similar to what it looked before. However, Katello implementation didn't fit here. Probably because I am not using Pagination and Empty State is rendered by Rails now.

  • I didn't enter the pagination here, I will do that in the next PR. I wanted this PR to be smaller and easy to review as much as possible.

Thanks.

@theforeman-bot
Copy link
Member

Issues: #24041

app/models/model.rb Outdated Show resolved Hide resolved
app/models/model.rb Outdated Show resolved Hide resolved
app/models/model.rb Outdated Show resolved Hide resolved
app/models/model.rb Outdated Show resolved Hide resolved
app/models/model.rb Outdated Show resolved Hide resolved
app/models/model.rb Outdated Show resolved Hide resolved
Copy link

@waldenraines waldenraines left a comment

Choose a reason for hiding this comment

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

Code looks good overall to me, just a few comments. Would be good to get @sharvit, @amirfefer, and/or @tstrachota to have a look as well.

app/models/model.rb Outdated Show resolved Hide resolved
Copy link
Member

@ohadlevy ohadlevy left a comment

Choose a reason for hiding this comment

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

basic comments on the rails side, didnt look at the js yet.

app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/models/model.rb Outdated Show resolved Hide resolved
));

const orderChars = {
ASC: '▲',
Copy link
Member

Choose a reason for hiding this comment

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

looking at PF documentation at https://www.patternfly.org/pattern-library/

they have the following html for table headers:

<th
  class="sorting_asc"
  tabindex="0"
  aria-controls="patternTable"
  rowspan="1"
  colspan="1"
  aria-sort="ascending"
  aria-label="Pattern: activate to sort column descending"
>
  Pattern
</th>

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.

@ripcurld Great progress, I left some inline comments.

Looks like there is no tooltip:
screenshot from 2018-07-04 15-22-32
you can use EllipsisWithTooltip

Foreman test failures are related: Please fix the hw-model integration test.

app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/controllers/models_controller.rb Outdated Show resolved Hide resolved
app/controllers/models_controller.rb Outdated Show resolved Hide resolved
@ohadlevy
Copy link
Member

@boaz0
Copy link
Member Author

boaz0 commented Feb 14, 2019

@sharvit @ohadlevy can you please take a look?
Thanks.

@ohadlevy
Copy link
Member

ohadlevy commented Feb 14, 2019 via email

@ohadlevy
Copy link
Member

@glekner can you review please? thanks.

@timogoebel timogoebel dismissed their stale review February 15, 2019 08:08

I don't have time to check again.

@timogoebel
Copy link
Member

@ohadlevy: I trust you with this one. Feel free to merge whenever you think this is ready.

sharvit
sharvit previously approved these changes Feb 17, 2019
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

@sharvit
Copy link
Contributor

sharvit commented Feb 17, 2019

Test failures seem related

Copy link
Contributor

@glekner glekner left a comment

Choose a reason for hiding this comment

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

Awesome work @boaz0 !
I believe we need to change render method of the table

* the parameters and the values are the parameters' values.
* @param {String} url - the URL
*/
export const getURIQuery = url => new URI(url).query(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll probably want to move all the URI helpers from PaginationHelper to common/helpers or another file in the future.

);

return (
<Spinner size="lg" loading={this.state.initialLoading}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I have mixed feelings about this.
I think its good to show a spinner for the initial loading, but it also shows when changing pages,
the page flickers and the table disappears.

IMO, you should check the state, if the results array is empty, show a spinner, if not show the table. this way, there won't be any flickers, and I think you can remove the internal state of the component along with the componentDidUpdate and stopSpinner

Suggested change
<Spinner size="lg" loading={this.state.initialLoading}>
if (results.length > 0) return renderTable;
return <Spinner size="lg" loading />;

@ohadlevy
Copy link
Member

ohadlevy commented Feb 17, 2019 via email

@ohadlevy
Copy link
Member

@boaz0 what did you decided to do with the PR? please let me know AFAIU the options are:

  1. revert back to ERB generating 3 react components (search, table, pagination)
  2. combine the table and pagination into one component?

thanks!

iNecas
iNecas previously approved these changes Feb 20, 2019
Copy link
Member

@iNecas iNecas left a comment

Choose a reason for hiding this comment

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

Seems like Ohad's request for reusing the loading state was incorporated. Tested from user's perspective and works well.

I've hit some weird stuff when having Redux dev tools enabled (I guess it might be related to the fact we're mixing redux with turbolinks or something like that) but haven't observed this weirdness wiwhout the Redux dev tools.

Rebase needed (+ probably fixing some pending tests)

);
};

TableBody.propTypes = {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure where this is coming from (pf?) but I get this error in my console:

checkPropTypes.js:19 Warning: Failed prop type: The prop `children` is marked as required in `EllipisWithTooltip`, but its value is `null`.
    in EllipisWithTooltip (created by BodyRow)
    in BodyRow (created by Body)
    in tbody (created by Body)
    in Body (created by TableBody)
    in TableBody (created by Table)
    in table (created by Provider)
    in Provider (created by TablePfProvider)
    in TablePfProvider (created by Table)
    in div (created by Table)
    in Table (created by ModelsTable)
    in LoadingState (created by ModelsTable)
    in ModelsTable (created by Connect(ModelsTable))
    in Connect(ModelsTable) (created by I18nProviderWrapper(Connect(ModelsTable)))
    in IntlProvider (created by I18nProviderWrapper(Connect(ModelsTable)))
    in I18nProviderWrapper(Connect(ModelsTable)) (created by StoreProvider(I18nProviderWrapper(Connect(ModelsTable))))
    in Provider (created by StoreProvider(I18nProviderWrapper(Connect(ModelsTable))))
    in StoreProvider(I18nProviderWrapper(Connect(ModelsTable))) (created by DataProvider(StoreProvider(I18nProviderWrapper(Connect(ModelsTable)))))
    in DataProvider(StoreProvider(I18nProviderWrapper(Connect(ModelsTable))))

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't reproduce it. I guess it's because I am not checking the value in common/table/formatters/ellipsisCellFormatter.js. Let me know if it is fixed.

@ohadlevy
Copy link
Member

@amirfefer @sharvit @LaViro I've rebased this PR, can you please have another look prior to merge? I'm OK with small follow up PR's if you think that is required, but I think this PR is pretty much ready? thanks!

Copy link
Member

@Ron-Lavi Ron-Lavi left a comment

Choose a reason for hiding this comment

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

Awesome work @boaz0 !!
Left some inline comments which I am fine with adding to a follow up PR :)

</table>
<%= will_paginate_with_info @models %>
<div id="models_table"></div>
<%= mount_react_component("ModelsTable", "#models_table", {
Copy link
Member

Choose a reason for hiding this comment

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

could be added as a follow up PR,
Maybe create an helper file for it, e.g.: search_bar_helper.rb
and maybe use the component wrapper so props won't be accessed in react by the data object.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we should use the component-wrapper only when we want to update those props with redux.
data prop became a standard for us to know those props came from server rendering and it feels useful to me.

Copy link
Member

Choose a reason for hiding this comment

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

@amirfefer what are you thoughts ?
can you share about the flat option in mount_react_component as we discussed offline ?

Copy link
Member

Choose a reason for hiding this comment

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

you can use {flattenData: true} in the componentRegistery,
I do agree with @sharvit on this, but if we use a component both server and client rendering (like charts) IMO it would be better to use the flattenData


class ModelsTable extends React.Component {
componentDidMount() {
this.props.getTableItems('models', getURIQuery(window.location.href));
Copy link
Member

Choose a reason for hiding this comment

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

we started to use more objects destruction in our components:
e.g: const { getTableItems } = this.props

if you want to get the query from the url, you could use the URI library which is already used in the project,
https://medialize.github.io/URI.js/docs.html#accessors-search

error,
status,
results,
data: { pagination },
Copy link
Member

Choose a reason for hiding this comment

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

as mentioned above, if we use the component wrapper, we won't need the data object here.

@boaz0
Copy link
Member Author

boaz0 commented Feb 21, 2019

@ohadlevy I will revert models.html.erb and @glekner will take it from there.

@boaz0
Copy link
Member Author

boaz0 commented Feb 21, 2019

@LaViro feel free to open tickets and work on those. I think this PR is old and bloated.

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 @boaz0 🥇

@ohadlevy
Copy link
Member

ohadlevy commented Feb 21, 2019 via email

@ohadlevy
Copy link
Member

test failures not related, thanks!

@ohadlevy ohadlevy merged commit 35e37e3 into theforeman:develop Feb 21, 2019
@sharvit
Copy link
Contributor

sharvit commented Feb 21, 2019

Thanks @boaz0 and everyone who contributed to this PR ❤️

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.