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: Resources page with routing and list of resource types #788

Merged
merged 10 commits into from
Nov 28, 2024

Conversation

llorentelemmc
Copy link
Contributor

No description provided.

@llorentelemmc llorentelemmc requested a review from mburri November 5, 2024 09:46
@llorentelemmc llorentelemmc self-assigned this Nov 5, 2024
@llorentelemmc llorentelemmc changed the title Resources page with routing Resources page with routing and list of resources Nov 5, 2024
@llorentelemmc llorentelemmc changed the title Resources page with routing and list of resources Resources page with routing and list of resource types Nov 5, 2024
@llorentelemmc llorentelemmc marked this pull request as draft November 5, 2024 16:25
Comment on lines 24 to 32
loadingPermissions = computed(() => {
if (this.authService.restrictions().length > 0) {
this.getUserPermissions();
} else {
return `<div>Could not load permissions</div>`;
}
});
Copy link
Member

Choose a reason for hiding this comment

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

see commit a9f6e80 as an example on how to improve this

Comment on lines 58 to 57
List<ResourceTypeEntity> predefinedResourceTypes = new ArrayList<>();
for (ResourceTypeEntity e : resourceTypeDomainService.getResourceTypes()) {
if (e.getParentResourceType() == null && ResourceType.createByResourceType(e, null).isDefaultResourceType()) {
predefinedResourceTypes.add(e);
}
}
if (predefinedResourceTypes.isEmpty()) {
throw new NotFoundException("No predefined resource types found");
}
return predefinedResourceTypes;
}
Copy link
Member

@mburri mburri Nov 6, 2024

Choose a reason for hiding this comment

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

I assume that this is new code (or taken from one of the view beans?)

Try to use modern java - with lambdas and streams (maybe optionals) - basically, there is almost never a reason to use for loops.

so this could look like this:

 public List<ResourceTypeEntity> getPredefinedResourceTypes() throws NotFoundException {
        List<ResourceTypeEntity> predefinedResourceTypes = resourceTypeDomainService.getResourceTypes()
                .stream()
                .filter(resourceTypeEntity -> resourceTypeEntity == null && ResourceType.createByResourceType(resourceTypeEntity, null).isDefaultResourceType())
                .collect(Collectors.toList());

        if (predefinedResourceTypes.isEmpty()) {
            throw new NotFoundException("No predefined resource types found");
        }
        return predefinedResourceTypes;
    }

Copy link
Member

Choose a reason for hiding this comment

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

I also think that the NotFoundException should not be thrown here. The exception is only relevant for the rest point (where the NotFoundExcpetionMapper exists).

It might be perfectly valid to get an empty list for other use cases in the future. Additionally - it will throw an error in the frontend. The more I think about it - just remove the exception - an empty list should not return an HTTP status 404.

Copy link
Member

Choose a reason for hiding this comment

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

GET /thing/:id should return 404 if the thing with the given id was not found
GET /thing should not return 404 if the list is empty

@ApiOperation(value = "Get all available ResourceTypes - used by Angular")
public List<ResourceTypeDTO> getAllResourceTypes() throws ValidationException {
@ApiOperation(value = "Get all resource types")
public List<ResourceTypeDTO> getAllResourceTypes() throws NotFoundException {
Copy link
Member

Choose a reason for hiding this comment

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

some as above - empty lists should not return a 404

Comment on lines 56 to 59
for (ResourceTypeEntity resourceType : resourceTypes) {
resourceTypeDTOs.add(new ResourceTypeDTO(resourceType));
}
return resourceTypeDTOs;
Copy link
Member

Choose a reason for hiding this comment

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

replace with stream().map()

Comment on lines 66 to 69
List<ResourceTypeEntity> resourceTypes = resourceTypeLocator.getPredefinedResourceTypes();
List<ResourceTypeDTO> resourceTypeDTOs = new ArrayList<>();
for (ResourceTypeEntity resourceType : resourceTypes) {
resourceTypeDTOs.add(new ResourceTypeDTO(resourceType));
Copy link
Member

Choose a reason for hiding this comment

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

replace with stream().map()

Comment on lines 78 to 83
List<ResourceTypeEntity> resourceTypes = resourceTypeLocator.getRootResourceTypes();
List<ResourceTypeDTO> resourceTypeDTOs = new ArrayList<>();
for (ResourceTypeEntity resourceType : resourceTypes) {
resourceTypeDTOs.add(new ResourceTypeDTO(resourceType));
}
return resourceTypeDTOs;
Copy link
Member

Choose a reason for hiding this comment

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

replace with stream().map()

Copy link
Member

@mburri mburri left a comment

Choose a reason for hiding this comment

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

It would also have been nice to split this PR along the stories:

  • create page skeleton and routing in the frontend
  • show List of ResourceTypes

@llorentelemmc llorentelemmc force-pushed the resources-page-component branch 2 times, most recently from 305be7d to 842ce79 Compare November 10, 2024 23:57
@llorentelemmc llorentelemmc marked this pull request as ready for review November 11, 2024 12:12
@llorentelemmc llorentelemmc requested a review from mburri November 11, 2024 12:12
@llorentelemmc llorentelemmc force-pushed the resources-page-component branch from e5630cb to 27d431e Compare November 11, 2024 12:25
<span>{{ expandedResourceTypeId === resourceType.id ? '-' : '+' }}</span>
}
</a>
@if (expandedResourceTypeId === resourceType.id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@if (expandedResourceTypeId === resourceType.id) {
@if (resourceType.hasChildren && expandedResourceTypeId === resourceType.id) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion above:
Because otherwise you can also expand those that have no children, only then an "empty list" or simply no list is displayed, but you can see that something has been expanded in the UI.

@BeriBoss BeriBoss force-pushed the resources-page-component branch from 02dd6e3 to 783f021 Compare November 20, 2024 08:46
@llorentelemmc llorentelemmc merged commit 43b4b4f into development Nov 28, 2024
1 check passed
@llorentelemmc llorentelemmc deleted the resources-page-component branch November 28, 2024 13:25
@llorentelemmc llorentelemmc changed the title Resources page with routing and list of resource types feature: Resources page with routing and list of resource types Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants