From f9bec1edf8216ed65f547686c57b774f3ff813f8 Mon Sep 17 00:00:00 2001 From: bowen <54492610+jiaowoxiaobala@users.noreply.github.com> Date: Mon, 28 Aug 2023 19:48:53 +0800 Subject: [PATCH] chore: perfect type definition (#1003) --- web/app/(commonLayout)/apps/AppCard.tsx | 7 +++--- .../[datasetId]/layout.tsx | 8 +++---- web/app/components/app-sidebar/index.tsx | 9 ++++---- web/app/components/app-sidebar/navLink.tsx | 23 +++++++++++++++---- .../app/chat/icon-component/index.tsx | 8 +++---- .../app/configuration/config-var/index.tsx | 7 +++--- .../config-var/input-type-icon.tsx | 2 +- web/app/components/app/log/index.tsx | 4 ++-- web/app/components/app/log/list.tsx | 4 ++-- web/app/components/app/overview/appCard.tsx | 4 ++-- .../components/base/emoji-picker/index.tsx | 15 ++++++------ web/app/components/base/input/index.tsx | 10 ++++---- web/app/components/base/notion-icon/index.tsx | 2 +- .../base/notion-page-selector/base.tsx | 7 +++--- .../base/radio/component/radio/index.tsx | 2 +- .../create/embedding-process/index.tsx | 13 ++++++----- .../datasets/create/file-uploader/index.tsx | 2 +- web/app/components/datasets/create/index.tsx | 8 +++---- .../create/notion-page-preview/index.tsx | 5 ++-- .../datasets/create/step-one/index.tsx | 8 +++---- .../datasets/create/step-two/index.tsx | 14 +++++------ .../detail/completed/InfiniteVirtualList.tsx | 2 +- .../detail/completed/SegmentCard.tsx | 2 +- .../documents/detail/completed/index.tsx | 4 ++-- .../documents/detail/embedding/index.tsx | 6 ++--- .../components/datasets/documents/index.tsx | 10 ++++---- .../components/datasets/documents/list.tsx | 10 ++++---- .../datasets/hit-testing/hit-detail.tsx | 2 +- web/app/components/explore/app-list/index.tsx | 7 +++--- web/app/components/explore/category.tsx | 7 +++--- .../header/account-setting/index.tsx | 4 ++-- .../model-page/model-item/Card.tsx | 2 +- .../share/text-generation/result/index.tsx | 2 +- web/models/common.ts | 4 ++++ web/models/explore.ts | 4 +++- 35 files changed, 123 insertions(+), 105 deletions(-) diff --git a/web/app/(commonLayout)/apps/AppCard.tsx b/web/app/(commonLayout)/apps/AppCard.tsx index c56a029be7..a7aaf01510 100644 --- a/web/app/(commonLayout)/apps/AppCard.tsx +++ b/web/app/(commonLayout)/apps/AppCard.tsx @@ -9,6 +9,7 @@ import style from '../list.module.css' import AppModeLabel from './AppModeLabel' import s from './style.module.css' import SettingsModal from '@/app/components/app/overview/settings' +import type { ConfigParams } from '@/app/components/app/overview/settings' import type { App } from '@/types/app' import Confirm from '@/app/components/base/confirm' import { ToastContext } from '@/app/components/base/toast' @@ -73,7 +74,7 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => { } const onSaveSiteConfig = useCallback( - async (params: any) => { + async (params: ConfigParams) => { const [err] = await asyncRunSafe( updateAppSiteConfig({ url: `/apps/${app.id}/site`, @@ -100,12 +101,12 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => { ) const Operations = (props: any) => { - const onClickSettings = async (e: any) => { + const onClickSettings = async (e: React.MouseEvent) => { props?.onClose() e.preventDefault() await getAppDetail() } - const onClickDelete = async (e: any) => { + const onClickDelete = async (e: React.MouseEvent) => { props?.onClose() e.preventDefault() setShowConfirmDelete(true) diff --git a/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx b/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx index 2ed48d1653..bf205820ee 100644 --- a/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx +++ b/web/app/(commonLayout)/datasets/(datasetDetailLayout)/[datasetId]/layout.tsx @@ -1,5 +1,5 @@ 'use client' -import type { FC } from 'react' +import type { FC, SVGProps } from 'react' import React, { useEffect } from 'react' import { usePathname } from 'next/navigation' import useSWR from 'swr' @@ -57,7 +57,7 @@ const LikedItem: FC<{ type?: 'plugin' | 'app'; appStatus?: boolean; detail: Rela ) } -const TargetIcon: FC<{ className?: string }> = ({ className }) => { +const TargetIcon = ({ className }: SVGProps) => { return @@ -70,7 +70,7 @@ const TargetIcon: FC<{ className?: string }> = ({ className }) => { } -const TargetSolidIcon: FC<{ className?: string }> = ({ className }) => { +const TargetSolidIcon = ({ className }: SVGProps) => { return @@ -78,7 +78,7 @@ const TargetSolidIcon: FC<{ className?: string }> = ({ className }) => { } -const BookOpenIcon: FC<{ className?: string }> = ({ className }) => { +const BookOpenIcon = ({ className }: SVGProps) => { return diff --git a/web/app/components/app-sidebar/index.tsx b/web/app/components/app-sidebar/index.tsx index 86f66df9d0..73579acd66 100644 --- a/web/app/components/app-sidebar/index.tsx +++ b/web/app/components/app-sidebar/index.tsx @@ -1,8 +1,9 @@ import React from 'react' -import type { FC } from 'react' import NavLink from './navLink' import AppBasic from './basic' +import type { NavIcon } from './navLink' + export type IAppDetailNavProps = { iconType?: 'app' | 'dataset' | 'notion' title: string @@ -12,13 +13,13 @@ export type IAppDetailNavProps = { navigation: Array<{ name: string href: string - icon: any - selectedIcon: any + icon: NavIcon + selectedIcon: NavIcon }> extraInfo?: React.ReactNode } -const AppDetailNav: FC = ({ title, desc, icon, icon_background, navigation, extraInfo, iconType = 'app' }) => { +const AppDetailNav = ({ title, desc, icon, icon_background, navigation, extraInfo, iconType = 'app' }: IAppDetailNavProps) => { return (
diff --git a/web/app/components/app-sidebar/navLink.tsx b/web/app/components/app-sidebar/navLink.tsx index df82d317d8..63a0b44726 100644 --- a/web/app/components/app-sidebar/navLink.tsx +++ b/web/app/components/app-sidebar/navLink.tsx @@ -1,17 +1,30 @@ 'use client' + import { useSelectedLayoutSegment } from 'next/navigation' import classNames from 'classnames' import Link from 'next/link' +export type NavIcon = React.ComponentType< +React.PropsWithoutRef> & { + title?: string | undefined + titleId?: string | undefined +} +> + +export type NavLinkProps = { + name: string + href: string + iconMap: { + selected: NavIcon + normal: NavIcon + } +} + export default function NavLink({ name, href, iconMap, -}: { - name: string - href: string - iconMap: { selected: any; normal: any } -}) { +}: NavLinkProps) { const segment = useSelectedLayoutSegment() const isActive = href.toLowerCase().split('/')?.pop() === segment?.toLowerCase() const NavIcon = isActive ? iconMap.selected : iconMap.normal diff --git a/web/app/components/app/chat/icon-component/index.tsx b/web/app/components/app/chat/icon-component/index.tsx index 52eb87f4d0..e880b5958a 100644 --- a/web/app/components/app/chat/icon-component/index.tsx +++ b/web/app/components/app/chat/icon-component/index.tsx @@ -1,4 +1,4 @@ -import type { FC } from 'react' +import type { FC, SVGProps } from 'react' import { HandThumbDownIcon, HandThumbUpIcon } from '@heroicons/react/24/outline' export const stopIcon = ( @@ -7,7 +7,7 @@ export const stopIcon = ( ) -export const OpeningStatementIcon: FC<{ className?: string }> = ({ className }) => ( +export const OpeningStatementIcon = ({ className }: SVGProps) => ( @@ -17,13 +17,13 @@ export const RatingIcon: FC<{ isLike: boolean }> = ({ isLike }) => { return isLike ? : } -export const EditIcon: FC<{ className?: string }> = ({ className }) => { +export const EditIcon = ({ className }: SVGProps) => { return } -export const EditIconSolid: FC<{ className?: string }> = ({ className }) => { +export const EditIconSolid = ({ className }: SVGProps) => { return diff --git a/web/app/components/app/configuration/config-var/index.tsx b/web/app/components/app/configuration/config-var/index.tsx index edbab2fafb..4e18cb42d2 100644 --- a/web/app/components/app/configuration/config-var/index.tsx +++ b/web/app/components/app/configuration/config-var/index.tsx @@ -10,6 +10,7 @@ import OperationBtn from '../base/operation-btn' import VarIcon from '../base/icons/var-icon' import EditModel from './config-model' import IconTypeIcon from './input-type-icon' +import type { IInputTypeIconProps } from './input-type-icon' import s from './style.module.css' import Tooltip from '@/app/components/base/tooltip' import type { PromptVariable } from '@/models/debug' @@ -37,8 +38,8 @@ const ConfigVar: FC = ({ promptVariables, readonly, onPromptVar return obj })() - const updatePromptVariable = (key: string, updateKey: string, newValue: any) => { - const newPromptVariables = promptVariables.map((item, i) => { + const updatePromptVariable = (key: string, updateKey: string, newValue: string | boolean) => { + const newPromptVariables = promptVariables.map((item) => { if (item.key === key) { return { ...item, @@ -179,7 +180,7 @@ const ConfigVar: FC = ({ promptVariables, readonly, onPromptVar
- + {!readonly ? ( = ({ className }) => { +const ThreeDotsIcon = ({ className }: SVGProps) => { return diff --git a/web/app/components/app/log/list.tsx b/web/app/components/app/log/list.tsx index 175e96e827..033f7834ec 100644 --- a/web/app/components/app/log/list.tsx +++ b/web/app/components/app/log/list.tsx @@ -1,5 +1,5 @@ 'use client' -import type { FC } from 'react' +import type { FC, SVGProps } from 'react' import React, { useEffect, useState } from 'react' // import type { Log } from '@/models/log' import useSWR from 'swr' @@ -47,7 +47,7 @@ type IDrawerContext = { const DrawerContext = createContext({} as IDrawerContext) -export const OpenAIIcon: FC<{ className?: string }> = ({ className }) => { +export const OpenAIIcon = ({ className }: SVGProps) => { return diff --git a/web/app/components/app/overview/appCard.tsx b/web/app/components/app/overview/appCard.tsx index 5c4ae75239..b0e46e99ab 100644 --- a/web/app/components/app/overview/appCard.tsx +++ b/web/app/components/app/overview/appCard.tsx @@ -1,5 +1,5 @@ 'use client' -import type { FC } from 'react' +import type { HTMLProps } from 'react' import React, { useMemo, useState } from 'react' import { Cog8ToothIcon, @@ -37,7 +37,7 @@ export type IAppCardProps = { onGenerateCode?: () => Promise } -const EmbedIcon: FC<{ className?: string }> = ({ className = '' }) => { +const EmbedIcon = ({ className = '' }: HTMLProps) => { return
} diff --git a/web/app/components/base/emoji-picker/index.tsx b/web/app/components/base/emoji-picker/index.tsx index 94db4debb6..7cfbbfa75a 100644 --- a/web/app/components/base/emoji-picker/index.tsx +++ b/web/app/components/base/emoji-picker/index.tsx @@ -3,6 +3,7 @@ import type { ChangeEvent, FC } from 'react' import React, { useState } from 'react' import data from '@emoji-mart/data' +import type { Emoji, EmojiMartData } from '@emoji-mart/data' import { SearchIndex, init } from 'emoji-mart' import cn from 'classnames' import { @@ -30,9 +31,9 @@ declare global { init({ data }) async function search(value: string) { - const emojis = await SearchIndex.search(value) || [] + const emojis: Emoji[] = await SearchIndex.search(value) || [] - const results = emojis.map((emoji: any) => { + const results = emojis.map((emoji) => { return emoji.skins[0].native }) return results @@ -59,6 +60,7 @@ const backgroundColors = [ '#ECE9FE', '#FFE4E8', ] + type IEmojiPickerProps = { isModal?: boolean onSelect?: (emoji: string, background: string) => void @@ -69,14 +71,13 @@ const EmojiPicker: FC = ({ isModal = true, onSelect, onClose, - }) => { const { t } = useTranslation() - const { categories } = data as any + const { categories } = data as EmojiMartData const [selectedEmoji, setSelectedEmoji] = useState('') const [selectedBackground, setSelectedBackground] = useState(backgroundColors[0]) - const [searchedEmojis, setSearchedEmojis] = useState([]) + const [searchedEmojis, setSearchedEmojis] = useState([]) const [isSearching, setIsSearching] = useState(false) return isModal ? = ({
} - {categories.map((category: any, index: number) => { + {categories.map((category, index: number) => { return

{category.id}

- {category.emojis.map((emoji: string, index: number) => { + {category.emojis.map((emoji, index: number) => { return
void + onChange?: (v: string) => void className?: string wrapperClassName?: string type?: string @@ -16,13 +16,13 @@ type InputProps = { prefixIcon?: React.ReactNode } -const GlassIcon: FC<{ className?: string }> = ({ className }) => ( +const GlassIcon = ({ className }: SVGProps) => ( ) -const Input: FC = ({ value, defaultValue, onChange, className = '', wrapperClassName = '', placeholder, type, showPrefix, prefixIcon }) => { +const Input = ({ value, defaultValue, onChange, className = '', wrapperClassName = '', placeholder, type, showPrefix, prefixIcon }: InputProps) => { const [localValue, setLocalValue] = useState(value ?? defaultValue) const { t } = useTranslation() return ( @@ -31,7 +31,7 @@ const Input: FC = ({ value, defaultValue, onChange, className = '', { setLocalValue(e.target.value) diff --git a/web/app/components/base/notion-icon/index.tsx b/web/app/components/base/notion-icon/index.tsx index bc56094ab6..599592a1c5 100644 --- a/web/app/components/base/notion-icon/index.tsx +++ b/web/app/components/base/notion-icon/index.tsx @@ -7,7 +7,7 @@ type NotionIconProps = { type?: IconTypes name?: string | null className?: string - src?: string | null | Pick['page_icon'] + src?: string | null | DataSourceNotionPage['page_icon'] } const NotionIcon = ({ type = 'workspace', diff --git a/web/app/components/base/notion-page-selector/base.tsx b/web/app/components/base/notion-page-selector/base.tsx index 578c68bd0f..71feb1c81d 100644 --- a/web/app/components/base/notion-page-selector/base.tsx +++ b/web/app/components/base/notion-page-selector/base.tsx @@ -10,17 +10,16 @@ import PageSelector from './page-selector' import { preImportNotionPages } from '@/service/datasets' import AccountSetting from '@/app/components/header/account-setting' import { NotionConnector } from '@/app/components/datasets/create/step-one' -import type { DataSourceNotionPage, DataSourceNotionPageMap, DataSourceNotionWorkspace } from '@/models/common' +import type { DataSourceNotionPageMap, DataSourceNotionWorkspace, NotionPage } from '@/models/common' import { ToastContext } from '@/app/components/base/toast' -export type NotionPageSelectorValue = DataSourceNotionPage & { workspace_id: string } type NotionPageSelectorProps = { value?: string[] - onSelect: (selectedPages: NotionPageSelectorValue[]) => void + onSelect: (selectedPages: NotionPage[]) => void canPreview?: boolean previewPageId?: string - onPreview?: (selectedPage: NotionPageSelectorValue) => void + onPreview?: (selectedPage: NotionPage) => void datasetId?: string countLimit: number countUsed: number diff --git a/web/app/components/base/radio/component/radio/index.tsx b/web/app/components/base/radio/component/radio/index.tsx index 5767896b15..c6f237ab74 100644 --- a/web/app/components/base/radio/component/radio/index.tsx +++ b/web/app/components/base/radio/component/radio/index.tsx @@ -12,7 +12,7 @@ export type IRadioProps = { checked?: boolean value?: string | number disabled?: boolean - onChange?: (e: any) => void + onChange?: (e?: IRadioProps['value']) => void } export default function Radio({ diff --git a/web/app/components/datasets/create/embedding-process/index.tsx b/web/app/components/datasets/create/embedding-process/index.tsx index 6b311b5490..f5678ac391 100644 --- a/web/app/components/datasets/create/embedding-process/index.tsx +++ b/web/app/components/datasets/create/embedding-process/index.tsx @@ -87,7 +87,7 @@ const EmbeddingProcess: FC = ({ datasetId, batchId, documents = [], index setIndexingStatusDetail(status.data) } - const [runId, setRunId, getRunId] = useGetState(null) + const [_, setRunId, getRunId] = useGetState>() const stopQueryStatus = () => { clearInterval(getRunId()) @@ -136,10 +136,10 @@ const EmbeddingProcess: FC = ({ datasetId, batchId, documents = [], index } const isEmbedding = useMemo(() => { - return indexingStatusBatchDetail.some((indexingStatusDetail: { indexing_status: any }) => ['indexing', 'splitting', 'parsing', 'cleaning'].includes(indexingStatusDetail?.indexing_status || '')) + return indexingStatusBatchDetail.some(indexingStatusDetail => ['indexing', 'splitting', 'parsing', 'cleaning'].includes(indexingStatusDetail?.indexing_status || '')) }, [indexingStatusBatchDetail]) const isEmbeddingCompleted = useMemo(() => { - return indexingStatusBatchDetail.every((indexingStatusDetail: { indexing_status: any }) => ['completed', 'error'].includes(indexingStatusDetail?.indexing_status || '')) + return indexingStatusBatchDetail.every(indexingStatusDetail => ['completed', 'error'].includes(indexingStatusDetail?.indexing_status || '')) }, [indexingStatusBatchDetail]) const getSourceName = (id: string) => { @@ -159,10 +159,11 @@ const EmbeddingProcess: FC = ({ datasetId, batchId, documents = [], index const doc = documents.find(document => document.id === id) return doc?.data_source_type as DataSourceType } - const getIcon = (id: string) => { - const doc = documents.find(document => document.id === id) as any // TODO type fix - return doc.data_source_info.notion_page_icon + const getIcon = (id: string) => { + const doc = documents.find(document => document.id === id) + + return doc?.data_source_info.notion_page_icon } const isSourceEmbedding = (detail: IndexingStatusResponse) => ['indexing', 'splitting', 'parsing', 'cleaning', 'waiting'].includes(detail.indexing_status || '') diff --git a/web/app/components/datasets/create/file-uploader/index.tsx b/web/app/components/datasets/create/file-uploader/index.tsx index a23075d8e2..387e9e0c6c 100644 --- a/web/app/components/datasets/create/file-uploader/index.tsx +++ b/web/app/components/datasets/create/file-uploader/index.tsx @@ -16,7 +16,7 @@ type IFileUploaderProps = { titleClassName?: string prepareFileList: (files: FileItem[]) => void onFileUpdate: (fileItem: FileItem, progress: number, list: FileItem[]) => void - onFileListUpdate?: (files: any) => void + onFileListUpdate?: (files: FileItem[]) => void onPreview: (file: File) => void countLimit: number countUsed: number diff --git a/web/app/components/datasets/create/index.tsx b/web/app/components/datasets/create/index.tsx index 34ee3ef2ad..2771087ddd 100644 --- a/web/app/components/datasets/create/index.tsx +++ b/web/app/components/datasets/create/index.tsx @@ -11,13 +11,11 @@ import { DataSourceType } from '@/models/datasets' import type { DataSet, FileItem, createDocumentResponse } from '@/models/datasets' import { fetchDataSource } from '@/service/common' import { fetchDataDetail } from '@/service/datasets' -import type { DataSourceNotionPage } from '@/models/common' +import type { NotionPage } from '@/models/common' import { useProviderContext } from '@/context/provider-context' import AccountSetting from '@/app/components/header/account-setting' -type Page = DataSourceNotionPage & { workspace_id: string } - type DatasetUpdateFormProps = { datasetId?: string } @@ -35,8 +33,8 @@ const DatasetUpdateForm = ({ datasetId }: DatasetUpdateFormProps) => { const [hasError, setHasError] = useState(false) const { embeddingsDefaultModel } = useProviderContext() - const [notionPages, setNotionPages] = useState([]) - const updateNotionPages = (value: Page[]) => { + const [notionPages, setNotionPages] = useState([]) + const updateNotionPages = (value: NotionPage[]) => { setNotionPages(value) } diff --git a/web/app/components/datasets/create/notion-page-preview/index.tsx b/web/app/components/datasets/create/notion-page-preview/index.tsx index 4a55c1fdcd..82a8cead98 100644 --- a/web/app/components/datasets/create/notion-page-preview/index.tsx +++ b/web/app/components/datasets/create/notion-page-preview/index.tsx @@ -4,13 +4,12 @@ import { useTranslation } from 'react-i18next' import cn from 'classnames' import { XMarkIcon } from '@heroicons/react/20/solid' import s from './index.module.css' -import type { DataSourceNotionPage } from '@/models/common' +import type { NotionPage } from '@/models/common' import NotionIcon from '@/app/components/base/notion-icon' import { fetchNotionPagePreview } from '@/service/datasets' -type Page = DataSourceNotionPage & { workspace_id: string } type IProps = { - currentPage?: Page + currentPage?: NotionPage hidePreview: () => void } diff --git a/web/app/components/datasets/create/step-one/index.tsx b/web/app/components/datasets/create/step-one/index.tsx index 1873eb8b56..bcae398e7e 100644 --- a/web/app/components/datasets/create/step-one/index.tsx +++ b/web/app/components/datasets/create/step-one/index.tsx @@ -9,7 +9,7 @@ import NotionPagePreview from '../notion-page-preview' import EmptyDatasetCreationModal from '../empty-dataset-creation-modal' import s from './index.module.css' import type { FileItem } from '@/models/datasets' -import type { DataSourceNotionPage } from '@/models/common' +import type { NotionPage } from '@/models/common' import { DataSourceType } from '@/models/datasets' import Button from '@/app/components/base/button' import { NotionPageSelector } from '@/app/components/base/notion-page-selector' @@ -25,14 +25,12 @@ type IStepOneProps = { files: FileItem[] updateFileList: (files: FileItem[]) => void updateFile: (fileItem: FileItem, progress: number, list: FileItem[]) => void - notionPages?: any[] - updateNotionPages: (value: any[]) => void + notionPages?: NotionPage[] + updateNotionPages: (value: NotionPage[]) => void onStepChange: () => void changeType: (type: DataSourceType) => void } -type Page = DataSourceNotionPage & { workspace_id: string } - type NotionConnectorProps = { onSetting: () => void } diff --git a/web/app/components/datasets/create/step-two/index.tsx b/web/app/components/datasets/create/step-two/index.tsx index e7d5fb8e38..cd0237ab6f 100644 --- a/web/app/components/datasets/create/step-two/index.tsx +++ b/web/app/components/datasets/create/step-two/index.tsx @@ -23,7 +23,7 @@ import Loading from '@/app/components/base/loading' import Toast from '@/app/components/base/toast' import { formatNumber } from '@/utils/format' -import type { DataSourceNotionPage } from '@/models/common' +import type { NotionPage } from '@/models/common' import { DataSourceType, DocForm } from '@/models/datasets' import NotionIcon from '@/app/components/base/notion-icon' import Switch from '@/app/components/base/switch' @@ -33,8 +33,6 @@ import { useDatasetDetailContext } from '@/context/dataset-detail' import I18n from '@/context/i18n' import { IS_CE_EDITION } from '@/config' -type Page = DataSourceNotionPage & { workspace_id: string } - type StepTwoProps = { isSetting?: boolean documentDetail?: FullDocumentDetail @@ -44,7 +42,7 @@ type StepTwoProps = { indexingType?: string dataSourceType: DataSourceType files: CustomFile[] - notionPages?: Page[] + notionPages?: NotionPage[] onStepChange?: (delta: number) => void updateIndexingTypeCache?: (type: string) => void updateResultCache?: (res: createDocumentResponse) => void @@ -110,16 +108,16 @@ const StepTwo = ({ return segmentationType === SegmentType.AUTO ? automaticFileIndexingEstimate : customFileIndexingEstimate })() - const scrollHandle = (e: any) => { - if (e.target.scrollTop > 0) + const scrollHandle = (e: Event) => { + if ((e.target as HTMLDivElement).scrollTop > 0) setScrolled(true) else setScrolled(false) } - const previewScrollHandle = (e: any) => { - if (e.target.scrollTop > 0) + const previewScrollHandle = (e: Event) => { + if ((e.target as HTMLDivElement).scrollTop > 0) setPreviewScrolled(true) else diff --git a/web/app/components/datasets/documents/detail/completed/InfiniteVirtualList.tsx b/web/app/components/datasets/documents/detail/completed/InfiniteVirtualList.tsx index c4365091f0..92dca3f966 100644 --- a/web/app/components/datasets/documents/detail/completed/InfiniteVirtualList.tsx +++ b/web/app/components/datasets/documents/detail/completed/InfiniteVirtualList.tsx @@ -10,7 +10,7 @@ type IInfiniteVirtualListProps = { hasNextPage?: boolean // Are there more items to load? (This information comes from the most recent API request.) isNextPageLoading: boolean // Are we currently loading a page of items? (This may be an in-flight flag in your Redux store for example.) items: Array // Array of items loaded so far. - loadNextPage: () => Promise // Callback function responsible for loading the next page of items. + loadNextPage: () => Promise // Callback function responsible for loading the next page of items. onClick: (detail: SegmentDetailModel) => void onChangeSwitch: (segId: string, enabled: boolean) => Promise onDelete: (segId: string) => Promise diff --git a/web/app/components/datasets/documents/detail/completed/SegmentCard.tsx b/web/app/components/datasets/documents/detail/completed/SegmentCard.tsx index bfdc9c9b1c..a1fab8faad 100644 --- a/web/app/components/datasets/documents/detail/completed/SegmentCard.tsx +++ b/web/app/components/datasets/documents/detail/completed/SegmentCard.tsx @@ -66,7 +66,7 @@ const SegmentCard: FC = ({ hit_count, index_node_hash, answer, - } = detail as any + } = detail as Required['detail'] const isDocScene = scene === 'doc' const [showModal, setShowModal] = useState(false) diff --git a/web/app/components/datasets/documents/detail/completed/index.tsx b/web/app/components/datasets/documents/detail/completed/index.tsx index af720fd5fd..fb629f38f5 100644 --- a/web/app/components/datasets/documents/detail/completed/index.tsx +++ b/web/app/components/datasets/documents/detail/completed/index.tsx @@ -177,8 +177,8 @@ const SegmentDetailComponent: FC = ({
-
{formatNumber(segInfo?.word_count as any)} {t('datasetDocuments.segment.characters')} -
{formatNumber(segInfo?.hit_count as any)} {t('datasetDocuments.segment.hitCount')} +
{formatNumber(segInfo?.word_count as number)} {t('datasetDocuments.segment.characters')} +
{formatNumber(segInfo?.hit_count as number)} {t('datasetDocuments.segment.hitCount')}
{t('datasetDocuments.segment.vectorHash')}{segInfo?.index_node_hash}
diff --git a/web/app/components/datasets/documents/detail/embedding/index.tsx b/web/app/components/datasets/documents/detail/embedding/index.tsx index a7f8f4e2df..c4063e0b68 100644 --- a/web/app/components/datasets/documents/detail/embedding/index.tsx +++ b/web/app/components/datasets/documents/detail/embedding/index.tsx @@ -1,4 +1,4 @@ -import type { FC } from 'react' +import type { FC, SVGProps } from 'react' import React, { useCallback, useEffect, useMemo, useState } from 'react' import useSWR from 'swr' import { useRouter } from 'next/navigation' @@ -33,7 +33,7 @@ type Props = { detailUpdate: VoidFunction } -const StopIcon: FC<{ className?: string }> = ({ className }) => { +const StopIcon = ({ className }: SVGProps) => { return @@ -46,7 +46,7 @@ const StopIcon: FC<{ className?: string }> = ({ className }) => { } -const ResumeIcon: FC<{ className?: string }> = ({ className }) => { +const ResumeIcon = ({ className }: SVGProps) => { return diff --git a/web/app/components/datasets/documents/index.tsx b/web/app/components/datasets/documents/index.tsx index 967616128a..a7d29e58de 100644 --- a/web/app/components/datasets/documents/index.tsx +++ b/web/app/components/datasets/documents/index.tsx @@ -17,26 +17,26 @@ import { get } from '@/service/base' import { createDocument, fetchDocuments } from '@/service/datasets' import { useDatasetDetailContext } from '@/context/dataset-detail' import { NotionPageSelectorModal } from '@/app/components/base/notion-page-selector' -import type { DataSourceNotionPage } from '@/models/common' +import type { NotionPage } from '@/models/common' import type { CreateDocumentReq } from '@/models/datasets' import { DataSourceType } from '@/models/datasets' // Custom page count is not currently supported. const limit = 15 -const FolderPlusIcon: FC<{ className?: string }> = ({ className }) => { +const FolderPlusIcon = ({ className }: React.SVGProps) => { return } -const ThreeDotsIcon: FC<{ className?: string }> = ({ className }) => { +const ThreeDotsIcon = ({ className }: React.SVGProps) => { return } -const NotionIcon: FC<{ className?: string }> = ({ className }) => { +const NotionIcon = ({ className }: React.SVGProps) => { return @@ -142,7 +142,7 @@ const Documents: FC = ({ datasetId }) => { const isLoading = !documentsRes && !error - const handleSaveNotionPageSelected = async (selectedPages: (DataSourceNotionPage & { workspace_id: string })[]) => { + const handleSaveNotionPageSelected = async (selectedPages: NotionPage[]) => { const workspacesMap = groupBy(selectedPages, 'workspace_id') const workspaces = Object.keys(workspacesMap).map((workspaceId) => { return { diff --git a/web/app/components/datasets/documents/list.tsx b/web/app/components/datasets/documents/list.tsx index afbe734ce8..8dbf84d1e6 100644 --- a/web/app/components/datasets/documents/list.tsx +++ b/web/app/components/datasets/documents/list.tsx @@ -1,6 +1,6 @@ /* eslint-disable no-mixed-operators */ 'use client' -import type { FC } from 'react' +import type { FC, SVGProps } from 'react' import React, { useEffect, useState } from 'react' import { ArrowDownIcon, TrashIcon } from '@heroicons/react/24/outline' import { ExclamationCircleIcon } from '@heroicons/react/24/solid' @@ -29,25 +29,25 @@ import { DataSourceType, type DocumentDisplayStatus, type SimpleDocumentDetail } import type { CommonResponse } from '@/models/common' import { DotsHorizontal, HelpCircle } from '@/app/components/base/icons/src/vender/line/general' -export const SettingsIcon: FC<{ className?: string }> = ({ className }) => { +export const SettingsIcon = ({ className }: SVGProps) => { return } -export const SyncIcon: FC<{ className?: string }> = () => { +export const SyncIcon = () => { return } -export const FilePlusIcon: FC<{ className?: string }> = ({ className }) => { +export const FilePlusIcon = ({ className }: SVGProps) => { return } -export const ArchiveIcon: FC<{ className?: string }> = ({ className }) => { +export const ArchiveIcon = ({ className }: SVGProps) => { return diff --git a/web/app/components/datasets/hit-testing/hit-detail.tsx b/web/app/components/datasets/hit-testing/hit-detail.tsx index 455eba39ba..2ad266ab7e 100644 --- a/web/app/components/datasets/hit-testing/hit-detail.tsx +++ b/web/app/components/datasets/hit-testing/hit-detail.tsx @@ -89,7 +89,7 @@ const HitDetail: FC = ({ segInfo, vectorInfo }) => {
{!segInfo?.keywords?.length ? '-' - : segInfo?.keywords?.map((word: any) => { + : segInfo?.keywords?.map((word) => { return
{word}
})}
diff --git a/web/app/components/explore/app-list/index.tsx b/web/app/components/explore/app-list/index.tsx index 382e462c4d..f219358738 100644 --- a/web/app/components/explore/app-list/index.tsx +++ b/web/app/components/explore/app-list/index.tsx @@ -7,7 +7,7 @@ import { useContext } from 'use-context-selector' import Toast from '../../base/toast' import s from './style.module.css' import ExploreContext from '@/context/explore-context' -import type { App } from '@/models/explore' +import type { App, AppCategory } from '@/models/explore' import Category from '@/app/components/explore/category' import AppCard from '@/app/components/explore/app-card' import { fetchAppDetail, fetchAppList, installApp } from '@/service/explore' @@ -22,7 +22,7 @@ const Apps: FC = () => { const { t } = useTranslation() const router = useRouter() const { setControlUpdateInstalledApps, hasEditPermission } = useContext(ExploreContext) - const [currCategory, setCurrCategory] = React.useState('') + const [currCategory, setCurrCategory] = React.useState('') const [allList, setAllList] = React.useState([]) const [isLoaded, setIsLoaded] = React.useState(false) @@ -31,7 +31,8 @@ const Apps: FC = () => { return allList return allList.filter(item => item.category === currCategory) })() - const [categories, setCategories] = React.useState([]) + + const [categories, setCategories] = React.useState([]) useEffect(() => { (async () => { const { categories, recommended_apps }: any = await fetchAppList() diff --git a/web/app/components/explore/category.tsx b/web/app/components/explore/category.tsx index 0a705b69a0..dc5dbf1b7a 100644 --- a/web/app/components/explore/category.tsx +++ b/web/app/components/explore/category.tsx @@ -4,14 +4,15 @@ import React from 'react' import { useTranslation } from 'react-i18next' import cn from 'classnames' import exploreI18n from '@/i18n/lang/explore.en' +import type { AppCategory } from '@/models/explore' const categoryI18n = exploreI18n.category export type ICategoryProps = { className?: string - list: string[] + list: AppCategory[] value: string - onChange: (value: string) => void + onChange: (value: AppCategory | '') => void } const Category: FC = ({ @@ -40,7 +41,7 @@ const Category: FC = ({ style={itemStyle(name === value)} onClick={() => onChange(name)} > - {(categoryI18n as any)[name] ? t(`explore.category.${name}`) : name} + {categoryI18n[name] ? t(`explore.category.${name}`) : name}
))}
diff --git a/web/app/components/header/account-setting/index.tsx b/web/app/components/header/account-setting/index.tsx index e011a8ac10..bc6bff13f9 100644 --- a/web/app/components/header/account-setting/index.tsx +++ b/web/app/components/header/account-setting/index.tsx @@ -95,8 +95,8 @@ export default function AccountSetting({ ] const scrollRef = useRef(null) const [scrolled, setScrolled] = useState(false) - const scrollHandle = (e: any) => { - if (e.target.scrollTop > 0) + const scrollHandle = (e: Event) => { + if ((e.target as HTMLDivElement).scrollTop > 0) setScrolled(true) else diff --git a/web/app/components/header/account-setting/model-page/model-item/Card.tsx b/web/app/components/header/account-setting/model-page/model-item/Card.tsx index 98485054df..5b2dfbd30e 100644 --- a/web/app/components/header/account-setting/model-page/model-item/Card.tsx +++ b/web/app/components/header/account-setting/model-page/model-item/Card.tsx @@ -9,7 +9,7 @@ import Button from '@/app/components/base/button' type CardProps = { providerType: ProviderEnum models: Model[] - onOpenModal: (v: any) => void + onOpenModal: (v: Omit & Model['config']) => void onOperate: (v: Record) => void } diff --git a/web/app/components/share/text-generation/result/index.tsx b/web/app/components/share/text-generation/result/index.tsx index 443d0dd1a3..64820ccc88 100644 --- a/web/app/components/share/text-generation/result/index.tsx +++ b/web/app/components/share/text-generation/result/index.tsx @@ -133,7 +133,7 @@ const Result: FC = ({ setResponsingTrue() sendCompletionMessage(data, { - onData: (data: string, _isFirstMessage: boolean, { messageId }: any) => { + onData: (data: string, _isFirstMessage: boolean, { messageId }) => { tempMessageId = messageId res.push(data) setCompletionRes(res.join('')) diff --git a/web/models/common.ts b/web/models/common.ts index 853104317f..80ebf7ff3d 100644 --- a/web/models/common.ts +++ b/web/models/common.ts @@ -138,6 +138,10 @@ export type DataSourceNotionPage = { is_bound: boolean } +export type NotionPage = DataSourceNotionPage & { + workspace_id: string +} + export type DataSourceNotionPageMap = Record export type DataSourceNotionWorkspace = { diff --git a/web/models/explore.ts b/web/models/explore.ts index 7f49ee6572..fbb14cca4e 100644 --- a/web/models/explore.ts +++ b/web/models/explore.ts @@ -8,13 +8,15 @@ export type AppBasicInfo = { icon_background: string } +export type AppCategory = 'Writing' | 'Translate' | 'HR' | 'Programming' | 'Assistant' + export type App = { app: AppBasicInfo app_id: string description: string copyright: string privacy_policy: string - category: string + category: AppCategory position: number is_listed: boolean install_count: number