Skip to content

Resolve "/unlabel quick action - limit autocomplete to applied labels"

What does this MR do?

The MR adds filtering of labels available on ~, /label ~, /unlabel ~, and /relabel ~ commands.

What does this MR not do?

The MR does not support real-time synchronization.
gfm_auto_complete.js loads labels only once (by current design).
So synchronizing data is out of this MR's scope.

Expected behavior

  1. /label should show only labels that are
  • available for current project
  • not set to current issuable yet
  1. /lab[TAB] should behave exactly as above.
  2. /unlabel should show only labels that are
  • available for current project
  • already set to current issuable
  1. /unlab[TAB] should behave exactly as above.
  2. /relabel should show only labels that are available for current project.
  3. /relab[TAB] should behave exactly as above.
  4. ~ should show only labels that are available for current project regardless which ones are set.

Details

Backend

  1. autocomplete_sources_controller.rb#labels now respects parameters type and type_id (like in #commands action).
  2. If parameters are presented, AutocompleteService.labels mixes available labels with current set labels of passed issuable.
  3. Frontend receives such an response:
..., {"title":"backend","color":"#FFECDB","set":true}, ...

Frontend

gfm_auto_complete.js#setupLabels now has both modified matcher (to parse slash commands) and filter (to filter only needed labels).

Are there points in the code the reviewer needs to double check?

  1. Feature specs work correctly only for ~ command, but fail on command + ~ construction like /label ~. Modification of switch (adding an unneeded extra variable) in filter of gfm_auto_complete.js#setupLabels fixes the specs, but it looks strange to me.
  2. Frontend code is not maximal DRYed. I'm not sure if part of matcher code should be moved to a standalone function.

Why was this MR needed?

It makes UX better and improves user's workflow.

Screenshots

When no labels set yet

Command Description Screenshot
~ List of all available labels Screenshot_20170526_112841
**/label ~** List of all available labels to be set image
**/relabel ~** List of all unset labels to be set image
**/unlabel ~** List of all set labels to be unset image

When labels frontend and backend are already set

Command Description Screenshot
~ List of all available labels image
**/label ~** List of all available labels to be set image
**/relabel ~** List of all unset labels to be set image
**/unlabel ~** List of all set labels to be unset image

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Closes #22680 (moved) and #27319 (moved)

Edited by username-removed-86853

Merge request reports