Skip to content

Commit

Permalink
temporary field
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Jan 19, 2025
1 parent f27979e commit 018efe0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
12 changes: 3 additions & 9 deletions web/src/app/admin/assistants/AssistantEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ export function AssistantEditor({
"#6FFFFF",
];

const [showSearchTool, setShowSearchTool] = useState(false);

const [showAdvancedOptions, setShowAdvancedOptions] = useState(false);

// state to persist across formik reformatting
Expand Down Expand Up @@ -787,14 +785,8 @@ export function AssistantEditor({
}`}
>
<Switch
checked={
values.enabled_tools_map[
searchTool.id
]
}
size="sm"
onCheckedChange={(checked) => {
setShowSearchTool(checked);
setFieldValue("num_chunks", null);
toggleToolInValues(searchTool.id);
}}
Expand Down Expand Up @@ -828,7 +820,7 @@ export function AssistantEditor({
)}
{ccPairs.length > 0 &&
searchTool &&
showSearchTool &&
values.enabled_tools_map[searchTool.id] &&
!(user?.role != "admin" && documentSets.length === 0) && (
<CollapsibleSection>
<div className="mt-2">
Expand Down Expand Up @@ -979,6 +971,7 @@ export function AssistantEditor({
onCheckedChange={() => {
toggleToolInValues(internetSearchTool.id);
}}
name={`enabled_tools_map.${internetSearchTool.id}`}
/>
<div className="flex flex-col ml-2">
<span className="text-sm">
Expand Down Expand Up @@ -1072,6 +1065,7 @@ export function AssistantEditor({
<div className="min-h-[100px]">
<div className="flex items-center mb-2">
<Switch
name="is_public"
size="md"
checked={values.is_public}
onCheckedChange={(checked) => {
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ModalProps {
noScroll?: boolean;
heightOverride?: string;
removeBottomPadding?: boolean;
removePadding?: boolean;
}

export function Modal({
Expand All @@ -39,6 +40,7 @@ export function Modal({
noScroll,
heightOverride,
removeBottomPadding,
removePadding,
}: ModalProps) {
const modalRef = useRef<HTMLDivElement>(null);
const [isMounted, setIsMounted] = useState(false);
Expand Down Expand Up @@ -114,7 +116,9 @@ export function Modal({
{icon && icon({ size: 30 })}
</h2>
</div>
{!hideDividerForTitle && <Separator className="mb-0" />}
{!hideDividerForTitle && (
<Separator className={` ${!removePadding ? "mb-0" : ""}`} />
)}
</>
)}
</div>
Expand Down
18 changes: 17 additions & 1 deletion web/src/components/ui/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@
import * as React from "react";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
import { Check } from "lucide-react";
import { useField, FieldInputProps } from "formik";

import { cn } from "@/lib/utils";

const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> & {
size?: "sm" | "md" | "lg";
name?: string;
}
>(({ className, size = "md", type = "button", ...props }, ref) => {
>(({ className, size = "md", type = "button", name, ...props }, ref) => {
const sizeClasses = {
sm: "h-3 w-3",
md: "h-4 w-4",
lg: "h-5 w-5",
};

const [field] = name
? useField({ name, type: "checkbox" })
: [
{
value: props.checked,
onChange: props.onCheckedChange,
} as FieldInputProps<boolean>,
];

return (
<CheckboxPrimitive.Root
ref={ref}
Expand All @@ -28,6 +39,11 @@ const Checkbox = React.forwardRef<
className
)}
{...props}
checked={field.value}
onCheckedChange={(checked) => {
field.onChange({ target: { name, checked } });
props.onCheckedChange?.(checked);
}}
>
<CheckboxPrimitive.Indicator
className={cn("flex items-center justify-center text-current")}
Expand Down
18 changes: 17 additions & 1 deletion web/src/components/ui/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as React from "react";
import * as SwitchPrimitives from "@radix-ui/react-switch";
import { useField, FieldInputProps } from "formik";

import { cn } from "@/lib/utils";

Expand All @@ -10,8 +11,9 @@ const Switch = React.forwardRef<
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root> & {
circleClassName?: string;
size?: "sm" | "md" | "lg";
name?: string;
}
>(({ circleClassName, className, size = "md", ...props }, ref) => {
>(({ circleClassName, className, size = "md", name, ...props }, ref) => {
const sizeClasses = {
sm: "h-4 w-8",
md: "h-5 w-10",
Expand All @@ -30,6 +32,15 @@ const Switch = React.forwardRef<
lg: "data-[state=checked]:translate-x-6",
};

const [field] = name
? useField({ name, type: "checkbox" })
: [
{
value: props.checked,
onChange: props.onCheckedChange,
} as FieldInputProps<boolean>,
];

return (
<SwitchPrimitives.Root
className={cn(
Expand All @@ -38,6 +49,11 @@ const Switch = React.forwardRef<
className
)}
{...props}
checked={field.value}
onCheckedChange={(checked) => {
field.onChange({ target: { name, checked } });
props.onCheckedChange?.(checked);
}}
ref={ref}
>
<SwitchPrimitives.Thumb
Expand Down

0 comments on commit 018efe0

Please sign in to comment.