Skip to content

Commit

Permalink
fix: refresh dataset after it is deaccessioned
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Mar 7, 2025
1 parent 023cdf1 commit f908181
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/sections/dataset/DatasetContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { Dataset } from '../../dataset/domain/models/Dataset'
interface DatasetContextProps {
dataset: Dataset | undefined
isLoading: boolean
refreshDataset: () => void
}
export const DatasetContext = createContext<DatasetContextProps>({
dataset: undefined,
isLoading: false
isLoading: false,
refreshDataset: () => {}
})

export const useDataset = () => useContext(DatasetContext)
10 changes: 9 additions & 1 deletion src/sections/dataset/DatasetFactory.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ReactElement, useEffect } from 'react'
import { ReactElement, useEffect, useContext } from 'react'
import { useSearchParams } from 'react-router-dom'
import { useLocation } from 'react-router-dom'
import { Dataset } from './Dataset'
import { DatasetContext } from './DatasetContext'
import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository'
import { useAnonymized } from './anonymized/AnonymizedContext'
import { AnonymizedProvider } from './anonymized/AnonymizedProvider'
Expand Down Expand Up @@ -57,11 +58,18 @@ function DatasetWithSearchParams() {
const created = state?.created ?? false
const publishInProgress = state?.publishInProgress ?? false
const metadataUpdated = state?.metadataUpdated ?? false
const datasetContext = useContext(DatasetContext)

useEffect(() => {
if (privateUrlToken) setAnonymizedView(true)
}, [privateUrlToken, setAnonymizedView])

useEffect(() => {
if (datasetContext?.refreshDataset) {
datasetContext.refreshDataset()
}
}, [version, datasetContext])

if (privateUrlToken) {
return (
<DatasetProvider
Expand Down
16 changes: 12 additions & 4 deletions src/sections/dataset/DatasetProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PropsWithChildren, useEffect, useState } from 'react'
import { PropsWithChildren, useEffect, useState, useCallback } from 'react'
import { useDeepCompareCallback } from 'use-deep-compare'
import { DatasetContext } from './DatasetContext'
import { DatasetRepository } from '../../dataset/domain/repositories/DatasetRepository'
Expand All @@ -15,6 +15,7 @@ interface DatasetProviderProps {
}
isPublishing?: boolean
}

export function DatasetProvider({
repository,
searchParams,
Expand All @@ -34,7 +35,8 @@ export function DatasetProvider({
return Promise.resolve(undefined)
}, [repository, searchParams])

useEffect(() => {
// Fetch dataset on mount or when dependencies change
const fetchDataset = useCallback(() => {
if (isPublishing) return
setIsLoading(true)

Expand All @@ -47,9 +49,15 @@ export function DatasetProvider({
console.error('There was an error getting the dataset', error)
setIsLoading(false)
})
}, [repository, getDataset, isPublishing])
}, [getDataset, isPublishing])

useEffect(() => {
fetchDataset()
}, [fetchDataset])

return (
<DatasetContext.Provider value={{ dataset, isLoading }}>{children}</DatasetContext.Provider>
<DatasetContext.Provider value={{ dataset, isLoading, refreshDataset: fetchDataset }}>
{children}
</DatasetContext.Provider>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { toast } from 'react-toastify'
import { useContext } from 'react'
import { DatasetContext } from '@/sections/dataset/DatasetContext'
import { Dataset } from '../../../../dataset/domain/models/Dataset'
import { DropdownButtonItem, DropdownSeparator } from '@iqss/dataverse-design-system'
import { useTranslation } from 'react-i18next'
Expand All @@ -22,6 +24,7 @@ export function DeaccessionDatasetButton({
}: DeaccessionDatasetButtonProps) {
const { t } = useTranslation('dataset')
const navigate = useNavigate()

Check warning on line 26 in src/sections/dataset/dataset-action-buttons/edit-dataset-menu/DeaccessionDatasetButton.tsx

View workflow job for this annotation

GitHub Actions / lint

'navigate' is assigned a value but never used. Allowed unused vars must match /^_/u
const datasetContext = useContext(DatasetContext)
const [showDeaccessionModal, setShowDeaccessionModal] = useState(false)
const [showConfirmationModal, setShowConfirmationModal] = useState(false)
const { submissionStatus, submitDeaccession, deaccessionError } = useDeaccessionDataset(
Expand All @@ -36,7 +39,7 @@ export function DeaccessionDatasetButton({
const defaultVersions = publishedVersions.length === 1 ? [publishedVersions[0].versionNumber] : []
function onDeaccessionSucceed() {
setShowConfirmationModal(false)
navigate(0)
datasetContext?.refreshDataset()
toast.success('Dataset deaccessioned successfully')
}
const {
Expand Down

0 comments on commit f908181

Please sign in to comment.