| } from '@heroicons/react/24/solid' | } from '@heroicons/react/24/solid' | ||||
| import Link from 'next/link' | import Link from 'next/link' | ||||
| import s from './style.module.css' | import s from './style.module.css' | ||||
| import { fetchDataDetail, fetchDatasetRelatedApps } from '@/service/datasets' | |||||
| import { fetchDatasetDetail, fetchDatasetRelatedApps } from '@/service/datasets' | |||||
| import type { RelatedApp } from '@/models/datasets' | import type { RelatedApp } from '@/models/datasets' | ||||
| import { getLocaleOnClient } from '@/i18n/client' | import { getLocaleOnClient } from '@/i18n/client' | ||||
| import AppSideBar from '@/app/components/app-sidebar' | import AppSideBar from '@/app/components/app-sidebar' | ||||
| import DatasetDetailContext from '@/context/dataset-detail' | import DatasetDetailContext from '@/context/dataset-detail' | ||||
| import { DataSourceType } from '@/models/datasets' | import { DataSourceType } from '@/models/datasets' | ||||
| // import { fetchDatasetDetail } from '@/service/datasets' | |||||
| export type IAppDetailLayoutProps = { | export type IAppDetailLayoutProps = { | ||||
| children: React.ReactNode | children: React.ReactNode | ||||
| params: { datasetId: string } | params: { datasetId: string } | ||||
| const hideSideBar = /documents\/create$/.test(pathname) | const hideSideBar = /documents\/create$/.test(pathname) | ||||
| const { t } = useTranslation() | const { t } = useTranslation() | ||||
| const { data: datasetRes, error, mutate: mutateDatasetRes } = useSWR({ | const { data: datasetRes, error, mutate: mutateDatasetRes } = useSWR({ | ||||
| action: 'fetchDataDetail', | |||||
| url: 'fetchDatasetDetail', | |||||
| datasetId, | datasetId, | ||||
| }, apiParams => fetchDataDetail(apiParams.datasetId)) | |||||
| }, apiParams => fetchDatasetDetail(apiParams.datasetId)) | |||||
| const { data: relatedApps } = useSWR({ | const { data: relatedApps } = useSWR({ | ||||
| action: 'fetchDatasetRelatedApps', | action: 'fetchDatasetRelatedApps', |
| const Datasets = () => { | const Datasets = () => { | ||||
| const { isCurrentWorkspaceManager } = useAppContext() | const { isCurrentWorkspaceManager } = useAppContext() | ||||
| const { data, isLoading, setSize, mutate } = useSWRInfinite(getKey, fetchDatasets, { revalidateFirstPage: false }) | |||||
| const { data, isLoading, setSize, mutate } = useSWRInfinite(getKey, fetchDatasets, { revalidateFirstPage: false, revalidateAll: true }) | |||||
| const loadingStateRef = useRef(false) | const loadingStateRef = useRef(false) | ||||
| const pageContainerRef = useSelector(state => state.pageContainerRef) | const pageContainerRef = useSelector(state => state.pageContainerRef) | ||||
| const anchorRef = useRef<HTMLAnchorElement>(null) | const anchorRef = useRef<HTMLAnchorElement>(null) |
| import { DataSourceType } from '@/models/datasets' | import { DataSourceType } from '@/models/datasets' | ||||
| import type { DataSet, FileItem, createDocumentResponse } from '@/models/datasets' | import type { DataSet, FileItem, createDocumentResponse } from '@/models/datasets' | ||||
| import { fetchDataSource } from '@/service/common' | import { fetchDataSource } from '@/service/common' | ||||
| import { fetchDataDetail } from '@/service/datasets' | |||||
| import { fetchDatasetDetail } from '@/service/datasets' | |||||
| import type { NotionPage } from '@/models/common' | import type { NotionPage } from '@/models/common' | ||||
| import { useProviderContext } from '@/context/provider-context' | import { useProviderContext } from '@/context/provider-context' | ||||
| (async () => { | (async () => { | ||||
| if (datasetId) { | if (datasetId) { | ||||
| try { | try { | ||||
| const detail = await fetchDataDetail(datasetId) | |||||
| const detail = await fetchDatasetDetail(datasetId) | |||||
| setDetail(detail) | setDetail(detail) | ||||
| } | } | ||||
| catch (e) { | catch (e) { | ||||
| ) | ) | ||||
| } | } | ||||
| export default DatasetUpdateForm | |||||
| export default DatasetUpdateForm |
| 'use client' | 'use client' | ||||
| import { useEffect, useState } from 'react' | import { useEffect, useState } from 'react' | ||||
| import type { Dispatch } from 'react' | import type { Dispatch } from 'react' | ||||
| import useSWR from 'swr' | |||||
| import { useContext } from 'use-context-selector' | import { useContext } from 'use-context-selector' | ||||
| import { BookOpenIcon } from '@heroicons/react/24/outline' | import { BookOpenIcon } from '@heroicons/react/24/outline' | ||||
| import { useTranslation } from 'react-i18next' | import { useTranslation } from 'react-i18next' | ||||
| import cn from 'classnames' | import cn from 'classnames' | ||||
| import { useSWRConfig } from 'swr' | |||||
| import { unstable_serialize } from 'swr/infinite' | |||||
| import PermissionsRadio from '../permissions-radio' | import PermissionsRadio from '../permissions-radio' | ||||
| import IndexMethodRadio from '../index-method-radio' | import IndexMethodRadio from '../index-method-radio' | ||||
| import { ToastContext } from '@/app/components/base/toast' | import { ToastContext } from '@/app/components/base/toast' | ||||
| import Button from '@/app/components/base/button' | import Button from '@/app/components/base/button' | ||||
| import { fetchDataDetail, updateDatasetSetting } from '@/service/datasets' | |||||
| import type { DataSet } from '@/models/datasets' | |||||
| import { updateDatasetSetting } from '@/service/datasets' | |||||
| import type { DataSet, DataSetListResponse } from '@/models/datasets' | |||||
| import ModelSelector from '@/app/components/header/account-setting/model-page/model-selector' | import ModelSelector from '@/app/components/header/account-setting/model-page/model-selector' | ||||
| import type { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations' | import type { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations' | ||||
| import { ModelType } from '@/app/components/header/account-setting/model-page/declarations' | import { ModelType } from '@/app/components/header/account-setting/model-page/declarations' | ||||
| import AccountSetting from '@/app/components/header/account-setting' | import AccountSetting from '@/app/components/header/account-setting' | ||||
| import DatasetDetailContext from '@/context/dataset-detail' | |||||
| const rowClass = ` | const rowClass = ` | ||||
| flex justify-between py-4 | flex justify-between py-4 | ||||
| }, [depend]) | }, [depend]) | ||||
| } | } | ||||
| type Props = { | |||||
| datasetId: string | |||||
| const getKey = (pageIndex: number, previousPageData: DataSetListResponse) => { | |||||
| if (!pageIndex || previousPageData.has_more) | |||||
| return { url: 'datasets', params: { page: pageIndex + 1, limit: 30 } } | |||||
| return null | |||||
| } | } | ||||
| const Form = ({ | |||||
| datasetId, | |||||
| }: Props) => { | |||||
| const Form = () => { | |||||
| const { t } = useTranslation() | const { t } = useTranslation() | ||||
| const { notify } = useContext(ToastContext) | const { notify } = useContext(ToastContext) | ||||
| const { data: currentDataset, mutate: mutateDatasets } = useSWR(datasetId, fetchDataDetail) | |||||
| const { mutate } = useSWRConfig() | |||||
| const { dataset: currentDataset, mutateDatasetRes: mutateDatasets } = useContext(DatasetDetailContext) | |||||
| const [loading, setLoading] = useState(false) | const [loading, setLoading] = useState(false) | ||||
| const [name, setName] = useState(currentDataset?.name ?? '') | const [name, setName] = useState(currentDataset?.name ?? '') | ||||
| const [description, setDescription] = useState(currentDataset?.description ?? '') | const [description, setDescription] = useState(currentDataset?.description ?? '') | ||||
| }, | }, | ||||
| }) | }) | ||||
| notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) | notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) | ||||
| await mutateDatasets() | |||||
| if (mutateDatasets) { | |||||
| await mutateDatasets() | |||||
| mutate(unstable_serialize(getKey)) | |||||
| } | |||||
| } | } | ||||
| catch (e) { | catch (e) { | ||||
| notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) | notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) |
| import useSWRInfinite from 'swr/infinite' | import useSWRInfinite from 'swr/infinite' | ||||
| import { flatten } from 'lodash-es' | import { flatten } from 'lodash-es' | ||||
| import Nav from '../nav' | import Nav from '../nav' | ||||
| import { fetchDataDetail, fetchDatasets } from '@/service/datasets' | |||||
| import { fetchDatasetDetail, fetchDatasets } from '@/service/datasets' | |||||
| import { Database01 } from '@/app/components/base/icons/src/vender/line/development' | import { Database01 } from '@/app/components/base/icons/src/vender/line/development' | ||||
| import { Database02 } from '@/app/components/base/icons/src/vender/solid/development' | import { Database02 } from '@/app/components/base/icons/src/vender/solid/development' | ||||
| import type { DataSetListResponse } from '@/models/datasets' | import type { DataSetListResponse } from '@/models/datasets' | ||||
| const { t } = useTranslation() | const { t } = useTranslation() | ||||
| const router = useRouter() | const router = useRouter() | ||||
| const { datasetId } = useParams() | const { datasetId } = useParams() | ||||
| const { data: currentDataset } = useSWR(datasetId || null, fetchDataDetail) | |||||
| const { data: datasetsData, setSize } = useSWRInfinite(datasetId ? getKey : () => null, fetchDatasets, { revalidateFirstPage: true }) | |||||
| const { data: currentDataset } = useSWR( | |||||
| datasetId | |||||
| ? { | |||||
| url: 'fetchDatasetDetail', | |||||
| datasetId, | |||||
| } | |||||
| : null, | |||||
| apiParams => fetchDatasetDetail(apiParams.datasetId)) | |||||
| const { data: datasetsData, setSize } = useSWRInfinite(datasetId ? getKey : () => null, fetchDatasets, { revalidateFirstPage: false, revalidateAll: true }) | |||||
| const datasetItems = flatten(datasetsData?.map(datasetData => datasetData.data)) | const datasetItems = flatten(datasetsData?.map(datasetData => datasetData.data)) | ||||
| const handleLoadmore = useCallback(() => { | const handleLoadmore = useCallback(() => { |
| export type MetadataType = 'all' | 'only' | 'without' | export type MetadataType = 'all' | 'only' | 'without' | ||||
| export const fetchDataDetail: Fetcher<DataSet, string> = (datasetId: string) => { | |||||
| export const fetchDatasetDetail: Fetcher<DataSet, string> = (datasetId: string) => { | |||||
| return get<DataSet>(`/datasets/${datasetId}`) | return get<DataSet>(`/datasets/${datasetId}`) | ||||
| } | } | ||||