Skip to content

Commit

Permalink
[cleanup] Improve the code of EditProjectView
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
  • Loading branch information
sbegaudeau committed Jun 20, 2024
1 parent 67747ca commit 3b0633c
Show file tree
Hide file tree
Showing 19 changed files with 437 additions and 376 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.web.application.project.dto;

import jakarta.validation.constraints.NotNull;

/**
* DTO used to represent the nature of a project.
*
* @author sbegaudeau
*/
public record NatureDTO(@NotNull String name) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.web.application.project.dto;

import java.util.List;
import java.util.UUID;

import jakarta.validation.constraints.NotNull;
Expand All @@ -23,5 +24,6 @@
*/
public record ProjectDTO(
@NotNull UUID id,
@NotNull String name) {
@NotNull String name,
@NotNull List<NatureDTO> natures) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.web.application.project.services;

import org.eclipse.sirius.web.application.project.dto.NatureDTO;
import org.eclipse.sirius.web.application.project.services.api.IProjectMapper;
import org.eclipse.sirius.web.domain.boundedcontexts.project.Project;
import org.eclipse.sirius.web.application.project.dto.ProjectDTO;
Expand All @@ -26,6 +27,9 @@
public class ProjectMapper implements IProjectMapper {
@Override
public ProjectDTO toDTO(Project project) {
return new ProjectDTO(project.getId(), project.getName());
var natures = project.getNatures().stream()
.map(nature -> new NatureDTO(nature.name()))
.toList();
return new ProjectDTO(project.getId(), project.getName(), natures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type Project {
id: ID!
name: String!
currentEditingContext: EditingContext!
natures: [Nature!]!
}

type Nature {
name: String!
}

type ViewerProjectTemplatesConnection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type Project {
name: String!
currentEditingContext: EditingContext!
images: [ImageMetadata!]!
natures: [Nature!]!
}

type Nature {
name: String!
}

extend type Subscription {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@
package org.eclipse.sirius.web.services.api.projects;

import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

Expand All @@ -26,9 +27,12 @@ public class Project {

private final String name;

public Project(UUID id, String name) {
private final List<Nature> natures;

public Project(UUID id, String name, List<Nature> natures) {
this.id = Objects.requireNonNull(id);
this.name = Objects.requireNonNull(name);
this.natures = Objects.requireNonNull(natures);
}

public UUID getId() {
Expand All @@ -39,6 +43,10 @@ public String getName() {
return this.name;
}

public List<Nature> getNatures() {
return this.natures;
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, name: {2}'}'";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.web.services.documents;

import java.util.List;

import org.eclipse.sirius.web.persistence.entities.DocumentEntity;
import org.eclipse.sirius.web.persistence.entities.ProjectEntity;
import org.eclipse.sirius.web.services.api.document.Document;
Expand All @@ -26,7 +28,7 @@ public class DocumentMapper {
public Document toDTO(DocumentEntity documentEntity) {
ProjectEntity projectEntity = documentEntity.getProject();

Project project = new Project(projectEntity.getId(), projectEntity.getName());
Project project = new Project(projectEntity.getId(), projectEntity.getName(), List.of());
return new Document(documentEntity.getId(), project, documentEntity.getName(), documentEntity.getContent());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.web.services.projects;

import java.util.List;

import org.eclipse.sirius.web.persistence.entities.ProjectEntity;
import org.eclipse.sirius.web.services.api.projects.Project;

Expand All @@ -22,6 +24,6 @@
*/
public class ProjectMapper {
public Project toDTO(ProjectEntity projectEntity) {
return new Project(projectEntity.getId(), projectEntity.getName());
return new Project(projectEntity.getId(), projectEntity.getName(), List.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export {
export { routerExtensionPoint } from './router/RouterExtensionPoints';
export { type EditProjectNavbarSubtitleProps } from './views/edit-project/EditProjectNavbar/EditProjectNavbar.types';
export { editProjectNavbarSubtitleExtensionPoint } from './views/edit-project/EditProjectNavbar/EditProjectNavbarExtensionPoints';
export { useCurrentProject } from './views/edit-project/useCurrentProject';
export type { UseCurrentProjectValue } from './views/edit-project/useCurrentProject.types';
export type { GQLProject } from './views/edit-project/useProjectAndRepresentationMetadata.types';
export { type CreateProjectAreaCardProps } from './views/project-browser/create-projects-area/CreateProjectArea.types';
export { createProjectAreaCardExtensionPoint } from './views/project-browser/create-projects-area/CreateProjectAreaExtensionPoints';
export { projectActionButtonMenuItemExtensionPoint } from './views/project-browser/list-projects-area/ProjectActionButtonExtensionPoints';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Obeo.
* Copyright (c) 2021, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -10,11 +10,10 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

import { Project } from '../EditProjectView.types';
import { GQLProject } from '../useProjectAndRepresentationMetadata.types';

export interface EditProjectNavbarProps {
project: Project;
project: GQLProject;
}

export interface EditProjectNavbarSubtitleProps {}
Expand Down
Loading

0 comments on commit 3b0633c

Please sign in to comment.