From 4ae936b2636a5551fce555dd3dbfd968c34b5c6a Mon Sep 17 00:00:00 2001 From: twwu Date: Thu, 29 May 2025 15:48:54 +0800 Subject: [PATCH] refactor: refactor navigation handling in dataset components to use button elements --- .../datasets/create-from-pipeline/header.tsx | 29 +++++++++++-------- .../create-from-pipeline/left-header.tsx | 23 +++++++++------ .../datasets/list/new-dataset-card/index.tsx | 19 +++++++++--- .../datasets/list/new-dataset-card/link.tsx | 19 +++++++----- 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/web/app/components/datasets/create-from-pipeline/header.tsx b/web/app/components/datasets/create-from-pipeline/header.tsx index 48c7612b7a..78e2606051 100644 --- a/web/app/components/datasets/create-from-pipeline/header.tsx +++ b/web/app/components/datasets/create-from-pipeline/header.tsx @@ -1,23 +1,28 @@ -import React from 'react' +import React, { useCallback } from 'react' import { RiArrowLeftLine } from '@remixicon/react' import Button from '../../base/button' import { useTranslation } from 'react-i18next' +import { useRouter } from 'next/navigation' const Header = () => { const { t } = useTranslation() + const { push } = useRouter() + + const goBack = useCallback(() => { + push('/datasets') + }, [push]) return ( -
- {t('datasetPipeline.creation.title')} - - - -
+
+ {t('datasetPipeline.creation.title')} + +
) } diff --git a/web/app/components/datasets/documents/create-from-pipeline/left-header.tsx b/web/app/components/datasets/documents/create-from-pipeline/left-header.tsx index 6ea4f3ace5..76e9c38eaa 100644 --- a/web/app/components/datasets/documents/create-from-pipeline/left-header.tsx +++ b/web/app/components/datasets/documents/create-from-pipeline/left-header.tsx @@ -1,7 +1,7 @@ -import React from 'react' +import React, { useCallback } from 'react' import { RiArrowLeftLine } from '@remixicon/react' import Button from '@/app/components/base/button' -import { useParams } from 'next/navigation' +import { useParams, useRouter } from 'next/navigation' import Effect from '@/app/components/base/effect' import type { Step } from './step-indicator' import StepIndicator from './step-indicator' @@ -18,6 +18,12 @@ const LeftHeader = ({ currentStep, }: LeftHeaderProps) => { const { datasetId } = useParams() + const { push } = useRouter() + + const goBack = useCallback(() => { + if (datasetId) + push(`/datasets/${datasetId}/documents`) + }, [datasetId, push]) return (
@@ -32,14 +38,13 @@ const LeftHeader = ({ {steps[currentStep - 1]?.label}
{currentStep !== steps.length && ( - - - + + )} diff --git a/web/app/components/datasets/list/new-dataset-card/index.tsx b/web/app/components/datasets/list/new-dataset-card/index.tsx index 541c9d38ab..2cdb213fb9 100644 --- a/web/app/components/datasets/list/new-dataset-card/index.tsx +++ b/web/app/components/datasets/list/new-dataset-card/index.tsx @@ -1,7 +1,6 @@ 'use client' import React from 'react' import { useTranslation } from 'react-i18next' -import { basePath } from '@/utils/var' import { RiAddLine, RiFunctionAddLine, @@ -15,11 +14,23 @@ const CreateAppCard = () => { return (
- - + +
- +
) diff --git a/web/app/components/datasets/list/new-dataset-card/link.tsx b/web/app/components/datasets/list/new-dataset-card/link.tsx index 696a11a01e..21d613c315 100644 --- a/web/app/components/datasets/list/new-dataset-card/link.tsx +++ b/web/app/components/datasets/list/new-dataset-card/link.tsx @@ -1,27 +1,32 @@ +import { useRouter } from 'next/navigation' import React from 'react' type LinkProps = { Icon: React.ComponentType<{ className?: string }> text: string href: string - ref?: React.RefObject } const Link = ({ Icon, text, href, - ref, }: LinkProps) => { + const { push } = useRouter() + + const navigateTo = () => { + push(href) + } + return ( - - {text} - + {text} + ) }