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

344 - Display real collection data in the Collection Page #352

Merged
merged 12 commits into from
Apr 12, 2024

Conversation

MellyGray
Copy link
Contributor

@MellyGray MellyGray commented Mar 22, 2024

What this PR does / why we need it:

This PR adds the integration with js-dataverse getCollection use case to display real collection data in the Collection Page.

Depends on:

Which issue(s) this PR closes:

Special notes for your reviewer:

e2e MetadataBlock test is failing because of some recent changes to the API. This is fixed in another PR:

The UI does not exactly match that of JSF, as best practices dictate that breadcrumbs should always be positioned at the top, before anything else

image

Suggestions on how to test this:

Step 1: Run the Development Environment

  1. Execute npm i.
  2. Navigate with cd packages/design-system && npm run build.
  3. Return with cd ../../.
  4. Ensure you have a .env file similar to .env.example, with the variable VITE_DATAVERSE_BACKEND_URL=http://localhost:8000.
  5. Navigate with cd dev-env.
  6. Start the environment using ./run-env.sh unstable.
  7. To verify the environment, visit http://localhost:8000 and check your local Dataverse installation.

Step 2: Test the Form

  1. Navigate to http://localhost:8000.
  2. Log in as an admin using the username: dataverseAdmin and password: admin1.
  3. Create a new Dataverse collection.
  4. Go to <http://localhost:8000/spa/collections?id=>
  5. Check that the collection data is correct and that the breadcrumbs are correct.

Does This PR Introduce a User Interface Change? If Mockups Are Available, Please Link/Include Them Here:

image

Is There a Release Notes Update Needed for This Change?:

Collection Page now displays real collection data

@MellyGray MellyGray marked this pull request as ready for review March 22, 2024 09:35
@MellyGray MellyGray added Size: 3 A percentage of a sprint. 2.1 hours. pm.GREI-d-2.7.1 NIH, yr2, aim7, task1: R&D UI modules for creating datasets and supporting publishing workflows pm.GREI-d-2.7.2 NIH, yr2, aim7, task2: Implement UI modules for creating datasets and publishing workflows integration Tasks involving the connection and interaction of UI features with the Dataverse API SPA: Collection Page labels Mar 22, 2024
@coveralls
Copy link

coveralls commented Mar 22, 2024

Coverage Status

coverage: 97.494% (+0.04%) from 97.459%
when pulling bd9ce3c on feature-344-display-real-collection-data
into c0f2d0b on develop.

@ekraffmiller ekraffmiller self-assigned this Mar 28, 2024
Copy link
Contributor

@ekraffmiller ekraffmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MellyGray it looks good, I just have a couple of comments, and also can you resolve the merge conflicts? thank you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the description, we need to support markup, like we do in the Metadata Fields, for example this is what the description looks like in JSF:
Screenshot 2024-03-28 at 4 32 38 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted! I've applied the changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It is handling the markdown now. I tried it again though, and the e2e test isn't working, I realized js-dataverse needs to be converting the html to markdown. I created an issue for that: IQSS/dataverse-client-javascript#140

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks!

import { Collection } from '../models/Collection'

export interface CollectionRepository {
getById: (id: string) => Promise<Collection | undefined>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does getById() need to return undefined as well as Collection? In the js-dataverse useCase, it returns only Collection

https://github.com/IQSS/dataverse-client-javascript/blob/e0438a257ec5a1aaf56300da73a1b68c79cd80d5/src/collections/infra/repositories/CollectionsRepository.ts#L9

Copy link
Contributor Author

@MellyGray MellyGray Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning Collection | undefined in TypeScript works like Java's Optional. It means the 'get' function could return a Collection if one is found, or undefined if not. This ensures type safety: just as you must unwrap an Optional in Java to access its value, in TypeScript, checking for undefined ensures you're aware when a value might not be present. If the Collection isn't found, we typically show a 'Page Not Found' message. For other errors, we throw an exception

Using this type definition, when we create a hook to get the collection, we acknowledge that the collection might not be found and could be undefined. Therefore, we need to handle the possibility of undefined when accessing the collection's properties, ensuring our code safely deals with the absence of a value.

It's a matter of design choice, but another approach could be to always return a Collection and throw an error for any scenario where this isn't possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see what you mean and how it compares to Java Optional, that makes sense. And in the hook useCollections.tsx it makes sense for collection to be type Collection | undefined . But the js-dataverse doesn't return undefined when the id is not found, it throws an error. So because the useCase doesn't handle the error from js-dataverse, it doesn't return undefined, but the error is caught in the hook. So that's why I was confused about Collection | undefined being declared in the useCase. It implies that the function handles the error if the collection ins't found.

Now that I look at the logic for getting Datasets, the same thing is happening - if a dataset isn't found, js-dataverse throws an error, and it isn't handled by the useCase, it's handled by the caller of the useCase. So I think the same question applies, should we be handling the error in the useCase, if it is declared to sometimes return undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think js-dataverse should return undefined if it can't find a dataset or any other entity. This way, users know when something doesn't exist and can decide what to do next, like showing an error page or something else. It adds an extra step, but I believe it's useful. However, I might see it this way because of how we do things on the frontend.

We should talk about this with @GPortas. If we decide against returning undefined in js-dataverse, we'll just handle that part on the frontend.

Copy link
Contributor

@GPortas GPortas Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekraffmiller @MellyGray

I think js-dataverse should always throw errors for any API operation that returns an error. Since it's an API wrapper, IMO it seems more natural to return an error to the consumer than an undefined value, like the API does (the API doesn't return a 200 response with a null body if a resource is not found). Note that the message accompanying the 404 error returned by the API may provide useful information to the consumer, which would be lost if we return undefined.

Regarding what Melina says about ensuring our code safely handles the absence of a value, this can still be done by throwing an error. In js-dataverse there are different types of errors defined, very high level and general purpose for now: https://github.com/IQSS/dataverse-client-javascript/tree/develop/src/core/domain/repositories. For now any error returned by the API in a read operation returns a ReadError, which includes the message with the HTTP error code as a very simple string, but we can define a new NotFoundError that extends ReadError also including more refined data. This way we can safely identify a not found error within the block catch of the promise, and carry out the necessary actions in the SPA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GPortas sounds good! How do we proceed with this PR? Should I remove the undefined from the repository definition or keep it until we implement the NotFoundError in js-dataverse?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MellyGray I would remove the undefined type in this PR and then create two new issues:

  1. Create the NotFoundError in js-dataverse (js-dataverse repository)
  2. Handle the NotFoundError properly in the frontend (dependent on the previous one) (SPA repository)

Please tell me what you think!

Copy link
Contributor

@GPortas GPortas Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the undefined

@MellyGray MellyGray removed their assignment Apr 8, 2024
Copy link
Contributor

@ekraffmiller ekraffmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

@ekraffmiller ekraffmiller removed their assignment Apr 10, 2024
@g-saracca g-saracca self-assigned this Apr 12, 2024
@g-saracca
Copy link
Contributor

Looks good!
Screenshot 2024-04-12 at 11 15 59
Screenshot 2024-04-12 at 11 16 09

@g-saracca g-saracca merged commit 9addf4d into develop Apr 12, 2024
9 of 14 checks passed
@g-saracca g-saracca deleted the feature-344-display-real-collection-data branch April 12, 2024 14:21
@g-saracca g-saracca removed their assignment Apr 12, 2024
jayanthkomarraju pushed a commit to jayanthkomarraju/dataverse-frontend that referenced this pull request May 31, 2024
…tion-data

344 - Display real collection data in the Collection Page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration Tasks involving the connection and interaction of UI features with the Dataverse API pm.GREI-d-2.7.1 NIH, yr2, aim7, task1: R&D UI modules for creating datasets and supporting publishing workflows pm.GREI-d-2.7.2 NIH, yr2, aim7, task2: Implement UI modules for creating datasets and publishing workflows Size: 3 A percentage of a sprint. 2.1 hours. SPA: Collection Page
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display real Collection name, description and affiliation in the Collection Page
5 participants