Add AwardEmoji widget to work items
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)
- 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
Screenshots or screen recordings
Database migration
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 plan (internal): https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/17624/commands/58851
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 plan (internal): https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/17624/commands/58849
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
- query plan (internal): https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/17624/commands/58856
How to set up and validate locally
- Create a work item and add emoji
- 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 }
}
}
}
}
}
}
}
}
}
}
- Expected response should include the total count for
thumbsup
andthumbsdown
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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Eugenia Grieff