-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
143 additions
and
146 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/components/src/ProfileTagsList/ProfileTagsList.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ProfileTagsList } from './ProfileTagsList' | ||
|
||
import type { Meta, StoryFn } from '@storybook/react' | ||
|
||
export default { | ||
title: 'Components/ProfileTagsList', | ||
component: ProfileTagsList, | ||
} as Meta<typeof ProfileTagsList> | ||
|
||
export const Default: StoryFn<typeof ProfileTagsList> = () => ( | ||
<ProfileTagsList | ||
tagIds={{ uCzWZbz3aVKyx2keoqRi: true, J3LF7fMsDfniYT2ZX3rf: false }} | ||
/> | ||
) |
19 changes: 19 additions & 0 deletions
19
packages/components/src/ProfileTagsList/ProfileTagsList.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import '@testing-library/jest-dom/vitest' | ||
|
||
import { describe, expect, it } from 'vitest' | ||
|
||
import { render } from '../test/utils' | ||
import { Default } from './ProfileTagsList.stories' | ||
|
||
import type { IProps } from './ProfileTagsList' | ||
|
||
describe('ProfileTagsList', () => { | ||
it('validates the component behaviour', () => { | ||
const { getByText, queryByText } = render( | ||
<Default {...(Default.args as IProps)} />, | ||
) | ||
|
||
expect(getByText('Electronics')).toBeInTheDocument() | ||
expect(queryByText('Machining')).toBeNull() | ||
}) | ||
}) |
32 changes: 32 additions & 0 deletions
32
packages/components/src/ProfileTagsList/ProfileTagsList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { profileTags } from 'oa-shared' | ||
import { Flex } from 'theme-ui' | ||
|
||
import { Category } from '../Category/Category' | ||
|
||
import type { ISelectedTags } from 'oa-shared' | ||
|
||
export interface IProps { | ||
tagIds: ISelectedTags | ||
} | ||
|
||
export const ProfileTagsList = ({ tagIds }: IProps) => { | ||
const selectedTagIds = Object.keys(tagIds).filter((id) => tagIds[id] === true) | ||
const tags = selectedTagIds | ||
.map((id) => profileTags.find(({ _id }) => id === _id)) | ||
.filter((tag) => tag !== undefined) | ||
|
||
if (tags.length === 0) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Flex sx={{ gap: 2 }}> | ||
{tags.map( | ||
(tag, index) => | ||
tag?.label && ( | ||
<Category key={index} category={{ label: tag.label }} /> | ||
), | ||
)} | ||
</Flex> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.