-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI Create Peer: replace drop down with columns of buttons (#1611)
Reduces clicks, with dropdown it's: 1. click dropdown 2. scroll list 3. click peer type 4. click create Now user only needs one click Co-authored-by: Amogh-Bharadwaj <[email protected]>
- Loading branch information
1 parent
4027a4e
commit c73853d
Showing
3 changed files
with
71 additions
and
80 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,81 @@ | ||
'use client'; | ||
import SelectTheme from '@/app/styles/select'; | ||
import TitleCase from '@/app/utils/titlecase'; | ||
import { DBType } from '@/grpc_generated/peers'; | ||
import { Button } from '@/lib/Button/Button'; | ||
import Image from 'next/image'; | ||
import { Dispatch, SetStateAction } from 'react'; | ||
import ReactSelect from 'react-select'; | ||
import Link from 'next/link'; | ||
import { DBTypeToImageMapping } from './PeerComponent'; | ||
|
||
interface SelectSourceProps { | ||
peerType: string; | ||
setPeerType: Dispatch<SetStateAction<string>>; | ||
} | ||
|
||
function SourceLabel({ value, label }: { value: string; label: string }) { | ||
function SourceLabel({ label }: { label: string }) { | ||
const peerLogo = DBTypeToImageMapping(label); | ||
return ( | ||
<div style={{ display: 'flex', alignItems: 'center' }}> | ||
<Image src={peerLogo} alt='peer' height={15} width={15} /> | ||
<div style={{ marginLeft: 10 }}>{TitleCase(label)}</div> | ||
</div> | ||
<Button | ||
as={Link} | ||
href={`/peers/create/${label}`} | ||
style={{ | ||
justifyContent: 'space-between', | ||
padding: '0.5rem', | ||
backgroundColor: 'white', | ||
borderRadius: '1rem', | ||
border: '1px solid rgba(0,0,0,0.1)', | ||
}} | ||
> | ||
<Image | ||
src={peerLogo} | ||
alt='peer' | ||
width={20} | ||
height={20} | ||
objectFit='cover' | ||
/> | ||
<div>{TitleCase(label)}</div> | ||
</Button> | ||
); | ||
} | ||
|
||
export default function SelectSource({ | ||
peerType, | ||
setPeerType, | ||
}: SelectSourceProps) { | ||
const dbTypes = Object.values(DBType) | ||
.filter( | ||
(value): value is string => | ||
typeof value === 'string' && | ||
(value === 'POSTGRESQL' || | ||
value === 'SNOWFLAKE' || | ||
value === 'BIGQUERY' || | ||
value === 'S3' || | ||
value === 'CLICKHOUSE' || | ||
value === 'KAFKA' || | ||
value === 'EVENTHUBS' || | ||
value === 'PUBSUB' || | ||
value === 'ELASTICSEARCH') | ||
) | ||
.map((value) => ({ label: value, value })); | ||
const dbTypes = [ | ||
[ | ||
'Postgres', | ||
'POSTGRESQL', | ||
'RDS POSTGRESQL', | ||
'GOOGLE CLOUD POSTGRESQL', | ||
'AZURE FLEXIBLE POSTGRESQL', | ||
'TEMBO', | ||
'CRUNCHY POSTGRES', | ||
], | ||
['Warehouses', 'SNOWFLAKE', 'BIGQUERY', 'S3', 'CLICKHOUSE', 'ELASTICSEARCH'], | ||
['Queues', 'KAFKA', 'EVENTHUBS', 'PUBSUB'], | ||
]; | ||
|
||
dbTypes.push( | ||
{ value: 'POSTGRESQL', label: 'POSTGRESQL' }, | ||
{ value: 'POSTGRESQL', label: 'RDS POSTGRESQL' }, | ||
{ value: 'POSTGRESQL', label: 'GOOGLE CLOUD POSTGRESQL' }, | ||
{ value: 'POSTGRESQL', label: 'AZURE FLEXIBLE POSTGRESQL' }, | ||
{ value: 'POSTGRESQL', label: 'TEMBO' }, | ||
{ value: 'POSTGRESQL', label: 'CRUNCHY POSTGRES' } | ||
); | ||
return ( | ||
<ReactSelect | ||
className='w-full' | ||
placeholder='Select a source' | ||
options={dbTypes} | ||
defaultValue={dbTypes.find((opt) => opt.label === peerType)} | ||
onChange={(val, _) => val && setPeerType(val.label)} | ||
formatOptionLabel={SourceLabel} | ||
theme={SelectTheme} | ||
getOptionValue={(option) => option.label} | ||
/> | ||
); | ||
const gridContainerStyle = { | ||
display: 'flex', | ||
gap: '20px', | ||
flexWrap: 'wrap', | ||
border: 'solid #18794e', | ||
borderRadius: '20px', | ||
position: 'relative', | ||
padding: '20px', | ||
marginTop: '20px', | ||
} as const; | ||
const gridHeaderStyle = { | ||
position: 'absolute', | ||
top: '-15px', | ||
height: '30px', | ||
display: 'flex', | ||
alignItems: 'center', | ||
color: '#fff', | ||
backgroundColor: '#18794e', | ||
borderRadius: '15px', | ||
marginLeft: '10px', | ||
paddingLeft: '10px', | ||
paddingRight: '10px', | ||
} as const; | ||
|
||
export default function SelectSource() { | ||
return dbTypes.map(([category, ...items]) => ( | ||
<div key={category} style={gridContainerStyle}> | ||
<div style={gridHeaderStyle}>{category}</div> | ||
{items.map((item) => ( | ||
<SourceLabel key={item} label={item} /> | ||
))} | ||
</div> | ||
)); | ||
} |