Skip to content

Commit

Permalink
[4343] Keep filters when opening a table
Browse files Browse the repository at this point in the history
Bug: #4343
Signed-off-by: Florian ROUËNÉ <[email protected]>
  • Loading branch information
frouene authored and sbegaudeau committed Jan 14, 2025
1 parent 7257069 commit 79d6ebd
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 52 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ This may have some consequences for downstream applications which are embedding
- https://github.com/eclipse-sirius/sirius-web/issues/4398[#4398] [sirius-web] Fix an issue where the swagger page listing all REST APIs (YOUR_SERVER/swagger-ui/index.html) and the OpenAPI file (YOUR_SERVER/v3/api-docs/rest-apis) were not accessible anymore.
- https://github.com/eclipse-sirius/sirius-web/issues/4400[#4400] [sirius-web] Fix an issue where the swagger page listing all REST APIs (YOUR_SERVER/swagger-ui/index.html) was not listing all response codes for each endpoint.
- https://github.com/eclipse-sirius/sirius-web/issues/4366[#4366] [form] Fix a warning in the reference widget
- https://github.com/eclipse-sirius/sirius-web/issues/4343[#4343] [table] Fix an issue where filters were reset on table opening
- https://github.com/eclipse-sirius/sirius-web/issues/4311[#4311] [table] Fix typos in table variables

=== New Features

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 Down Expand Up @@ -55,7 +55,7 @@ public Element render() {
Boolean readOnly = tableWidgetDescription.getIsReadOnlyProvider().apply(variableManager);

Element tableElement = new Element(TableComponent.class,
new TableComponentProps(variableManager, tableWidgetDescription.getTableDescription(), Optional.empty(), List.of(), null, List.of()));
new TableComponentProps(variableManager, tableWidgetDescription.getTableDescription(), Optional.empty(), List.of(), "", List.of()));

List<Element> children = new ArrayList<>();
children.add(tableElement);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 CEA LIST.
* Copyright (c) 2024, 2025 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
Expand Down Expand Up @@ -30,6 +30,7 @@
import org.eclipse.sirius.components.collaborative.api.IEditingContextEventProcessorRegistry;
import org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput;
import org.eclipse.sirius.components.collaborative.tables.TableColumnFilterPayload;
import org.eclipse.sirius.components.collaborative.tables.TableEventInput;
import org.eclipse.sirius.components.collaborative.tables.TableGlobalFilterValuePayload;
import org.eclipse.sirius.components.collaborative.tables.TableRefreshedEventPayload;
import org.eclipse.sirius.components.collaborative.tables.dto.ChangeColumnFilterInput;
Expand All @@ -39,8 +40,10 @@
import org.eclipse.sirius.components.tables.ColumnFilter;
import org.eclipse.sirius.components.tables.tests.graphql.ChangeColumnFilterMutationRunner;
import org.eclipse.sirius.components.tables.tests.graphql.ChangeGlobalFilterMutationRunner;
import org.eclipse.sirius.components.tables.tests.graphql.TableEventSubscriptionRunner;
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.IGivenCreatedTableSubscription;
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -53,6 +56,7 @@
import org.springframework.test.context.transaction.TestTransaction;
import org.springframework.transaction.annotation.Transactional;

import graphql.execution.DataFetcherResult;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

Expand Down Expand Up @@ -83,6 +87,12 @@ public class PapayaTableControllerIntegrationTests extends AbstractIntegrationTe
@Autowired
private ChangeColumnFilterMutationRunner changeColumnFilterMutationRunner;

@Autowired
private IGivenCommittedTransaction givenCommittedTransaction;

@Autowired
private TableEventSubscriptionRunner tableEventSubscriptionRunner;


@BeforeEach
public void beforeEach() {
Expand Down Expand Up @@ -303,4 +313,39 @@ public void givenTableWhenColumnFilterMutationTriggeredThenPayloadWithNewColumnF
.verify(Duration.ofSeconds(10));
}

@Test
@DisplayName("Given a table with filters, when the existing representation is opened, then persisted filters are preserved")
@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 givenTableWithFiltersWhenRepresentationIsOpenedThenPersistedFiltersArePreserved() {
this.givenCommittedTransaction.commit();

var tableEventInput = new TableEventInput(UUID.randomUUID(), PapayaIdentifiers.PAPAYA_PROJECT.toString(), PapayaIdentifiers.PAPAYA_PACKAGE_TABLE_REPRESENTATION.toString());
var flux = this.tableEventSubscriptionRunner.run(tableEventInput);

TestTransaction.flagForCommit();
TestTransaction.end();
TestTransaction.start();


Consumer<Object> initialTableContentConsumer = payload -> Optional.of(payload)
.filter(DataFetcherResult.class::isInstance)
.map(DataFetcherResult.class::cast)
.map(DataFetcherResult::getData)
.filter(TableRefreshedEventPayload.class::isInstance)
.map(TableRefreshedEventPayload.class::cast)
.map(TableRefreshedEventPayload::table)
.ifPresentOrElse(table -> {
assertThat(table).isNotNull();
assertThat(table.getGlobalFilter()).isEqualTo("PUB");
assertThat(table.getColumnFilters()).hasSize(1);
assertThat(table.getColumnFilters().get(0).value()).isEqualTo("LIC");
}, () -> fail(MISSING_TABLE));

StepVerifier.create(flux)
.consumeNextWith(initialTableContentConsumer)
.thenCancel()
.verify(Duration.ofSeconds(10));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,13 @@ INSERT INTO public.representation_content (
"label": "Visibility"
}
],
"globalFilter": ""
"globalFilter": "PUB",
"columnFilters": [
{
"id": "eabb569d-f99e-3e6e-86a6-db600b1fa526",
"value": "LIC"
}
]
}',
'none',
'0',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 CEA LIST.
* Copyright (c) 2024, 2025 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
Expand Down Expand Up @@ -141,8 +141,8 @@ public TableCreationParameters build() {
tableCreationParameters.editingContext = Objects.requireNonNull(this.editingContext);
tableCreationParameters.cursorBasedPaginationData = Objects.requireNonNull(this.cursorBasedPaginationData);
tableCreationParameters.targetObject = Objects.requireNonNull(this.targetObject);
tableCreationParameters.globalFilter = this.globalFilter;
tableCreationParameters.columnFilters = this.columnFilters; // Optional on purpose
tableCreationParameters.globalFilter = Objects.requireNonNull(this.globalFilter);
tableCreationParameters.columnFilters = Objects.requireNonNull(this.columnFilters);
return tableCreationParameters;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 CEA LIST.
* Copyright (c) 2024, 2025 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
Expand Down Expand Up @@ -49,7 +49,7 @@ public class TableEventProcessorFactory implements IRepresentationEventProcessor
private static final String SIZE = "size";
private static final String GLOBAL_FILTER = "globalFilter";
private static final String COLUMN_FILTERS = "columnFilters";

private final IRepresentationSearchService representationSearchService;

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;
Expand Down Expand Up @@ -96,22 +96,17 @@ public Optional<IRepresentationEventProcessor> createRepresentationEventProcesso
TableDescription tableDescription = optionalTableDescription.get();
Object object = optionalObject.get();

var tableCreationParametersBuilder = TableCreationParameters.newTableCreationParameters(this.getTableIdFromRepresentationId(representationId))
var tableCreationParameters = TableCreationParameters.newTableCreationParameters(this.getTableIdFromRepresentationId(representationId))
.tableDescription(tableDescription)
.editingContext(editingContext)
.targetObject(object)
.cursorBasedPaginationData(this.getCursorBasedPaginationData(editingContext, representationId))
.targetObject(object);
var globalFilter = this.getGlobalFilter(representationId);
if (globalFilter != null) {
tableCreationParametersBuilder.globalFilter(globalFilter);
}
var columnFilters = this.getColumnFilters(representationId);
if (columnFilters != null) {
tableCreationParametersBuilder.columnFilters(columnFilters);
}

IRepresentationEventProcessor tableEventProcessor = new TableEventProcessor(tableCreationParametersBuilder.build(), this.tableEventHandlers, new TableContext(table),
.targetObject(object)
.globalFilter(this.getGlobalFilter(representationId, table))
.columnFilters(this.getColumnFilters(representationId, table))
.build();

IRepresentationEventProcessor tableEventProcessor = new TableEventProcessor(tableCreationParameters, this.tableEventHandlers, new TableContext(table),
this.subscriptionManagerFactory.create(), new SimpleMeterRegistry(), this.representationRefreshPolicyRegistry, this.representationPersistenceService);
return Optional.of(tableEventProcessor);
}
Expand Down Expand Up @@ -149,8 +144,8 @@ private CursorBasedPaginationData getCursorBasedPaginationData(IEditingContext e
return new CursorBasedPaginationData(cursor, direction, size);
}

private String getGlobalFilter(String representationId) {
String globalFilter = "";
private String getGlobalFilter(String representationId, Table table) {
String globalFilter = table.getGlobalFilter();
if (representationId.indexOf(GLOBAL_FILTER) > 0) {
var param = this.urlParser.getParameterValues(representationId);
if (param.containsKey(GLOBAL_FILTER)) {
Expand All @@ -162,7 +157,7 @@ private String getGlobalFilter(String representationId) {
return globalFilter;
}

private List<ColumnFilter> getColumnFilters(String representationId) {
private List<ColumnFilter> getColumnFilters(String representationId, Table table) {
if (representationId.indexOf(COLUMN_FILTERS) > 0) {
var param = this.urlParser.getParameterValues(representationId);
if (param.containsKey(COLUMN_FILTERS)) {
Expand All @@ -172,7 +167,7 @@ private List<ColumnFilter> getColumnFilters(String representationId) {
}).toList();
}
}
return List.of();
return table.getColumnFilters();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 Down Expand Up @@ -129,9 +129,9 @@ private List<Element> getCells(VariableManager lineVariableManager, UUID parentL
List<Element> elements = new ArrayList<>();
Map<UUID, Object> columnIdToObject = this.props.cache().getColumnIdToObject();

columnIdToObject.forEach((columnId, columTargetObject) -> {
columnIdToObject.forEach((columnId, columnTargetObject) -> {
VariableManager variableManager = lineVariableManager.createChild();
variableManager.put(ColumnDescription.COLUMN_TARGET_OBJECT, columTargetObject);
variableManager.put(ColumnDescription.COLUMN_TARGET_OBJECT, columnTargetObject);

String rawIdentifier = parentLineId.toString() + columnId;
UUID cellId = UUID.nameUUIDFromBytes(rawIdentifier.getBytes());
Expand All @@ -143,19 +143,19 @@ private List<Element> getCells(VariableManager lineVariableManager, UUID parentL

Element cellElement = null;
if (cellDescription instanceof SelectCellDescription selectCellDescription) {
var cellComponentProps = new SelectCellComponentProps(variableManager, selectCellDescription, cellId, columnId, columTargetObject);
var cellComponentProps = new SelectCellComponentProps(variableManager, selectCellDescription, cellId, columnId, columnTargetObject);
cellElement = new Element(SelectCellComponent.class, cellComponentProps);
} else if (cellDescription instanceof MultiSelectCellDescription multiSelectCellDescription) {
var cellComponentProps = new MultiSelectCellComponentProps(variableManager, multiSelectCellDescription, cellId, columnId, columTargetObject);
var cellComponentProps = new MultiSelectCellComponentProps(variableManager, multiSelectCellDescription, cellId, columnId, columnTargetObject);
cellElement = new Element(MultiSelectCellComponent.class, cellComponentProps);
} else if (cellDescription instanceof CheckboxCellDescription checkboxCellDescription) {
var cellComponentProps = new CheckboxCellComponentProps(variableManager, checkboxCellDescription, cellId, columnId, columTargetObject);
var cellComponentProps = new CheckboxCellComponentProps(variableManager, checkboxCellDescription, cellId, columnId, columnTargetObject);
cellElement = new Element(CheckboxCellComponent.class, cellComponentProps);
} else if (cellDescription instanceof TextfieldCellDescription textfieldCellDescription) {
var cellComponentProps = new TextfieldCellComponentProps(variableManager, textfieldCellDescription, cellId, columnId, columTargetObject);
var cellComponentProps = new TextfieldCellComponentProps(variableManager, textfieldCellDescription, cellId, columnId, columnTargetObject);
cellElement = new Element(TextfieldCellComponent.class, cellComponentProps);
} else if (cellDescription instanceof IconLabelCellDescription iconLabelCellDescription) {
var cellComponentProps = new IconLabelCellComponentProps(variableManager, iconLabelCellDescription, cellId, columnId, columTargetObject);
var cellComponentProps = new IconLabelCellComponentProps(variableManager, iconLabelCellDescription, cellId, columnId, columnTargetObject);
cellElement = new Element(IconLabelCellComponent.class, cellComponentProps);
}
if (cellElement != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 Down Expand Up @@ -58,18 +58,7 @@ public Element render() {
TableRenderingCache cache = new TableRenderingCache();
ITableElementRequestor tableElementRequestor = new TableElementRequestor();

var globalFilter = this.props.globalFilter();
if (this.props.globalFilter() == null) {
globalFilter = optionalPreviousTable.map(Table::getGlobalFilter).orElse("");
variableManager.put(TableRenderer.GLOBAL_FILTER_DATA, globalFilter);
}

List<ColumnFilter> columnsFilters;
if (this.props.columnFilters() == null) {
columnsFilters = optionalPreviousTable.map(Table::getColumnFilters).orElse(List.of());
} else {
columnsFilters = this.props.columnFilters();
}
List<ColumnFilter> columnsFilters = this.props.columnFilters();

var childrenColumns = tableDescription.getColumnDescriptions().stream()
.map(columnDescription -> {
Expand Down Expand Up @@ -110,7 +99,7 @@ public Element render() {
.stripeRow(stripeRow)
.children(children)
.paginationData(new PaginationData(paginatedData.hasPreviousPage(), paginatedData.hasNextPage(), paginatedData.totalRowCount()))
.globalFilter(globalFilter)
.globalFilter(this.props.globalFilter())
.columnFilters(columnsFilters)
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 Down Expand Up @@ -41,5 +41,7 @@ public record TableComponentProps(
Objects.requireNonNull(tableDescription);
Objects.requireNonNull(previousTable);
Objects.requireNonNull(tableEvents);
Objects.requireNonNull(globalFilter);
Objects.requireNonNull(columnFilters);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 Down Expand Up @@ -30,9 +30,9 @@
@Immutable
public final class ColumnDescription {

public static final String COLUMN_TARGET_OBJECT = "columTargetObject";
public static final String COLUMN_TARGET_OBJECT = "columnTargetObject";

public static final String COLUMN_TARGET_OBJECT_ID = "columTargetObjectId";
public static final String COLUMN_TARGET_OBJECT_ID = "columnTargetObjectId";

private String id;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Obeo.
* Copyright (c) 2024, 2025 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 Down Expand Up @@ -37,6 +37,7 @@ public record TableElementProps(String id, String descriptionId, String targetOb
Objects.requireNonNull(targetObjectKind);
Objects.requireNonNull(children);
Objects.requireNonNull(paginationData);
Objects.requireNonNull(globalFilter);
Objects.requireNonNull(columnFilters);
}

Expand Down

0 comments on commit 79d6ebd

Please sign in to comment.