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 #21737 - move about page to react #5024

Closed
wants to merge 1 commit into from

Conversation

amirfefer
Copy link
Member

@amirfefer amirfefer commented Nov 22, 2017

About page uses 3 different old js files in order to check the status of compute resources and smart proxies.
I've extracted this status rendering to a react component <About>, in addition, I've united the UI style (by using Icons instead of labels).

new components from pf-react:

  • Empty State
  • Tabs
  • Table

Todo

  • tests

updated gif (March) :

After

before:

nov 22 2017 6-10 pm

@theforeman-bot
Copy link
Member

Issues: #21737

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.

nice @amirfefer - first review round..

</table>
<% end %>
<%= data = @smart_proxies.map {|proxy| {:id => {:name => proxy.name, :id => proxy.id},
:features => h(proxy.features.map(&:name).to_sentence)}} %>
Copy link
Member

Choose a reason for hiding this comment

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

h is probably no longer required (it's the default).

</tbody>
</table>
<% end %>
<%= data = @compute_resources.map {|compute| {:id => {:name => compute.name, :id => compute.id},
Copy link
Member

Choose a reason for hiding this comment

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

when there are none, you get a generic message ````No data found``` - we should use the PF empty state instead.

config/routes.rb Outdated
@@ -404,7 +404,7 @@
post 'template_selected'
post 'cluster_selected'
get 'resource_pools'
post 'ping'
get 'ping'
Copy link
Member

Choose a reason for hiding this comment

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

doesnt this break CR test connection?

return `/${controller}/${id ? `${id}/` : ''}${action}`;
},
getQueryParam(query) {
const urlParams = new URLSearchParams(window.location.search);
Copy link
Member

Choose a reason for hiding this comment

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

how is this different from the urijs lib that we currently use? - also does this work across browsers?

Copy link
Member Author

Choose a reason for hiding this comment

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

It becomes a standard interface, most of the browsers support it, and there's a polyfill

Copy link
Member

Choose a reason for hiding this comment

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

should we replace than the urijs?

render() {
const columns = [
{
Header: 'Name',
Copy link
Member

Choose a reason for hiding this comment

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

please extract all strings

? rowData
: undefined,
style: {
textAlign: 'center',
Copy link
Member

Choose a reason for hiding this comment

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

why pass style here?

@@ -8,6 +8,10 @@ import PowerStatus from './hosts/powerStatus/';
import NotificationContainer from './notifications/';
import ToastsList from './toastNotifications/';
import StorageContainer from './hosts/storage/vmware/';
import AboutComputeTable from './about/compute';
Copy link
Member

Choose a reason for hiding this comment

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

TBH: I am not too happy about having so many entry level components, is there any chance we can take over multiple tabs in one hoc ? this will allow to have all of the "logic" in one place vs across multiple components

@@ -0,0 +1,12 @@
import { STATUS_REQUEST, STATUS_SUCCESS, STATUS_FAILURE } from '../../consts';
Copy link
Member

Choose a reason for hiding this comment

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

shouldnt these const be more specific? e.g. HOST_STATUS or COMPUTE_RESOURCE_STATUS?

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've extracted it out of the tree, something like this:

STATUS
-COMPUTE_RESOURCE
[-X...]
-SMART_PROXY
[-Y...]


switch (action.type) {
case STATUS_REQUEST:
return state;
Copy link
Member

Choose a reason for hiding this comment

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

why? shouldn't this set the state so that the request has started?

case STATUS_REQUEST:
return state;
case STATUS_SUCCESS:
return state.set(payload.id, { ...payload });
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 a bit worried that ID's can override each other, while I've seen you've prefixed it, the fact is that these actions are used for multiple objects, can confuse a future developer?

@ohadlevy
Copy link
Member

@amirfefer also note the lack of tests + current failing tests.

@sharvit
Copy link
Contributor

sharvit commented Nov 23, 2017

@amirfefer It's is great to see more and more code moving to react.
I would love to see the whole about/index.html.erb moving to react, including the tabs and the layout.
Then, you will need to add only 1 component to the registry (instead of 4).

You can use react-bootstrap for the tabs:
https://react-bootstrap.github.io/components.html#tabs

The row and col can be replaced with:
https://react-bootstrap.github.io/components.html#grid

Those components will be apart of patternfly-react in the future so it will be easy to move them later, probably by only change the import statement.

<% @smart_proxies.each do |proxy| %>
<tr class="proxy-show" data-url="<%= ping_smart_proxy_path(proxy) %>">
<td><%= link_to_if_authorized proxy.name, hash_for_smart_proxy_path(proxy) %></td>
<td><%=h proxy.features.map(&:name).to_sentence %></td>
Copy link
Member

Choose a reason for hiding this comment

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

I wonder how translation worked here before?

@amirfefer
Copy link
Member Author

amirfefer commented Nov 28, 2017

@ohadlevy
I've changed the table library to react-bootstrap-table for an easy integration with pf styling. (react-table doesn't use the regular table, th, td tr tags)
I've created a new Tabs component, so there's only one registered component (instead of 4)
I've implemented a new empty state component that renders when no data instead of a no data string.

empty state component:
empty_state

bootsrap & pf table style:
new_table_style

@ohadlevy
Copy link
Member

@amirfefer i think you forgot to push your new implementation.

regardless, I would suggest to send PR's to patternfly-react repo with all of pf related components (tabs, emptystate etc)

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.

I ran out of time, but here is some feedback

@@ -250,7 +250,7 @@ select {

table {
clear: both;
margin-bottom: 6px !important;
//margin-bottom: 6px !important;
Copy link
Member

Choose a reason for hiding this comment

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

?

@@ -335,7 +335,7 @@ table {
}

#pagination {
margin-top: -6px;
margin-top: -19px !important;
Copy link
Member

Choose a reason for hiding this comment

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

why change style for all pagination?

@@ -0,0 +1,31 @@
module AboutHelper
def plugins
Copy link
Member

Choose a reason for hiding this comment

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

if you are creating a controller per action, then I would expect AboutPluginController with only index action.

having said that, I would default to use the API first and only if it doesnt fit create a UI end point

Copy link
Member Author

@amirfefer amirfefer Dec 5, 2017

Choose a reason for hiding this comment

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

I've created About controller namespace, inspired by this post.

Copy link
Member

Choose a reason for hiding this comment

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

in that case why do you need the helper than?
also.. can't we simply use the existing api?

Copy link
Member

Choose a reason for hiding this comment

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

Using an api endpoint would definitely be more systemic. Such endpoint doesn't exist at the moment. We can only list proxies and compute profiles separately. How about moving it to a new api endpoint? It would help with http://projects.theforeman.org/issues/3036.

But I understand it's adds some work and there are probably issues with higher priority. So if you don't have space for moving it to API, I can live with the current state ;)

</div>
</div>
<div id="tabs"></div>
<%= mount_react_component('About', '#tabs', {:compute => compute_resources, :proxy => proxies,
Copy link
Member

Choose a reason for hiding this comment

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

probably makes sense to combine it under a method, so in theory we can expand it later vs hard code it. e.g.

def about_data
  {:compute => compute_resources, :proxy => proxies,...
end

package.json Outdated
@@ -68,12 +68,13 @@
"lodash": "~4.15.0",
"multiselect": "~0.9.12",
"patternfly": "^3.29.5",
"patternfly-react": "^0.8.1",
"patternfly-react": "^0.11.0",
Copy link
Member

Choose a reason for hiding this comment

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

all package upgrades seems not related?

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've upgraded in order to use Icon component

return `/${controller}/${id ? `${id}/` : ''}${action}`;
},
getQueryParam(query) {
const urlParams = new URLSearchParams(window.location.search);
Copy link
Member

Choose a reason for hiding this comment

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

should we replace than the urijs?

render() {
const columns = [
{
header: 'Name',
Copy link
Member

Choose a reason for hiding this comment

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

string not extracted?

Copy link
Member Author

Choose a reason for hiding this comment

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

extracted already in <Table> component

} = this.props.data;
const tabs = [__('Smart Proxies'), __('Available Providers'), __('Compute Resources'), __('Plugins')];

return <ForemanTabs id='about_tabs' tabs={tabs} >
Copy link
Member

Choose a reason for hiding this comment

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

this looks really close to how react-router works.. I wonder if we should combine the two? (so if you refresh you come back to the same tab)

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds great, though this PR becomes too large, maybe should we combine react-router in a different PR?

</p>
<div className="blank-slate-pf-main-action">
<button
onClick={e => window.Turbolinks.visit(action.url)}
Copy link
Member

Choose a reason for hiding this comment

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

wouldnt turbolink catch these regardless?

<h1>{header}</h1>
<p>{description}</p>
<p>
Learn more about this{' '}
Copy link
Member

Choose a reason for hiding this comment

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

not extracted..


<<<<<<< HEAD

Choose a reason for hiding this comment

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

Parsing error: Unexpected token

@@ -655,3 +655,7 @@ code.transparent {
padding: 0;
margin-bottom: 0;
}

.react-bs-table table {
margin-bottom: 0px !important

Choose a reason for hiding this comment

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

Unexpected unit length-zero-no-unit
Unexpected missing end-of-source newline no-missing-end-of-source-newline
Expected a trailing semicolon declaration-block-trailing-semicolon

@@ -239,7 +239,7 @@ select {

table {
clear: both;
margin-bottom: 6px !important;
margin-bottom: 6px !important;

Choose a reason for hiding this comment

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

Expected newline after ";" in a multi-line declaration block declaration-block-semicolon-newline-after
Unexpected whitespace at end of line no-eol-whitespace

@@ -655,3 +655,7 @@ code.transparent {
padding: 0;
margin-bottom: 0;
}

.react-bs-table table {
margin-bottom: 0 !important;

Choose a reason for hiding this comment

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

Unexpected missing end-of-source newline no-missing-end-of-source-newline

@tstrachota
Copy link
Member

@amirfefer ping, could you rebase, please?

@xprazak2
Copy link
Contributor

@amirfefer, could you rebase please?

@tstrachota
Copy link
Member

@amirfefer ping

@amirfefer
Copy link
Member Author

It was among the latter in the priority tasks list,
I'll rebase and have a look on it soon.

@amirfefer
Copy link
Member Author

@tstrachota , @waldenraines
Rebased, and ready for a another look :)

return this.isEmpty() ? (
<EmptyState {...emptyState} />
) : (
<PfTable.PfProvider
Copy link
Member

@boaz0 boaz0 Jun 28, 2018

Choose a reason for hiding this comment

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

Hi @amirfefer, this looks good but what if I want to use components in <PfTable.PfProvider> - I am not sure I can do that through Table. In Hardware Models I am using it to set how the heading and cells will look like.

Copy link
Member

Choose a reason for hiding this comment

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

This has been solved in Katello: https://github.com/Katello/katello/blob/master/webpack/move_to_foreman/components/common/table/components/Table.js That component is based on @amirfefer 's solution and is going to be moved to foreman soon. AFAIR the interfaces should be compatible.
So, if you don't mind @ripcurld, I wouldn't block merging this PR by that. It contains lot of other good stuff, has been open for quite some time and is quite ready to be merged.

Copy link
Member

Choose a reason for hiding this comment

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

@tstrachota I didn't mean to block 😃 but just to raise a concern I have in Hardware Models.

@tstrachota
Copy link
Member

There's minor conflict again. I wasn't fast enough with the final review:( I'm sorry for that. Please rebase @amirfefer

@amirfefer
Copy link
Member Author

@tstrachota - rebased :)

Copy link
Member

@tstrachota tstrachota left a comment

Choose a reason for hiding this comment

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

I found two more issues on the empty states. Hopefully they'll be easy to fix.
The rest looks good and worked fine for me.

description: __('Foreman supports creating and managing hosts on a number of virtualization and cloud services - referred to as “compute resources” - as well as bare metal hosts.'),
documentation: {
// eslint-disable-next-line no-undef
url: `https://www.theforeman.org/manuals/${VERSION}/index.html#5.2ComputeResources`,
Copy link
Member

Choose a reason for hiding this comment

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

I found out that the docs link (and the other too) leads to 404. VERSION is 1.19.0 but the manual url has to contain only 1.19. We probably need both VERSION and VERSION_MAJOR or something similar, maybe an object containing multiple version formats and with toString() defined.

{url &&
<PfEmptyState.Help>
{label}
<a href={url}> {buttonLabel} </a>
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick:
this indend doesn't put any space between the text and the link. Spaces in <a> work but they look weird on hover:
screenshot from 2018-07-09 15-57-09

Please indent correctly and remove spaces form the anchor. {" "} should help with preserving the space in between.

@mmoll
Copy link
Contributor

mmoll commented Aug 15, 2018

@amirfefer could you rebase and fix the last two small comments from @tstrachota? :)

@mmoll
Copy link
Contributor

mmoll commented Sep 1, 2018

what's the status here?

@tstrachota
Copy link
Member

This needs a rebase again.

@waldenraines
Copy link

@amirfefer any updates on this?

@amirfefer
Copy link
Member Author

amirfefer commented Nov 14, 2018

@waldenraines - basically i'd like to use table from this PR, will re-prioritize this soon :)

@mmoll
Copy link
Contributor

mmoll commented Apr 6, 2019

@amirfefer what's the status here?

@mmoll
Copy link
Contributor

mmoll commented May 16, 2019

any news here? :)

@ares
Copy link
Member

ares commented Jul 24, 2019

@amirfefer this needs a bigger rebase now, could you please let us know if you plan to look at this soon? If there's no activity before next triage (2 weeks), we'd lean towards closing this. It would be unfrotunate as there were just 2 small things to finish this, but of course it can be reopened later if your availability for this PR changes.

@ares
Copy link
Member

ares commented Aug 7, 2019

Unfortunatelly there was no reply for 2 weeks so we are closing this PR now. Please reopen if you're still interested in getting this in.

@ares ares closed this Aug 7, 2019
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.