Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/322 support infinite scrolling #342

Merged
merged 35 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c8d7024
feat(Infinite Scrolling): Install classnames library for conditional …
g-saracca Mar 5, 2024
73d62b8
feat(Infinite Scrolling): Accumulate datasets
g-saracca Mar 5, 2024
b6f9a07
feat(Infinite Scrolling): Pagination results formated different when …
g-saracca Mar 5, 2024
31c1b19
feat(Infinite Scrolling): Initial basic flag for future configuration
g-saracca Mar 5, 2024
38d5621
feat(Infinite Scrolling): Install react-infinite-scroll-hook library
g-saracca Mar 6, 2024
21b0ad5
feat(Infinite Scrolling): Boolean indicator of infinite scrolling ena…
g-saracca Mar 6, 2024
64e75c5
feat(Infinite Scrolling): Infinite scrolling implementation in progress
g-saracca Mar 6, 2024
7cd93a1
feat(Infinite Scrolling): Command for story book script on windows
g-saracca Mar 7, 2024
8e9a4f8
feat(Infinite Scrolling): Remove unnecesary inital page for infinite …
g-saracca Mar 7, 2024
5e3cb4b
feat(Infinite Scrolling): Error catch and shown to user
g-saracca Mar 7, 2024
e9c47c6
feat(Infinite Scrolling): change locale and make tests to pagination
g-saracca Mar 7, 2024
cbb56d3
feat(Infinite Scrolling): remove eslint disable for underscore
g-saracca Mar 7, 2024
74127f6
feat(Infinite Scrolling): component testings done
g-saracca Mar 8, 2024
e9b41f3
feat(Infinite Scrolling): Responsive
g-saracca Mar 8, 2024
0abe663
feat(Infinite Scrolling): new hook specific for infinite scrolling an…
g-saracca Mar 11, 2024
5f785af
feat(Infinite Scrolling): mocks and testing
g-saracca Mar 11, 2024
6cdca54
feat(Infinite Scrolling): fix prettier end line
g-saracca Mar 11, 2024
c7f97e5
feat(Infinite Scrolling): fix collection infinite scrolling enabled test
g-saracca Mar 11, 2024
dd26047
Merge branch 'develop' into feature/322-support-infinite-scrolling
g-saracca Mar 11, 2024
a4a0ef0
feat(Infinite Scrolling): match env example port with docker exposed …
g-saracca Mar 12, 2024
744871b
feat(Infinite Scrolling): Add spec for error & improve accesibility
g-saracca Mar 12, 2024
bc73fde
feat(Infinite Scrolling): Add E2E tests
g-saracca Mar 12, 2024
0903abb
Merge branch 'develop' into feature/322-support-infinite-scrolling
g-saracca Mar 13, 2024
6c830d7
feat(Infinite Scrolling): back to interface
g-saracca Mar 13, 2024
a33fa11
feat(Infinite Scrolling): move constants to config file
g-saracca Mar 14, 2024
037802f
feat(Infinite Scrolling): refactor component and custom hook for simp…
g-saracca Mar 14, 2024
54a5f28
feat(Infinite Scrolling): change method naming as it is redundant add…
g-saracca Mar 14, 2024
1de9ecf
feat(Infinite Scrolling): remove eslint ignore for underscore on unus…
g-saracca Mar 14, 2024
263df5b
feat(Infinite Scrolling): refactor tests
g-saracca Mar 14, 2024
9786342
feat(Infinite Scrolling): remove carets
g-saracca Mar 14, 2024
aba2bc3
feat(Infinite Scrolling): make scrollable container stay in screen wi…
g-saracca Mar 14, 2024
ab8a7de
feat(Infinite Scrolling): Refactor function name
g-saracca Mar 14, 2024
c58cb1e
docs(Infinite Scrolling): add functionality behaviour change
g-saracca Mar 22, 2024
544f586
Merge branch 'develop' into feature/322-support-infinite-scrolling
g-saracca Mar 24, 2024
8cb9d10
feat(Infinite Scrolling) Remove carets
g-saracca Mar 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_DATAVERSE_BACKEND_URL=http://localhost:8080
VITE_DATAVERSE_BACKEND_URL=http://localhost:8000
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ The new SPA does not use Solr as the API endpoint it uses performs all queries o

The decision of this change is made on the assumption that Solr may not be required in the context of files tab search, whose search facets are reduced compared to other in-application searches. Therefore, if we find evidence that the assumption is incorrect, we will work on extending the search capabilities to support Solr.

#### Dataverses/Datasets list

The original JSF Dataverses/Datasets list on the home page uses normal paging buttons at the bottom of the list.
We have implemented infinite scrolling in this list, replacing the normal paging buttons, but the goal would be to be able to toggle between normal paging and infinite scrolling via a toggle setting or button.

## Publishing the Design System

The Design System is published to the npm Package Registry. To publish a new version, follow these steps:
Expand Down
30 changes: 27 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@types/react": "18.0.27",
"@types/react-dom": "18.0.10",
"bootstrap": "5.2.3",
"classnames": "2.5.1",
"html-react-parser": "3.0.16",
"i18next": "22.4.9",
"i18next-browser-languagedetector": "7.0.1",
Expand All @@ -32,6 +33,7 @@
"react-bootstrap": "2.7.2",
"react-bootstrap-icons": "1.10.3",
"react-i18next": "12.1.5",
"react-infinite-scroll-hook": "4.1.1",
"react-loader-spinner": "5.3.4",
"react-markdown": "8.0.7",
"react-router-dom": "6.8.1",
Expand Down Expand Up @@ -61,6 +63,7 @@
"test:coverage-merge": "lcov-result-merger '**/*/lcov.info' 'merged-coverage/lcov.info' && perl -pi -e 's/src\\/lib/packages\\/design-system\\/src\\/lib/g' merged-coverage/lcov.info",
"git:add": "git add .",
"storybook": "concurrently 'storybook dev -p 6006 && open \"http://localhost:6006\"' 'cd packages/design-system && npm run storybook'",
"storybook:windows": "concurrently \"storybook dev -p 6006\" \"npm run storybook -w packages/design-system\"",
"build-storybook": "storybook build",
"test:storybook": "test-storybook",
"test:storybook-all": "concurrently 'test-storybook' 'cd packages/design-system && npm run test:storybook'",
Expand Down
5 changes: 5 additions & 0 deletions public/locales/en/pagination.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"results_one": "1 {{item}}",
"results_other": "{{start}} to {{end}} of {{count}} {{item}}s",
"accumulated": {
"one": "{{count}} {{item}}",
"lessThanPageSize": "{{count}} {{item}}s",
"moreThanPageSize": "{{accumulated}} of {{count}} {{item}}s seen"
},
"pageSize": "{{item}}s per page"
}
7 changes: 7 additions & 0 deletions src/dataset/domain/models/DatasetsWithCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DatasetPreview } from '../../domain/models/DatasetPreview'
import { TotalDatasetsCount } from './TotalDatasetsCount'

export interface DatasetsWithCount {
datasetPreviews: DatasetPreview[]
totalCount: TotalDatasetsCount
}
5 changes: 5 additions & 0 deletions src/dataset/domain/repositories/DatasetRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import { TotalDatasetsCount } from '../models/TotalDatasetsCount'
import { DatasetPaginationInfo } from '../models/DatasetPaginationInfo'
import { DatasetPreview } from '../models/DatasetPreview'
import { DatasetFormFields } from '../models/DatasetFormFields'
import { DatasetsWithCount } from '../models/DatasetsWithCount'

export interface DatasetRepository {
getByPersistentId: (persistentId: string, version?: string) => Promise<Dataset | undefined>
getByPrivateUrlToken: (privateUrlToken: string) => Promise<Dataset | undefined>
getAll: (collectionId: string, paginationInfo: DatasetPaginationInfo) => Promise<DatasetPreview[]>
getTotalDatasetsCount: (collectionId: string) => Promise<TotalDatasetsCount>
getAllWithCount: (
collectionId: string,
paginationInfo: DatasetPaginationInfo
) => Promise<DatasetsWithCount>
// Created as placeholder for https://github.com/IQSS/dataverse-frontend/pull/251
createDataset: (fields: DatasetFormFields) => Promise<string>
}
13 changes: 13 additions & 0 deletions src/dataset/domain/useCases/getDatasetsWithCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { DatasetRepository } from '../repositories/DatasetRepository'
import { DatasetPaginationInfo } from '../models/DatasetPaginationInfo'
import { DatasetsWithCount } from '../models/DatasetsWithCount'

export async function getDatasetsWithCount(
datasetRepository: DatasetRepository,
collectionId: string,
paginationInfo: DatasetPaginationInfo
): Promise<DatasetsWithCount> {
return datasetRepository.getAllWithCount(collectionId, paginationInfo).catch((error: Error) => {
throw new Error(error.message)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DatasetPaginationInfo } from '../../domain/models/DatasetPaginationInfo
import { DatasetPreview } from '../../domain/models/DatasetPreview'
import { JSDatasetPreviewMapper } from '../mappers/JSDatasetPreviewMapper'
import { DatasetFormFields } from '../../domain/models/DatasetFormFields'
import { DatasetsWithCount } from '../../domain/models/DatasetsWithCount'

const includeDeaccessioned = true

Expand All @@ -47,6 +48,24 @@ export class DatasetJSDataverseRepository implements DatasetRepository {
})
}

getAllWithCount(
collectionId: string,
paginationInfo: DatasetPaginationInfo
): Promise<DatasetsWithCount> {
return getAllDatasetPreviews
.execute(paginationInfo.pageSize, paginationInfo.offset, collectionId)
.then((subset: DatasetPreviewSubset) => {
const datasetPreviewsMapped = subset.datasetPreviews.map(
(datasetPreview: JSDatasetPreview) =>
JSDatasetPreviewMapper.toDatasetPreview(datasetPreview)
)
return {
datasetPreviews: datasetPreviewsMapped,
totalCount: subset.totalDatasetCount
}
})
}

getByPersistentId(
persistentId: string,
version?: string,
Expand Down
15 changes: 13 additions & 2 deletions src/sections/collection/Collection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Row } from '@iqss/dataverse-design-system'
import { DatasetRepository } from '../../dataset/domain/repositories/DatasetRepository'
import { DatasetsList } from './datasets-list/DatasetsList'
import { DatasetsListWithInfiniteScroll } from './datasets-list/DatasetsListWithInfiniteScroll'
import { BreadcrumbsGenerator } from '../shared/hierarchy/BreadcrumbsGenerator'
import {
DvObjectType,
Expand All @@ -14,6 +15,7 @@ interface CollectionProps {
datasetRepository: DatasetRepository
id: string
page?: number
infiniteScrollEnabled?: boolean
}
const rootNode = new UpwardHierarchyNode(
'Root',
Expand All @@ -24,7 +26,12 @@ const rootNode = new UpwardHierarchyNode(
undefined
)

export function Collection({ datasetRepository, id, page }: CollectionProps) {
export function Collection({
datasetRepository,
id,
page,
infiniteScrollEnabled = false
}: CollectionProps) {
const { user } = useSession()

return (
Expand All @@ -49,7 +56,11 @@ export function Collection({ datasetRepository, id, page }: CollectionProps) {
<AddDataActionsButton />
</div>
)}
<DatasetsList datasetRepository={datasetRepository} page={page} collectionId={id} />
{infiniteScrollEnabled ? (
<DatasetsListWithInfiniteScroll datasetRepository={datasetRepository} collectionId={id} />
) : (
<DatasetsList datasetRepository={datasetRepository} page={page} collectionId={id} />
)}
</Row>
)
}
Expand Down
10 changes: 9 additions & 1 deletion src/sections/collection/CollectionFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ReactElement } from 'react'
import { Collection } from './Collection'
import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository'
import { useSearchParams } from 'react-router-dom'
import { INFINITE_SCROLL_ENABLED } from './config'

const datasetRepository = new DatasetJSDataverseRepository()
export class CollectionFactory {
Expand All @@ -15,5 +16,12 @@ function CollectionWithSearchParams() {
const page = searchParams.get('page') ? parseInt(searchParams.get('page') as string) : undefined
const id = searchParams.get('id') ? (searchParams.get('id') as string) : 'root'

return <Collection datasetRepository={datasetRepository} page={page} id={id} />
return (
<Collection
datasetRepository={datasetRepository}
page={page}
id={id}
infiniteScrollEnabled={INFINITE_SCROLL_ENABLED}
/>
)
}
1 change: 1 addition & 0 deletions src/sections/collection/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const INFINITE_SCROLL_ENABLED = true
43 changes: 40 additions & 3 deletions src/sections/collection/datasets-list/DatasetsList.module.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,50 @@
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module";
@import 'node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module';

.container {
min-height: calc(100vh + 100px);
padding:15px;
padding: 15px;
border: 1px solid #ddd;
MellyGray marked this conversation as resolved.
Show resolved Hide resolved
border-radius: 4px;
}

.empty-message-container {
padding: .5em 1em;
padding: 0.5em 1em;
background: $dv-warning-box-color;
}

// Infinite scroll enabled
.scrollable-container {
--inline-padding: 1rem;

height: 650px;
max-height: 650px;
padding-inline: var(--inline-padding);
overflow-x: hidden;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;

@media screen and (max-width: 768px) {
--inline-padding: 8px;
}

@media screen and (min-width: 1280px) {
height: 60vh;
max-height: 60vh;
}

&--empty-or-error {
padding-block: 1rem;
}

.sticky-pagination-results {
position: sticky;
top: 0;
z-index: 10;
width: calc(100% + (var(--inline-padding) * 2));
padding: 1rem var(--inline-padding) 0.5rem;
background-color: var(--bs-white);
box-shadow: 0 0 10px 0 rgba(0 0 0 / 30%);
transform: translateX(calc(var(--inline-padding) * -1));
}
}
Loading
Loading