Skip to content

Commit

Permalink
fix(editor): 🐛 FIx Webhook settings debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 10, 2022
1 parent 6cf89d8 commit 31298e3
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 15 deletions.
6 changes: 4 additions & 2 deletions apps/builder/components/shared/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import { useDebouncedCallback } from 'use-debounce'
type Props = {
value: string
lang?: 'css' | 'json' | 'js' | 'html'
onChange?: (value: string) => void
isReadOnly?: boolean
debounceTimeout?: number
onChange?: (value: string) => void
}
export const CodeEditor = ({
value,
lang,
onChange,
isReadOnly = false,
debounceTimeout = 1000,
...props
}: Props & Omit<BoxProps, 'onChange'>) => {
const editorContainer = useRef<HTMLDivElement | null>(null)
Expand All @@ -28,7 +30,7 @@ export const CodeEditor = ({
setPlainTextValue(value)
onChange && onChange(value)
},
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : 1000
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : debounceTimeout
)

useEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const KeyValueInputs = ({
onItemChange,
keyPlaceholder,
valuePlaceholder,
debounceTimeout,
}: TableListItemProps<KeyValue> & {
keyPlaceholder?: string
valuePlaceholder?: string
Expand All @@ -45,6 +46,7 @@ export const KeyValueInputs = ({
defaultValue={item.key ?? ''}
onChange={handleKeyChange}
placeholder={keyPlaceholder}
debounceTimeout={debounceTimeout}
/>
</FormControl>
<FormControl>
Expand All @@ -54,6 +56,7 @@ export const KeyValueInputs = ({
defaultValue={item.value ?? ''}
onChange={handleValueChange}
placeholder={valuePlaceholder}
debounceTimeout={debounceTimeout}
/>
</FormControl>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const DataVariableInputs = ({
item,
onItemChange,
dataItems,
debounceTimeout,
}: TableListItemProps<ResponseVariableMapping> & { dataItems: string[] }) => {
const handleBodyPathChange = (bodyPath: string) =>
onItemChange({ ...item, bodyPath })
Expand All @@ -23,6 +24,7 @@ export const DataVariableInputs = ({
value={item.bodyPath}
onValueChange={handleBodyPathChange}
placeholder="Select the data"
debounceTimeout={debounceTimeout}
/>
</FormControl>
<FormControl>
Expand All @@ -31,6 +33,7 @@ export const DataVariableInputs = ({
onSelectVariable={handleVariableChange}
placeholder="Search for a variable"
initialVariableId={item.variableId}
debounceTimeout={debounceTimeout}
/>
</FormControl>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { VariableForTest, Variable } from 'models'
export const VariableForTestInputs = ({
item,
onItemChange,
debounceTimeout,
}: TableListItemProps<VariableForTest>) => {
const handleVariableSelect = (variable?: Variable) =>
onItemChange({ ...item, variableId: variable?.id })
Expand All @@ -22,6 +23,7 @@ export const VariableForTestInputs = ({
id={'name' + item.id}
initialVariableId={item.variableId}
onSelectVariable={handleVariableSelect}
debounceTimeout={debounceTimeout}
/>
</FormControl>
<FormControl>
Expand All @@ -30,6 +32,7 @@ export const VariableForTestInputs = ({
id={'value' + item.id}
defaultValue={item.value ?? ''}
onChange={handleValueChange}
debounceTimeout={debounceTimeout}
/>
</FormControl>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const WebhookSettings = ({

return () => {
setLocalWebhook((localWebhook) => {
console.log(localWebhook)
if (!localWebhook) return
updateWebhook(webhookId, localWebhook).then()
return localWebhook
Expand Down Expand Up @@ -148,6 +149,7 @@ export const WebhookSettings = ({
placeholder="Your Webhook URL..."
defaultValue={localWebhook.url ?? ''}
onChange={handleUrlChange}
debounceTimeout={0}
/>
<SwitchWithLabel
id={'easy-config'}
Expand Down Expand Up @@ -177,6 +179,7 @@ export const WebhookSettings = ({
onItemsChange={handleQueryParamsChange}
Item={QueryParamsInputs}
addLabel="Add a param"
debounceTimeout={0}
/>
</AccordionPanel>
</AccordionItem>
Expand All @@ -191,6 +194,7 @@ export const WebhookSettings = ({
onItemsChange={handleHeadersChange}
Item={HeadersInputs}
addLabel="Add a value"
debounceTimeout={0}
/>
</AccordionPanel>
</AccordionItem>
Expand All @@ -211,6 +215,7 @@ export const WebhookSettings = ({
value={localWebhook.body ?? ''}
lang="json"
onChange={handleBodyChange}
debounceTimeout={0}
/>
)}
</AccordionPanel>
Expand All @@ -228,6 +233,7 @@ export const WebhookSettings = ({
onItemsChange={handleVariablesChange}
Item={VariableForTestInputs}
addLabel="Add an entry"
debounceTimeout={0}
/>
</AccordionPanel>
</AccordionItem>
Expand Down Expand Up @@ -258,6 +264,7 @@ export const WebhookSettings = ({
onItemsChange={handleResponseMappingChange}
Item={ResponseMappingInputs}
addLabel="Add an entry"
debounceTimeout={0}
/>
</AccordionPanel>
</AccordionItem>
Expand Down
4 changes: 3 additions & 1 deletion apps/builder/components/shared/SearchableDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ import { useDebounce } from 'use-debounce'
type Props = {
selectedItem?: string
items: string[]
debounceTimeout?: number
onValueChange?: (value: string) => void
} & InputProps

export const SearchableDropdown = ({
selectedItem,
items,
debounceTimeout = 1000,
onValueChange,
...inputProps
}: Props) => {
const { onOpen, onClose, isOpen } = useDisclosure()
const [inputValue, setInputValue] = useState(selectedItem ?? '')
const [debouncedInputValue] = useDebounce(
inputValue,
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : 1000
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : debounceTimeout
)
const [filteredItems, setFilteredItems] = useState([
...items
Expand Down
4 changes: 3 additions & 1 deletion apps/builder/components/shared/SmartNumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import { useDebounce } from 'use-debounce'
export const SmartNumberInput = ({
value,
onValueChange,
debounceTimeout = 1000,
...props
}: {
value?: number
debounceTimeout?: number
onValueChange: (value?: number) => void
} & NumberInputProps) => {
const [currentValue, setCurrentValue] = useState(value?.toString() ?? '')
Expand All @@ -23,7 +25,7 @@ export const SmartNumberInput = ({
)
const [debouncedValue] = useDebounce(
valueToReturn,
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : 1000
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : debounceTimeout
)

useEffect(() => {
Expand Down
11 changes: 9 additions & 2 deletions apps/builder/components/shared/TableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ type ItemWithId<T> = T & { id: string }

export type TableListItemProps<T> = {
item: T
debounceTimeout?: number
onItemChange: (item: T) => void
}

type Props<T> = {
initialItems: ItemWithId<T>[]
onItemsChange: (items: ItemWithId<T>[]) => void
addLabel?: string
debounceTimeout?: number
onItemsChange: (items: ItemWithId<T>[]) => void
Item: (props: TableListItemProps<T>) => JSX.Element
ComponentBetweenItems?: (props: unknown) => JSX.Element
}
Expand All @@ -25,6 +27,7 @@ export const TableList = <T,>({
initialItems,
onItemsChange,
addLabel = 'Add',
debounceTimeout,
Item,
ComponentBetweenItems = () => <></>,
}: Props<T>) => {
Expand Down Expand Up @@ -75,7 +78,11 @@ export const TableList = <T,>({
onMouseLeave={handleMouseLeave}
mt={itemIndex !== 0 && ComponentBetweenItems ? 4 : 0}
>
<Item item={item} onItemChange={handleCellChange(itemIndex)} />
<Item
item={item}
onItemChange={handleCellChange(itemIndex)}
debounceTimeout={debounceTimeout}
/>
<Fade in={showDeleteIndex === itemIndex}>
<IconButton
icon={<TrashIcon />}
Expand Down
4 changes: 3 additions & 1 deletion apps/builder/components/shared/Textbox/TextBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export type TextBoxProps = {
| ComponentWithAs<'textarea', TextareaProps>
| ComponentWithAs<'input', InputProps>
withVariableButton?: boolean
debounceTimeout?: number
} & Omit<InputProps & TextareaProps, 'onChange'>

export const TextBox = ({
onChange,
TextBox,
withVariableButton = true,
debounceTimeout = 1000,
...props
}: TextBoxProps) => {
const textBoxRef = useRef<(HTMLInputElement & HTMLTextAreaElement) | null>(
Expand All @@ -39,7 +41,7 @@ export const TextBox = ({
(value) => {
onChange(value)
},
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : 1000
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : debounceTimeout
)

useEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,14 @@ const CollaborationTypeMenuButton = ({
{convertCollaborationTypeEnumToReadable(type)}
</MenuButton>
<MenuList minW={0}>
<MenuItem onClick={() => onChange(CollaborationType.READ)}>
{convertCollaborationTypeEnumToReadable(CollaborationType.READ)}
</MenuItem>
<MenuItem onClick={() => onChange(CollaborationType.WRITE)}>
{convertCollaborationTypeEnumToReadable(CollaborationType.WRITE)}
</MenuItem>
<Stack maxH={'35vh'} overflowY="scroll" spacing="0">
<MenuItem onClick={() => onChange(CollaborationType.READ)}>
{convertCollaborationTypeEnumToReadable(CollaborationType.READ)}
</MenuItem>
<MenuItem onClick={() => onChange(CollaborationType.WRITE)}>
{convertCollaborationTypeEnumToReadable(CollaborationType.WRITE)}
</MenuItem>
</Stack>
</MenuList>
</Menu>
)
Expand Down
6 changes: 4 additions & 2 deletions apps/builder/components/shared/VariableSearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ import { byId, isNotDefined } from 'utils'

type Props = {
initialVariableId?: string
debounceTimeout?: number
isDefaultOpen?: boolean
onSelectVariable: (
variable: Pick<Variable, 'id' | 'name'> | undefined
) => void
isDefaultOpen?: boolean
} & InputProps

export const VariableSearchInput = ({
initialVariableId,
onSelectVariable,
isDefaultOpen,
debounceTimeout = 1000,
...inputProps
}: Props) => {
const { onOpen, onClose, isOpen } = useDisclosure()
Expand All @@ -40,7 +42,7 @@ export const VariableSearchInput = ({
)
const [debouncedInputValue] = useDebounce(
inputValue,
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : 1000
process.env.NEXT_PUBLIC_E2E_TEST ? 0 : debounceTimeout
)
const [filteredItems, setFilteredItems] = useState<Variable[]>(
variables ?? []
Expand Down

2 comments on commit 31298e3

@vercel
Copy link

@vercel vercel bot commented on 31298e3 Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.