feat(editor): ♿️ Better Gsheets dropdowns
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
import { Input } from '@chakra-ui/react'
|
||||||
import { SearchableDropdown } from 'components/shared/SearchableDropdown'
|
import { SearchableDropdown } from 'components/shared/SearchableDropdown'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { Sheet } from 'services/integrations'
|
import { Sheet } from 'services/integrations'
|
||||||
@ -25,13 +26,15 @@ export const SheetsDropdown = ({
|
|||||||
const id = sheets?.find((s) => s.name === name)?.id
|
const id = sheets?.find((s) => s.name === name)?.id
|
||||||
if (isDefined(id)) onSelectSheetId(id)
|
if (isDefined(id)) onSelectSheetId(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isLoading) return <Input value="Loading..." isDisabled />
|
||||||
|
if (!sheets) return <Input value="No sheets found" isDisabled />
|
||||||
return (
|
return (
|
||||||
<SearchableDropdown
|
<SearchableDropdown
|
||||||
selectedItem={currentSheet?.name}
|
selectedItem={currentSheet?.name}
|
||||||
items={(sheets ?? []).map((s) => s.name)}
|
items={(sheets ?? []).map((s) => s.name)}
|
||||||
onValueChange={handleSpreadsheetSelect}
|
onValueChange={handleSpreadsheetSelect}
|
||||||
placeholder={'Select the sheet'}
|
placeholder={'Select the sheet'}
|
||||||
isLoading={isLoading}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Input } from '@chakra-ui/react'
|
||||||
import { SearchableDropdown } from 'components/shared/SearchableDropdown'
|
import { SearchableDropdown } from 'components/shared/SearchableDropdown'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { useSpreadsheets } from 'services/integrations'
|
import { useSpreadsheets } from 'services/integrations'
|
||||||
@ -23,13 +24,14 @@ export const SpreadsheetsDropdown = ({
|
|||||||
const id = spreadsheets?.find((s) => s.name === name)?.id
|
const id = spreadsheets?.find((s) => s.name === name)?.id
|
||||||
if (id) onSelectSpreadsheetId(id)
|
if (id) onSelectSpreadsheetId(id)
|
||||||
}
|
}
|
||||||
|
if (isLoading) return <Input value="Loading..." isDisabled />
|
||||||
|
if (!spreadsheets) return <Input value="No spreadsheets found" isDisabled />
|
||||||
return (
|
return (
|
||||||
<SearchableDropdown
|
<SearchableDropdown
|
||||||
selectedItem={currentSpreadsheet?.name}
|
selectedItem={currentSpreadsheet?.name}
|
||||||
items={(spreadsheets ?? []).map((s) => s.name)}
|
items={(spreadsheets ?? []).map((s) => s.name)}
|
||||||
onValueChange={handleSpreadsheetSelect}
|
onValueChange={handleSpreadsheetSelect}
|
||||||
placeholder={'Search for spreadsheet'}
|
placeholder={'Search for spreadsheet'}
|
||||||
isLoading={isLoading}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
Button,
|
Button,
|
||||||
Text,
|
|
||||||
InputProps,
|
InputProps,
|
||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
import { useState, useRef, useEffect, ChangeEvent } from 'react'
|
import { useState, useRef, useEffect, ChangeEvent } from 'react'
|
||||||
@ -17,14 +16,12 @@ type Props = {
|
|||||||
selectedItem?: string
|
selectedItem?: string
|
||||||
items: string[]
|
items: string[]
|
||||||
onValueChange?: (value: string) => void
|
onValueChange?: (value: string) => void
|
||||||
isLoading?: boolean
|
|
||||||
} & InputProps
|
} & InputProps
|
||||||
|
|
||||||
export const SearchableDropdown = ({
|
export const SearchableDropdown = ({
|
||||||
selectedItem,
|
selectedItem,
|
||||||
items,
|
items,
|
||||||
onValueChange,
|
onValueChange,
|
||||||
isLoading = false,
|
|
||||||
...inputProps
|
...inputProps
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { onOpen, onClose, isOpen } = useDisclosure()
|
const { onOpen, onClose, isOpen } = useDisclosure()
|
||||||
@ -66,6 +63,7 @@ export const SearchableDropdown = ({
|
|||||||
}, [debouncedInputValue])
|
}, [debouncedInputValue])
|
||||||
|
|
||||||
const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
if (!isOpen) onOpen()
|
||||||
setInputValue(e.target.value)
|
setInputValue(e.target.value)
|
||||||
if (e.target.value === '') {
|
if (e.target.value === '') {
|
||||||
setFilteredItems([...items.slice(0, 50)])
|
setFilteredItems([...items.slice(0, 50)])
|
||||||
@ -111,7 +109,7 @@ export const SearchableDropdown = ({
|
|||||||
w="inherit"
|
w="inherit"
|
||||||
shadow="lg"
|
shadow="lg"
|
||||||
>
|
>
|
||||||
{filteredItems.length > 0 ? (
|
{filteredItems.length > 0 && (
|
||||||
<>
|
<>
|
||||||
{filteredItems.map((item, idx) => {
|
{filteredItems.map((item, idx) => {
|
||||||
return (
|
return (
|
||||||
@ -132,10 +130,6 @@ export const SearchableDropdown = ({
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</>
|
</>
|
||||||
) : (
|
|
||||||
<Text p={4} color="gray.500">
|
|
||||||
{isLoading ? 'Loading...' : 'Not found.'}
|
|
||||||
</Text>
|
|
||||||
)}
|
)}
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
Reference in New Issue
Block a user