You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

notion-page-preview.tsx 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use client'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import type { NotionPage } from '@/models/common'
  5. import { usePreviewNotionPage } from '@/service/knowledge/use-dataset'
  6. import { RiCloseLine } from '@remixicon/react'
  7. import { formatNumberAbbreviated } from '@/utils/format'
  8. import Loading from './loading'
  9. import { Notion } from '@/app/components/base/icons/src/public/common'
  10. type NotionPagePreviewProps = {
  11. currentPage: NotionPage
  12. hidePreview: () => void
  13. }
  14. const NotionPagePreview = ({
  15. currentPage,
  16. hidePreview,
  17. }: NotionPagePreviewProps) => {
  18. const { t } = useTranslation()
  19. const { data: notionPageData, isFetching } = usePreviewNotionPage({
  20. workspaceID: currentPage.workspace_id,
  21. pageID: currentPage.page_id,
  22. pageType: currentPage.type,
  23. })
  24. return (
  25. <div className='h-full rounded-t-xl border-l border-t border-components-panel-border bg-background-default-lighter shadow-md shadow-shadow-shadow-5'>
  26. <div className='flex gap-x-2 pb-3 pl-6 pr-4 pt-4'>
  27. <div className='flex grow flex-col gap-y-1'>
  28. <div className='system-2xs-semibold-uppercase'>{t('datasetPipeline.addDocuments.stepOne.preview')}</div>
  29. <div className='title-md-semi-bold text-tex-primary'>{currentPage?.page_name}</div>
  30. <div className='system-xs-medium flex gap-x-1 text-text-tertiary'>
  31. <Notion className='size-3.5' />
  32. <span>·</span>
  33. <span>Notion Page</span>
  34. <span>·</span>
  35. {notionPageData && (
  36. <>
  37. <span>·</span>
  38. <span>{`${formatNumberAbbreviated(notionPageData.content.length)} ${t('datasetPipeline.addDocuments.characters')}`}</span>
  39. </>
  40. )}
  41. </div>
  42. </div>
  43. <button
  44. type='button'
  45. className='flex h-8 w-8 shrink-0 items-center justify-center'
  46. onClick={hidePreview}
  47. >
  48. <RiCloseLine className='size-[18px]' />
  49. </button>
  50. </div>
  51. <div className='px-6 py-5'>
  52. {isFetching && <Loading />}
  53. {!isFetching && notionPageData && (
  54. <div className='body-md-regular overflow-hidden text-text-secondary'>{notionPageData.content}</div>
  55. )}
  56. </div>
  57. </div>
  58. )
  59. }
  60. export default NotionPagePreview