Skip to content

Add AwardEmoji widget to work items

Eugenia Grieff requested to merge 393598-be-work-items-emoji-awards into master

What does this MR do and why?

Related to #393598 (closed)

Adds a new widget to the work items GraphQL endpoint.

This widget is called AwardEmoji and returns all emoji that has been awarded to the work item as well as the count of upvotes and downvotes (represented with thumbsup and thumbs-down emoji)

Summary of changes:

  • DB migration to add new records for this widget in the work_item_widget_definitions table
  • Add model and GraphQL type for the new widget
  • Add widget to Types::WorkItems::WidgetInterface
  • Update WorkItems::WidgetDefinition to include a new enum value for the widget
  • Update WorkItems::BaseTypeImporter

🚧 The ability to award an emoji will be implemented in a following MR.

Screenshots or screen recordings

Database migration

No changes in structure.sql

DB migration output
❯ rake db:migrate VERSION=20230323101138
main: == 20230323101138 AddAwardEmojiWorkItemWidget: migrating ===================
main: == 20230323101138 AddAwardEmojiWorkItemWidget: migrated (0.0250s) ==========

ci: == 20230228142350 AddAwardEmojiWorkItemWidget: migrating ===================
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20230228142350 AddAwardEmojiWorkItemWidget: migrated (0.0069s) ==========

❯ rake db:migrate:down:main db:migrate:down:ci VERSION=20230323101138
main: == 20230323101138 AddAwardEmojiWorkItemWidget: reverting ======================
main: == 20230323101138 AddAwardEmojiWorkItemWidget: reverted (0.0174s) =============

ci: == 20230323101138 AddAwardEmojiWorkItemWidget: reverting ======================
ci: -- The migration is skipped since it modifies the schemas: [:gitlab_main].
ci: -- This database can only apply migrations in one of the following schemas: [:gitlab_ci, :gitlab_shared, :gitlab_internal].
ci: == 20230323101138 AddAwardEmojiWorkItemWidget: reverted (0.0168s) =============

Database Queries

Query work items upvotes

SQL query
SELECT "award_emoji"."name", "award_emoji"."awardable_id", COUNT(*) as count FROM "award_emoji" WHERE (name IN ('thumbsdown','thumbsup') AND awardable_type = 'Issue' AND awardable_id IN (1667)) AND "award_emoji"."name" = 'thumbsup' GROUP BY "award_emoji"."name", "award_emoji"."awardable_id"

Query work items downvotes

SQL query
SELECT "award_emoji"."name", "award_emoji"."awardable_id", COUNT(*) as count FROM "award_emoji" WHERE (name IN ('thumbsdown','thumbsup') AND awardable_type = 'Issue' AND awardable_id IN (1667)) AND "award_emoji"."name" = 'thumbsdown' GROUP BY "award_emoji"."name", "award_emoji"."awardable_id"

Query work items emoji

SQL query
SELECT "award_emoji"."id", "award_emoji"."name", "award_emoji"."user_id", "award_emoji"."awardable_id", "award_emoji"."awardable_type", "award_emoji"."created_at", "award_emoji"."updated_at" FROM "award_emoji" WHERE "award_emoji"."awardable_type" = 'Issue' AND "award_emoji"."awardable_id" = 1667 ORDER BY "award_emoji"."id" ASC

How to set up and validate locally

  1. Create a work item and add emoji
  2. Visit http://gdk.test:3000/-/graphql-explorer and test the following queries
GQL queries
query getWorkItems {
  project(fullPath: "gitlab-org/gitlab-test") {
    workItems(last: 1) {
      edges {
        node {
          id
          widgets {
            ... on WorkItemWidgetAwardEmoji {
              upvotes
              downvotes
              awardEmoji {
                edges {
                  node {
                    name
                    user { username }
                  }
                }   
              }     
            }
          }
        }
      }
    }
  }
}
  1. Expected response should include the total count for thumbsup and thumbsdown emoji as well as the collection of emoji awarded to the work item.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugenia Grieff

Merge request reports