Skip to content

DEV: Use discourse tags instead of "labels"#19

Merged
SamSaffron merged 15 commits intomainfrom
labels-to-tags
Apr 14, 2026
Merged

DEV: Use discourse tags instead of "labels"#19
SamSaffron merged 15 commits intomainfrom
labels-to-tags

Conversation

@jordanvidrine
Copy link
Copy Markdown
Contributor

Replace custom labels system with Discourse's native tag chooser — cards now store tags instead of freeform labels, which carry over to the composer when promoting a card to a topic.

cards-with-tags.mp4

Copy link
Copy Markdown
Contributor

@martin-brennan martin-brennan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good so far, I just pushed some spec improvements. @SamSaffron I made comments on stuff you added too here I think, not sure which is yours and which is from @jordanvidrine

.group_by(&:topic_id)
end

def preload_floater_card_tags(cards)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only do this when SiteSetting.tagging_enabled is true, otherwise return {}

Comment thread app/models/discourse_kanban/card.rb Outdated
Comment on lines +30 to +43
normalized_tag_ids =
raw_values
.filter_map do |value|
next if value.blank?
value.is_a?(String) ? Integer(value, 10) : Integer(value)
rescue ArgumentError, TypeError
raise Discourse::InvalidParameters.new(
I18n.t(
"discourse_kanban.errors.unknown_tag_ids",
tag_ids: raw_values.join(","),
),
)
end
.uniq
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ruby is a bit weird, should be more like this:

Suggested change
normalized_tag_ids =
raw_values
.filter_map do |value|
next if value.blank?
value.is_a?(String) ? Integer(value, 10) : Integer(value)
rescue ArgumentError, TypeError
raise Discourse::InvalidParameters.new(
I18n.t(
"discourse_kanban.errors.unknown_tag_ids",
tag_ids: raw_values.join(","),
),
)
end
.uniq
normalized_tag_ids =
raw_values
.compact
.map(&:to_i)
.uniq

This will get rid of blank values early, and we don't need this odd way of converting to integer

Comment thread app/models/discourse_kanban/card.rb Outdated
Comment on lines +54 to +55
normalized_tag_ids = Array(tag_ids).map(&:to_i).reject(&:zero?).uniq
return [] if normalized_tag_ids.blank?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use normalize_tag_ids! here

Comment thread app/models/discourse_kanban/card.rb Outdated
Comment on lines +62 to +63
normalized_tag_ids = Array(tag_ids).map(&:to_i).reject(&:zero?).uniq
return [] if normalized_tag_ids.blank?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use normalize_tag_ids! here

Comment on lines +37 to +41
def tags
return [] if object.topic?

ordered_tags.map { |tag| CardTagSerializer.new(tag, root: false, scope: scope).as_json }
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nicer way to do this would be to use has_many :tags, embed: :object, serializer: CardTagSerializer at the top of this serializer, then adding changing this method like so:

Suggested change
def tags
return [] if object.topic?
ordered_tags.map { |tag| CardTagSerializer.new(tag, root: false, scope: scope).as_json }
end
def tags
object.topic? ? [] : ordered_tags
end

guardian:,
params: card_mutation_params.to_h.merge("board_id" => params[:board_id]),
constraint_fix: constraint_fix_params,
**service_params.deep_merge(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**service_params.deep_merge(
service_params.deep_merge(

** not necessary, the service_params is a hash not kwargs

params: raw_params.merge("board_id" => params[:board_id], "id" => params[:id]),
raw_card_params: raw_params,
constraint_fix: constraint_fix_params,
**service_params.deep_merge(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**service_params.deep_merge(
service_params.deep_merge(

** not necessary, the service_params is a hash not kwargs

board_id: params[:board_id],
column_id: params[:column_id],
},
**service_params.deep_merge(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**service_params.deep_merge(
service_params.deep_merge(

** not necessary, the service_params is a hash not kwargs

board_id: params[:board_id],
id: params[:id],
},
**service_params.deep_merge(params: { board_id: params[:board_id], id: params[:id] }),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**service_params.deep_merge(params: { board_id: params[:board_id], id: params[:id] }),
service_params.deep_merge(

** not necessary, the service_params is a hash not kwargs

params: card_mutation_params.to_h.merge("board_id" => params[:board_id]),
constraint_fix: constraint_fix_params,
**service_params.deep_merge(
params: card_mutation_params.to_h.merge("board_id" => params[:board_id]),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are inconsistent with merging string key hashes and symbol key hashes like DestroyCard, we should standardize on the latter

@SamSaffron SamSaffron merged commit 0451d2a into main Apr 14, 2026
6 checks passed
@SamSaffron SamSaffron deleted the labels-to-tags branch April 14, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants