-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4250] Add icons to table column headers
Bug: #4250 Signed-off-by: Florian ROUËNÉ <[email protected]>
- Loading branch information
1 parent
013a800
commit 94c77a3
Showing
13 changed files
with
245 additions
and
12 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
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
130 changes: 130 additions & 0 deletions
130
...va/org/eclipse/sirius/web/application/controllers/tables/TableIconURLControllerTests.java
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,130 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 CEA LIST. | ||
* 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.controllers.tables; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import com.jayway.jsonpath.JsonPath; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.function.Consumer; | ||
|
||
import org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput; | ||
import org.eclipse.sirius.components.collaborative.tables.TableEventInput; | ||
import org.eclipse.sirius.components.collaborative.tables.TableRefreshedEventPayload; | ||
import org.eclipse.sirius.components.graphql.api.URLConstants; | ||
import org.eclipse.sirius.components.graphql.tests.api.IGraphQLRequestor; | ||
import org.eclipse.sirius.web.AbstractIntegrationTests; | ||
import org.eclipse.sirius.web.data.PapayaIdentifiers; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenCommittedTransaction; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenCreatedRepresentation; | ||
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.test.context.jdbc.SqlConfig; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import reactor.test.StepVerifier; | ||
|
||
/** | ||
* Integration tests of the table icon URL controller. | ||
* | ||
* @author frouene | ||
*/ | ||
@Transactional | ||
@SuppressWarnings("checkstyle:MultipleStringLiterals") | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class TableIconURLControllerTests extends AbstractIntegrationTests { | ||
|
||
private static final String TABLE_EVENT_SUBSCRIPTION = """ | ||
subscription tableEvent($input: TableEventInput!) { | ||
tableEvent(input: $input) { | ||
__typename | ||
... on TableRefreshedEventPayload { | ||
table { | ||
id | ||
columns { | ||
id | ||
iconURLs | ||
} | ||
} | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
@Autowired | ||
private IGivenCreatedRepresentation givenCreatedRepresentation; | ||
|
||
@Autowired | ||
private IGraphQLRequestor graphQLRequestor; | ||
|
||
@Autowired | ||
private IGivenInitialServerState givenInitialServerState; | ||
|
||
@Autowired | ||
private IGivenCommittedTransaction givenCommittedTransaction; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
this.givenInitialServerState.initialize(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Given a papaya package, when we subscribe to a table with icon define, then the URL of its icons are valid") | ||
@Sql(scripts = {"/scripts/papaya.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(scripts = {"/scripts/cleanup.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED)) | ||
public void givenPapayaPackageWhenWeSubscribeToTableWithIconThenURLOfItsIconsAreValid() { | ||
this.givenCommittedTransaction.commit(); | ||
var input = new CreateRepresentationInput( | ||
UUID.randomUUID(), | ||
PapayaIdentifiers.PAPAYA_PROJECT.toString(), | ||
"papaya_package_table_description", | ||
PapayaIdentifiers.SIRIUS_WEB_DOMAIN_PACKAGE.toString(), | ||
"Table" | ||
); | ||
String representationId = this.givenCreatedRepresentation.createRepresentation(input); | ||
var tableEventInput = new TableEventInput(UUID.randomUUID(), PapayaIdentifiers.PAPAYA_PROJECT.toString(), representationId); | ||
var flux = this.graphQLRequestor.subscribeToSpecification(TABLE_EVENT_SUBSCRIPTION, tableEventInput); | ||
|
||
Consumer<String> tableContentConsumer = payload -> Optional.of(payload) | ||
.ifPresentOrElse(body -> { | ||
String typename = JsonPath.read(body, "$.data.tableEvent.__typename"); | ||
assertThat(typename).isEqualTo(TableRefreshedEventPayload.class.getSimpleName()); | ||
|
||
List<List<String>> tableStubRowIconURLs = JsonPath.read(body, "$.data.tableEvent.table.columns[*].iconURLs"); | ||
assertThat(tableStubRowIconURLs) | ||
.isNotEmpty() | ||
.allSatisfy(iconURLs -> { | ||
assertThat(iconURLs) | ||
.isNotEmpty() | ||
.hasSize(1) | ||
.allSatisfy(iconURL -> assertThat(iconURL).startsWith(URLConstants.IMAGE_BASE_PATH)); | ||
}); | ||
}, () -> fail("Missing table")); | ||
|
||
StepVerifier.create(flux) | ||
.consumeNextWith(tableContentConsumer) | ||
.thenCancel() | ||
.verify(Duration.ofSeconds(10)); | ||
} | ||
|
||
} |
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
48 changes: 48 additions & 0 deletions
48
.../org/eclipse/sirius/components/tables/graphql/datafetchers/ColumnIconURLsDataFetcher.java
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,48 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 CEA LIST. | ||
* 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.components.tables.graphql.datafetchers; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher; | ||
import org.eclipse.sirius.components.core.api.IImageURLSanitizer; | ||
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; | ||
import org.eclipse.sirius.components.graphql.api.URLConstants; | ||
import org.eclipse.sirius.components.tables.Column; | ||
|
||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
/** | ||
* The data fetcher used to concatenate the server image URL to the column image path. | ||
* | ||
* @author frouene | ||
*/ | ||
@QueryDataFetcher(type = "Column", field = "iconURLs") | ||
public class ColumnIconURLsDataFetcher implements IDataFetcherWithFieldCoordinates<List<String>> { | ||
|
||
private final IImageURLSanitizer imageURLSanitizer; | ||
|
||
public ColumnIconURLsDataFetcher(IImageURLSanitizer imageURLSanitizer) { | ||
this.imageURLSanitizer = Objects.requireNonNull(imageURLSanitizer); | ||
} | ||
|
||
@Override | ||
public List<String> get(DataFetchingEnvironment environment) throws Exception { | ||
Column source = environment.getSource(); | ||
|
||
return source.getIconURLs().stream() | ||
.map(url -> this.imageURLSanitizer.sanitize(URLConstants.IMAGE_BASE_PATH, url)) | ||
.toList(); | ||
} | ||
} |
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
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
Oops, something went wrong.