mirror of
https://github.com/ONLYOFFICE/desktop-sdk.git
synced 2026-02-10 18:15:05 +08:00
Fixed Bug 78630 - The default action for the Enter key in the Add Provider window does not work
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import useServersStore from "@/store/useServersStore";
|
import useServersStore from "@/store/useServersStore";
|
||||||
@ -24,10 +24,10 @@ const ManageToolDialog = ({
|
|||||||
|
|
||||||
const [isAllowAlways, setIsAllowAlways] = useState(false);
|
const [isAllowAlways, setIsAllowAlways] = useState(false);
|
||||||
|
|
||||||
const onAllowAction = () => {
|
const onAllowAction = React.useCallback(() => {
|
||||||
onAllow(isAllowAlways);
|
onAllow(isAllowAlways);
|
||||||
onClose();
|
onClose();
|
||||||
};
|
}, [onAllow, isAllowAlways, onClose]);
|
||||||
|
|
||||||
const onDenyAction = () => {
|
const onDenyAction = () => {
|
||||||
onDeny();
|
onDeny();
|
||||||
@ -36,6 +36,21 @@ const ManageToolDialog = ({
|
|||||||
|
|
||||||
const toolCall = manageToolData?.message?.content[manageToolData.idx];
|
const toolCall = manageToolData?.message?.content[manageToolData.idx];
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
onAllowAction();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
}, [onAllowAction]);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!toolCall ||
|
!toolCall ||
|
||||||
typeof toolCall !== "object" ||
|
typeof toolCall !== "object" ||
|
||||||
|
|||||||
@ -62,8 +62,11 @@ const AddProviderDialog = ({ onClose }: AddProviderDialogProps) => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmitAction = async () => {
|
const isDisabled =
|
||||||
if (isRequestRunningRef.current) return;
|
!value.name || !value.url || !!error.key || !!error.url || !!error.name;
|
||||||
|
|
||||||
|
const onSubmitAction = React.useCallback(async () => {
|
||||||
|
if (isRequestRunningRef.current || isDisabled) return;
|
||||||
isRequestRunningRef.current = true;
|
isRequestRunningRef.current = true;
|
||||||
setIsRequestRunning(true);
|
setIsRequestRunning(true);
|
||||||
|
|
||||||
@ -84,7 +87,7 @@ const AddProviderDialog = ({ onClose }: AddProviderDialogProps) => {
|
|||||||
}
|
}
|
||||||
isRequestRunningRef.current = false;
|
isRequestRunningRef.current = false;
|
||||||
setIsRequestRunning(false);
|
setIsRequestRunning(false);
|
||||||
};
|
}, [addProvider, selectedProviderInfo, value, onClose, isDisabled]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setValue((prevValue) => ({
|
setValue((prevValue) => ({
|
||||||
@ -100,8 +103,20 @@ const AddProviderDialog = ({ onClose }: AddProviderDialogProps) => {
|
|||||||
}
|
}
|
||||||
}, [buttonWidth]);
|
}, [buttonWidth]);
|
||||||
|
|
||||||
const isDisabled =
|
React.useEffect(() => {
|
||||||
!value.name || !value.url || !!error.key || !!error.url || !!error.name;
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
onSubmitAction();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
}, [onSubmitAction]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={true}>
|
<Dialog open={true}>
|
||||||
|
|||||||
@ -44,10 +44,25 @@ const DeleteProviderDialog = ({ name, onClose }: DeleteProviderDialogProps) => {
|
|||||||
setProvider(provider);
|
setProvider(provider);
|
||||||
}, [providers, name]);
|
}, [providers, name]);
|
||||||
|
|
||||||
const onSubmitAction = async () => {
|
const onSubmitAction = React.useCallback(async () => {
|
||||||
await deleteProvider(provider);
|
await deleteProvider(provider);
|
||||||
onClose();
|
onClose();
|
||||||
};
|
}, [deleteProvider, provider, onClose]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
onSubmitAction();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
}, [onSubmitAction]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={true}>
|
<Dialog open={true}>
|
||||||
|
|||||||
@ -91,7 +91,20 @@ const EditProviderDialog = ({ name, onClose }: EditProviderDialogProps) => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmitAction = async () => {
|
const isSameUrlAndName =
|
||||||
|
value.name === provider.name && value.url === provider.baseUrl;
|
||||||
|
|
||||||
|
const isSameKey = value.key === provider.key;
|
||||||
|
|
||||||
|
const isDisabled =
|
||||||
|
(isSameKey && isSameUrlAndName) ||
|
||||||
|
!!error.key ||
|
||||||
|
!!error.url ||
|
||||||
|
!!error.name;
|
||||||
|
|
||||||
|
const onSubmitAction = React.useCallback(async () => {
|
||||||
|
if (isDisabled) return;
|
||||||
|
|
||||||
const result = await editProvider(
|
const result = await editProvider(
|
||||||
{
|
{
|
||||||
type: provider!.type,
|
type: provider!.type,
|
||||||
@ -110,18 +123,22 @@ const EditProviderDialog = ({ name, onClose }: EditProviderDialogProps) => {
|
|||||||
[result.field]: result.message,
|
[result.field]: result.message,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
};
|
}, [isDisabled, editProvider, provider, value, onClose]);
|
||||||
|
|
||||||
const isSameUrlAndName =
|
React.useEffect(() => {
|
||||||
value.name === provider.name && value.url === provider.baseUrl;
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
onSubmitAction();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const isSameKey = value.key === provider.key;
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
const isDisabled =
|
return () => {
|
||||||
(isSameKey && isSameUrlAndName) ||
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
!!error.key ||
|
};
|
||||||
!!error.url ||
|
}, [onSubmitAction]);
|
||||||
!!error.name;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={true}>
|
<Dialog open={true}>
|
||||||
|
|||||||
@ -111,6 +111,29 @@ const ConfigDialog = ({ open, onClose }: ConfigDialogProps) => {
|
|||||||
};
|
};
|
||||||
}, [open, getConfig]);
|
}, [open, getConfig]);
|
||||||
|
|
||||||
|
const onSubmitAction = React.useCallback(() => {
|
||||||
|
if (!isValidJson) return;
|
||||||
|
saveConfig(JSON.parse(value));
|
||||||
|
onClose();
|
||||||
|
}, [isValidJson, saveConfig, value, onClose]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
||||||
|
e.preventDefault();
|
||||||
|
onSubmitAction();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
}, [open, onSubmitAction]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={() => {}}>
|
<Dialog open={open} onOpenChange={() => {}}>
|
||||||
<DialogContent
|
<DialogContent
|
||||||
@ -138,13 +161,7 @@ const ConfigDialog = ({ open, onClose }: ConfigDialogProps) => {
|
|||||||
<Button onClick={onClose} variant="default">
|
<Button onClick={onClose} variant="default">
|
||||||
{t("Cancel")}
|
{t("Cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button disabled={!isValidJson} onClick={onSubmitAction}>
|
||||||
disabled={!isValidJson}
|
|
||||||
onClick={() => {
|
|
||||||
saveConfig(JSON.parse(value));
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("Save")}
|
{t("Save")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { Dialog, DialogContent } from "@/components/dialog";
|
import { Dialog, DialogContent } from "@/components/dialog";
|
||||||
@ -15,10 +16,25 @@ const DeleteServerDialog = ({ name, onClose }: DeleteServerDialogProps) => {
|
|||||||
|
|
||||||
const { deleteCustomServer } = useServersStore();
|
const { deleteCustomServer } = useServersStore();
|
||||||
|
|
||||||
const onSubmitAction = () => {
|
const onSubmitAction = React.useCallback(() => {
|
||||||
deleteCustomServer(name);
|
deleteCustomServer(name);
|
||||||
onClose();
|
onClose();
|
||||||
};
|
}, [deleteCustomServer, name, onClose]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
onSubmitAction();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
}, [onSubmitAction]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={true}>
|
<Dialog open={true}>
|
||||||
|
|||||||
@ -25,14 +25,14 @@ const WebSearch = () => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const saveWebSearchData = () => {
|
const saveWebSearchData = React.useCallback(() => {
|
||||||
if (!selectedProvider || !apiKey) return;
|
if (!selectedProvider || !apiKey) return;
|
||||||
client.setWebSearchData({
|
client.setWebSearchData({
|
||||||
provider: selectedProvider,
|
provider: selectedProvider,
|
||||||
key: apiKey,
|
key: apiKey,
|
||||||
});
|
});
|
||||||
setSaved(true);
|
setSaved(true);
|
||||||
};
|
}, [selectedProvider, apiKey]);
|
||||||
|
|
||||||
const resetSettings = () => {
|
const resetSettings = () => {
|
||||||
setSelectedProvider("");
|
setSelectedProvider("");
|
||||||
@ -41,6 +41,21 @@ const WebSearch = () => {
|
|||||||
client.setWebSearchData(null);
|
client.setWebSearchData(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
saveWebSearchData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
}, [saveWebSearchData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex flex-col gap-[16px] mt-[16px]">
|
<div className="flex flex-col gap-[16px] mt-[16px]">
|
||||||
|
|||||||
Reference in New Issue
Block a user