Skip to content

Commit

Permalink
feat: disable insteaed of hiding UI buttons if the user explicitely r…
Browse files Browse the repository at this point in the history
…enders them (#771)
  • Loading branch information
Yonom authored Sep 8, 2024
1 parent 79d7a14 commit ded8b64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
11 changes: 5 additions & 6 deletions packages/react/src/ui/assistant-action-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ const AssistantActionBarSpeak = forwardRef<
} = {},
} = useThreadConfig();
const allowSpeak = useAllowSpeak();
if (!allowSpeak) return null;

return (
<ActionBarPrimitive.Speak asChild>
<ActionBarPrimitive.Speak disabled={!allowSpeak} asChild>
<TooltipIconButton tooltip={tooltip} {...props} ref={ref}>
{props.children ?? <AudioLinesIcon />}
</TooltipIconButton>
Expand All @@ -141,9 +141,9 @@ const AssistantActionBarStopSpeaking = forwardRef<
} = {},
} = useThreadConfig();
const allowSpeak = useAllowSpeak();
if (!allowSpeak) return null;

return (
<ActionBarPrimitive.StopSpeaking asChild>
<ActionBarPrimitive.StopSpeaking disabled={!allowSpeak} asChild>
<TooltipIconButton tooltip={stopTooltip} {...props} ref={ref}>
{props.children ?? <StopCircleIcon />}
</TooltipIconButton>
Expand All @@ -163,9 +163,8 @@ const AssistantActionBarReload = forwardRef<
} = {},
} = useThreadConfig();
const allowReload = useAllowReload();
if (!allowReload) return null;
return (
<ActionBarPrimitive.Reload asChild>
<ActionBarPrimitive.Reload disabled={!allowReload} asChild>
<TooltipIconButton tooltip={tooltip} {...props} ref={ref}>
<RefreshCwIcon />
</TooltipIconButton>
Expand Down
10 changes: 6 additions & 4 deletions packages/react/src/ui/branch-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { useThreadConfig } from "./thread-config";
import { BranchPickerPrimitive } from "../primitives";
import { useThreadContext } from "../context";

const useAllowBranchPicker = () => {
const useAllowBranchPicker = (ensureCapability = false) => {
const { branchPicker: { allowBranchPicker = true } = {} } = useThreadConfig();
const { useThread } = useThreadContext();
const branchPickerSupported = useThread((t) => t.capabilities.edit);
return branchPickerSupported && allowBranchPicker;
return allowBranchPicker && (!ensureCapability || branchPickerSupported);
};

const BranchPicker: FC = () => {
Expand Down Expand Up @@ -48,8 +48,9 @@ const BranchPickerPrevious = forwardRef<
branchPicker: { previous: { tooltip = "Previous" } = {} } = {},
} = {},
} = useThreadConfig();
const allowBranchPicker = useAllowBranchPicker();
return (
<BranchPickerPrimitive.Previous asChild>
<BranchPickerPrimitive.Previous disabled={!allowBranchPicker} asChild>
<TooltipIconButton tooltip={tooltip} {...props} ref={ref}>
{props.children ?? <ChevronLeftIcon />}
</TooltipIconButton>
Expand Down Expand Up @@ -83,8 +84,9 @@ const BranchPickerNext = forwardRef<
const {
strings: { branchPicker: { next: { tooltip = "Next" } = {} } = {} } = {},
} = useThreadConfig();
const allowBranchPicker = useAllowBranchPicker();
return (
<BranchPickerPrimitive.Next asChild>
<BranchPickerPrimitive.Next disabled={!allowBranchPicker} asChild>
<TooltipIconButton tooltip={tooltip} {...props} ref={ref}>
{props.children ?? <ChevronRightIcon />}
</TooltipIconButton>
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/ui/user-action-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ const UserActionBarEdit = forwardRef<
strings: { userMessage: { edit: { tooltip = "Edit" } = {} } = {} } = {},
} = useThreadConfig();
const allowEdit = useAllowEdit();
if (!allowEdit) return null;
return (
<ActionBarPrimitive.Edit asChild>
<ActionBarPrimitive.Edit disabled={!allowEdit} asChild>
<TooltipIconButton tooltip={tooltip} {...props} ref={ref}>
{props.children ?? <PencilIcon />}
</TooltipIconButton>
Expand Down

0 comments on commit ded8b64

Please sign in to comment.