Spaces:
Configuration error
Configuration error
Download src/components/input/WebsiteSelect.tsx from SreejithSHR/umami: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/input/WebsiteSelect.tsx
- Command line
-
hf download hf://spaces/SreejithSHR/umami/src/components/input/WebsiteSelect.tsx
-
curl -L -o WebsiteSelect.tsx https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/input/WebsiteSelect.tsx
1.59 kB
| import { useState, Key } from 'react'; | |
| import { Dropdown, Item } from 'react-basics'; | |
| import { useWebsite, useWebsites, useMessages } from 'components/hooks'; | |
| import Empty from 'components/common/Empty'; | |
| import styles from './WebsiteSelect.module.css'; | |
| export function WebsiteSelect({ | |
| websiteId, | |
| teamId, | |
| onSelect, | |
| }: { | |
| websiteId?: string; | |
| teamId?: string; | |
| onSelect?: (key: any) => void; | |
| }) { | |
| const { formatMessage, labels, messages } = useMessages(); | |
| const [query, setQuery] = useState(''); | |
| const [selectedId, setSelectedId] = useState<Key>(websiteId); | |
| const { data: website } = useWebsite(selectedId as string); | |
| const queryResult = useWebsites({ teamId }, { query, pageSize: 5 }); | |
| const renderValue = () => { | |
| return website?.name; | |
| }; | |
| const renderEmpty = () => { | |
| return <Empty message={formatMessage(messages.noResultsFound)} />; | |
| }; | |
| const handleSelect = (value: any) => { | |
| setSelectedId(value); | |
| onSelect?.(value); | |
| }; | |
| const handleSearch = (value: string) => { | |
| setQuery(value); | |
| }; | |
| return ( | |
| <Dropdown | |
| menuProps={{ className: styles.dropdown }} | |
| items={queryResult?.result?.data as any[]} | |
| value={selectedId as string} | |
| renderValue={renderValue} | |
| renderEmpty={renderEmpty} | |
| onChange={handleSelect} | |
| alignment="end" | |
| placeholder={formatMessage(labels.selectWebsite)} | |
| allowSearch={true} | |
| onSearch={handleSearch} | |
| isLoading={queryResult.query.isLoading} | |
| > | |
| {({ id, name }) => <Item key={id}>{name}</Item>} | |
| </Dropdown> | |
| ); | |
| } | |
| export default WebsiteSelect; | |