-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DatasetsList): add no datasets message
- Loading branch information
Showing
11 changed files
with
153 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
{ | ||
"title": "Root" | ||
"title": "Root", | ||
"noDatasetsMessage": { | ||
"authenticated": "This dataverse currently has no datasets. You can add to it by using the Add Data button on this page.", | ||
"anonymous": "This dataverse currently has no datasets. Please <1>log in</1> to see if you are able to add to it." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
@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/typography.module"; | ||
@import "src/sections/assets/variables"; | ||
|
||
.container { | ||
padding:15px; | ||
border: 1px solid #ddd; | ||
border-radius: 4px; | ||
} | ||
|
||
.empty-message-container { | ||
padding: .5em 1em; | ||
background: $dv-warning-box-color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import styles from './DatasetsList.module.scss' | ||
import { Trans, useTranslation } from 'react-i18next' | ||
import { useSession } from '../../session/SessionContext' | ||
import { Route } from '../../Route.enum' | ||
|
||
export function NoDatasetsMessage() { | ||
const { t } = useTranslation('home') | ||
const { user } = useSession() | ||
|
||
return ( | ||
<div className={styles['empty-message-container']}> | ||
{user ? ( | ||
<p>{t('noDatasetsMessage.authenticated')}</p> | ||
) : ( | ||
<Trans i18nKey="noDatasetsMessage.anonymous"> | ||
<p> | ||
This dataverse currently has no datasets. Please <a href={Route.LOG_IN}>log in</a> to | ||
see if you are able to add to it. | ||
</p> | ||
</Trans> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DatasetMockRepository } from './DatasetMockRepository' | ||
import { DatasetPaginationInfo } from '../../dataset/domain/models/DatasetPaginationInfo' | ||
import { DatasetPreview } from '../../dataset/domain/models/DatasetPreview' | ||
import { TotalDatasetsCount } from '../../dataset/domain/models/TotalDatasetsCount' | ||
export class NoDatasetsMockRepository extends DatasetMockRepository { | ||
// eslint-disable-next-line unused-imports/no-unused-vars | ||
getAll(paginationInfo: DatasetPaginationInfo): Promise<DatasetPreview[]> { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve([]) | ||
}, 1000) | ||
}) | ||
} | ||
|
||
getTotalDatasetsCount(): Promise<TotalDatasetsCount> { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(0) | ||
}, 1000) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/stories/home/datasets-list/NoDatasetsMessage.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import { Home } from '../../../sections/home/Home' | ||
import { WithI18next } from '../../WithI18next' | ||
import { NoDatasetsMessage } from '../../../sections/home/datasets-list/NoDatasetsMessage' | ||
import { WithLoggedInUser } from '../../WithLoggedInUser' | ||
|
||
const meta: Meta<typeof Home> = { | ||
title: 'Sections/Home/NoDatasetsMessage', | ||
component: Home, | ||
decorators: [WithI18next] | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof Home> | ||
|
||
export const AnonymousUser: Story = { | ||
render: () => <NoDatasetsMessage /> | ||
} | ||
|
||
export const AuthenticatedUser: Story = { | ||
decorators: [WithLoggedInUser], | ||
render: () => <NoDatasetsMessage /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tests/component/sections/home/datasets-list/NoDatasetsMessage.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { NoDatasetsMessage } from '../../../../../src/sections/home/datasets-list/NoDatasetsMessage' | ||
|
||
describe('No Datasets Message', () => { | ||
it('renders the message for anonymous user', () => { | ||
cy.customMount(<NoDatasetsMessage />) | ||
cy.findByText(/This dataverse currently has no datasets. Please /).should('exist') | ||
cy.findByRole('link', { name: 'log in' }).should( | ||
'have.attr', | ||
'href', | ||
'/loginpage.xhtml?redirectPage=%2Fdataverse.xhtml' | ||
) | ||
}) | ||
|
||
it('renders the message for authenticated user', () => { | ||
cy.mountAuthenticated(<NoDatasetsMessage />) | ||
cy.findByText( | ||
'This dataverse currently has no datasets. You can add to it by using the Add Data button on this page.' | ||
).should('exist') | ||
}) | ||
}) |