-
Notifications
You must be signed in to change notification settings - Fork 993
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
Conversation
Issues: #24041 |
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.
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.
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableFormats.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableSchema.js
Outdated
Show resolved
Hide resolved
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.
basic comments on the rails side, didnt look at the js yet.
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableFormats.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableFormats.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableFormats.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableFormats.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableReducer.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableSchema.js
Outdated
Show resolved
Hide resolved
)); | ||
|
||
const orderChars = { | ||
ASC: '▲', |
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.
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>
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.
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableSchema.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableFormats.test.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/index.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTableActions.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
Outdated
Show resolved
Hide resolved
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
Outdated
Show resolved
Hide resolved
test failures not related https://community.theforeman.org/t/can-we-drop-node-js-6-14-from-travis-javascript-test-matrix/12737 |
have a look at Gilad's audit commit, as he is pretty much doing something
similar.
…On Thu, Feb 14, 2019 at 2:42 PM boaz0 ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
<#5755 (comment)>:
> @@ -0,0 +1,57 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Table } from '../common/table';
+import { STATUS } from '../../constants';
+import MessageBox from '../common/MessageBox';
+import { translate as __ } from '../../common/I18n';
+import createModelsTableSchema from './ModelsTableSchema';
+import { getURIQuery } from '../../common/helpers';
+
+class ModelsTable extends React.Component {
+ componentDidMount() {
+ this.props.getTableItems('models', getURIQuery(window.location.href));
Need a follow up: Pagination to be rendered inside the ModelsTable.
Right now it is rendered from erb. I am checking how much work it
required. If it is not a lot, I will update this commit.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5755 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABOx9YpEzi18CWv4m6f4tWm4ChpltRfks5vNVnIgaJpZM4U8um9>
.
|
@glekner can you review please? thanks. |
@ohadlevy: I trust you with this one. Feel free to merge whenever you think this is ready. |
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
Test failures seem related |
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.
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); |
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.
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}> |
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 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
<Spinner size="lg" loading={this.state.initialLoading}> | |
if (results.length > 0) return renderTable; | |
return <Spinner size="lg" loading />; |
… On Sun, Feb 17, 2019 at 12:09 PM Gilad Lekner ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Awesome work @boaz0 <https://github.com/boaz0> !
I believe we need to change render method of the table
------------------------------
In webpack/assets/javascripts/react_app/common/helpers.js
<#5755 (comment)>:
> @@ -72,6 +73,13 @@ export const translateObject = obj =>
*/
export const translateArray = arr => arr.map(str => __(str));
+/**
+ * Return the query in URL as Objects where keys are
+ * the parameters and the values are the parameters' values.
+ * @param {String} url - the URL
+ */
+export const getURIQuery = url => new URI(url).query(true);
We'll probably want to move all the URI helpers from PaginationHelper to
common/helpers or another file in the future.
------------------------------
In
webpack/assets/javascripts/react_app/components/ModelsTable/ModelsTable.js
<#5755 (comment)>:
> + />
+ ) : (
+ <React.Fragment>
+ <Table
+ key="models-table"
+ columns={createModelsTableSchema(getTableItems, sortBy, sortOrder)}
+ rows={results}
+ />
+ <div id="pagination">
+ <Pagination data={pagination} />
+ </div>
+ </React.Fragment>
+ );
+
+ return (
+ <Spinner size="lg" loading={this.state.initialLoading}>
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 />;
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5755 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABOxw4qoDx93qx0bLSBNcqG7cq1Rd8-ks5vOSpzgaJpZM4U8um9>
.
|
@boaz0 what did you decided to do with the PR? please let me know AFAIU the options are:
thanks! |
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.
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 = { |
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'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))))
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 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.
@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! |
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.
Awesome work @boaz0 !!
Left some inline comments which I am fine with adding to a follow up PR :)
app/views/models/index.html.erb
Outdated
</table> | ||
<%= will_paginate_with_info @models %> | ||
<div id="models_table"></div> | ||
<%= mount_react_component("ModelsTable", "#models_table", { |
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.
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.
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.
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.
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.
@amirfefer what are you thoughts ?
can you share about the flat
option in mount_react_component
as we discussed offline ?
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.
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)); |
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.
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 }, |
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.
as mentioned above, if we use the component wrapper, we won't need the data object here.
@LaViro feel free to open tickets and work on those. I think this PR is old and bloated. |
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! Thanks @boaz0 🥇
how is this different than other places we use the mounter? if its not
specific to this PR, lets do this in a follow up pr for all mount points?
…On Thu, Feb 21, 2019 at 4:14 PM Avi Sharvit ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In app/views/models/index.html.erb
<#5755 (comment)>:
> - hash_for_edit_model_path(:id => model).merge(:auth_object => model, :authorizer => authorizer) %></td>
- <td class="ellipsis"><%= model.vendor_class %></td>
- <td class="ellipsis"><%= model.hardware_model %></td>
- <td class='ra'><%= link_to hosts_count[model], hosts_path(:search => "model = \"#{model}\"") %></td>
- <td class="col-md-1">
- <%= action_buttons(display_delete_if_authorized(hash_for_model_path(:id => model).
- merge(:auth_object => model, :authorizer => authorizer),
- :confirm => _("Delete %s?") % model.name)) %>
- </td>
- </tr>
- <% end %>
- </tbody>
-</table>
-<%= will_paginate_with_info @models %>
+<div id="models_table"></div>
+<%= mount_react_component("ModelsTable", "#models_table", {
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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5755 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABOx28izb1_tck4uOm2OdXZjFTKlGAnks5vPqnCgaJpZM4U8um9>
.
|
test failures not related, thanks! |
Thanks @boaz0 and everyone who contributed to this PR ❤️ |
This is almost ready -
Need to add tests to
Rails
. I will be working on it. In addition, I will add integration tests toModelsTable
.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
andEmpty 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.