Skip to content

Commit

Permalink
[4242] Add support to stub location for row in table
Browse files Browse the repository at this point in the history
Bug: #4242
Signed-off-by: Florian ROUËNÉ <[email protected]>
  • Loading branch information
frouene authored and sbegaudeau committed Dec 4, 2024
1 parent 6cfcc05 commit c2366d6
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Specifiers can implement this new interface with a spring `Service`.
A new `IRestDataVersionPayloadSerializerService` interface is available, allowing to customize the default implementation of the JSON serialization of the payload object of `RestDataVersion`.
Specifiers are also encouraged to implement their own `IRestDataVersionPayloadSerializerService` for their domains, as the default one may not return expected results.
- https://github.com/eclipse-sirius/sirius-web/issues/4250[#4250] [table] Add icons to table column headers
- https://github.com/eclipse-sirius/sirius-web/issues/4242[#4242] [table] Add support to stub location for row in table

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public List<IRepresentationDescription> getRepresentationDescriptions(IEditingCo
.targetObjectIdProvider(new TableTargetObjectIdProvider(this.identityService))
.targetObjectKindProvider(new TableTargetObjectKindProvider(this.identityService))
.semanticElementsProvider(this::getSemanticElements)
.stubLabelProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.labelService::getLabel).orElse(null))
.stubIconURLsProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.labelService::getImagePath).orElse(List.of()))
.stubHeaderProvider(variableManager -> variableManager.get("rowIndex", Integer.class).map(String::valueOf).orElse(null))
.build();

var tableDescription = TableDescription.newTableDescription(TABLE_DESCRIPTION_ID)
Expand All @@ -86,6 +89,7 @@ public List<IRepresentationDescription> getRepresentationDescriptions(IEditingCo
return List.of(tableDescription);
}


private boolean canCreate(VariableManager variableManager) {
return variableManager.get(VariableManager.SELF, Object.class)
.filter(PackageSpec.class::isInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,25 @@
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
}
}
}
}
}
""";
subscription tableEvent($input: TableEventInput!) {
tableEvent(input: $input) {
__typename
... on TableRefreshedEventPayload {
table {
id
columns {
id
iconURLs
}
lines {
id
stubIconURLs
}
}
}
}
}
""";

@Autowired
private IGivenCreatedRepresentation givenCreatedRepresentation;
Expand Down Expand Up @@ -110,15 +114,25 @@ public void givenPapayaPackageWhenWeSubscribeToTableWithIconThenURLOfItsIconsAre
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)
List<List<String>> columnIconURLs = JsonPath.read(body, "$.data.tableEvent.table.columns[*].iconURLs");
assertThat(columnIconURLs)
.isNotEmpty()
.allSatisfy(iconURLs -> {
assertThat(iconURLs)
.isNotEmpty()
.hasSize(1)
.allSatisfy(iconURL -> assertThat(iconURL).startsWith(URLConstants.IMAGE_BASE_PATH));
});

List<List<String>> rowIconURLs = JsonPath.read(body, "$.data.tableEvent.table.lines[*].stubIconURLs");
assertThat(rowIconURLs)
.isNotEmpty()
.allSatisfy(iconURLs -> {
assertThat(iconURLs)
.isNotEmpty()
.hasSize(2)
.allSatisfy(iconURL -> assertThat(iconURL).startsWith(URLConstants.IMAGE_BASE_PATH));
});
}, () -> fail("Missing table"));

StepVerifier.create(flux)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type Line {
targetObjectId: ID!
targetObjectKind: String!
cells: [Cell!]!
stubLabel: String
stubIconURLs: [String!]!
stubHeader: String
}

interface Cell {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* 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 org.eclipse.sirius.components.annotations.spring.graphql.QueryDataFetcher;
import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates;
import org.eclipse.sirius.components.graphql.api.URLConstants;
import org.eclipse.sirius.components.tables.Line;

import graphql.schema.DataFetchingEnvironment;

/**
* The data fetcher used to concatenate the server image URL to the stub row image path.
*
* @author frouene
*/
@QueryDataFetcher(type = "Line", field = "stubIconURLs")
public class StubRowIconURLDataFetcher implements IDataFetcherWithFieldCoordinates<List<String>> {

@Override
public List<String> get(DataFetchingEnvironment environment) throws Exception {
Line source = environment.getSource();

return source.getStubIconURLs().stream().map(url -> URLConstants.IMAGE_BASE_PATH + url).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public final class Line {

private List<ICell> cells;

private String stubLabel;

private List<String> stubIconURLs;

private String stubHeader;

private Line() {
// Prevent instantiation
}
Expand All @@ -61,6 +67,18 @@ public List<ICell> getCells() {
return this.cells;
}

public String getStubLabel() {
return this.stubLabel;
}

public List<String> getStubIconURLs() {
return this.stubIconURLs;
}

public String getStubHeader() {
return this.stubHeader;
}

public static Builder newLine(UUID id) {
return new Builder(id);
}
Expand Down Expand Up @@ -89,6 +107,12 @@ public static final class Builder {

private List<ICell> cells;

private String stubLabel;

private List<String> stubIconURLs;

private String stubHeader;

private Builder(UUID id) {
this.id = Objects.requireNonNull(id);
}
Expand Down Expand Up @@ -120,13 +144,31 @@ public Builder cells(List<ICell> cells) {
return this;
}

public Builder stubLabel(String stubLabel) {
this.stubLabel = Objects.requireNonNull(stubLabel);
return this;
}

public Builder stubIconURLs(List<String> stubIconURLs) {
this.stubIconURLs = Objects.requireNonNull(stubIconURLs);
return this;
}

public Builder stubHeader(String stubHeader) {
this.stubHeader = Objects.requireNonNull(stubHeader);
return this;
}

public Line build() {
Line line = new Line();
line.id = Objects.requireNonNull(this.id);
line.targetObjectId = Objects.requireNonNull(this.targetObjectId);
line.targetObjectKind = Objects.requireNonNull(this.targetObjectKind);
line.descriptionId = Objects.requireNonNull(this.descriptionId);
line.cells = Objects.requireNonNull(this.cells);
line.stubLabel = this.stubLabel;
line.stubIconURLs = Objects.requireNonNull(this.stubIconURLs);
line.stubHeader = this.stubHeader;
return line;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public Element render() {

List<Element> children = new ArrayList<>();
List<Object> semanticElements = lineDescription.getSemanticElementsProvider().apply(variableManager);

var index = 0;
for (Object semanticElement : semanticElements) {
VariableManager lineVariableManager = variableManager.createChild();
lineVariableManager.put(VariableManager.SELF, semanticElement);
lineVariableManager.put("rowIndex", index++);

String targetObjectId = lineDescription.getTargetObjectIdProvider().apply(lineVariableManager);
var optionalPreviousLine = linesRequestor.getByTargetObjectId(targetObjectId);
Expand All @@ -77,19 +78,30 @@ private Element doRender(VariableManager lineVariableManager, String targetObjec

String targetObjectKind = lineDescription.getTargetObjectKindProvider().apply(lineVariableManager);

String stubLabel = lineDescription.getStubLabelProvider().apply(lineVariableManager);
List<String> stubIconURLs = lineDescription.getStubIconURLsProvider().apply(lineVariableManager);
String stubHeader = lineDescription.getStubHeaderProvider().apply(lineVariableManager);

var cells = this.getCells(lineVariableManager, lineId);

List<Element> children = new ArrayList<>();
children.addAll(cells);

LineElementProps lineElementProps = LineElementProps.newLineElementProps(lineId)
var lineElementPropsBuilder = LineElementProps.newLineElementProps(lineId)
.descriptionId(lineDescription.getId())
.targetObjectId(targetObjectId)
.targetObjectKind(targetObjectKind)
.children(children)
.build();
.stubIconURLs(stubIconURLs)
.children(children);

if (stubLabel != null) {
lineElementPropsBuilder.stubLabel(stubLabel);
}
if (stubHeader != null) {
lineElementPropsBuilder.stubHeader(stubHeader);
}

return new Element(LineElementProps.TYPE, lineElementProps);
return new Element(LineElementProps.TYPE, lineElementPropsBuilder.build());
}

private List<Element> getCells(VariableManager lineVariableManager, UUID parentLineId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public final class LineDescription {

private Function<VariableManager, List<Object>> semanticElementsProvider;

private Function<VariableManager, String> stubLabelProvider;

private Function<VariableManager, List<String>> stubIconURLsProvider;

private Function<VariableManager, String> stubHeaderProvider;

private LineDescription() {
// Prevent instantiation
}
Expand All @@ -57,6 +63,18 @@ public Function<VariableManager, List<Object>> getSemanticElementsProvider() {
return this.semanticElementsProvider;
}

public Function<VariableManager, String> getStubLabelProvider() {
return this.stubLabelProvider;
}

public Function<VariableManager, List<String>> getStubIconURLsProvider() {
return this.stubIconURLsProvider;
}

public Function<VariableManager, String> getStubHeaderProvider() {
return this.stubHeaderProvider;
}

public static Builder newLineDescription(UUID id) {
return new Builder(id);
}
Expand All @@ -83,6 +101,12 @@ public static final class Builder {

private Function<VariableManager, List<Object>> semanticElementsProvider;

private Function<VariableManager, String> stubLabelProvider = variableManager -> null;

private Function<VariableManager, List<String>> stubIconURLsProvider = variableManager -> List.of();

private Function<VariableManager, String> stubHeaderProvider = variableManager -> null;

public Builder(UUID id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -102,12 +126,30 @@ public Builder semanticElementsProvider(Function<VariableManager, List<Object>>
return this;
}

public Builder stubLabelProvider(Function<VariableManager, String> stubLabelProvider) {
this.stubLabelProvider = Objects.requireNonNull(stubLabelProvider);
return this;
}

public Builder stubIconURLsProvider(Function<VariableManager, List<String>> stubIconURLsProvider) {
this.stubIconURLsProvider = Objects.requireNonNull(stubIconURLsProvider);
return this;
}

public Builder stubHeaderProvider(Function<VariableManager, String> stubHeaderProvider) {
this.stubHeaderProvider = Objects.requireNonNull(stubHeaderProvider);
return this;
}

public LineDescription build() {
LineDescription lineDescription = new LineDescription();
lineDescription.id = Objects.requireNonNull(this.id);
lineDescription.targetObjectIdProvider = Objects.requireNonNull(this.targetObjectIdProvider);
lineDescription.targetObjectKindProvider = Objects.requireNonNull(this.targetObjectKindProvider);
lineDescription.semanticElementsProvider = Objects.requireNonNull(this.semanticElementsProvider);
lineDescription.stubLabelProvider = Objects.requireNonNull(this.stubLabelProvider);
lineDescription.stubIconURLsProvider = Objects.requireNonNull(this.stubIconURLsProvider);
lineDescription.stubHeaderProvider = Objects.requireNonNull(this.stubHeaderProvider);
return lineDescription;
}
}
Expand Down
Loading

0 comments on commit c2366d6

Please sign in to comment.