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 #25640 - keep breadcrumb's title after invalid editing #6312

Closed
wants to merge 1 commit into from

Conversation

amirfefer
Copy link
Member

Before:
with_spaces-2

After:
with_spaces-1

Copy link
Member

@ares ares left a comment

Choose a reason for hiding this comment

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

Not tested yet, few code comments

return title(_('Edit', page_header)) unless obj

valid_obj = obj
label_attr = attrbiture || 'to_s'
Copy link
Member

Choose a reason for hiding this comment

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

spelling of attribute

Copy link
Member

Choose a reason for hiding this comment

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

also why not setting :to_s for attribute argument?

return title(_('Edit', page_header)) unless obj

valid_obj = obj
label_attr = attrbiture || 'to_s'
Copy link
Member

Choose a reason for hiding this comment

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

spelling of attribute

@@ -63,6 +63,20 @@ def title(page_title, page_header = nil)
@page_header ||= page_header || page_title.to_s
end

def edit_title(obj = nil, page_header: nil, attrbiture: nil)
Copy link
Member

Choose a reason for hiding this comment

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

Why it combines keyword args with positional args if all are optional?

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 think the obj parameter shouldn't be optional, after all it's Edit page of a resource, do we have edit pages without any resource to edit?

old_attributes = obj.attributes.merge(obj.changed_attributes)
valid_obj = obj.class.new(old_attributes)
end
title(_('Edit %s') % valid_obj.send(label_attr), page_header)
Copy link
Member

Choose a reason for hiding this comment

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

please use public_send instead of send that can also call private methods


unless obj.valid?
# we need all attributes and then we need to override changed values to old ones
old_attributes = obj.attributes.merge(obj.changed_attributes)
Copy link
Member

Choose a reason for hiding this comment

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

I might be missing something here but I don't the comment correctly describes the behavior. You take existing (uodated) attributes and merge chages to them. Then you build new object with new attributes. Of course the object is valid since no valid? or save was called on it. But imho it has the same values of attributes. Could maybe a bit better explain what is the cause and why this helps? Thanks

@amirfefer
Copy link
Member Author

@ares can you re-review please?

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

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

Comments inline, I also noticed that you missed operating systems, please double check there aren't any others missing

@@ -63,6 +63,17 @@ def title(page_title, page_header = nil)
@page_header ||= page_header || page_title.to_s
end

def edit_title(obj, page_header: nil, attribute: :to_s)
Copy link
Member

Choose a reason for hiding this comment

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

do we actually pass in page_header anywhere? i couldn't find any

# we need to override changed values with previous ones,
# in order to show the valid name in the page title after an unsuccessful editing
old_attributes = obj.attributes.merge(obj.changed_attributes)
valid_obj = obj.class.new(old_attributes)
Copy link
Member

Choose a reason for hiding this comment

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

you could simplify this and remove the merge using obj.class.new(attributes_in_database)

@@ -1,3 +1,3 @@
<% title _("Edit %s") % @subnet.to_label %>
<% edit_title @subnet %>
Copy link
Member

Choose a reason for hiding this comment

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

:to_label?

@@ -1,4 +1,4 @@
<% title _("Edit %s") % @taxonomy.title %>
<% edit_title @taxonomy, page_header: nil, attrbiture: :title %>
Copy link
Member

Choose a reason for hiding this comment

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

since you are using kwargs, you don't need to pass all the options - just the ones you don't want the default for.

@@ -1,3 +1,3 @@
<% title _("Edit %s") % @usergroup.to_label %>
<% edit_title @usergroup, page_header: nil, attrbiture: :to_label %>
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@sharvit
Copy link
Contributor

sharvit commented Feb 20, 2019

@amirfefer what is the status here?

@theforeman-bot
Copy link
Member

@amirfefer, this pull request is currently not mergeable. Please rebase against the develop branch and push again.

If you have a remote called 'upstream' that points to this repository, you can do this by running:

    $ git pull --rebase upstream develop

This message was auto-generated by Foreman's prprocessor

@tbrisker
Copy link
Member

ping @amirfefer what is the status here? do you intend to finish it or shall we close it?

@amirfefer amirfefer closed this Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants