Skip to content

Extract crmSearchAdminTags into a shared crmEntityTags component - #36492

Merged
colemanw merged 1 commit into
civicrm:masterfrom
mattwire:shared-crm-entity-tags-component
Aug 15, 2026
Merged

Extract crmSearchAdminTags into a shared crmEntityTags component#36492
colemanw merged 1 commit into
civicrm:masterfrom
mattwire:shared-crm-entity-tags-component

Conversation

@mattwire

@mattwire mattwire commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Overview

search_kit's crmSearchAdminTags (an inline "Tags" dropdown with colored badges and inline quick-create) was hardcoded to civicrm_saved_search in exactly three spots. A follow-up PR (#36489) needs the same widget for Message Templates, so this extracts it into a shared core component first.

This extracts the widget into a new core module (ang/crmEntityTags.ang.php/.js/.css + ang/crmEntityTags/crmEntityTags.html), parameterized on entityTable (also used as the used_for value) and an optional entityId (omitted for a not-yet-saved record, matching the "local until save" mode the search-settings panel already relied on). Instead of each caller publishing its own settings-factory tag-list global, the component fetches its own tags via Tag.get, cached per entity_table so a list with many rows triggers one API call, not one per row.

search_kit (list widget + search-settings panel) now uses the shared component; the now-dead crmSearchAdminTags component files and CSS are removed.

Test plan

  • SearchKit > Saved Searches list: Tags column still shows/toggles/creates tags correctly.
  • SearchKit search editor > Configure Settings: Tags widget still shows/toggles tags for the search being edited.
  • No console errors; crmEntityTags module loads correctly.

@civibot

civibot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
PR commands & links...
  • /rebase <branch-name> will rebase your branch and change the base of the PR.
  • /squash will combine all commits (keeping only the first commit messsage).
  • /port <branch-name> will create a copy of this PR against a different branch.
  • /lintroll will automatically fix linting errors, amending commits as needed.
  • retest this please will rerun the tests and rebuild the demo site.
  • 📖 Review standards
  • 🗒️ Review template (brief or verbose)

➡️ Online demo of this PR 🔗

@civibot civibot Bot added the master label Aug 14, 2026
@mattwire
mattwire force-pushed the shared-crm-entity-tags-component branch from 960a397 to 3883d15 Compare August 14, 2026 13:35
@mattwire
mattwire force-pushed the shared-crm-entity-tags-component branch from 3883d15 to ad2607b Compare August 14, 2026 14:59
Comment thread ang/crmEntityTags.js Outdated
Comment thread ang/crmEntityTags.css Outdated
display: none;
}

#bootstrap-theme .dropdown-menu li .form-inline {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This css rule doesn't seem to have anything to do with tags.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was actually copied straight from the searchkit css. Now updated and simplified.

Comment thread ang/crmEntityTags.js Outdated
// DB-table entities), cached so a list with many rows - each embedding its own
// <crm-entity-tags> - triggers one API call per distinct table, not one per row.
angular.module('crmEntityTags').factory('crmEntityTagsCache', function(crmApi4) {
const cache = {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe this variable should be declared a few lines above so each instance of crmEntityTagsCache doesn't need its own cache.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread ang/crmEntityTags.js Outdated
where: [['used_for', 'CONTAINS', entityTable]]
});
}
return cache[entityTable];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So what happens when someone creates a new tag on-the-fly? It ought to be added to the cache no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now handled via tags.push(tag);

Comment thread ang/crmEntityTags.js Outdated
Comment on lines +49 to +51
crmEntityTagsCache(ctrl.entityTable).then(function(tags) {
ctrl.allTags = tags;
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see any function with this name. Should this be crmEntityTagsCache.getTagsForTable instead? But that function doesn't return a promise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now implemented at the top as "crmEntityTagsCache.get"

@mattwire
mattwire force-pushed the shared-crm-entity-tags-component branch from ad2607b to 2d7e814 Compare August 14, 2026 20:18
search_kit's crmSearchAdminTags (ang/crmSearchAdmin/crmSearchAdminTags.component.js) - an inline "Tags" dropdown showing colored badges for the tags currently applied to an entity, with inline quick-create - was hardcoded to civicrm_saved_search in exactly three spots: the entity_table used by EntityTag.create/delete, the used_for value passed to Tag.create, and the CRM.crmSearchAdmin.tags global it read its tag list from. A follow-up change needs the same widget for Message Templates, and copying it a second time (with just those three spots swapped) isn't worth repeating a third time down the line, so this extracts it into a shared core component first.

The new module, ang/crmEntityTags.ang.php/.js/.css and ang/crmEntityTags/crmEntityTags.html, is parameterized on entityTable (also used as the used_for value, since for a real DB-table entity those are the same string) and an optional entityId - omitted for a not-yet-saved record, in which case tagIds is mutated locally with no EntityTag API calls, the same "local until save" mode crmSearchAdminTags already supported for the search-settings panel. Rather than requiring each caller to keep publishing its own settingsFactory-populated tag list global, the component now fetches its own tags via Tag.get(where: used_for CONTAINS entityTable), cached per entity_table so a list with many rows - each embedding its own <crm-entity-tags> - triggers one API call per distinct table, not one per row; a newly quick-created tag is pushed into that same cached array, so it's immediately visible to every other row's widget too.

search_kit now uses the shared component: crmSearchAdminTags.component.js/.html are deleted, both existing usages (the per-row list widget in searchListing/tags.html, and the search-settings panel in crmSearch-settings.html) switched to <crm-entity-tags>, and the CSS rules the widget's dropdown markup relies on (tag-color swatch, hiding the button's text label in compact/xs contexts, and the dropdown's form-inline layout) moved to crmEntityTags.css, since they're only ever exercised by that markup, not anything else in crmSearchAdmin.css.

Verified live: search_kit's Saved Search list (Tags column) and its search-settings panel still show/toggle/create tags correctly through the shared component, with no console errors.
@mattwire
mattwire force-pushed the shared-crm-entity-tags-component branch from 2d7e814 to fe83480 Compare August 14, 2026 20:46
@colemanw
colemanw merged commit 38fe8e7 into civicrm:master Aug 15, 2026
1 check passed
@colemanw

Copy link
Copy Markdown
Member

Looks good. Thanks @mattwire

@mattwire
mattwire deleted the shared-crm-entity-tags-component branch August 15, 2026 16:13
mattwire added a commit to mattwire/civicrm-core that referenced this pull request Aug 15, 2026
…cker

Swaps the editor's plain multiselect for the crmEntityTags component from
civicrm#36492, so the widget code (toggle, colored badges, inline tag creation)
isn't duplicated. Afform.tags is stored as tag names for portability
across sites, while the widget works in terms of real tag ids, so the
editor controller maintains an afformTagIds array translated to/from
those names - kept in sync on load, on toggle, and across undo/redo.
Afform has no EntityTag rows, so entity-id is deliberately left unset,
putting the widget in its local-mutation-only mode until Afform.save()
persists the names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants