Skip to content

Commit

Permalink
fix: report bug (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaojin3616 authored Dec 5, 2023
2 parents 1fc1e08 + 887c9b5 commit 1e7acfc
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/frontend/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ server {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
client_max_body_size 50m;
client_max_body_size 200m;
# proxy_set_header Connection "Upgrade";
}
}
3 changes: 2 additions & 1 deletion src/frontend/src/components/inputFileComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ export default function InputFileComponent({
// if (file && checkFileType(file.name)) {
// Upload the file
isSSO ? uploadFileWithProgress(file, (progress) => { }).then(res => {
setLoading(false);
if (typeof res === 'string') return setErrorData({title: "Error", list: [res]})
const { file_path } = res;
setMyValue(file.name);
onChange(file.name);
// sets the value that goes to the backend
onFileChange(file_path);
setLoading(false);
}) : uploadFile(file, tabId)
.then((res) => res.data)
.then((data) => {
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/contexts/tabsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ export function TabsProvider({ children }: { children: ReactNode }) {
});
}
} catch (err) {
setErrorData(err);
setErrorData({ title: `Error`, list: [err.response.data.detail] });
throw err
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/modals/UploadModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export default function UploadModal({ id, accept, open, desc = '', children = nu

<div className="flex justify-end gap-4">
<Button variant='outline' className="h-8" onClick={() => setOpen(false)}>{t('cancel')}</Button>
<Button type="submit" className="h-8" disabled={!end} onClick={() => !loading && handleSubmit()}>{t('create')}</Button>
<Button type="submit" className="h-8" disabled={loading || !end} onClick={() => !loading && handleSubmit()}>{t('create')}</Button>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/modals/UploadModal/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const uploadFileWithProgress = async (file, callback) => {
// Handle the response data as needed
} catch (error) {
console.error('Error uploading file:', error);
return false
return error.response.statusText || 'Upload error'
// Handle errors
}
};
12 changes: 6 additions & 6 deletions src/frontend/src/modals/formModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function FormModal({
if (!formKeysData) {
throw new Error("formKeysData is undefined");
}
const inputKeys = formKeysData.input_keys.filter(el => !el.type)[0];
const inputKeys = formKeysData.input_keys.filter(el => !el.type)[0] || {};
const handleKeys = formKeysData.handle_keys;

const keyToUse = Object.keys(inputKeys).find(
Expand Down Expand Up @@ -359,7 +359,7 @@ export default function FormModal({
let nodeValidationErrors = validateNodes(reactFlowInstance);
if (nodeValidationErrors.length === 0) {
let inputs: any = tabsState[id.current].formKeysData.input_keys;
inputs = inputs.find((el: any) => !el.type)
inputs = inputs.find((el: any) => !el.type) || {}
// const chatKey = Object.keys(inputs)[0];

// if (!chatKey) return setErrorData({ title: "提示", list: ["至少选择一个inputkey"] });
Expand Down Expand Up @@ -406,7 +406,7 @@ export default function FormModal({
function handleOnCheckedChange(checked: boolean, i: string) {
if (checked === true) {
setChatKey(i);
const input = tabsState[flow.id].formKeysData.input_keys.find((el: any) => !el.type)
const input = tabsState[flow.id].formKeysData.input_keys.find((el: any) => !el.type) || {}
setChatValue(input[i]);
} else {
setChatKey(null);
Expand All @@ -415,7 +415,7 @@ export default function FormModal({
}

const input_keys = useMemo(() => {
return tabsState[flow.id].formKeysData.input_keys.find((el: any) => !el.type)
return tabsState[flow.id].formKeysData.input_keys.find((el: any) => !el.type) || {}
}, [tabsState])

const { t } = useTranslation()
Expand Down Expand Up @@ -500,7 +500,7 @@ export default function FormModal({
onChange={(e) => {
setTabsState((old) => {
let newTabsState = _.cloneDeep(old);
const input = newTabsState[id.current].formKeysData.input_keys.find((el: any) => !el.type)
const input = newTabsState[id.current].formKeysData.input_keys.find((el: any) => !el.type) || {}
input[i] = e.target.value;
return newTabsState;
});
Expand Down Expand Up @@ -585,7 +585,7 @@ export default function FormModal({
setChatValue(value);
setTabsState((old) => {
let newTabsState = _.cloneDeep(old);
const input = newTabsState[id.current].formKeysData.input_keys.find((el: any) => !el.type)
const input = newTabsState[id.current].formKeysData.input_keys.find((el: any) => !el.type) || {}
input[chatKey] = value;
return newTabsState;
});
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/pages/FileLibPage/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export default function FilesPage() {
</TabsContent>
<TabsContent value="password"></TabsContent>
</Tabs>
{/* upload modal */}
<UploadModal id={id} accept={appConfig.libAccepts} open={open} setOpen={handleOpen}></UploadModal>
{/* Delete confirmation */}
<dialog className={`modal ${delShow && 'modal-open'}`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ export default function ExtraSidebar({ flow }: { flow: FlowType }) {
</ShadTooltip>

<ShadTooltip content={t('save')} side="bottom">
<button className="extra-side-bar-buttons" onClick={(event) => {
saveFlow(flow);
setSuccessData({ title: t('success') });
}}
<button className="extra-side-bar-buttons" onClick={(event) =>
saveFlow(flow).then(_ =>
setSuccessData({ title: t('success') }))
}
disabled={!isPending}
>
<Save strokeWidth={1.5} className={"side-bar-button-size" + (isPending ? " " : " extra-side-bar-save-disable")} ></Save>
Expand Down
19 changes: 9 additions & 10 deletions src/frontend/src/pages/SkillChatPage/components/ChatPanne.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default forwardRef(function ChatPanne({ chatId, flow, libId }: Iprops) {
useEffect(() => {
initChat()
return () => {
console.log('销毁, 没销毁要在 initChat 销毁 :>> ');
closeWs()
setChatHistory([])
}
Expand All @@ -69,7 +68,7 @@ export default forwardRef(function ChatPanne({ chatId, flow, libId }: Iprops) {
}, [flow])

const handleSend = async () => {
const val = inputRef.current?.value
const msg = inputRef.current?.value
setTimeout(() => {
if (inputRef.current) {
inputRef.current.value = ''
Expand All @@ -78,17 +77,17 @@ export default forwardRef(function ChatPanne({ chatId, flow, libId }: Iprops) {
setInputEmpty(true)
}, 100);

if (val.trim() === '') return
if (msg.trim() === '') return

setInputState({ lock: true, errorCode: '' });
let inputs = tabsState[flow.id].formKeysData.input_keys;
const input = inputs.find((el: any) => !el.type)
const inputKey = Object.keys(input)[0];
const inputKey = input ? Object.keys(input)[0] : '';
setChatHistory((old) => {
let newChat = _.cloneDeep(old);
newChat.push({
isSend: true,
message: { ...input, [inputKey]: val },
message: { ...input, [inputKey]: msg },
chatKey: inputKey,
thought: '',
category: '',
Expand All @@ -108,7 +107,7 @@ export default forwardRef(function ChatPanne({ chatId, flow, libId }: Iprops) {
isRoom && chating ? sendAll({ action: "continue", "inputs": { ...input, [inputKey]: msg } })
: sendAll({
...flow.data,
inputs: { ...input, [inputKey]: val },
inputs: { ...input, [inputKey]: msg },
chatHistory: messages,
name: flow.name,
description: flow.description
Expand All @@ -120,7 +119,7 @@ export default forwardRef(function ChatPanne({ chatId, flow, libId }: Iprops) {
const sendReport = (items: Variable[], str) => {
let inputs = tabsState[flow.id].formKeysData.input_keys;
const input = inputs.find((el: any) => !el.type)
const inputKey = Object.keys(input)[0];
const inputKey = input ? Object.keys(input)[0] : '';
setChatHistory((old) => {
let newChat = _.cloneDeep(old);
newChat.push({
Expand Down Expand Up @@ -257,11 +256,11 @@ const useInputState = ({ flow, chatId, chating, messages, isReport }) => {
const useFlowState = (flow: FlowType) => {
const flowSate = useMemo(() => {
// 是否群聊
const isRoom = !!flow.data.nodes.find(node => node.data.type === "AutoGenChain")
const isRoom = !!flow.data?.nodes.find(node => node.data.type === "AutoGenChain")
// 是否展示表单
const isForm = !!flow?.data?.nodes.find(node => ["VariableNode", "InputFileNode"].includes(node.data.type))
const isForm = !!flow.data?.nodes.find(node => ["VariableNode", "InputFileNode"].includes(node.data.type))
// 是否报表
const isReport = !!flow?.data?.nodes.find(node => "Report" === node.data.type)
const isReport = !!flow.data?.nodes.find(node => "Report" === node.data.type)
return { isRoom, isForm, isReport }
}, [flow])

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/pages/SkillPage/components/FormSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default forwardRef(function FormSet({ id }: any, ref) {

return <div className="mt-4">
<p className="text-center text-gray-400 mt-4 cursor-pointer flex justify-center" onClick={showContent}>{t('report.formSettings')}<ChevronUp /></p>
<div className="w-[68%] mx-auto overflow-hidden transition-all pl-8">
<div className="w-[68%] mx-auto overflow-hidden transition-all pl-8 px-1">
<DragDropContext onDragEnd={handleDragEnd}>
<Droppable droppableId={'list'} direction="vertical">
{(provided) => (
Expand Down
26 changes: 16 additions & 10 deletions src/frontend/src/pages/SkillPage/l2Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,19 @@ export default function l2Edit() {

// 编辑回填参数
const { id } = useParams()
const handleJumpFlow = async () => {
const handleJumpFlow = () => {
const name = nameRef.current.value
const description = descRef.current.value
if (isParamError(name, description, true)) return navigate('/flow/' + id, { replace: true })
// 保存在跳
setLoading(true)
formRef.current?.save()
await saveFlow({ ...flow, name, description });
setLoading(false)
navigate('/flow/' + id, { replace: true })
saveFlow({ ...flow, name, description }).then(_ => {
setLoading(false)
navigate('/flow/' + id, { replace: true })
}).catch(e => {
setLoading(false)
});
}

const [flow, setFlow] = useState(null)
Expand All @@ -100,10 +103,13 @@ export default function l2Edit() {
if (isParamError(flow.name, flow.description)) return
setLoading(true)
formRef.current?.save()
await saveFlow(flow);
setLoading(false)
setSuccessData({ title: t('success') });
setTimeout(() => /^\/skill\/[\w\d-]+/.test(location.pathname) && navigate(-1), 2000);
saveFlow(flow).then(_ => {
setLoading(false)
setSuccessData({ title: t('success') });
setTimeout(() => /^\/skill\/[\w\d-]+/.test(location.pathname) && navigate(-1), 2000);
}).catch(e => {
setLoading(false)
});
}

const showContent = (e) => {
Expand Down Expand Up @@ -138,7 +144,7 @@ export default function l2Edit() {
<ChevronUp />
</p>
{/* base form */}
<div className="w-[68%] mx-auto overflow-hidden transition-all">
<div className="w-[68%] mx-auto overflow-hidden transition-all px-1">
<div className="mt-4">
<Label htmlFor="name" className="text-right">{t('skills.skillName')}</Label>
<Input ref={nameRef} placeholder={t('skills.skillName')} className={`col-span-2 mt-2 ${error.name && 'border-red-400'}`} />
Expand All @@ -164,7 +170,7 @@ export default function l2Edit() {
{
// 自定义组件
Object.keys(data.node.template).map(k => (
data.node.template[k].l2 && <div className="w-[68%] mx-auto mt-4" key={k}>
data.node.template[k].l2 && <div className="w-[68%] mx-auto mt-4 px-1" key={k}>
<Label htmlFor="name" className="text-right">
{data.node.template[k].l2_name || data.node.template[k].name}
</Label>
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ export function getConnectedNodes(edge: Edge, nodes: Array<Node>): Array<Node> {
return nodes.filter((node) => node.id === targetId || node.id === sourceId);
}

// 控制节点链接的验证,false 不可连
export function isValidConnection(
{ source, target, sourceHandle, targetHandle }: Connection,
reactFlowInstance: ReactFlowInstance
Expand Down

0 comments on commit 1e7acfc

Please sign in to comment.