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

Chargeback Rates non explorer #7039

Merged
merged 18 commits into from
May 19, 2020
Merged

Conversation

h-kataria
Copy link
Contributor

@h-kataria h-kataria commented May 11, 2020

Converted Chargeback Rates explorer to be a non-explorer screen, this will help with direct linking of Chargeback Rates list/show screen.
Added a new Tree View button to GTL views toolbar, to support switching between list/tree view on the Chargeback Rates screen
Added a new Type drop down on Add a new Chargeback Rate form, that defaults to Compute

Depends on #7016

Direct link to list view: http://localhost:3000/chargeback_rate/show_list
Direct link to summary screen: http://localhost:3000/chargeback_rate/show/7

tree_view

list_view

summary

menus

default_rate_edit_message

@h-kataria
Copy link
Contributor Author

@gtanzillo @Fryguy @chessbyte cc

@h-kataria h-kataria force-pushed the cb_rates_no_explorer branch 2 times, most recently from 5260a86 to c3381c0 Compare May 11, 2020 21:00
@chessbyte
Copy link
Member

/cc @gtanzillo

- Added a button in GTL view toolbar to add ability to toggle between list view and tree view. Tree has links to Chargeback Rate records, User can click on "Rates" link in breadcrumbs to go back to list view.
- Updated all toolbar buttons to work in non-explorer modes

Follow up PR for ManageIQ#7016

Fixes ManageIQ#6996
@h-kataria h-kataria force-pushed the cb_rates_no_explorer branch from 6c35fd4 to c083fc0 Compare May 12, 2020 19:38
@h-kataria h-kataria removed the wip label May 13, 2020
@h-kataria h-kataria changed the title [WIP] - Chargeback Rates non explorer Chargeback Rates non explorer May 13, 2020
@@ -211,7 +211,7 @@ def set_summary_pdf_data
:page_layout => "portrait",
:page_size => "us-letter",
:run_date => run_time.strftime("%m/%d/%y %l:%m %p %z"),
:title => "#{klass} \"#{@record.name}\"".html_safe,
:title => "#{klass} \"#{@record.respond_to?(:name) ? @record.name : @record.description}\"".html_safe,
Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain why is this extra complexity necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skateman because ChargebackRate record does not have name field. Previously we did not have download buttons on the Chargeback Rates list view because we did not render gtl view toolbar on the screen.

Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

This is a good start, but let's make some stuff nicer. I'd like to have things here as a pattern to how to convert from explorer to non-explorer.

Also I think it would need more people to review the complexity stuff. We want to simplify things, not add more if-else and constant in global places if possible.

@breadcrumbs = []
@explorer = true
build_accordions_and_trees
send_action = CB_X_BUTTON_ALLOWED_ACTIONS[action]
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename this to just BUTTON_ALLOWED_ACTIONS? The X_ prefix means explorer and I guess we want this as a pattern in other screens, so there's no reason to keep the CB_. Also maybe merge the test with the ˙sendand move it to theGenericButtonMixin`? Here we should keep something like:

BUTTON_ALLOWED_ACTIONS = {}.freeze
evaluate_button(action, BUTTON_ALLOWED_ACTIONS)


render :layout => "application" unless request.xml_http_request?
if params[:pressed].ends_with?("_copy", "_edit", "_new") && @flash_array.nil?
Copy link
Member

Choose a reason for hiding this comment

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

You're testing params[:pressed] but above you allocated it as action


render :layout => "application" unless request.xml_http_request?
if params[:pressed].ends_with?("_copy", "_edit", "_new") && @flash_array.nil?
if @flash_array
Copy link
Member

Choose a reason for hiding this comment

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

One line above you test against the @flash_array˙ if it's nil` and I think this is dead code then...

replace_gtl_main_div
else
render_flash unless performed?
end
Copy link
Member

Choose a reason for hiding this comment

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

In general this huge if-else thing isn't really clean, I think we should do something like on other non-explorer controllers. This is from CloudNetworkController:

  def button
    @edit = session[:edit] # Restore @edit for adv search box
    params[:display] = @display if %w[vms instances images].include?(@display)
    params[:page] = @current_page unless @current_page.nil? # Save current page for list refresh

    @refresh_div = "main_div"

    case params[:pressed]
    when 'cloud_network_delete'
      delete_networks
      javascript_redirect(previous_breadcrumb_url)
    when "cloud_network_edit"
      javascript_redirect(:action => "edit", :id => checked_item_id)
    when "cloud_network_new"
      javascript_redirect(:action => "new")
    else
      super
    end
  end

I would prefer something like this even if it goes against my suggestion above about evaluate_button. Consistency is more important 😉

super
# only need these gtl type buttons on the screen
@gtl_buttons = %w[view_list view_tree]
cb_rates_build_tree if @gtl_type == 'tree'
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want to keep this a little bit cleaner, what about defining them similarly to the toolbar in some of the explorers and pulling it in and adding the logic into the GenericListMixin#show_list the same way as we do with @center_toolbar?

I need to dig a little more, because my fulltext search on @gtl_buttons doesn't find much, so I don't completely understand the dataflow yet, but you might come up with a better idea in the meantime.

@@ -2,7 +2,7 @@ class TreeBuilderChargeback < TreeBuilder
private

def tree_init_options
{:open_all => true, :full_ids => true}
{:open_all => true, :full_ids => true, :click_url => "/chargeback_rate/tree_select/", :onclick => "miqOnClickGeneric"}
Copy link
Member

Choose a reason for hiding this comment

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

You're doing this in the wrong TreeBuilder as it could break stuff in the other subclasses. Can you please redefine it in the TreeBuilderChargebackRates and call super.merge? Also let's make it there a multiline and you can set full_ids to false (there). Maybe it would need a slight change at the tree_select but it should probably simplify stuff.

@@ -13,6 +13,7 @@ def x_get_tree_roots
{
:id => type,
:text => type,
:selectable => false,
Copy link
Member

Choose a reason for hiding this comment

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

Again, this breaks stuff in the other trees. Please redefine it TreeBuilderChargeBackRates and call super.map to set them non-selectable.

app/presenters/tree_node/chargeback_rate.rb Show resolved Hide resolved
@@ -0,0 +1 @@
= render(:partial => "shared/tree", :locals => {:tree => @tree, :name => @tree.name})
Copy link
Member

Choose a reason for hiding this comment

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

This won't make @brumik happy 😆 not really this one, but that his PR is still not in 😕

@@ -0,0 +1,3 @@
#main_div
= render :partial => 'layouts/gtl'
= render :partial => 'tree' if @tree.present?
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like this, but as long as we're not using the react component, why not. Maybe you could move the one-liner from the tree.html.haml directly here...

h-kataria added 2 commits May 15, 2020 12:59
Added condition to only render gtl or tree
moved out chargeback rates tree specific code changes to `TreeBuilderChargeBackRates`
Copy link
Contributor

@ZitaNemeckova ZitaNemeckova left a comment

Choose a reason for hiding this comment

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

Tested in UI. LGTM 👍

And changed to use toolbar module to load toolbars for chargeback rates list/show
config/routes.rb Outdated Show resolved Hide resolved
config/routes.rb Outdated Show resolved Hide resolved
config/routes.rb Outdated Show resolved Hide resolved
app/helpers/application_helper/toolbar_chooser.rb Outdated Show resolved Hide resolved
- Removed `db_list` that was accidentally added in this PR
- Fixed routing spec tests.
- Reverted changes made in toolbar_chooser, see ManageIQ#7039 (comment) for more info
config/routes.rb Outdated
cb_rate_form_field_changed
cb_rate_show
cb_rates_delete
Copy link
Member

Choose a reason for hiding this comment

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

Can we simplify this into just delete?

@miq-bot
Copy link
Member

miq-bot commented May 19, 2020

Checked commits h-kataria/manageiq-ui-classic@c083fc0~...bf3fb4d with ruby 2.5.7, rubocop 0.69.0, haml-lint 0.28.0, and yamllint
25 files checked, 53 offenses detected

app/controllers/application_controller/report_downloads.rb

app/controllers/chargeback_rate_controller.rb

app/helpers/application_helper/toolbar/chargeback_rate_center.rb

app/helpers/application_helper/toolbar_chooser.rb

app/presenters/menu/default_menu.rb

app/views/chargeback_rate/_cb_rate_edit_table.html.haml

  • ⚠️ - Line 1 - Avoid using instance variables in partials views

app/views/chargeback_rate/_cb_rate_show.html.haml

  • ⚠️ - Line 16 - Avoid using instance variables in partials views

app/views/chargeback_rate/_edit.html.haml

  • ⚠️ - Line 12 - Avoid using instance variables in partials views
  • ⚠️ - Line 1 - Avoid using instance variables in partials views
  • ⚠️ - Line 20 - Style/UnlessElse: Do not use unless with else. Rewrite these with the positive case first.
  • ⚠️ - Line 21 - Avoid using instance variables in partials views
  • ⚠️ - Line 28 - Avoid using instance variables in partials views
  • ⚠️ - Line 41 - Avoid using instance variables in partials views
  • ⚠️ - Line 41 - Layout/ExtraSpacing: Unnecessary spacing detected.
  • ⚠️ - Line 41 - Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.
  • ⚠️ - Line 4 - Layout/TrailingBlankLines: Final newline missing.
  • ⚠️ - Line 4 - id attribute must be in lisp-case
  • ⚠️ - Line 54 - Style/UnlessElse: Do not use unless with else. Rewrite these with the positive case first.
  • ⚠️ - Line 58 - Layout/ExtraSpacing: Unnecessary spacing detected.
  • ⚠️ - Line 58 - Layout/ExtraSpacing: Unnecessary spacing detected.
  • ⚠️ - Line 58 - Layout/ExtraSpacing: Unnecessary spacing detected.
  • ⚠️ - Line 58 - Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.
  • ⚠️ - Line 58 - Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.
  • ⚠️ - Line 58 - Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.
  • ⚠️ - Line 64 - Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.
  • ⚠️ - Line 64 - Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.
  • ⚠️ - Line 64 - Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.
  • ⚠️ - Line 70 - The - symbol should have one space separating it from code
  • ⚠️ - Line 71 - Avoid using instance variables in partials views
  • ⚠️ - Line 71 - Layout/ExtraSpacing: Unnecessary spacing detected.
  • ⚠️ - Line 71 - Layout/SpaceAroundOperators: Operator => should be surrounded by a single space.

app/views/chargeback_rate/_tier_first_row.haml

  • ⚠️ - Line 3 - Avoid using instance variables in partials views

app/views/chargeback_rate/_tier_row.haml

  • ⚠️ - Line 2 - Avoid using instance variables in partials views

app/views/chargeback_rate/edit.html.haml

  • ⚠️ - Line 1 - Layout/TrailingBlankLines: Final newline missing.

app/views/chargeback_rate/show_list.html.haml

  • ⚠️ - Line 1 - Layout/TrailingBlankLines: Final newline missing.
  • ⚠️ - Line 1 - id attribute must be in lisp-case

spec/controllers/chargeback_rate_controller_spec.rb

spec/presenters/tree_builder_spec.rb

@skateman
Copy link
Member

When I try to copy a chargeback rate and edit it's name, the new name doesn't get saved.

@skateman
Copy link
Member

If I try to add a new chargeback rate, I am getting the following error:
Screenshot from 2020-05-19 18-03-12

`javascript_tag(javascript_focus('description'))` for some reason was not working well with `javascript_redirect`
Copy link
Member

@skateman skateman left a comment

Choose a reason for hiding this comment

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

The Seal of Approval

@skateman skateman merged commit cdf3b48 into ManageIQ:master May 19, 2020
h-kataria added a commit to h-kataria/manageiq-ui-classic that referenced this pull request May 20, 2020
simaishi pushed a commit that referenced this pull request May 21, 2020
Chargeback Rates non explorer

(cherry picked from commit cdf3b48)
@simaishi
Copy link
Contributor

Jansa backport details:

$ git log -1
commit 9b8376f5390a6b08ba87368262421a4dbc5e1b75
Author: Halász Dávid <[email protected]>
Date:   Tue May 19 19:18:47 2020 +0200

    Merge pull request #7039 from h-kataria/cb_rates_no_explorer

    Chargeback Rates non explorer

    (cherry picked from commit cdf3b4813979c66a821cf1afa0d847380d2e7f0f)

kbrock pushed a commit to kbrock/manageiq-ui-classic that referenced this pull request Aug 8, 2020
ManageIQ#7039 (comment). Reverted any gtl_view buttons related code that was introduced in this PR.
kbrock pushed a commit to kbrock/manageiq-ui-classic that referenced this pull request Aug 8, 2020
- Removed `db_list` that was accidentally added in this PR
- Fixed routing spec tests.
- Reverted changes made in toolbar_chooser, see ManageIQ#7039 (comment) for more info
kbrock pushed a commit to kbrock/manageiq-ui-classic that referenced this pull request Aug 8, 2020
@h-kataria h-kataria deleted the cb_rates_no_explorer branch January 18, 2021 21:48
@himdel himdel mentioned this pull request Jan 28, 2021
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.

7 participants