From f27933965ff63351f08427a219ba5b29dfacc121 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Fri, 12 May 2023 11:51:00 -0400 Subject: [PATCH] Allow non-owners to see pinned tags --- app/soapbox/components/ui/icon/icon.tsx | 7 ++- .../__tests__/group-tag-list-item.test.tsx | 43 ++++++++++--------- .../group/components/group-tag-list-item.tsx | 30 +++++++++---- app/soapbox/features/group/group-tags.tsx | 2 +- 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/app/soapbox/components/ui/icon/icon.tsx b/app/soapbox/components/ui/icon/icon.tsx index f51c3ca38..709b3126f 100644 --- a/app/soapbox/components/ui/icon/icon.tsx +++ b/app/soapbox/components/ui/icon/icon.tsx @@ -17,11 +17,16 @@ interface IIcon extends Pick, 'strokeWidth'> { src: string /** Width and height of the icon in pixels. */ size?: number + /** Override the data-testid */ + 'data-testid'?: string } /** Renders and SVG icon with optional counter. */ const Icon: React.FC = ({ src, alt, count, size, countMax, ...filteredProps }): JSX.Element => ( -
+
{count ? ( diff --git a/app/soapbox/features/group/components/__tests__/group-tag-list-item.test.tsx b/app/soapbox/features/group/components/__tests__/group-tag-list-item.test.tsx index 4418fff86..f91853dc4 100644 --- a/app/soapbox/features/group/components/__tests__/group-tag-list-item.test.tsx +++ b/app/soapbox/features/group/components/__tests__/group-tag-list-item.test.tsx @@ -91,31 +91,32 @@ describe('', () => { expect(screen.queryAllByTestId('pin-icon')).toHaveLength(0); }); }); + }); - describe('as a non-owner', () => { - const group = buildGroup({ - relationship: buildGroupRelationship({ - role: GroupRoles.ADMIN, - member: true, - }), + describe('as a non-owner', () => { + const group = buildGroup({ + relationship: buildGroupRelationship({ + role: GroupRoles.ADMIN, + member: true, + }), + }); + + describe('when the tag is pinned', () => { + const tag = buildGroupTag({ pinned: true, visible: true }); + + it('does render the pin icon', () => { + render(); + screen.debug(); + expect(screen.queryAllByTestId('pin-icon')).toHaveLength(1); }); + }); - describe('when the tag is visible', () => { - const tag = buildGroupTag({ visible: true }); + describe('when the tag is not pinned', () => { + const tag = buildGroupTag({ pinned: false, visible: true }); - it('does not render the pin icon', () => { - render(); - expect(screen.queryAllByTestId('pin-icon')).toHaveLength(0); - }); - }); - - describe('when the tag is not visible', () => { - const tag = buildGroupTag({ visible: false }); - - it('does not render the pin icon', () => { - render(); - expect(screen.queryAllByTestId('pin-icon')).toHaveLength(0); - }); + it('does not render the pin icon', () => { + render(); + expect(screen.queryAllByTestId('pin-icon')).toHaveLength(0); }); }); }); diff --git a/app/soapbox/features/group/components/group-tag-list-item.tsx b/app/soapbox/features/group/components/group-tag-list-item.tsx index bf02cc202..07660cf21 100644 --- a/app/soapbox/features/group/components/group-tag-list-item.tsx +++ b/app/soapbox/features/group/components/group-tag-list-item.tsx @@ -3,7 +3,7 @@ import { defineMessages, useIntl } from 'react-intl'; import { Link } from 'react-router-dom'; import { useUpdateGroupTag } from 'soapbox/api/hooks'; -import { HStack, IconButton, Stack, Text, Tooltip } from 'soapbox/components/ui'; +import { HStack, Icon, IconButton, Stack, Text, Tooltip } from 'soapbox/components/ui'; import { importEntities } from 'soapbox/entity-store/actions'; import { Entities } from 'soapbox/entity-store/entities'; import { useAppDispatch } from 'soapbox/hooks'; @@ -84,6 +84,20 @@ const GroupTagListItem = (props: IGroupMemberListItem) => { }; const renderPinIcon = () => { + if (!isOwner && tag.pinned) { + return ( + + ); + } + + if (!isOwner) { + return null; + } + if (isPinnable) { return ( { - {isOwner ? ( - - {tag.visible ? ( - renderPinIcon() - ) : null} + + {tag.visible ? ( + renderPinIcon() + ) : null} + {isOwner ? ( { iconClassName='h-5 w-5 text-primary-500 dark:text-accent-blue' /> - - ) : null} + ) : null} + ); }; diff --git a/app/soapbox/features/group/group-tags.tsx b/app/soapbox/features/group/group-tags.tsx index 710a4fdb5..d5335e844 100644 --- a/app/soapbox/features/group/group-tags.tsx +++ b/app/soapbox/features/group/group-tags.tsx @@ -36,7 +36,7 @@ const GroupTopics: React.FC = (props) => { showLoading={!group || isLoading && tags.length === 0} placeholderComponent={PlaceholderAccount} placeholderCount={3} - className='divide-y divide-solid divide-gray-300' + className='divide-y divide-solid divide-gray-300 dark:divide-gray-800' itemClassName='py-3 last:pb-0' emptyMessage={