fix: refactor OptionCard and StepTwo components for improved structure and readability

feat/rag-2
twwu 10 months ago
parent d77d86f53b
commit 60f3832c65

@ -1,6 +1,6 @@
'use client' 'use client'
import type { FC, PropsWithChildren } from 'react' import type { FC, PropsWithChildren } from 'react'
import React, { useCallback, useEffect, useRef, useState } from 'react' import React, { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useContext } from 'use-context-selector' import { useContext } from 'use-context-selector'
import { import {
@ -10,7 +10,6 @@ import {
} from '@remixicon/react' } from '@remixicon/react'
import Link from 'next/link' import Link from 'next/link'
import Image from 'next/image' import Image from 'next/image'
import { useHover } from 'ahooks'
import SettingCog from '../assets/setting-gear-mod.svg' import SettingCog from '../assets/setting-gear-mod.svg'
import OrangeEffect from '../assets/option-card-effect-orange.svg' import OrangeEffect from '../assets/option-card-effect-orange.svg'
import FamilyMod from '../assets/family-mod.svg' import FamilyMod from '../assets/family-mod.svg'
@ -60,7 +59,6 @@ import Badge from '@/app/components/base/badge'
import { SkeletonContainer, SkeletonPoint, SkeletonRectangle, SkeletonRow } from '@/app/components/base/skeleton' import { SkeletonContainer, SkeletonPoint, SkeletonRectangle, SkeletonRow } from '@/app/components/base/skeleton'
import Tooltip from '@/app/components/base/tooltip' import Tooltip from '@/app/components/base/tooltip'
import CustomDialog from '@/app/components/base/dialog' import CustomDialog from '@/app/components/base/dialog'
import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger } from '@/app/components/base/portal-to-follow-elem'
import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback' import { AlertTriangle } from '@/app/components/base/icons/src/vender/solid/alertsAndFeedback'
import { noop } from 'lodash-es' import { noop } from 'lodash-es'
import { useDocLink } from '@/context/i18n' import { useDocLink } from '@/context/i18n'
@ -611,9 +609,6 @@ const StepTwo = ({
setIndexType(isAPIKeySet ? IndexingType.QUALIFIED : IndexingType.ECONOMICAL) setIndexType(isAPIKeySet ? IndexingType.QUALIFIED : IndexingType.ECONOMICAL)
}, [isAPIKeySet, indexingType, datasetId]) }, [isAPIKeySet, indexingType, datasetId])
const economyDomRef = useRef<HTMLDivElement>(null)
const isHoveringEconomy = useHover(economyDomRef)
const isModelAndRetrievalConfigDisabled = !!datasetId && !!currentDataset?.data_source_type const isModelAndRetrievalConfigDisabled = !!datasetId && !!currentDataset?.data_source_type
return ( return (
@ -873,7 +868,8 @@ const StepTwo = ({
<div className={'system-md-semibold mb-1 text-text-secondary'}>{t('datasetCreation.stepTwo.indexMode')}</div> <div className={'system-md-semibold mb-1 text-text-secondary'}>{t('datasetCreation.stepTwo.indexMode')}</div>
<div className='flex items-center gap-2'> <div className='flex items-center gap-2'>
{(!hasSetIndexType || (hasSetIndexType && indexingType === IndexingType.QUALIFIED)) && ( {(!hasSetIndexType || (hasSetIndexType && indexingType === IndexingType.QUALIFIED)) && (
<OptionCard className='flex-1 self-stretch' <OptionCard
className='flex-1 self-stretch'
title={<div className='flex items-center'> title={<div className='flex items-center'>
{t('datasetCreation.stepTwo.qualified')} {t('datasetCreation.stepTwo.qualified')}
<Badge className={cn('ml-1 h-[18px]', (!hasSetIndexType && indexType === IndexingType.QUALIFIED) ? 'border-text-accent-secondary text-text-accent-secondary' : '')} uppercase> <Badge className={cn('ml-1 h-[18px]', (!hasSetIndexType && indexType === IndexingType.QUALIFIED) ? 'border-text-accent-secondary text-text-accent-secondary' : '')} uppercase>
@ -919,35 +915,33 @@ const StepTwo = ({
</Button> </Button>
</div> </div>
</CustomDialog> </CustomDialog>
<PortalToFollowElem <Tooltip
open={ popupContent={
isHoveringEconomy && docForm !== ChunkingMode.text <div className='rounded-lg border-components-panel-border bg-components-tooltip-bg p-3 text-xs font-medium text-text-secondary shadow-lg'>
{
docForm === ChunkingMode.qa
? t('datasetCreation.stepTwo.notAvailableForQA')
: t('datasetCreation.stepTwo.notAvailableForParentChild')
}
</div>
} }
placement={'top'} noDecoration
position='top'
asChild={false}
triggerClassName='flex-1 self-stretch'
> >
<PortalToFollowElemTrigger asChild> <OptionCard
<OptionCard className='flex-1 self-stretch' className='h-full'
title={t('datasetCreation.stepTwo.economical')} title={t('datasetCreation.stepTwo.economical')}
description={t('datasetCreation.stepTwo.economicalTip')} description={t('datasetCreation.stepTwo.economicalTip')}
icon={<Image src={indexMethodIcon.economical} alt='' />} icon={<Image src={indexMethodIcon.economical} alt='' />}
isActive={!hasSetIndexType && indexType === IndexingType.ECONOMICAL} isActive={!hasSetIndexType && indexType === IndexingType.ECONOMICAL}
disabled={hasSetIndexType || docForm !== ChunkingMode.text} disabled={hasSetIndexType || docForm !== ChunkingMode.text}
ref={economyDomRef}
onSwitched={() => { onSwitched={() => {
setIndexType(IndexingType.ECONOMICAL) setIndexType(IndexingType.ECONOMICAL)
}} }}
/> />
</PortalToFollowElemTrigger> </Tooltip>
<PortalToFollowElemContent>
<div className='rounded-lg border-components-panel-border bg-components-tooltip-bg p-3 text-xs font-medium text-text-secondary shadow-lg'>
{
docForm === ChunkingMode.qa
? t('datasetCreation.stepTwo.notAvailableForQA')
: t('datasetCreation.stepTwo.notAvailableForParentChild')
}
</div>
</PortalToFollowElemContent>
</PortalToFollowElem>
</>)} </>)}
</div> </div>
{!hasSetIndexType && indexType === IndexingType.QUALIFIED && ( {!hasSetIndexType && indexType === IndexingType.QUALIFIED && (

@ -21,7 +21,7 @@ type OptionCardHeaderProps = {
export const OptionCardHeader: FC<OptionCardHeaderProps> = (props) => { export const OptionCardHeader: FC<OptionCardHeaderProps> = (props) => {
const { icon, title, description, isActive, activeClassName, effectImg, disabled } = props const { icon, title, description, isActive, activeClassName, effectImg, disabled } = props
return <div className={classNames( return <div className={classNames(
'flex h-full overflow-hidden rounded-t-xl relative', 'relative flex h-full overflow-hidden rounded-t-xl',
isActive && activeClassName, isActive && activeClassName,
!disabled && 'cursor-pointer', !disabled && 'cursor-pointer',
)}> )}>
@ -34,7 +34,7 @@ export const OptionCardHeader: FC<OptionCardHeaderProps> = (props) => {
</div> </div>
</div> </div>
<TriangleArrow <TriangleArrow
className={classNames('absolute left-4 -bottom-1.5 text-transparent', isActive && 'text-components-panel-bg')} className={classNames('absolute -bottom-1.5 left-4 text-transparent', isActive && 'text-components-panel-bg')}
/> />
<div className='flex-1 space-y-0.5 py-3 pr-4'> <div className='flex-1 space-y-0.5 py-3 pr-4'>
<div className='system-md-semibold text-text-secondary'>{title}</div> <div className='system-md-semibold text-text-secondary'>{title}</div>
@ -64,13 +64,14 @@ export const OptionCard: FC<OptionCardProps> = (
}, },
) => { ) => {
const { icon, className, title, description, isActive, children, actions, activeHeaderClassName, style, effectImg, onSwitched, noHighlight, disabled, ...rest } = props const { icon, className, title, description, isActive, children, actions, activeHeaderClassName, style, effectImg, onSwitched, noHighlight, disabled, ...rest } = props
return <div return (
<div
className={classNames( className={classNames(
'rounded-xl bg-components-option-card-option-bg shadow-xs', 'rounded-xl bg-components-option-card-option-bg shadow-xs',
(isActive && !noHighlight) (isActive && !noHighlight)
? 'border-[1.5px] border-components-option-card-option-selected-border' ? 'border-[1.5px] border-components-option-card-option-selected-border'
: 'border border-components-option-card-option-border', : 'border border-components-option-card-option-border',
disabled && 'opacity-50 pointer-events-none', disabled && 'pointer-events-none opacity-50',
className, className,
)} )}
style={{ style={{
@ -101,6 +102,7 @@ export const OptionCard: FC<OptionCardProps> = (
} }
</div>} </div>}
</div> </div>
)
} }
OptionCard.displayName = 'OptionCard' OptionCard.displayName = 'OptionCard'

Loading…
Cancel
Save