Control tags (#7433)

* Add prefix to all internal tags

* Strip internal tag prefix from form labels

Co-authored-by: Dan Peterson <dan@dan-peterson.ca>
This commit is contained in:
jessopb 2022-01-21 20:43:45 -05:00 committed by GitHub
parent f06b3bd877
commit c1a54f9707
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View file

@ -5,7 +5,7 @@ import Tag from 'component/tag';
import { setUnion, setDifference } from 'util/set-operations'; import { setUnion, setDifference } from 'util/set-operations';
import I18nMessage from 'component/i18nMessage'; import I18nMessage from 'component/i18nMessage';
import analytics from 'analytics'; import analytics from 'analytics';
import { UTILITY_TAGS } from 'constants/tags'; import { CONTROL_TAGS, INTERNAL_TAGS, INTERNAL_TAG_PREFIX } from 'constants/tags';
type Props = { type Props = {
tagsPassedIn: Array<Tag>, tagsPassedIn: Array<Tag>,
@ -79,7 +79,7 @@ export default function TagsSearch(props: Props) {
const remainingUnfollowedTagsSet = setDifference(unfollowedTagsSet, selectedTagsSet); const remainingUnfollowedTagsSet = setDifference(unfollowedTagsSet, selectedTagsSet);
const suggestedTagsSet = setUnion(remainingFollowedTagsSet, remainingUnfollowedTagsSet); const suggestedTagsSet = setUnion(remainingFollowedTagsSet, remainingUnfollowedTagsSet);
const SPECIAL_TAGS = [...UTILITY_TAGS, 'lbry-first', 'mature']; const SPECIAL_TAGS = [...INTERNAL_TAGS, 'mature'];
let countWithoutSpecialTags = selectedTagsSet.size; let countWithoutSpecialTags = selectedTagsSet.size;
SPECIAL_TAGS.forEach((t) => { SPECIAL_TAGS.forEach((t) => {
@ -179,7 +179,7 @@ export default function TagsSearch(props: Props) {
{countWithoutSpecialTags === 0 && <Tag key={`placeholder-tag`} name={'example'} disabled type={'remove'} />} {countWithoutSpecialTags === 0 && <Tag key={`placeholder-tag`} name={'example'} disabled type={'remove'} />}
{Boolean(tagsPassedIn.length) && {Boolean(tagsPassedIn.length) &&
tagsPassedIn tagsPassedIn
.filter((t) => !UTILITY_TAGS.includes(t.name)) .filter((t) => !INTERNAL_TAGS.includes(t.name))
.map((tag) => ( .map((tag) => (
<Tag <Tag
key={`passed${tag.name}`} key={`passed${tag.name}`}
@ -234,7 +234,7 @@ export default function TagsSearch(props: Props) {
onSelect && ( // onSelect ensures this does not appear on TagFollow onSelect && ( // onSelect ensures this does not appear on TagFollow
<fieldset-section> <fieldset-section>
<label>{__('Control Tags')}</label> <label>{__('Control Tags')}</label>
{UTILITY_TAGS.map((t) => ( {CONTROL_TAGS.map((t) => (
<FormField <FormField
key={t} key={t}
name={t} name={t}
@ -242,6 +242,7 @@ export default function TagsSearch(props: Props) {
blockWrap={false} blockWrap={false}
label={__( label={__(
t t
.replace(INTERNAL_TAG_PREFIX, '')
.split('-') .split('-')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ') .join(' ')

View file

@ -13,11 +13,21 @@ export const DEFAULT_FOLLOWED_TAGS = [
'technology', 'technology',
]; ];
export const DISABLE_COMMENTS_TAG = 'disable-comments'; export const INTERNAL_TAG_PREFIX = 'c:';
export const DISABLE_SUPPORT_TAG = 'disable-support';
export const PREFERENCE_EMBED = 'preference-embed';
export const UTILITY_TAGS = [DISABLE_COMMENTS_TAG, DISABLE_SUPPORT_TAG, PREFERENCE_EMBED]; export const DISABLE_COMMENTS_TAG = 'c:disable-comments';
export const DISABLE_SUPPORT_TAG = 'disable-support';
export const PREFERENCE_EMBED = 'c:preference-embed';
export const SCHEDULED_LIVESTREAM_TAG = 'c:scheduled-livestream';
export const LBRY_FIRST_TAG = 'c:lbry-first';
// Control tags are special tags that are available to the user in some situations.
export const CONTROL_TAGS = [DISABLE_COMMENTS_TAG, DISABLE_SUPPORT_TAG, PREFERENCE_EMBED];
// System tags are special tags that are not available to the user.
export const SYSTEM_TAGS = [SCHEDULED_LIVESTREAM_TAG, LBRY_FIRST_TAG];
export const INTERNAL_TAGS = [...CONTROL_TAGS, ...SYSTEM_TAGS];
export const MATURE_TAGS = [ export const MATURE_TAGS = [
'porn', 'porn',