Skip to content

Commit

Permalink
Fix slack bot form + LLM provider form
Browse files Browse the repository at this point in the history
  • Loading branch information
Weves committed Nov 4, 2024
1 parent bafb95d commit 8e55566
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
57 changes: 33 additions & 24 deletions web/src/components/admin/connectors/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "@radix-ui/react-tooltip";
import ReactMarkdown from "react-markdown";
import { FaMarkdown } from "react-icons/fa";
import { useState } from "react";
import { useRef, useState } from "react";
import remarkGfm from "remark-gfm";
import { EditIcon } from "@/components/icons/icons";
import { Button } from "@/components/ui/button";
Expand Down Expand Up @@ -602,6 +602,11 @@ export function SelectorFormField({
}: SelectorFormFieldProps) {
const [field] = useField<string>(name);
const { setFieldValue } = useFormikContext();
const [container, setContainer] = useState<HTMLDivElement | null>(null);

const currentlySelected = options.find(
(option) => option.value?.toString() === field.value?.toString()
);

return (
<div>
Expand All @@ -612,7 +617,7 @@ export function SelectorFormField({
</div>
)}
{subtext && <SubLabel>{subtext}</SubLabel>}
<div className="mt-2">
<div className="mt-2" ref={setContainer}>
<Select
value={field.value || defaultValue}
onValueChange={
Expand All @@ -622,30 +627,34 @@ export function SelectorFormField({
>
<SelectTrigger>
<SelectValue placeholder="Select...">
{field.value || defaultValue || ""}
{currentlySelected?.name || defaultValue || ""}
</SelectValue>
</SelectTrigger>
<SelectContent
side={side}
className={maxHeight ? `max-h-[${maxHeight}]` : undefined}
>
{options.length == 0 && (
<SelectItem value="default">Select...</SelectItem>
)}
{defaultValue && (
<SelectItem value={defaultValue}>{defaultValue}</SelectItem>
)}
{options.map((option) => (
<SelectItem
icon={option.icon}
key={option.value}
value={String(option.value)}
selected={field.value === option.value}
>
{option.name}
</SelectItem>
))}
</SelectContent>

{container && (
<SelectContent
side={side}
className={maxHeight ? `max-h-[${maxHeight}]` : undefined}
container={container}
>
{options.length == 0 && (
<SelectItem value="default">Select...</SelectItem>
)}
{defaultValue && (
<SelectItem value={defaultValue}>{defaultValue}</SelectItem>
)}
{options.map((option) => (
<SelectItem
icon={option.icon}
key={option.value}
value={String(option.value)}
selected={field.value === option.value}
>
{option.name}
</SelectItem>
))}
</SelectContent>
)}
</Select>
</div>

Expand Down
8 changes: 5 additions & 3 deletions web/src/components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ SelectScrollDownButton.displayName =

const SelectContent = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
>(({ className, children, position = "popper", ...props }, ref) => (
<SelectPrimitive.Portal>
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> & {
container?: HTMLElement | null;
}
>(({ className, children, position = "popper", container, ...props }, ref) => (
<SelectPrimitive.Portal container={container}>
<SelectPrimitive.Content
ref={ref}
className={cn(
Expand Down

0 comments on commit 8e55566

Please sign in to comment.