mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 01:56:01 +08:00
fix: refresh list on delete (#178)
This commit is contained in:
parent
e2bf18053c
commit
380b4b3ddc
@ -16,10 +16,12 @@ import AppsContext from '@/context/app-context'
|
|||||||
|
|
||||||
export type AppCardProps = {
|
export type AppCardProps = {
|
||||||
app: App
|
app: App
|
||||||
|
onDelete?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const AppCard = ({
|
const AppCard = ({
|
||||||
app,
|
app,
|
||||||
|
onDelete
|
||||||
}: AppCardProps) => {
|
}: AppCardProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
@ -35,6 +37,8 @@ const AppCard = ({
|
|||||||
try {
|
try {
|
||||||
await deleteApp(app.id)
|
await deleteApp(app.id)
|
||||||
notify({ type: 'success', message: t('app.appDeleted') })
|
notify({ type: 'success', message: t('app.appDeleted') })
|
||||||
|
if (onDelete)
|
||||||
|
onDelete()
|
||||||
mutateApps()
|
mutateApps()
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
@ -47,7 +51,7 @@ const AppCard = ({
|
|||||||
<>
|
<>
|
||||||
<Link href={`/app/${app.id}/overview`} className={style.listItem}>
|
<Link href={`/app/${app.id}/overview`} className={style.listItem}>
|
||||||
<div className={style.listItemTitle}>
|
<div className={style.listItemTitle}>
|
||||||
<AppIcon size='small' icon={app.icon} background={app.icon_background}/>
|
<AppIcon size='small' icon={app.icon} background={app.icon_background} />
|
||||||
<div className={style.listItemHeading}>
|
<div className={style.listItemHeading}>
|
||||||
<div className={style.listItemHeadingContent}>{app.name}</div>
|
<div className={style.listItemHeadingContent}>{app.name}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -42,7 +42,9 @@ const Apps = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className='grid content-start grid-cols-1 gap-4 px-12 pt-8 sm:grid-cols-2 lg:grid-cols-4 grow shrink-0'>
|
<nav className='grid content-start grid-cols-1 gap-4 px-12 pt-8 sm:grid-cols-2 lg:grid-cols-4 grow shrink-0'>
|
||||||
{data?.map(({ data: apps }) => apps.map(app => (<AppCard key={app.id} app={app} />)))}
|
{data?.map(({ data: apps }) => apps.map(app => (
|
||||||
|
<AppCard key={app.id} app={app} onDelete={mutate} />
|
||||||
|
)))}
|
||||||
<NewAppCard ref={anchorRef} onSuccess={mutate} />
|
<NewAppCard ref={anchorRef} onSuccess={mutate} />
|
||||||
</nav>
|
</nav>
|
||||||
)
|
)
|
||||||
|
@ -18,16 +18,16 @@ import classNames from 'classnames'
|
|||||||
|
|
||||||
export type DatasetCardProps = {
|
export type DatasetCardProps = {
|
||||||
dataset: DataSet
|
dataset: DataSet
|
||||||
|
onDelete?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const DatasetCard = ({
|
const DatasetCard = ({
|
||||||
dataset,
|
dataset,
|
||||||
|
onDelete
|
||||||
}: DatasetCardProps) => {
|
}: DatasetCardProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
|
|
||||||
const { mutate: mutateDatasets } = useSWR({ url: '/datasets', params: { page: 1 } }, fetchDatasets)
|
|
||||||
|
|
||||||
const [showConfirmDelete, setShowConfirmDelete] = useState(false)
|
const [showConfirmDelete, setShowConfirmDelete] = useState(false)
|
||||||
const onDeleteClick: MouseEventHandler = useCallback((e) => {
|
const onDeleteClick: MouseEventHandler = useCallback((e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@ -37,7 +37,8 @@ const DatasetCard = ({
|
|||||||
try {
|
try {
|
||||||
await deleteDataset(dataset.id)
|
await deleteDataset(dataset.id)
|
||||||
notify({ type: 'success', message: t('dataset.datasetDeleted') })
|
notify({ type: 'success', message: t('dataset.datasetDeleted') })
|
||||||
mutateDatasets()
|
if (onDelete)
|
||||||
|
onDelete()
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
notify({ type: 'error', message: `${t('dataset.datasetDeleteFailed')}${'message' in e ? `: ${e.message}` : ''}` })
|
notify({ type: 'error', message: `${t('dataset.datasetDeleteFailed')}${'message' in e ? `: ${e.message}` : ''}` })
|
||||||
|
@ -42,7 +42,9 @@ const Datasets = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className='grid content-start grid-cols-1 gap-4 px-12 pt-8 sm:grid-cols-2 lg:grid-cols-4 grow shrink-0'>
|
<nav className='grid content-start grid-cols-1 gap-4 px-12 pt-8 sm:grid-cols-2 lg:grid-cols-4 grow shrink-0'>
|
||||||
{data?.map(({ data: datasets }) => datasets.map(dataset => (<DatasetCard key={dataset.id} dataset={dataset} />)))}
|
{data?.map(({ data: datasets }) => datasets.map(dataset => (
|
||||||
|
<DatasetCard key={dataset.id} dataset={dataset} onDelete={mutate} />)
|
||||||
|
))}
|
||||||
<NewDatasetCard ref={anchorRef} />
|
<NewDatasetCard ref={anchorRef} />
|
||||||
</nav>
|
</nav>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user