In search result drop box: add given name next to username

Wups, no. Sorry about the confusion; I guess you must have read the email version of my reply? I kept editing my post after that. As you can see above, I’m describing the same thing as Sam reiterated here.

@rriemann you’re right that there’s an inconsistency there, but email conventions are a bit different. Practically any clickable element in an email notification should either be a button or have link-styling (i.e. either blue or underlined), because in theory there shouldn’t be that many of them. In the interactive app we need to de-emphasise most of these clickables, because there’s so many of them. The fact that they can be interacted with is made obvious through context such as it appearing in a drop-down.

1 Like

All clear now! thanks

unfortunately when i restart the branch to fix the style, i got the same error Robert got already here.

The u (user) object in js doesn’t get name information.
If :name is added to basic_user_serialize.rb error is raised.

I personally think the error is coming from these line of ams_include_without_root.rb

      if options[:include] == nil
        if @options.key?(:include)
          options[:include] = @options[:include].include?(name)
        elsif @options.include?(:exclude)
          options[:include] = !@options[:exclude].include?(name)
        end
      end

Is possible that options[:include] is never true, therefore is always false?
If i put binding.pry here:

association = association_class.new(name, self, options)

      if association.embed_ids?
        node[association.key] = association.serialize_ids

        if association.embed_in_root? && hash.nil?
          # Don't raise an error!
        elsif association.embed_in_root? && association.embeddable?
          binding.pry
          merge_association hash, association.root, association.serializables, unique_values
        end
      elsif association.embed_objects?
        node[association.key] = association.serialize
      end

and i check what’s inside options i see name: nil

So my questions are:

  • Is name correctly saved in options?
  • I guess this Active Model Serialize it doesn’t pass attributes just to basic_user_serialize.

If it pass name to other part of the app and there is successfully passed to the frontend, then the problem come from how the attribues is passed. Otherwise problem is coming from active model serialize.

1 Like

There is some code smell we need to clean up with our serializer

https://github.com/discourse/discourse/blob/master/app/serializers/basic_user_serializer.rb#L4-L6

the base serializer is deciding for serializers that inherit off it if it should include names or not… it just does not seem right at all.

I would not include name in basic user serializer, this is something that a specific user serializer used for search should add.

3 Likes

Unfortuantely my knowledge of ruby are very very limited.
if you think is something i can do it (this user serliazer for search) with some guidence, i’m happy to try.
But if it require more understanding of RoR, i unfortunately will have to setp back from this PR :pensive:

Keep looking into this issue and i find out that some pages display without errors the name like /users or /admin and some others give the MissingAttributeError like home page.
Whenever i check if name is enable (both FE and BE) i always get true.

@rriemann how did you identify Basic_user_serializer has the one connected to search result?
I’m try to understand where the attrs in widget are coming from… maybe @fantasticfears you know? Previously you said [quote=“fantasticfears, post:3, topic:48735”]
After that, Ember model and widget kicks in.
[/quote]

how exactly?

@sam clean up basic_user_serialize wouldn’t be quite big task? Look like is it used all over the app.
I notice some other serializer which inherit from basic_user, use the :name attribute. So maybe i have to find the one that work directly with search result and add :name to that search results?

I am sorry, I reported all my findings and I have never been an Ember specialist. I guess I just grep-ed through the source code.

1 Like

Widgets in Discourse usually are mounted upon a component or directly by {{mount-widget}}. So the widget retrieves the model is as the same as how the component binds to the model.

Search results should come from GroupedSearchResultsSerializer. As @sam’s suggest, you can replace the BasicUserSerializer with a new one specified for the search as well as some cleanup for that include_name? probably.

1 Like

Thank you @fantasticfears
I was able to create a new Serializer specific for search and use it in place of BasicUserSerializer and look like is working… in all the pages.

This is how my SearchResultUserSerializer look like:

class SearchResultUserSerializer < ApplicationSerializer
  attributes :id, :username, :avatar_template, :name

  def avatar_template
    if Hash === object
      User.avatar_template(user[:username], user[:uploaded_avatar_id])
    else
      user.try(:avatar_template)
    end
  end

  def user
    object[:user] || object
  end

end

Does it make sense? (again, no experience with Ruby/RoR so not sure if is ok to simply get rid of include_name? method)

If the serializer is good, the style now look like this:

3 Likes

@designbygio You can actually just inherit from BasicUserSerializer like so

class SearchResultUserSerializer < BasicUserSerializer
  attributes :name  
end

Generally, it is not recommended to duplicate logic in the code base.

1 Like

Good point!
Here is the new one:
https://github.com/gsambrotta/discourse/blob/d308638a1815a62cabac711a81b9d634a90bc219/app/serializers/search_result_user_serializer.rb

Done and merged!
https://github.com/discourse/discourse/pull/4706

Final result:

7 Likes

excellent job, looks awesome!

1 Like