Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge branch 'fix/bugs' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Wangtaofeng committed Apr 24, 2024
2 parents 33bc5a2 + b4f2212 commit 8ced035
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 127 deletions.
4 changes: 2 additions & 2 deletions apps/agent/src/components/BlackButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { FC } from "react"
import BlackButtonTheme from "@/config/them/theme-blackButton.json"

const BlackButton: FC<ButtonProps> = (props) => {
const { children, ...antdButtonProps } = props
const { children, type = "primary", ...antdButtonProps } = props
return (
<ConfigProvider theme={BlackButtonTheme as ThemeConfig}>
<Button {...antdButtonProps} type="primary">
<Button {...antdButtonProps} type={type}>
{children}
</Button>
</ConfigProvider>
Expand Down
14 changes: 3 additions & 11 deletions apps/agent/src/components/EmailCode/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { App, Statistic } from "antd"
import { App, Statistic, Typography } from "antd"
import { FC } from "react"
import { useFormContext } from "react-hook-form"
import { useTranslation } from "react-i18next"
import { getColor } from "@illa-public/color-scheme"
import LinkButton from "../LinkButton"
import { EmailCodeProps } from "./interface"

const { Countdown } = Statistic
Expand Down Expand Up @@ -49,15 +48,8 @@ export const EmailCode: FC<EmailCodeProps> = (props) => {
}}
/>
) : (
<LinkButton
style={{
height: "auto",
border: "none",
}}
fontSize={14}
onClick={handleClickSend}
>
<Typography.Link onClick={handleClickSend}>
{t("page.user.sign_up.actions.send")}
</LinkButton>
</Typography.Link>
)
}
46 changes: 0 additions & 46 deletions apps/agent/src/components/LinkButton/index.tsx

This file was deleted.

16 changes: 11 additions & 5 deletions apps/agent/src/components/PreviewChat/InputArea/mobile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,27 @@ const MobileInputArea: FC<IInputAreaProps> = (props) => {
setUploadKnowledgeLoading(true)
const currentFiles = [...knowledgeFiles]

const formatFiles = multipleFileHandler(
const { needUploadFiles, notAcceptFiles } = await multipleFileHandler(
files,
currentFiles,
chatUploadStoreRef.current,
)
if (notAcceptFiles.length > 0) {
messageAPI.warning({
content: t("homepage.tipi_chat.message.failed_to_add"),
})
}
currentFiles.push(
...formatFiles.map((item) => ({
...needUploadFiles.map((item) => ({
fileName: item.fileName,
contentType: item.file.type,
contentType: item.contentType,
fileID: "",
})),
)
setKnowledgeFiles(currentFiles)
try {
for (let item of formatFiles) {
const { fileName, file, abortController } = item
for (let item of needUploadFiles) {
const { fileName, file, abortController, contentType } = item
if (!file) break
if (file.size > MAX_FILE_SIZE) {
TipisTrack.track("chat_file_over_size", {
Expand All @@ -142,6 +147,7 @@ const MobileInputArea: FC<IInputAreaProps> = (props) => {
const uploadRes = await uploadChatFile(
item.queryID,
file,
contentType,
abortController.signal,
chatUploadStoreRef.current,
)
Expand Down
43 changes: 25 additions & 18 deletions apps/agent/src/components/PreviewChat/InputArea/pc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import { TipisTrack } from "@illa-public/track-utils"
import { useGetUserInfoQuery } from "@illa-public/user-data"
import UnselectComponentIcon from "@/assets/agent/unselectComponent.svg?react"
import {
ACCEPT,
MAX_FILE_SIZE,
MAX_MESSAGE_FILES_LENGTH,
} from "@/config/constants/knowledge"
import { UploadFileStore, useUploadFileToDrive } from "@/utils/drive"
import { multipleFileHandler } from "@/utils/drive/utils"
import { getRealFileType, multipleFileHandler } from "@/utils/drive/utils"
import { PRESET_OPTION_ID } from "../../PresetOptions/constants"
import { useGetPrompt } from "../../PresetOptions/hook"
import PresetOptions from "../../PresetOptions/pc"
Expand Down Expand Up @@ -124,24 +123,32 @@ const PCInputArea: FC<IInputAreaProps> = (props) => {
parameter1: useTo,
})
setUploadKnowledgeLoading(true)

const currentFiles = [...knowledgeFiles]

const formatFiles = multipleFileHandler(
const { needUploadFiles, notAcceptFiles } = await multipleFileHandler(
files,
currentFiles,
chatUploadStoreRef.current,
)
if (notAcceptFiles.length > 0) {
messageAPI.warning({
content: t("homepage.tipi_chat.message.failed_to_add"),
})
}

console.log("needUploadFiles", needUploadFiles)
currentFiles.push(
...formatFiles.map((item) => ({
...needUploadFiles.map((item) => ({
fileName: item.fileName,
contentType: item.file.type,
contentType: item.contentType,
fileID: "",
})),
)
setKnowledgeFiles(currentFiles)
try {
for (let item of formatFiles) {
const { fileName, file, abortController } = item
for (let item of needUploadFiles) {
const { fileName, file, abortController, contentType } = item
if (!file) break
if (file.size > MAX_FILE_SIZE) {
TipisTrack.track("chat_file_over_size", {
Expand All @@ -160,6 +167,7 @@ const PCInputArea: FC<IInputAreaProps> = (props) => {
const uploadRes = await uploadChatFile(
item.queryID,
file,
contentType,
abortController.signal,
chatUploadStoreRef.current,
)
Expand Down Expand Up @@ -263,17 +271,16 @@ const PCInputArea: FC<IInputAreaProps> = (props) => {
)

const getNeedUploadAndNotAcceptFiles = useCallback((files: FileList) => {
const acceptType = ACCEPT

console.log("test", files)

const needUpdateFilesArray = Array.from(files).filter((file) =>
acceptType.includes(file.type),
)
const notAcceptFilesArray = Array.from(files).filter(
(file) => !acceptType.includes(file.type),
)

const needUpdateFilesArray: File[] = []
const notAcceptFilesArray: File[] = []
Array.from(files).map((file) => {
const contentType = getRealFileType(file, file.name.split(".")[1])
if (!contentType) {
notAcceptFilesArray.push(file)
} else {
needUpdateFilesArray.push(file)
}
})
return { needUpdateFilesArray, notAcceptFilesArray }
}, [])

Expand Down
29 changes: 28 additions & 1 deletion apps/agent/src/config/constants/knowledge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const ACCEPT = [
export const ACCEPT_CONTENT_TYPES = [
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.sealed.csv",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
Expand All @@ -9,5 +9,32 @@ export const ACCEPT = [
"text/csv",
]

export enum SEND_CONTENT_TYPES {
DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
PDF = "application/pdf",
JSON = "application/json",
TEXT = "text/plain",
MD = "text/markdown",
CSV = "text/csv",
}

export const ACCEPT = [
".docx",
".csv",
".xlsx",
".pdf",
".json",
".txt",
".md",
".csv",
".mdx",
]

export const MAX_MESSAGE_FILES_LENGTH = 10
export const MAX_FILE_SIZE = 20971520 // 20MB

export enum TYPE_MAPPING {
ZIP = "0x50 0x4B 0x3 0x4",
PDF = "0x25 0x50 0x44 0x46 0x2D 0x31 0x2E",
}
13 changes: 4 additions & 9 deletions apps/agent/src/page/User/Login/mobile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Icon from "@ant-design/icons"
import { Button, Input } from "antd"
import { Button, Input, Typography } from "antd"
import { FC, useEffect, useState } from "react"
import { Controller, useFormContext } from "react-hook-form"
import { Trans, useTranslation } from "react-i18next"
import { useNavigate } from "react-router-dom"
import { GithubIcon } from "@illa-public/icon"
import { TipisTrack } from "@illa-public/track-utils"
import ErrorMessage from "@/components/InputErrorMessage"
import LinkButton from "@/components/LinkButton"
import { FORGOT_PASSWORD_PATH, REGISTER_PATH } from "@/utils/routeHelper"
import { OAuthButton } from "../../components/OAuthButton"
import { CAN_SHOW_OAUTH, EMAIL_FORMAT } from "../../constants"
Expand Down Expand Up @@ -83,11 +82,7 @@ export const MobileLogin: FC<LoginPageProps> = (props) => {
i18nKey="page.user.sign_in.description.register"
t={t}
components={[
<LinkButton
style={{
marginRight: 8,
}}
fontSize={14}
<Typography.Link
key="text-link"
onClick={handleClickRegister}
/>,
Expand Down Expand Up @@ -178,14 +173,14 @@ export const MobileLogin: FC<LoginPageProps> = (props) => {
</section>

<div css={forgotPwdStyle}>
<LinkButton
<Typography.Link
style={{
marginRight: 8,
}}
onClick={handleClickForgotPassword}
>
{t("page.user.sign_in.description.forgot_password")}
</LinkButton>
</Typography.Link>
</div>
<Button
type="primary"
Expand Down
13 changes: 7 additions & 6 deletions apps/agent/src/page/User/Login/pc/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Icon from "@ant-design/icons"
import { Button, Divider, Input } from "antd"
import { Button, Divider, Input, Typography } from "antd"
import { FC, useEffect, useState } from "react"
import { Controller, useFormContext } from "react-hook-form"
import { Trans, useTranslation } from "react-i18next"
Expand All @@ -8,7 +8,6 @@ import { GithubIcon } from "@illa-public/icon"
import { TipisTrack } from "@illa-public/track-utils"
import { EMAIL_FORMAT, isCloudVersion } from "@illa-public/utils"
import ErrorMessage from "@/components/InputErrorMessage"
import LinkButton from "@/components/LinkButton"
import { FORGOT_PASSWORD_PATH, REGISTER_PATH } from "@/utils/routeHelper"
import { OAuthButton } from "../../components/OAuthButton"
import { CAN_SHOW_OAUTH } from "../../constants"
Expand Down Expand Up @@ -91,9 +90,11 @@ export const PCLogin: FC<LoginPageProps> = (props) => {
i18nKey="page.user.sign_in.description.register"
t={t}
components={[
<LinkButton
fontSize={16}
<Typography.Link
key="text-link"
style={{
fontSize: 16,
}}
onClick={handleClickRegister}
/>,
]}
Expand Down Expand Up @@ -155,14 +156,14 @@ export const PCLogin: FC<LoginPageProps> = (props) => {
<label css={formLabelStyle}>
{t("page.user.sign_in.fields.password")}
</label>
<LinkButton
<Typography.Link
style={{
marginRight: 8,
}}
onClick={handleClickForgotPassword}
>
{t("page.user.sign_in.description.forgot_password")}
</LinkButton>
</Typography.Link>
</div>
<Controller
name="password"
Expand Down
6 changes: 2 additions & 4 deletions apps/agent/src/page/User/Register/mobile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Icon from "@ant-design/icons"
import { Button, Input } from "antd"
import { Button, Input, Typography } from "antd"
import { FC, useEffect, useState } from "react"
import { Controller, useFormContext } from "react-hook-form"
import { Trans, useTranslation } from "react-i18next"
Expand All @@ -8,7 +8,6 @@ import { GithubIcon } from "@illa-public/icon"
import { TipisTrack } from "@illa-public/track-utils"
import { EmailCode } from "@/components/EmailCode"
import ErrorMessage from "@/components/InputErrorMessage"
import LinkButton from "@/components/LinkButton"
import { LOGIN_PATH } from "@/utils/routeHelper"
import { OAuthButton } from "../../components/OAuthButton"
import { CAN_SHOW_OAUTH, EMAIL_FORMAT } from "../../constants"
Expand Down Expand Up @@ -89,11 +88,10 @@ export const MobileRegister: FC<RegisterProps> = (props) => {
i18nKey="page.user.sign_up.description.login"
t={t}
components={[
<LinkButton
<Typography.Link
style={{
marginRight: 8,
}}
fontSize={14}
key="go-to-login"
onClick={handleClickToLogin}
/>,
Expand Down
Loading

0 comments on commit 8ced035

Please sign in to comment.