mirror of
https://github.com/langgenius/dify.git
synced 2026-04-26 10:16:40 +08:00
refactor: refactor navigation components to use Link for improved routing
This commit is contained in:
parent
4ae936b263
commit
9f724c19db
@ -1,28 +1,26 @@
|
|||||||
import React, { useCallback } from 'react'
|
import React from 'react'
|
||||||
import { RiArrowLeftLine } from '@remixicon/react'
|
import { RiArrowLeftLine } from '@remixicon/react'
|
||||||
import Button from '../../base/button'
|
import Button from '../../base/button'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useRouter } from 'next/navigation'
|
import Link from 'next/link'
|
||||||
|
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { push } = useRouter()
|
|
||||||
|
|
||||||
const goBack = useCallback(() => {
|
|
||||||
push('/datasets')
|
|
||||||
}, [push])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='system-md-semibold relative flex px-16 pb-2 pt-5 text-text-primary'>
|
<Link
|
||||||
|
className='system-md-semibold relative flex px-16 pb-2 pt-5 text-text-primary'
|
||||||
|
href={'/datasets'}
|
||||||
|
replace
|
||||||
|
>
|
||||||
<span>{t('datasetPipeline.creation.title')}</span>
|
<span>{t('datasetPipeline.creation.title')}</span>
|
||||||
<Button
|
<Button
|
||||||
variant='secondary-accent'
|
variant='secondary-accent'
|
||||||
className='absolute bottom-0 left-5 size-9 rounded-full p-0'
|
className='absolute bottom-0 left-5 size-9 rounded-full p-0'
|
||||||
onClick={goBack}
|
|
||||||
>
|
>
|
||||||
<RiArrowLeftLine className='size-5 ' />
|
<RiArrowLeftLine className='size-5 ' />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import React, { useCallback } from 'react'
|
import React from 'react'
|
||||||
import { RiArrowLeftLine } from '@remixicon/react'
|
import { RiArrowLeftLine } from '@remixicon/react'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
import { useParams, useRouter } from 'next/navigation'
|
import { useParams } from 'next/navigation'
|
||||||
import Effect from '@/app/components/base/effect'
|
import Effect from '@/app/components/base/effect'
|
||||||
import type { Step } from './step-indicator'
|
import type { Step } from './step-indicator'
|
||||||
import StepIndicator from './step-indicator'
|
import StepIndicator from './step-indicator'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
type LeftHeaderProps = {
|
type LeftHeaderProps = {
|
||||||
steps: Array<Step>
|
steps: Array<Step>
|
||||||
@ -18,12 +19,6 @@ const LeftHeader = ({
|
|||||||
currentStep,
|
currentStep,
|
||||||
}: LeftHeaderProps) => {
|
}: LeftHeaderProps) => {
|
||||||
const { datasetId } = useParams()
|
const { datasetId } = useParams()
|
||||||
const { push } = useRouter()
|
|
||||||
|
|
||||||
const goBack = useCallback(() => {
|
|
||||||
if (datasetId)
|
|
||||||
push(`/datasets/${datasetId}/documents`)
|
|
||||||
}, [datasetId, push])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='relative flex flex-col gap-y-0.5 pb-2 pt-4'>
|
<div className='relative flex flex-col gap-y-0.5 pb-2 pt-4'>
|
||||||
@ -38,13 +33,17 @@ const LeftHeader = ({
|
|||||||
{steps[currentStep - 1]?.label}
|
{steps[currentStep - 1]?.label}
|
||||||
</div>
|
</div>
|
||||||
{currentStep !== steps.length && (
|
{currentStep !== steps.length && (
|
||||||
<Button
|
<Link
|
||||||
variant='secondary-accent'
|
href={`/datasets/${datasetId}/documents`}
|
||||||
className='absolute -left-11 top-3.5 size-9 rounded-full p-0'
|
replace
|
||||||
onClick={goBack}
|
|
||||||
>
|
>
|
||||||
<RiArrowLeftLine className='size-5 ' />
|
<Button
|
||||||
</Button>
|
variant='secondary-accent'
|
||||||
|
className='absolute -left-11 top-3.5 size-9 rounded-full p-0'
|
||||||
|
>
|
||||||
|
<RiArrowLeftLine className='size-5 ' />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
)}
|
)}
|
||||||
<Effect className='left-8 top-[-34px] opacity-20' />
|
<Effect className='left-8 top-[-34px] opacity-20' />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -322,6 +322,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|||||||
</div>
|
</div>
|
||||||
{isListLoading
|
{isListLoading
|
||||||
? <Loading type='app' />
|
? <Loading type='app' />
|
||||||
|
// eslint-disable-next-line sonarjs/no-nested-conditional
|
||||||
: total > 0
|
: total > 0
|
||||||
? <List
|
? <List
|
||||||
embeddingAvailable={embeddingAvailable}
|
embeddingAvailable={embeddingAvailable}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import {
|
|||||||
RiAddLine,
|
RiAddLine,
|
||||||
RiFunctionAddLine,
|
RiFunctionAddLine,
|
||||||
} from '@remixicon/react'
|
} from '@remixicon/react'
|
||||||
import Link from './link'
|
import Option from './option'
|
||||||
import { ApiConnectionMod } from '@/app/components/base/icons/src/vender/solid/development'
|
import { ApiConnectionMod } from '@/app/components/base/icons/src/vender/solid/development'
|
||||||
|
|
||||||
const CreateAppCard = () => {
|
const CreateAppCard = () => {
|
||||||
@ -14,19 +14,19 @@ const CreateAppCard = () => {
|
|||||||
return (
|
return (
|
||||||
<div className='flex h-[166px] flex-col gap-y-0.5 rounded-xl bg-background-default-dimmed'>
|
<div className='flex h-[166px] flex-col gap-y-0.5 rounded-xl bg-background-default-dimmed'>
|
||||||
<div className='flex grow flex-col items-center justify-center p-2'>
|
<div className='flex grow flex-col items-center justify-center p-2'>
|
||||||
<Link
|
<Option
|
||||||
href={'/datasets/create-from-pipeline'}
|
href={'/datasets/create-from-pipeline'}
|
||||||
Icon={RiFunctionAddLine}
|
Icon={RiFunctionAddLine}
|
||||||
text={t('dataset.createFromPipeline')}
|
text={t('dataset.createFromPipeline')}
|
||||||
/>
|
/>
|
||||||
<Link
|
<Option
|
||||||
href={'/datasets/create'}
|
href={'/datasets/create'}
|
||||||
Icon={RiAddLine}
|
Icon={RiAddLine}
|
||||||
text={t('dataset.createDataset')}
|
text={t('dataset.createDataset')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='border-t-[0.5px] border-divider-subtle p-2'>
|
<div className='border-t-[0.5px] border-divider-subtle p-2'>
|
||||||
<Link
|
<Option
|
||||||
href={'/datasets/connect'}
|
href={'/datasets/connect'}
|
||||||
Icon={ApiConnectionMod}
|
Icon={ApiConnectionMod}
|
||||||
text={t('dataset.connectDataset')}
|
text={t('dataset.connectDataset')}
|
||||||
|
|||||||
@ -1,33 +1,27 @@
|
|||||||
import { useRouter } from 'next/navigation'
|
import Link from 'next/link'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
type LinkProps = {
|
type OptionProps = {
|
||||||
Icon: React.ComponentType<{ className?: string }>
|
Icon: React.ComponentType<{ className?: string }>
|
||||||
text: string
|
text: string
|
||||||
href: string
|
href: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const Link = ({
|
const Option = ({
|
||||||
Icon,
|
Icon,
|
||||||
text,
|
text,
|
||||||
href,
|
href,
|
||||||
}: LinkProps) => {
|
}: OptionProps) => {
|
||||||
const { push } = useRouter()
|
|
||||||
|
|
||||||
const navigateTo = () => {
|
|
||||||
push(href)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<Link
|
||||||
type='button'
|
type='button'
|
||||||
className='flex w-full items-center gap-x-2 rounded-lg bg-transparent px-4 py-2 text-text-tertiary shadow-shadow-shadow-3 hover:bg-background-default-dodge hover:text-text-secondary hover:shadow-xs'
|
className='flex w-full items-center gap-x-2 rounded-lg bg-transparent px-4 py-2 text-text-tertiary shadow-shadow-shadow-3 hover:bg-background-default-dodge hover:text-text-secondary hover:shadow-xs'
|
||||||
onClick={navigateTo}
|
href={href}
|
||||||
>
|
>
|
||||||
<Icon className='h-4 w-4 shrink-0' />
|
<Icon className='h-4 w-4 shrink-0' />
|
||||||
<span className='system-sm-medium grow text-left'>{text}</span>
|
<span className='system-sm-medium grow text-left'>{text}</span>
|
||||||
</button>
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default React.memo(Link)
|
export default React.memo(Option)
|
||||||
Loading…
Reference in New Issue
Block a user