phac-nml / irida-next

IRIDA Next
https://phac-nml.github.io/irida-next/
Apache License 2.0
8 stars 2 forks source link

Members: Add searching and sorting to table (ENHC0010037) #641

Open deepsidhu85 opened 2 weeks ago

deepsidhu85 commented 2 weeks ago

Summary

Currently, the members table for both groups and projects does not have sorting or searching capability. We want to update the table to add this functionality to allow the user to sort and search

Acceptance Criteria

Note: Take a look at the files within app/components/samples for an example of how this should work.

ksierks commented 1 week ago

After a conversation with Deep today, we've decided to drop searching by access level for now.

For my future reference, we explored the following solutions:

  1. convert database to use enums
    CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
    CREATE TABLE person (
    name text,
    current_mood mood
    );
    INSERT INTO person VALUES ('Moe', 'happy');
    SELECT * FROM person where current_mood::text ILIKE 'ha%';
  2. use a dropdown to do access level searching/filtering
  3. use a ransacker to do complete name lookup
    ransacker :access_level, formatter: proc { |v| Member::AccessLevel.access_level_options_owner[v] } do |parent|
    parent.table[:access_level]
    end
  4. use ransackable_scope
    
    def self.ransackable_scopes(auth = nil)
    %i[access_level_or_email_like]
    end

def self.access_level_or_email_like(term) query = Arel.sql(format("'$.* ? (@ LIKE_REGEX \"(?i).%s.*\")'", term))

expression = Arel::Nodes::InfixOperation.new('@?', Member.arel_table[:access_level], query)

where(User.arel_table[:email].matches("%#{term}%")) end