Skip to content

Commit

Permalink
Epic/cv2-3939: replace table view with cards (#1924)
Browse files Browse the repository at this point in the history
* Expose projectMedia.fact_check_published_on field

* create epic brach

* Deprecate column picker settings page (#1771)

* Deprecate column picker settings page

Delete the GraphQL field list_columns from TeamType, delete the respective model method and any other dependent code and related tests

Reference: CV2-3920

Co-authored-by: Alexandre Amorim <[email protected]>
Co-authored-by: Brian Fleming <[email protected]>
  • Loading branch information
3 people authored Jul 4, 2024
1 parent 10c2d31 commit 8279c7c
Show file tree
Hide file tree
Showing 19 changed files with 7 additions and 375 deletions.
1 change: 0 additions & 1 deletion app/graph/mutations/team_mutations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class Update < Mutations::UpdateMutation
argument :language, GraphQL::Types::String, required: false
argument :languages, JsonStringType, required: false
argument :language_detection, GraphQL::Types::Boolean, required: false, camelize: false
argument :list_columns, JsonStringType, required: false, camelize: false
argument :tipline_inbox_filters, GraphQL::Types::String, required: false, camelize: false
argument :suggested_matches_filters, GraphQL::Types::String, required: false, camelize: false
argument :outgoing_urls_utm_code, GraphQL::Types::String, required: false, camelize: false
Expand Down
1 change: 0 additions & 1 deletion app/graph/types/project_media_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ProjectMediaType < DefaultObject
field :last_seen, GraphQL::Types::String, null: true
field :status, GraphQL::Types::String, null: true
field :share_count, GraphQL::Types::Int, null: true
field :list_columns_values, JsonStringType, null: true
field :feed_columns_values, JsonStringType, null: true
field :report_status, GraphQL::Types::String, null: true
field :confirmed_as_similar_by_name, GraphQL::Types::String, null: true
Expand Down
2 changes: 0 additions & 2 deletions app/graph/types/team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class TeamType < DefaultObject
field :get_language_detection, GraphQL::Types::Boolean, null: true
field :get_report, JsonStringType, null: true
field :get_fieldsets, JsonStringType, null: true
field :list_columns, JsonStringType, null: true
field :url, GraphQL::Types::String, null: true
field :data_report, JsonStringType, null: true
field :available_newsletter_header_types, JsonStringType, null: true # List of header type strings
Expand Down Expand Up @@ -112,7 +111,6 @@ def get_fieldsets
object.get_fieldsets
end

field :list_columns, JsonStringType, null: true
field :get_data_report_url, GraphQL::Types::String, null: true

def get_data_report_url
Expand Down
11 changes: 0 additions & 11 deletions app/helpers/validations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,4 @@ def fieldsets_format
errors.add(:settings, JSON::Validator.fully_validate(schema, fieldsets)) if !JSON::Validator.validate(schema, fieldsets)
end

def list_columns_format
return if self.get_list_columns.blank?
schema = {
type: 'array',
items: {
type: 'string',
}
}
columns = self.get_list_columns
errors.add(:settings, JSON::Validator.fully_validate(schema, columns)) if !JSON::Validator.validate(schema, columns)
end
end
4 changes: 0 additions & 4 deletions app/models/concerns/project_media_getters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ def full_url
"#{CheckConfig.get('checkdesk_client')}/#{self.team.slug}#{project_prefix}/media/#{self.id}"
end

def created_at_timestamp
self.created_at.to_i
end

def updated_at_timestamp
self.updated_at.to_i
end
Expand Down
3 changes: 0 additions & 3 deletions app/models/concerns/team_duplication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ def self.duplicate(t, custom_slug = nil, custom_name = nil)
end

def self.modify_settings(old_team, new_team)
team_task_map = self.team_task_map
new_list_columns = old_team.get_list_columns.to_a.collect{|lc| lc.include?("task_value_") ? "task_value_#{team_task_map[lc.split("_").last.to_i]}" : lc}
new_team.set_list_columns = new_list_columns unless new_list_columns.blank?
new_team.set_languages = old_team.get_languages
new_team.set_language = old_team.get_language
new_team
Expand Down
1 change: 0 additions & 1 deletion app/models/concerns/team_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ module TeamValidations
validate :language_format
validate :languages_format
validate :fieldsets_format
validate :list_columns_format
end
end
13 changes: 0 additions & 13 deletions app/models/project_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,6 @@ def method_missing(method, *args, &block)
end
end

def list_columns_values
values = {}
columns = self.team.list_columns || Team.default_list_columns
columns.each do |column|
c = column.with_indifferent_access
if c[:show]
key = c[:key]
values[key] = self.send(key)
end
end
values
end

def feed_columns_values
values = {}
columns = [
Expand Down
151 changes: 0 additions & 151 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,6 @@ def shorten_outgoing_urls=(bool)
self.set_shorten_outgoing_urls = bool
end

def clear_list_columns_cache
languages = self.get_languages.to_a + I18n.available_locales.map(&:to_s)
languages.uniq.each { |l| Rails.cache.delete("list_columns:team:#{l}:#{self.id}") }
end

def list_columns=(columns)
self.clear_list_columns_cache
columns = columns.is_a?(String) ? JSON.parse(columns) : columns
self.send(:set_list_columns, columns)
end

def search_id
CheckSearch.id({ 'parent' => { 'type' => 'team', 'slug' => self.slug } })
end
Expand Down Expand Up @@ -331,30 +320,6 @@ def delete_custom_media_verification_status(status_id, fallback_status_id)
end
end

def list_columns
Rails.cache.fetch("list_columns:team:#{I18n.locale}:#{self.id}") do
show_columns = self.get_list_columns || Team.default_list_columns.select{ |c| c[:show] }.collect{ |c| c[:key] }
columns = []
Team.default_list_columns.each do |column|
columns << column.merge({ show: show_columns.include?(column[:key]) })
end
TeamTask.where(team_id: self.id, fieldset: 'metadata', associated_type: 'ProjectMedia').each do |tt|
key = "task_value_#{tt.id}"
columns << {
key: key,
label: tt.label,
show: show_columns.include?(key),
type: tt.task_type
}
end
columns.sort_by! do |column|
index = show_columns.index(column[:key])
index.nil? ? show_columns.size : index
end
columns
end
end

def self.reindex_statuses_after_deleting_status(ids_json, fallback_status_id)
script = { source: "ctx._source.verification_status = params.status", params: { status: fallback_status_id } }
ProjectMedia.bulk_reindex(ids_json, script)
Expand Down Expand Up @@ -450,122 +415,6 @@ def self.update_reports_if_languages_changed(team_id, languages)
end
end

# This is a method and not a constant because we need the localizations to be evaluated in runtime
def self.default_list_columns
[
{
key: 'demand',
label: I18n.t(:list_column_demand),
show: true
},
{
key: 'share_count',
label: I18n.t(:list_column_share_count),
show: true
},
{
key: 'linked_items_count',
label: I18n.t(:list_column_linked_items_count),
show: true
},
{
key: 'type_of_media',
label: I18n.t(:list_column_type),
show: true
},
{
key: 'status',
label: I18n.t(:list_column_status),
show: true
},
{
key: 'created_at_timestamp',
label: I18n.t(:list_column_created_at),
show: true
},
{
key: 'last_seen',
label: I18n.t(:list_column_last_seen),
show: true
},
{
key: 'updated_at_timestamp',
label: I18n.t(:list_column_updated_at),
show: true
},
{
key: 'report_status',
label: I18n.t(:list_column_report_status),
show: false
},
{
key: 'tags_as_sentence',
label: I18n.t(:list_column_tags_as_sentence),
show: false
},
{
key: 'media_published_at',
label: I18n.t(:list_column_media_published_at),
show: false
},
{
key: 'published_by',
label: I18n.t(:list_column_published_by),
show: false
},
{
key: 'fact_check_published_on',
label: I18n.t(:list_column_fact_check_published_on),
show: false
},
{
key: 'comment_count',
label: I18n.t(:list_column_comment_count),
show: false
},
{
key: 'reaction_count',
label: I18n.t(:list_column_reaction_count),
show: false
},
{
key: 'related_count',
label: I18n.t(:list_column_related_count),
show: false
},
{
key: 'suggestions_count',
label: I18n.t(:list_column_suggestions_count),
show: false
},
{
key: 'folder',
label: I18n.t(:list_column_folder),
show: false
},
{
key: 'creator_name',
label: I18n.t(:list_column_creator_name),
show: false
},
{
key: 'team_name',
label: I18n.t(:list_column_team_name),
show: false
},
{
key: 'sources_as_sentence',
label: I18n.t(:list_column_sources_as_sentence),
show: false
},
{
key: 'fact_check_title',
label: I18n.t(:list_column_fact_check_title),
show: false
}
]
end

def default_language
self.get_language || 'en'
end
Expand Down
3 changes: 0 additions & 3 deletions app/models/team_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,10 @@ def tasks_with_answers_count
private

def add_teamwide_tasks
self.team&.clear_list_columns_cache
TeamTaskWorker.perform_in(1.second, 'add', self.id, User.current&.id)
end

def update_teamwide_tasks
self.team&.clear_list_columns_cache
fields = {
label: self.saved_change_to_label?,
description: self.saved_change_to_description?,
Expand All @@ -134,7 +132,6 @@ def update_teamwide_tasks
end

def delete_teamwide_tasks
self.team&.clear_list_columns_cache
self.keep_completed_tasks = self.keep_completed_tasks.nil? ? false : self.keep_completed_tasks
TeamTaskWorker.perform_in(1.second, 'destroy', self.id, User.current&.id, YAML::dump({}), self.keep_completed_tasks)
end
Expand Down
1 change: 0 additions & 1 deletion app/workers/project_media_cache_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ class ProjectMediaCacheWorker
def perform(pmid)
pm = ProjectMedia.find(pmid)
PROJECT_MEDIA_CACHED_FIELDS.each { |field| pm.send(field) } # Just cache if it's not cached yet
pm.list_columns_values
end
end
6 changes: 5 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,11 @@ def create_tipline_user_and_data(project_media)
Dynamic.create!(annotation_type: 'smooch_user', annotated: project_media.team, annotator: BotUser.smooch_user, set_fields: fields.to_json)

# Tipline request
plataform = ['whatsapp', 'telegram', 'messenger'].sample
smooch_data = {
'role': 'appUser',
'source': {
'type': ['whatsapp', 'telegram', 'messenger'].sample,
'type': plataform,
'id': random_string,
'integrationId': random_string,
'originalMessageId': random_string,
Expand All @@ -611,6 +612,9 @@ def create_tipline_user_and_data(project_media)
'app_id': random_string
}

mapping = {'whatsapp'=> CheckChannels::ChannelCodes::WHATSAPP, 'telegram' => CheckChannels::ChannelCodes::TELEGRAM, 'messenger'=>CheckChannels::ChannelCodes::MESSENGER}
project_media.update_columns(channel: {main: project_media.channel['main'], others: project_media.channel['others'].to_a.push(mapping[plataform]).uniq} )

TiplineRequest.create!(
associated: project_media,
team_id: project_media.team_id,
Expand Down
29 changes: 1 addition & 28 deletions lib/check_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,34 +523,7 @@ def team_tasks_conditions
end

def build_es_sort
# As per spec, for now the team task sort should be just based on "has data" / "has no data"
# Items without data appear first
if @options['sort'] =~ /^task_value_[0-9]+$/
team_task_id = @options['sort'].match(/^task_value_([0-9]+)$/)[1].to_i
missing = {
asc: '_first',
desc: '_last'
}[@options['sort_type'].to_s.downcase.to_sym]
return [
{
'task_responses.id': {
order: @options['sort_type'],
missing: missing,
nested: {
path: 'task_responses',
filter: {
bool: {
must: [
{ term: { 'task_responses.team_task_id': team_task_id } },
{ exists: { field: 'task_responses.value' } }
]
}
}
}
}
}
]
elsif SORT_MAPPING.keys.include?(@options['sort'].to_s)
if SORT_MAPPING.keys.include?(@options['sort'].to_s)
return [
{ SORT_MAPPING[@options['sort'].to_s] => @options['sort_type'].to_s.downcase.to_sym }
]
Expand Down
1 change: 0 additions & 1 deletion lib/tasks/migrate/20220715122310_update_cached_fields.rake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace :check do
failed = false
begin
CACHED_FIELDS.each { |field| pm.send(field) } # Just cache if it's not cached yet
pm.list_columns_values
rescue Exception => e
failed = e.message
end
Expand Down
Loading

0 comments on commit 8279c7c

Please sign in to comment.