Skip to content

Commit

Permalink
chore: replace hardcoded root words for constant
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Aug 16, 2024
1 parent 815e70a commit 71ac0f3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { DatasetDTO } from '../../domain/useCases/DTOs/DatasetDTO'
import { DatasetDTOMapper } from '../mappers/DatasetDTOMapper'
import { DatasetsWithCount } from '../../domain/models/DatasetsWithCount'
import { VersionUpdateType } from '../../domain/models/VersionUpdateType'
const defaultCollectionId = 'root'
import { ROOT_COLLECTION_ALIAS } from '../../../collection/domain/models/Collection'

const includeDeaccessioned = true
type DatasetDetails = [JSDataset, string[], string, JSDatasetPermissions, JSDatasetLock[]]

Expand Down Expand Up @@ -195,7 +196,7 @@ export class DatasetJSDataverseRepository implements DatasetRepository {

create(
dataset: DatasetDTO,
collectionId = defaultCollectionId
collectionId = ROOT_COLLECTION_ALIAS
): Promise<{ persistentId: string }> {
return createDataset
.execute(DatasetDTOMapper.toJSDatasetDTO(dataset), collectionId)
Expand Down
4 changes: 3 additions & 1 deletion src/sections/Route.enum.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ROOT_COLLECTION_ALIAS } from '../collection/domain/models/Collection'

export enum Route {
HOME = '/',
SIGN_UP = '/dataverseuser.xhtml?editMode=CREATE&redirectPage=%2Fdataverse.xhtml',
Expand All @@ -14,5 +16,5 @@ export enum Route {

export const RouteWithParams = {
CREATE_COLLECTION: (ownerCollectionId?: string) =>
`/collections/${ownerCollectionId ?? 'root'}/create`
`/collections/${ownerCollectionId ?? ROOT_COLLECTION_ALIAS}/create`
}
3 changes: 2 additions & 1 deletion src/sections/collection/CollectionFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repos
import { useLocation, useSearchParams } from 'react-router-dom'
import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository'
import { INFINITE_SCROLL_ENABLED } from './config'
import { ROOT_COLLECTION_ALIAS } from '../../collection/domain/models/Collection'

const datasetRepository = new DatasetJSDataverseRepository()
const repository = new CollectionJSDataverseRepository()
Expand All @@ -17,7 +18,7 @@ function CollectionWithSearchParams() {
const [searchParams] = useSearchParams()
const location = useLocation()
const page = searchParams.get('page') ? parseInt(searchParams.get('page') as string) : undefined
const id = searchParams.get('id') ? (searchParams.get('id') as string) : 'root'
const id = searchParams.get('id') ? (searchParams.get('id') as string) : ROOT_COLLECTION_ALIAS
const state = location.state as { created: boolean } | undefined
const created = state?.created ?? false

Expand Down
5 changes: 2 additions & 3 deletions src/sections/create-collection/CreateCollectionFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactElement } from 'react'
import { useParams } from 'react-router-dom'
import { CollectionJSDataverseRepository } from '../../collection/infrastructure/repositories/CollectionJSDataverseRepository'
import { CreateCollection } from './CreateCollection'
import { ROOT_COLLECTION_ALIAS } from '../../collection/domain/models/Collection'

const collectionRepository = new CollectionJSDataverseRepository()

Expand All @@ -12,9 +13,7 @@ export class CreateCollectionFactory {
}

function CreateCollectionWithParams() {
const { ownerCollectionId = 'root' } = useParams<{ ownerCollectionId: string }>()

// TODO:ME What roles can create a collection, what checks to do?
const { ownerCollectionId = ROOT_COLLECTION_ALIAS } = useParams<{ ownerCollectionId: string }>()

return (
<CreateCollection
Expand Down
3 changes: 2 additions & 1 deletion src/sections/create-dataset/CreateDataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DatasetMetadataForm } from '../shared/form/DatasetMetadataForm'
import { useGetCollectionUserPermissions } from '../../shared/hooks/useGetCollectionUserPermissions'
import { CollectionRepository } from '../../collection/domain/repositories/CollectionRepository'
import { useLoading } from '../loading/LoadingContext'
import { ROOT_COLLECTION_ALIAS } from '../../collection/domain/models/Collection'

interface CreateDatasetProps {
datasetRepository: DatasetRepository
Expand All @@ -23,7 +24,7 @@ export function CreateDataset({
datasetRepository,
metadataBlockInfoRepository,
collectionRepository,
collectionId = 'root'
collectionId = ROOT_COLLECTION_ALIAS
}: CreateDatasetProps) {
const { t } = useTranslation('createDataset')
const { isModalOpen, hideModal } = useNotImplementedModal()
Expand Down
3 changes: 2 additions & 1 deletion src/sections/layout/header/LoggedInHeaderActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSession } from '../../session/SessionContext'
import { Route, RouteWithParams } from '../../Route.enum'
import { User } from '../../../users/domain/models/User'
import { CollectionRepository } from '../../../collection/domain/repositories/CollectionRepository'
import { ROOT_COLLECTION_ALIAS } from '../../../collection/domain/models/Collection'

const currentPage = 0

Expand All @@ -23,7 +24,7 @@ export const LoggedInHeaderActions = ({
const navigate = useNavigate()

const { collectionUserPermissions } = useGetCollectionUserPermissions({
collectionIdOrAlias: 'root',
collectionIdOrAlias: ROOT_COLLECTION_ALIAS,
collectionRepository: collectionRepository
})

Expand Down
19 changes: 13 additions & 6 deletions tests/e2e-integration/shared/datasets/DatasetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DataverseApiHelper } from '../DataverseApiHelper'
import { FileData } from '../files/FileHelper'
import { DatasetLockReason } from '../../../../src/dataset/domain/models/Dataset'
import { TestsUtils } from '../TestsUtils'
import { ROOT_COLLECTION_ALIAS } from '../../../../src/collection/domain/models/Collection'

export interface DatasetResponse {
persistentId: string
Expand All @@ -16,7 +17,7 @@ export interface DatasetFileResponse {
}

export class DatasetHelper extends DataverseApiHelper {
static async create(collectionId = 'root'): Promise<DatasetResponse> {
static async create(collectionId = ROOT_COLLECTION_ALIAS): Promise<DatasetResponse> {
return this.request<DatasetResponse>(
`/dataverses/${collectionId}/datasets`,
'POST',
Expand All @@ -43,14 +44,17 @@ export class DatasetHelper extends DataverseApiHelper {
throw error
}
}
static async createAndPublish(collectionId = 'root'): Promise<DatasetResponse> {
static async createAndPublish(collectionId = ROOT_COLLECTION_ALIAS): Promise<DatasetResponse> {
const datasetResponse = await DatasetHelper.create(collectionId)
await DatasetHelper.publish(datasetResponse.persistentId)
await TestsUtils.waitForNoLocks(datasetResponse.persistentId)
return datasetResponse
}

static async createMany(amount: number, collectionId = 'root'): Promise<DatasetResponse[]> {
static async createMany(
amount: number,
collectionId = ROOT_COLLECTION_ALIAS
): Promise<DatasetResponse[]> {
const datasets = []
for (let i = 0; i < amount; i++) {
const datasetResponse = await this.create(collectionId)
Expand Down Expand Up @@ -136,22 +140,25 @@ export class DatasetHelper extends DataverseApiHelper {

static async createWithFiles(
filesData: FileData[],
collectionId = 'root'
collectionId = ROOT_COLLECTION_ALIAS
): Promise<DatasetResponse> {
const datasetResponse = await this.create(collectionId)
const files = await this.uploadFiles(datasetResponse.persistentId, filesData)
return { ...datasetResponse, files: files }
}

static async createWithFile(fileData: FileData, collectionId = 'root'): Promise<DatasetResponse> {
static async createWithFile(
fileData: FileData,
collectionId = ROOT_COLLECTION_ALIAS
): Promise<DatasetResponse> {
const datasetResponse = await this.create(collectionId)
const file = await this.uploadFile(datasetResponse.persistentId, fileData)
return { ...datasetResponse, file: file }
}

static async createWithFileAndPublish(
fileData: FileData,
collectionId = 'root'
collectionId = ROOT_COLLECTION_ALIAS
): Promise<DatasetResponse> {
const datasetResponse = await DatasetHelper.createWithFile(fileData, collectionId)
await DatasetHelper.publish(datasetResponse.persistentId)
Expand Down

0 comments on commit 71ac0f3

Please sign in to comment.