Extract crmSearchAdminTags into a shared crmEntityTags component - #36492
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
PR commands & links...
|
960a397 to
3883d15
Compare
3883d15 to
ad2607b
Compare
| display: none; | ||
| } | ||
|
|
||
| #bootstrap-theme .dropdown-menu li .form-inline { |
There was a problem hiding this comment.
This css rule doesn't seem to have anything to do with tags.
There was a problem hiding this comment.
It was actually copied straight from the searchkit css. Now updated and simplified.
| // 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 = {}; |
There was a problem hiding this comment.
Maybe this variable should be declared a few lines above so each instance of crmEntityTagsCache doesn't need its own cache.
| where: [['used_for', 'CONTAINS', entityTable]] | ||
| }); | ||
| } | ||
| return cache[entityTable]; |
There was a problem hiding this comment.
So what happens when someone creates a new tag on-the-fly? It ought to be added to the cache no?
There was a problem hiding this comment.
Now handled via tags.push(tag);
| crmEntityTagsCache(ctrl.entityTable).then(function(tags) { | ||
| ctrl.allTags = tags; | ||
| }); |
There was a problem hiding this comment.
I don't see any function with this name. Should this be crmEntityTagsCache.getTagsForTable instead? But that function doesn't return a promise.
There was a problem hiding this comment.
Now implemented at the top as "crmEntityTagsCache.get"
ad2607b to
2d7e814
Compare
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.
2d7e814 to
fe83480
Compare
|
Looks good. Thanks @mattwire |
…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.
Overview
search_kit'scrmSearchAdminTags(an inline "Tags" dropdown with colored badges and inline quick-create) was hardcoded tocivicrm_saved_searchin 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 onentityTable(also used as theused_forvalue) and an optionalentityId(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 viaTag.get, cached perentity_tableso 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-deadcrmSearchAdminTagscomponent files and CSS are removed.Test plan
crmEntityTagsmodule loads correctly.