feat: improve input and tooltip ux (#1923)

This commit is contained in:
Patrick Erichsen 2024-08-05 11:06:53 -07:00 • committed by GitHub
parent 593a930e04
commit 2c13776c06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 45 additions and 90 deletions

60
core/package-lock.json generated
View file

@ -65,7 +65,6 @@
"@biomejs/biome": "1.6.4",
"@google/generative-ai": "^0.11.4",
"@types/follow-redirects": "^1.14.4",
"@types/isomorphic-fetch": "^0.0.39",
"@types/jest": "^29.5.12",
"@types/jquery": "^3.5.29",
"@types/jsdom": "^21.1.6",
@ -80,7 +79,6 @@
"esbuild": "0.17.19",
"eslint": "^8",
"eslint-plugin-import": "^2.29.1",
"isomorphic-fetch": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"myers-diff": "^2.1.0",
@ -4363,12 +4361,6 @@
"@types/node": "*"
}
},
"node_modules/@types/isomorphic-fetch": {
"version": "0.0.39",
"resolved": "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.39.tgz",
"integrity": "sha512-I0gou/ZdA1vMG7t7gMzL7VYu2xAKU78rW9U1l10MI0nn77pEHq3tQqHQ8hMmXdMpBlkxZOorjI4sO594Z3kKJw==",
"dev": true
},
"node_modules/@types/istanbul-lib-coverage": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz",
@ -8598,58 +8590,6 @@
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
},
"node_modules/isomorphic-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz",
"integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==",
"dev": true,
"dependencies": {
"node-fetch": "^2.6.1",
"whatwg-fetch": "^3.4.1"
}
},
"node_modules/isomorphic-fetch/node_modules/node-fetch": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
"dev": true,
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/isomorphic-fetch/node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
"dev": true
},
"node_modules/isomorphic-fetch/node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
"dev": true
},
"node_modules/isomorphic-fetch/node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"dev": true,
"dependencies": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
},
"node_modules/isstream": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",

View file

@ -1,6 +1,7 @@
import React, { useState } from "react";
import ReactDOM from "react-dom";
import { HeaderButton, StyledTooltip } from ".";
import { type PlacesType } from "react-tooltip";
import { v4 as uuidv4 } from "uuid";
@ -17,6 +18,7 @@ interface HeaderButtonWithTextProps {
style?: React.CSSProperties;
backgroundColor?: string;
hoverBackgroundColor?: string;
tooltipPlacement?: PlacesType;
}
const HeaderButtonWithText = React.forwardRef<
@ -27,13 +29,14 @@ const HeaderButtonWithText = React.forwardRef<
const id = uuidv4();
const tooltipPortalDiv = document.getElementById("tooltip-portal-div");
const tooltipId = `header_button_${id}`;
return (
<>
<HeaderButton
hoverBackgroundColor={props.hoverBackgroundColor}
backgroundColor={props.backgroundColor}
data-tooltip-id={`header_button_${id}`}
data-tooltip-id={tooltipId}
inverted={props.inverted}
disabled={props.disabled}
onMouseEnter={() => {
@ -56,7 +59,10 @@ const HeaderButtonWithText = React.forwardRef<
{props.text &&
tooltipPortalDiv &&
ReactDOM.createPortal(
<StyledTooltip id={`header_button_${id}`} place="bottom">
<StyledTooltip
id={tooltipId}
place={props.tooltipPlacement ?? "bottom"}
>
{props.text}
</StyledTooltip>,
tooltipPortalDiv,

View file

@ -285,6 +285,7 @@ const Layout = () => {
<ProfileSwitcher />
<HeaderButtonWithText
tooltipPlacement="top-end"
text="Help"
onClick={() => {
if (location.pathname === "/help") {

View file

@ -219,6 +219,7 @@ function ProfileSwitcher(props: {}) {
{/* Settings button (either opens config.json or /settings page in control plane) */}
<HeaderButtonWithText
tooltipPlacement="top-end"
onClick={() => {
if (selectedProfileId === "local") {
ideMessenger.post("openConfigJson", undefined);
@ -237,6 +238,7 @@ function ProfileSwitcher(props: {}) {
{/* Only show login if beta explicitly enabled */}
{controlServerBetaEnabled && (
<HeaderButtonWithText
tooltipPlacement="top-end"
text={
session?.account
? `Logged in as ${session.account.label}`

View file

@ -54,7 +54,6 @@ interface ContinueInputBoxProps {
isLastUserInput: boolean;
isMainInput?: boolean;
onEnter: (editorState: JSONContent, modifiers: InputModifiers) => void;
editorState?: JSONContent;
contextItems?: ContextItemWithId[];
hidden?: boolean;

View file

@ -1,4 +1,7 @@
import { PhotoIcon as OutlinePhotoIcon } from "@heroicons/react/24/outline";
import {
PhotoIcon as OutlinePhotoIcon,
PlusIcon,
} from "@heroicons/react/24/outline";
import { PhotoIcon as SolidPhotoIcon } from "@heroicons/react/24/solid";
import { InputModifiers } from "core";
import { modelSupportsImages } from "core/llm/autodetect";
@ -106,7 +109,7 @@ function InputToolbar(props: InputToolbarProps) {
}}
className="hover:underline cursor-pointer"
>
+ Add Context
Add Context <PlusIcon className="h-2.5 w-2.5" aria-hidden="true" />
</StyledSpan>
{defaultModel &&
modelSupportsImages(
@ -116,7 +119,7 @@ function InputToolbar(props: InputToolbarProps) {
defaultModel.capabilities,
) && (
<span
className="ml-1 mt-0.5"
className="ml-1 mt-0.5 cursor-pointer"
onMouseLeave={() => setFileSelectHovered(false)}
onMouseEnter={() => setFileSelectHovered(true)}
>

View file

@ -60,7 +60,7 @@ import { ComboBoxItem } from "./types";
const InputBoxDiv = styled.div`
resize: none;
padding: 12px;
padding: 8px 12px;
padding-bottom: 4px;
font-family: inherit;
border-radius: ${defaultBorderRadius};
@ -139,7 +139,6 @@ interface TipTapEditorProps {
availableSlashCommands: ComboBoxItem[];
isMainInput: boolean;
onEnter: (editorState: JSONContent, modifiers: InputModifiers) => void;
editorState?: JSONContent;
}
@ -157,6 +156,7 @@ function TipTapEditor(props: TipTapEditorProps) {
const { saveSession } = useHistory(dispatch);
const posthog = usePostHog();
const [isEditorFocused, setIsEditorFocused] = useState(false);
const inSubmenuRef = useRef<string | undefined>(undefined);
const inDropdownRef = useRef(false);
@ -432,6 +432,8 @@ function TipTapEditor(props: TipTapEditorProps) {
},
},
content: props.editorState || mainEditorContent || "",
onFocus: () => setIsEditorFocused(true),
onBlur: () => setIsEditorFocused(false),
onUpdate: ({ editor, transaction }) => {
// If /edit is typed and no context items are selected, select the first
@ -826,27 +828,29 @@ function TipTapEditor(props: TipTapEditorProps) {
event.stopPropagation();
}}
/>
<InputToolbar
showNoContext={optionKeyHeld}
hidden={!(editorFocusedRef.current || props.isMainInput)}
onAddContextItem={() => {
if (editor.getText().endsWith("@")) {
} else {
editor.commands.insertContent("@");
}
}}
onEnter={onEnterRef.current}
onImageFileSelected={(file) => {
handleImageFile(file).then(([img, dataUrl]) => {
const { schema } = editor.state;
const node = schema.nodes.image.create({ src: dataUrl });
editor.commands.command(({ tr }) => {
tr.insert(0, node);
return true;
{(isEditorFocused || props.isMainInput) && (
<InputToolbar
showNoContext={optionKeyHeld}
hidden={!(editorFocusedRef.current || props.isMainInput)}
onAddContextItem={() => {
if (editor.getText().endsWith("@")) {
} else {
editor.commands.insertContent("@");
}
}}
onEnter={onEnterRef.current}
onImageFileSelected={(file) => {
handleImageFile(file).then(([img, dataUrl]) => {
const { schema } = editor.state;
const node = schema.nodes.image.create({ src: dataUrl });
editor.commands.command(({ tr }) => {
tr.insert(0, node);
return true;
});
});
});
}}
/>
}}
/>
)}
{showDragOverMsg &&
modelSupportsImages(
defaultModel.provider,

View file

@ -216,8 +216,8 @@ function ModelSelect() {
className="h-[18px] overflow-hidden"
style={{ padding: 0 }}
>
<div>{modelSelectTitle(defaultModel) || "Select model"}</div>
<div className="pointer-events-none flex items-center">
<div className="hover:underline">
{modelSelectTitle(defaultModel) || "Select model"}{" "}
<ChevronDownIcon className="h-2.5 w-2.5" aria-hidden="true" />
</div>
</StyledListboxButton>