-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add organization filter to event search page
- Loading branch information
1 parent
6d89bdc
commit edb4ab4
Showing
21 changed files
with
286 additions
and
31 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/common/components/filterTag/publisherFilterTag/PublisherFilterTag.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,26 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import useOrganizationOptions from '../../../../domain/organization/hooks/useOrganizationOptions'; | ||
import getValue from '../../../../utils/getValue'; | ||
import FilterTag, { FilterTagProps } from '../FilterTag'; | ||
|
||
type Props = Omit<FilterTagProps, 'text' | 'type'>; | ||
|
||
const PublisherFilterTag: React.FC<Props> = ({ value, ...rest }) => { | ||
const { t } = useTranslation(); | ||
const { loading, options } = useOrganizationOptions('id'); | ||
|
||
const name = getValue(options.find((o) => o.value)?.label, ''); | ||
|
||
return ( | ||
<FilterTag | ||
{...rest} | ||
text={loading ? t('common.loading') : name} | ||
type="publisher" | ||
value={value} | ||
/> | ||
); | ||
}; | ||
|
||
export default PublisherFilterTag; |
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
42 changes: 42 additions & 0 deletions
42
src/domain/eventSearch/searchPanel/publisherSelector/PublisherSelector.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,42 @@ | ||
import React from 'react'; | ||
|
||
import MultiSelectDropdown, { | ||
MultiselectDropdownProps, | ||
} from '../../../../common/components/multiSelectDropdown/MultiSelectDropdown'; | ||
import skipFalsyType from '../../../../utils/skipFalsyType'; | ||
import useOrganizationOptions from '../../../organization/hooks/useOrganizationOptions'; | ||
|
||
export type PublisherSelectorProps = { value: string[] } & Omit< | ||
MultiselectDropdownProps, | ||
'options' | 'value' | ||
>; | ||
|
||
const PublisherSelector: React.FC<PublisherSelectorProps> = ({ | ||
id, | ||
toggleButtonLabel, | ||
value, | ||
...rest | ||
}) => { | ||
const [searchValue, setSearchValue] = React.useState(''); | ||
|
||
const { loading, options } = useOrganizationOptions('id'); | ||
|
||
console.log(value); | ||
return ( | ||
<MultiSelectDropdown | ||
{...rest} | ||
id={id} | ||
options={options} | ||
searchValue={searchValue} | ||
setSearchValue={setSearchValue} | ||
showSearch={true} | ||
showLoadingSpinner={loading} | ||
toggleButtonLabel={toggleButtonLabel} | ||
value={value | ||
.map((v) => options.find((o) => o.value === v)) | ||
.filter(skipFalsyType)} | ||
/> | ||
); | ||
}; | ||
|
||
export default PublisherSelector; |
50 changes: 50 additions & 0 deletions
50
src/domain/eventSearch/searchPanel/publisherSelector/__tests__/PublisherSelector.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,50 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
configure, | ||
render, | ||
screen, | ||
userEvent, | ||
} from '../../../../../utils/testUtils'; | ||
import { | ||
mockedOrganizationsResponse, | ||
organizations, | ||
organizationsOverrides, | ||
} from '../../../../organizations/__mocks__/organizationsPage'; | ||
import PublisherSelector, { | ||
PublisherSelectorProps, | ||
} from '../PublisherSelector'; | ||
|
||
configure({ defaultHidden: true }); | ||
|
||
const mocks = [mockedOrganizationsResponse]; | ||
|
||
const toggleButtonLabel = 'Select place'; | ||
|
||
const defaultProps: PublisherSelectorProps = { | ||
onChange: vi.fn(), | ||
toggleButtonLabel, | ||
value: [], | ||
}; | ||
|
||
const renderComponent = (props?: Partial<PublisherSelectorProps>) => | ||
render(<PublisherSelector {...defaultProps} {...props} />, { mocks }); | ||
|
||
const getToggleButton = () => | ||
screen.getByRole('button', { name: toggleButtonLabel }); | ||
|
||
test('should render publisher selector', async () => { | ||
const publisherId = organizations.data[0]?.id as string; | ||
const publisherName = organizations.data[0]?.name as string; | ||
const user = userEvent.setup(); | ||
renderComponent({ value: [publisherId] }); | ||
|
||
await screen.findByText(publisherName); | ||
|
||
const toggleButton = getToggleButton(); | ||
await user.click(toggleButton); | ||
|
||
for (const { name } of organizationsOverrides) { | ||
await screen.findByLabelText(name as string); | ||
} | ||
}); |
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.