discourse/app/assets/stylesheets/common/components
Martin Brennan d3f02a1270
FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937)
This commit fleshes out and adds functionality for the new `#hashtag` search and
lookup system, still hidden behind the `enable_experimental_hashtag_autocomplete`
feature flag.

**Serverside**

We have two plugin API registration methods that are used to define data sources
(`register_hashtag_data_source`) and hashtag result type priorities depending on
the context (`register_hashtag_type_in_context`). Reading the comments in plugin.rb
should make it clear what these are doing. Reading the `HashtagAutocompleteService`
in full will likely help a lot as well.

Each data source is responsible for providing its own **lookup** and **search**
method that returns hashtag results based on the arguments provided. For example,
the category hashtag data source has to take into account parent categories and
how they relate, and each data source has to define their own icon to use for the
hashtag, and so on.

The `Site` serializer has two new attributes that source data from `HashtagAutocompleteService`.
There is `hashtag_icons` that is just a simple array of all the different icons that
can be used for allowlisting in our markdown pipeline, and there is `hashtag_context_configurations`
that is used to store the type priority orders for each registered context.

When sending emails, we cannot render the SVG icons for hashtags, so
we need to change the HTML hashtags to the normal `#hashtag` text.

**Markdown**

The `hashtag-autocomplete.js` file is where I have added the new `hashtag-autocomplete`
markdown rule, and like all of our rules this is used to cook the raw text on both the clientside
and on the serverside using MiniRacer. Only on the server side do we actually reach out to
the database with the `hashtagLookup` function, on the clientside we just render a plainer
version of the hashtag HTML. Only in the composer preview do we do further lookups based
on this.

This rule is the first one (that I can find) that uses the `currentUser` based on a passed
in `user_id` for guardian checks in markdown rendering code. This is the `last_editor_id`
for both the post and chat message. In some cases we need to cook without a user present,
so the `Discourse.system_user` is used in this case.

**Chat Channels**

This also contains the changes required for chat so that chat channels can be used
as a data source for hashtag searches and lookups. This data source will only be
used when `enable_experimental_hashtag_autocomplete` is `true`, so we don't have
to worry about channel results suddenly turning up.

------

**Known Rough Edges**

- Onebox excerpts will not render the icon svg/use tags, I plan to address that in a follow up PR
- Selecting a hashtag + pressing the Quote button will result in weird behaviour, I plan to address that in a follow up PR
- Mixed hashtag contexts for hashtags without a type suffix will not work correctly, e.g. #ux which is both a category and a channel slug will resolve to a category when used inside a post or within a [chat] transcript in that post. Users can get around this manually by adding the correct suffix, for example ::channel. We may get to this at some point in future
- Icons will not show for the hashtags in emails since SVG support is so terrible in email (this is not likely to be resolved, but still noting for posterity)
- Additional refinements and review fixes wil
2022-11-21 08:37:06 +10:00
..
_index.scss UX: drag new user menus, scroll primary user nav (#18690) 2022-10-25 07:22:02 +08:00
badges.scss DEV: Use more css vars (#18561) 2022-10-12 16:05:42 +02:00
banner.scss UX: Styling changes to global banner (#16191) 2022-03-15 16:19:55 +01:00
bookmark-list.scss DEV: Use more css vars (#18561) 2022-10-12 16:05:42 +02:00
bookmark-modal.scss UX: align the trash button on the bookmark modal (#16884) 2022-05-23 18:51:01 +04:00
buttons.scss DEV: allow themes to more easily set border-radii (#19037) 2022-11-16 11:35:09 -05:00
color-input.scss FEATURE: Use native color-picker (#15748) 2022-02-01 11:18:13 -03:00
conditional-loading-section.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
convert-to-public-topic-modal.scss FEATURE: Allow choice of category when making a PM public (#7907) 2019-07-19 11:52:50 -04:00
d-tooltip.scss DEV: a new d-tooltip component (#17513) 2022-07-28 18:33:20 +04:00
date-input.scss UX: Fix date input icon display issues (#14369) 2021-09-17 12:07:10 -04:00
date-picker.scss UX: Normalize sizing for inputs, buttons, dropdowns (#14226) 2021-09-09 11:01:56 -04:00
date-time-input-range.scss UX: Normalize sizing for inputs, buttons, dropdowns (#14226) 2021-09-09 11:01:56 -04:00
date-time-input.scss UX: Normalize sizing for inputs, buttons, dropdowns (#14226) 2021-09-09 11:01:56 -04:00
download-calendar.scss FIX: uses tippy for popover (#15409) 2022-05-02 17:10:26 +02:00
footer-nav.scss DEV: set CSS custom property for footer-nav-height (#17744) 2022-08-01 18:01:06 -04:00
group-member-dropdown.scss Replace deprecated dropdown-button with DropdownSelectBoxComponent (#6451) 2018-10-05 09:48:17 -04:00
groups-form-membership-fields.scss UX: Make group membership UI clearer (#8210) 2019-10-17 18:05:42 +01:00
hashtag.scss FEATURE: Generic hashtag autocomplete lookup and markdown cooking (#18937) 2022-11-21 08:37:06 +10:00
horizontal-overflow-nav.scss UX: drag new user menus, scroll primary user nav (#18690) 2022-10-25 07:22:02 +08:00
iframed-html.scss Merge pull request from GHSA-vw39-6w7q-gfx5 2020-02-27 11:47:15 -06:00
ignored-user-list.scss UX: Normalize sizing for inputs, buttons, dropdowns (#14226) 2021-09-09 11:01:56 -04:00
keyboard_shortcuts.scss DEV: Use more css vars (#18561) 2022-10-12 16:05:42 +02:00
navs.scss DEV: allow themes to more easily set border-radii (#19037) 2022-11-16 11:35:09 -05:00
pick-files-button.scss DEV: add pick-files-button component (#13764) 2021-07-16 21:50:50 +04:00
relative-time-picker.scss UX: Fix local-dates styling (#12085) 2021-02-15 10:44:30 +00:00
share-and-invite-modal.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
svg.scss DEV: Remove xlink hrefs (#15059) 2021-11-25 15:22:43 +11:00
tap-tile.scss FEATURE: automatic dark mode (#10341) 2020-08-03 22:57:10 -04:00
time-input.scss FEATURE: automatic dark mode (#10341) 2020-08-03 22:57:10 -04:00
time-shortcut-picker.scss UX: Normalize sizing for inputs, buttons, dropdowns (#14226) 2021-09-09 11:01:56 -04:00
user-card.scss FIX: User card focus state appearing on click (#18650) 2022-10-18 11:15:42 -07:00
user-info.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
user-status-message.scss UX: improve styles of the user status message component (#17904) 2022-08-14 18:55:54 +04:00
user-status-picker.scss FEATURE: user status emoji (#17025) 2022-06-22 18:15:33 +04:00
user-stream-item.scss DEV: Use css var font sizes (#18518) 2022-10-12 15:31:59 +02:00
user-stream.scss UX: remove unneeded margin from user stream (#11964) 2021-02-04 14:39:43 +11:00
widget-dropdown.scss FEATURE: automatic dark mode (#10341) 2020-08-03 22:57:10 -04:00