Skip to content

Commit

Permalink
chore: file alocations tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Dec 12, 2024
1 parent a13a2c9 commit e029c43
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 71 deletions.
7 changes: 7 additions & 0 deletions src/collection/domain/models/CollectionItemsQueryParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum CollectionItemsQueryParams {
SORT = 'sort',
ORDER = 'order',
START = 'start',
TYPES = 'types',
FILTER_QUERIES = 'fqs'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { type CollectionItemType } from './CollectionItemType'
import { FilterQuery, OrderType, SortType } from './GetCollectionItemsQueryParams'

export enum SortType {
NAME = 'name',
DATE = 'date'
}

export enum OrderType {
ASC = 'asc',
DESC = 'desc'
}

export type FilterQuery = `${string}:${string}`

export class CollectionSearchCriteria {
constructor(
Expand Down
19 changes: 0 additions & 19 deletions src/collection/domain/models/GetCollectionItemsQueryParams.ts

This file was deleted.

18 changes: 9 additions & 9 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { AppLoader } from './sections/shared/layout/app-loader/AppLoader'

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
root.render(
// <React.StrictMode>
<React.Suspense fallback={<AppLoader fullViewport />}>
<LoadingProvider>
<ThemeProvider>
<App />
</ThemeProvider>
</LoadingProvider>
</React.Suspense>
// </React.StrictMode>
<React.StrictMode>
<React.Suspense fallback={<AppLoader fullViewport />}>
<LoadingProvider>
<ThemeProvider>
<App />
</ThemeProvider>
</LoadingProvider>
</React.Suspense>
</React.StrictMode>
)
12 changes: 5 additions & 7 deletions src/sections/collection/CollectionHelper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
FilterQuery,
GetCollectionItemsQueryParams
} from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { CollectionItemType } from '../../collection/domain/models/CollectionItemType'
import { CollectionItemsQueryParams } from '@/collection/domain/models/CollectionItemsQueryParams'
import { FilterQuery } from '@/collection/domain/models/CollectionSearchCriteria'
import { CollectionItemType } from '@/collection/domain/models/CollectionItemType'
import { QueryParamKey } from '../Route.enum'

export class CollectionHelper {
Expand All @@ -15,7 +13,7 @@ export class CollectionHelper {
? decodeURIComponent(searchParams.get(QueryParamKey.QUERY) as string)
: undefined

const typesParam = searchParams.get(GetCollectionItemsQueryParams.TYPES) ?? undefined
const typesParam = searchParams.get(CollectionItemsQueryParams.TYPES) ?? undefined

const typesQuery = typesParam
?.split(',')
Expand All @@ -24,7 +22,7 @@ export class CollectionHelper {
Object.values(CollectionItemType).includes(type as CollectionItemType)
) as CollectionItemType[]

const filtersParam = searchParams.get(GetCollectionItemsQueryParams.FILTER_QUERIES) ?? undefined
const filtersParam = searchParams.get(CollectionItemsQueryParams.FILTER_QUERIES) ?? undefined

const filtersQuery: FilterQuery[] | undefined = filtersParam
? (filtersParam
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useSearchParams } from 'react-router-dom'
import { Stack } from '@iqss/dataverse-design-system'
import { CollectionRepository } from '@/collection/domain/repositories/CollectionRepository'
import { CollectionItemsPaginationInfo } from '@/collection/domain/models/CollectionItemsPaginationInfo'
import { CollectionSearchCriteria } from '@/collection/domain/models/CollectionSearchCriteria'
import { CollectionItemType } from '@/collection/domain/models/CollectionItemType'
import {
FilterQuery,
GetCollectionItemsQueryParams
} from '@/collection/domain/models/GetCollectionItemsQueryParams'
CollectionSearchCriteria,
FilterQuery
} from '@/collection/domain/models/CollectionSearchCriteria'
import { CollectionItemType } from '@/collection/domain/models/CollectionItemType'
import { CollectionItemsQueryParams } from '@/collection/domain/models/CollectionItemsQueryParams'
import { useGetAccumulatedItems } from './useGetAccumulatedItems'
import { UseCollectionQueryParamsReturnType } from '../useGetCollectionQueryParams'
import { useLoadMoreOnPopStateEvent } from './useLoadMoreOnPopStateEvent'
Expand Down Expand Up @@ -45,8 +45,6 @@ interface CollectionItemsPanelProps {
* Every time a load of items is triggered, the pagination info is updated and the URL is updated with the new query params so it can be shared and the user can navigate back and forward in the browser.
*/

// TODO:ME - Fix Tests

export const CollectionItemsPanel = ({
collectionId,
collectionRepository,
Expand Down Expand Up @@ -118,7 +116,7 @@ export const CollectionItemsPanel = ({
// Update the URL with the search value ,keep other querys and include all item types always
setSearchParams((currentSearchParams) => {
currentSearchParams.set(
GetCollectionItemsQueryParams.TYPES,
CollectionItemsQueryParams.TYPES,
[CollectionItemType.COLLECTION, CollectionItemType.DATASET, CollectionItemType.FILE].join(
','
)
Expand Down Expand Up @@ -159,9 +157,9 @@ export const CollectionItemsPanel = ({
const resetPaginationInfo = new CollectionItemsPaginationInfo()
setPaginationInfo(resetPaginationInfo)

// Update the URL with the new item types, keep other querys and include the search value if exists
// Update the URL with the new item types, keep other querys
setSearchParams((currentSearchParams) => {
currentSearchParams.set(GetCollectionItemsQueryParams.TYPES, newItemsTypes.join(','))
currentSearchParams.set(CollectionItemsQueryParams.TYPES, newItemsTypes.join(','))

return currentSearchParams
})
Expand Down Expand Up @@ -205,7 +203,7 @@ export const CollectionItemsPanel = ({
// Update the URL with the new facets, keep other querys and include the search value if exists
setSearchParams((currentSearchParams) => {
currentSearchParams.set(
GetCollectionItemsQueryParams.FILTER_QUERIES,
CollectionItemsQueryParams.FILTER_QUERIES,
newFilterQueriesWithFacetValueEncoded.join(',')
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FunnelFill } from 'react-bootstrap-icons'
import { CollectionItemType } from '@/collection/domain/models/CollectionItemType'
import { ItemTypeChange, TypeFilters } from './type-filters/TypeFilters'
import { CollectionItemsFacet } from '@/collection/domain/models/CollectionItemSubset'
import { FilterQuery } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { FilterQuery } from '@/collection/domain/models/CollectionSearchCriteria'
import { FacetsFilters } from './facets-filters/FacetsFilters'
import { RemoveAddFacetFilter } from './facets-filters/FacetFilterGroup'
import styles from './FilterPanel.module.scss'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cn from 'classnames'
import { Button, Col, Row } from '@iqss/dataverse-design-system'
import { X as CloseIcon } from 'react-bootstrap-icons'
import { CollectionItemsFacet } from '@/collection/domain/models/CollectionItemSubset'
import { FilterQuery } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { FilterQuery } from '@/collection/domain/models/CollectionSearchCriteria'
import styles from './FacetsFilters.module.scss'

const FACETS_PER_VIEW = 5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'
import { Stack } from '@iqss/dataverse-design-system'
import { CollectionItemsFacet } from '@/collection/domain/models/CollectionItemSubset'
import { FilterQuery } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { FilterQuery } from '@/collection/domain/models/CollectionSearchCriteria'
import { FacetFilterGroup, RemoveAddFacetFilter } from './FacetFilterGroup'
import styles from './FacetsFilters.module.scss'
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton'

interface FacetsFiltersProps {
facets: CollectionItemsFacet[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cn from 'classnames'
import { type CollectionItem } from '@/collection/domain/models/CollectionItemSubset'
import { CollectionItemsPaginationInfo } from '@/collection/domain/models/CollectionItemsPaginationInfo'
import { CollectionItemType } from '@/collection/domain/models/CollectionItemType'
import { FilterQuery } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { FilterQuery } from '@/collection/domain/models/CollectionSearchCriteria'
import { PaginationResultsInfo } from '@/sections/shared/pagination/PaginationResultsInfo'
import { NO_COLLECTION_ITEMS } from '../useGetAccumulatedItems'
import { ErrorItemsMessage } from './ErrorItemsMessage'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
max-width: 64px;
height: 48px;
max-height: 48px;
object-fit: contain;
vertical-align: top;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslation } from 'react-i18next'
import { Button } from '@iqss/dataverse-design-system'
import { X as CloseIcon } from 'react-bootstrap-icons'
import { FilterQuery } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { FilterQuery } from '@/collection/domain/models/CollectionSearchCriteria'
import styles from './SelectedFacets.module.scss'

interface SelectedFacetsProps {
Expand Down
2 changes: 1 addition & 1 deletion src/sections/collection/useGetCollectionQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSearchParams } from 'react-router-dom'
import { CollectionItemType } from '@/collection/domain/models/CollectionItemType'
import { FilterQuery } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { FilterQuery } from '@/collection/domain/models/CollectionSearchCriteria'
import { CollectionHelper } from './CollectionHelper'

export interface UseCollectionQueryParamsReturnType {
Expand Down
4 changes: 2 additions & 2 deletions src/sections/homepage/search-input/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Form, CloseButton } from '@iqss/dataverse-design-system'
import { Search as SearchIcon } from 'react-bootstrap-icons'
import { QueryParamKey, Route } from '../../Route.enum'
import { CollectionItemType } from '../../../collection/domain/models/CollectionItemType'
import { GetCollectionItemsQueryParams } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { CollectionItemsQueryParams } from '@/collection/domain/models/CollectionItemsQueryParams'
import styles from './SearchInput.module.scss'

export const SearchInput = () => {
Expand All @@ -28,7 +28,7 @@ export const SearchInput = () => {
const searchParams = new URLSearchParams()
searchParams.set(QueryParamKey.QUERY, encodedSearchValue)
searchParams.set(
GetCollectionItemsQueryParams.TYPES,
CollectionItemsQueryParams.TYPES,
[CollectionItemType.COLLECTION, CollectionItemType.DATASET, CollectionItemType.FILE].join(',')
)

Expand Down
8 changes: 4 additions & 4 deletions tests/component/sections/collection/CollectionHelper.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetCollectionItemsQueryParams } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { CollectionItemsQueryParams } from '@/collection/domain/models/CollectionItemsQueryParams'
import { CollectionHelper } from '@/sections/collection/CollectionHelper'
import { QueryParamKey } from '@/sections/Route.enum'
import { CollectionItemType } from '@iqss/dataverse-client-javascript'
Expand All @@ -11,12 +11,12 @@ describe('CollectionHelper', () => {
it('define collection query params correctly when all query params are in the url', () => {
const searchParams = new URLSearchParams({
[QueryParamKey.QUERY]: QUERY_VALUE,
[GetCollectionItemsQueryParams.TYPES]: [
[CollectionItemsQueryParams.TYPES]: [
CollectionItemType.COLLECTION,
CollectionItemType.DATASET
].join(','),
[QueryParamKey.PAGE]: PAGE_NUMBER.toString(),
[GetCollectionItemsQueryParams.FILTER_QUERIES]: [
[CollectionItemsQueryParams.FILTER_QUERIES]: [
'someFilter:someValue',
'otherFilter:otherValue'
].join(',')
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('CollectionHelper', () => {

it('define collection query params correctly when only types query param is in the url', () => {
const searchParams = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [
[CollectionItemsQueryParams.TYPES]: [
CollectionItemType.COLLECTION,
CollectionItemType.DATASET
].join(',')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CollectionItem } from '@/collection/domain/models/CollectionItemSubset'
import { CollectionItemType } from '@/collection/domain/models/CollectionItemType'
import { GetCollectionItemsQueryParams } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { CollectionItemsQueryParams } from '@/collection/domain/models/CollectionItemsQueryParams'
import { QueryParamKey } from '@/sections/Route.enum'
import { DatasetHelper } from '@tests/e2e-integration/shared/datasets/DatasetHelper'
import { FileHelper } from '@tests/e2e-integration/shared/files/FileHelper'
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('Collection Items Panel', () => {
cy.findAllByTestId('file-card').should('have.length', filesInResponse.length)

const firstExpectedURL = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [
[CollectionItemsQueryParams.TYPES]: [
CollectionItemType.COLLECTION,
CollectionItemType.DATASET,
CollectionItemType.FILE
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Collection Items Panel', () => {
cy.findAllByTestId('file-card').should('have.length', filesInResponse.length)

const secondExpectedURL = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [
[CollectionItemsQueryParams.TYPES]: [
CollectionItemType.COLLECTION,
CollectionItemType.DATASET,
CollectionItemType.FILE
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('Collection Items Panel', () => {
cy.findAllByTestId('file-card').should('have.length', filesInResponse.length)

const thirdExpectedURL = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [
[CollectionItemsQueryParams.TYPES]: [
CollectionItemType.COLLECTION,
CollectionItemType.DATASET,
CollectionItemType.FILE
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('Collection Items Panel', () => {
cy.findAllByTestId('file-card').should('have.length', filesInResponse.length)

const fourthExpectedURL = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [
[CollectionItemsQueryParams.TYPES]: [
CollectionItemType.DATASET,
CollectionItemType.FILE
].join(',')
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('Collection Items Panel', () => {
cy.findAllByTestId('file-card').should('have.length', filesInResponse.length)

const fifthExpectedURL = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [CollectionItemType.FILE].join(',')
[CollectionItemsQueryParams.TYPES]: [CollectionItemType.FILE].join(',')
}).toString()

cy.url().should('include', `/collections?${fifthExpectedURL}`)
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('Collection Items Panel', () => {
cy.findAllByTestId('file-card').should('have.length', filesInResponse.length)

const fourthExpectedURL = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [
[CollectionItemsQueryParams.TYPES]: [
CollectionItemType.DATASET,
CollectionItemType.FILE
].join(',')
Expand Down Expand Up @@ -289,11 +289,11 @@ describe('Collection Items Panel', () => {
cy.findAllByTestId('file-card').should('have.length', filesInResponse.length)

const expectedURL = new URLSearchParams({
[GetCollectionItemsQueryParams.TYPES]: [
[CollectionItemsQueryParams.TYPES]: [
CollectionItemType.DATASET,
CollectionItemType.FILE
].join(','),
[GetCollectionItemsQueryParams.FILTER_QUERIES]: [
[CollectionItemsQueryParams.FILTER_QUERIES]: [
`authorName_ss:${encodeURIComponent('Finch, Fiona')}`
].join(',')
}).toString()
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e-integration/e2e/sections/homepage/Homepage.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetCollectionItemsQueryParams } from '@/collection/domain/models/GetCollectionItemsQueryParams'
import { CollectionItemsQueryParams } from '@/collection/domain/models/CollectionItemsQueryParams'
import { CollectionItemType } from '../../../../../src/collection/domain/models/CollectionItemType'
import { QueryParamKey } from '../../../../../src/sections/Route.enum'

Expand All @@ -14,7 +14,7 @@ describe('Homepage', () => {
const searchParams = new URLSearchParams()
searchParams.set(QueryParamKey.QUERY, encodedSearchValue)
searchParams.set(
GetCollectionItemsQueryParams.TYPES,
CollectionItemsQueryParams.TYPES,
[CollectionItemType.COLLECTION, CollectionItemType.DATASET, CollectionItemType.FILE].join(',')
)

Expand Down

0 comments on commit e029c43

Please sign in to comment.