From 084ab145aa19270ee6e3569600368d054673676d Mon Sep 17 00:00:00 2001 From: Jerome Gout Date: Tue, 26 Nov 2024 15:53:29 +0100 Subject: [PATCH] [4234] Make rows resizable in table representation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: https://github.com/eclipse-sirius/sirius-web/issues/4234 Signed-off-by: Jerome Gout Signed-off-by: Florian ROUËNÉ --- CHANGELOG.adoc | 3 +- ...ableRepresentationDescriptionProvider.java | 2 + ...ableRepresentationDescriptionProvider.java | 2 + ...ayaTableRowControllerIntegrationTests.java | 137 ++++++++++++++++++ ...ableEditingContextDescriptionProvider.java | 2 + .../tables/TableEventProcessor.java | 2 +- .../tables/dto/ResizeTableRowInput.java | 26 ++++ .../handlers/ResizeTableRowEventHandler.java | 83 +++++++++++ .../src/main/resources/schema/table.graphqls | 14 ++ .../MutationResizeTableRowDataFetcher.java | 60 ++++++++ .../graphql/ResizeTableRowMutationRunner.java | 60 ++++++++ .../sirius/components/tables/Line.java | 28 ++++ .../tables/components/LineComponent.java | 24 ++- .../tables/components/LineComponentProps.java | 29 ++-- .../tables/components/TableComponent.java | 2 +- .../tables/descriptions/LineDescription.java | 28 ++++ .../tables/elements/LineElementProps.java | 21 ++- .../tables/events/ResizeTableRowEvent.java | 27 ++++ .../tables/renderer/TableElementFactory.java | 2 + .../representation/useTableSubscription.ts | 2 + .../src/rows/ResizeRowHandler.tsx | 119 +++++++++++++++ .../src/rows/ResizeRowHandler.types.ts | 56 +++++++ .../src/rows/RowHeader.tsx | 2 +- .../src/table/TableContent.tsx | 17 ++- .../src/table/TableContent.types.ts | 2 + .../table/ViewTableDescriptionConverter.java | 2 + 26 files changed, 730 insertions(+), 22 deletions(-) create mode 100644 packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/tables/PapayaTableRowControllerIntegrationTests.java create mode 100644 packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/dto/ResizeTableRowInput.java create mode 100644 packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/handlers/ResizeTableRowEventHandler.java create mode 100644 packages/tables/backend/sirius-components-tables-graphql/src/main/java/org/eclipse/sirius/components/tables/graphql/datafetchers/mutation/MutationResizeTableRowDataFetcher.java create mode 100644 packages/tables/backend/sirius-components-tables-tests/src/main/java/org/eclipse/sirius/components/tables/tests/graphql/ResizeTableRowMutationRunner.java create mode 100644 packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/events/ResizeTableRowEvent.java create mode 100644 packages/tables/frontend/sirius-components-tables/src/rows/ResizeRowHandler.tsx create mode 100644 packages/tables/frontend/sirius-components-tables/src/rows/ResizeRowHandler.types.ts diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e58f6999def..040bb75b711 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -89,7 +89,8 @@ Specifiers are also encouraged to implement their own `IRestDataVersionPayloadSe - https://github.com/eclipse-sirius/sirius-web/issues/4219[#4219] [table] Improve front-end performance - https://github.com/eclipse-sirius/sirius-web/issues/3823[#3823] [table] Remove cell type to use `ICellDescription` - +- https://github.com/eclipse-sirius/sirius-web/issues/4231[#4231] [table] Make table's column resizable +- https://github.com/eclipse-sirius/sirius-web/issues/4234[#4234] [table] Make table's row resizable == v2024.11.0 diff --git a/packages/sirius-web/backend/sirius-web-papaya/src/main/java/org/eclipse/sirius/web/papaya/representations/table/PackageTableRepresentationDescriptionProvider.java b/packages/sirius-web/backend/sirius-web-papaya/src/main/java/org/eclipse/sirius/web/papaya/representations/table/PackageTableRepresentationDescriptionProvider.java index e2ece4f8705..a6177ccc6d5 100644 --- a/packages/sirius-web/backend/sirius-web-papaya/src/main/java/org/eclipse/sirius/web/papaya/representations/table/PackageTableRepresentationDescriptionProvider.java +++ b/packages/sirius-web/backend/sirius-web-papaya/src/main/java/org/eclipse/sirius/web/papaya/representations/table/PackageTableRepresentationDescriptionProvider.java @@ -90,6 +90,8 @@ public List getRepresentationDescriptions(IEditingCo .headerLabelProvider(headerLabelProvider) .headerIconURLsProvider(headerIconURLsProvider) .headerIndexLabelProvider(headerIndexLabelProvider) + .isResizablePredicate(variableManager -> true) + .initialHeightProvider(variableManager -> 53) .build(); var tableDescription = TableDescription.newTableDescription(TABLE_DESCRIPTION_ID) diff --git a/packages/sirius-web/backend/sirius-web-papaya/src/main/java/org/eclipse/sirius/web/papaya/representations/table/ProjectTableRepresentationDescriptionProvider.java b/packages/sirius-web/backend/sirius-web-papaya/src/main/java/org/eclipse/sirius/web/papaya/representations/table/ProjectTableRepresentationDescriptionProvider.java index 690789e2d50..16f1a6efe1e 100644 --- a/packages/sirius-web/backend/sirius-web-papaya/src/main/java/org/eclipse/sirius/web/papaya/representations/table/ProjectTableRepresentationDescriptionProvider.java +++ b/packages/sirius-web/backend/sirius-web-papaya/src/main/java/org/eclipse/sirius/web/papaya/representations/table/ProjectTableRepresentationDescriptionProvider.java @@ -74,6 +74,8 @@ public List getRepresentationDescriptions(IEditingCo .headerLabelProvider(variableManager -> "") .headerIconURLsProvider(variableManager -> List.of()) .headerIndexLabelProvider(variableManager -> "") + .isResizablePredicate(variableManager -> true) + .initialHeightProvider(variableManager -> 53) .build(); var tableDescription = TableDescription.newTableDescription(TABLE_DESCRIPTION_ID) diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/tables/PapayaTableRowControllerIntegrationTests.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/tables/PapayaTableRowControllerIntegrationTests.java new file mode 100644 index 00000000000..1cd14eeb879 --- /dev/null +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/application/controllers/tables/PapayaTableRowControllerIntegrationTests.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * 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.Optional; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; + +import org.eclipse.sirius.components.collaborative.dto.CreateRepresentationInput; +import org.eclipse.sirius.components.collaborative.tables.TableRefreshedEventPayload; +import org.eclipse.sirius.components.collaborative.tables.dto.ResizeTableRowInput; +import org.eclipse.sirius.components.core.api.SuccessPayload; +import org.eclipse.sirius.components.tables.Line; +import org.eclipse.sirius.components.tables.tests.graphql.ResizeTableRowMutationRunner; +import org.eclipse.sirius.web.AbstractIntegrationTests; +import org.eclipse.sirius.web.data.PapayaIdentifiers; +import org.eclipse.sirius.web.tests.services.api.IGivenCreatedTableSubscription; +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.core.publisher.Flux; +import reactor.test.StepVerifier; + +/** + * Integration tests of the table's row with a papaya model. + * + * @author Jerome Gout + */ +@Transactional +@SuppressWarnings("checkstyle:MultipleStringLiterals") +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {"sirius.web.test.enabled=studio"}) +public class PapayaTableRowControllerIntegrationTests extends AbstractIntegrationTests { + + private static final String MISSING_TABLE = "Missing table"; + + @Autowired + private IGivenInitialServerState givenInitialServerState; + + @Autowired + private IGivenCreatedTableSubscription givenCreatedTableSubscription; + + @Autowired + private ResizeTableRowMutationRunner resizeTableRowMutationRunner; + + + @BeforeEach + public void beforeEach() { + this.givenInitialServerState.initialize(); + } + + private Flux givenSubscriptionToTable() { + var input = new CreateRepresentationInput( + UUID.randomUUID(), + PapayaIdentifiers.PAPAYA_PROJECT.toString(), + "papaya_package_table_description", + PapayaIdentifiers.SIRIUS_WEB_DOMAIN_PACKAGE.toString(), + "Table" + ); + return this.givenCreatedTableSubscription.createAndSubscribe(input); + } + + @Test + @DisplayName("Given a table, when a row resize mutation is triggered, then the representation is refreshed with the new row height") + @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 givenTableWhenRowResizeMutationTriggeredThenTheRepresentationIsRefreshedWithNewRowHeight() { + var flux = this.givenSubscriptionToTable(); + + var rowRef = new AtomicReference(); + var tableId = new AtomicReference(); + + Consumer initialTableContentConsumer = payload -> Optional.of(payload) + .filter(TableRefreshedEventPayload.class::isInstance) + .map(TableRefreshedEventPayload.class::cast) + .map(TableRefreshedEventPayload::table) + .ifPresentOrElse(table -> { + tableId.set(table.getId()); + assertThat(table).isNotNull(); + assertThat(table.getLines()).hasSize(2); + rowRef.set(table.getLines().get(0)); + assertThat(table.getLines().get(0).getHeight()).isEqualTo(53); + }, () -> fail(MISSING_TABLE)); + + Runnable resizeRow = () -> { + var lineToChange = rowRef.get(); + var resizeTableRowInput = new ResizeTableRowInput( + UUID.randomUUID(), + PapayaIdentifiers.PAPAYA_PROJECT.toString(), + tableId.get(), tableId.get(), lineToChange.getId().toString(), 100); + var result = this.resizeTableRowMutationRunner.run(resizeTableRowInput); + + String typename = JsonPath.read(result, "$.data.resizeTableRow.__typename"); + assertThat(typename).isEqualTo(SuccessPayload.class.getSimpleName()); + }; + + Consumer updatedTableContentConsumer = payload -> Optional.of(payload) + .filter(TableRefreshedEventPayload.class::isInstance) + .map(TableRefreshedEventPayload.class::cast) + .map(TableRefreshedEventPayload::table) + .ifPresentOrElse(table -> { + assertThat(table).isNotNull(); + assertThat(table.getLines()).hasSize(2); + assertThat(table.getLines().get(0).getHeight()).isEqualTo(100); + }, () -> fail(MISSING_TABLE)); + + StepVerifier.create(flux) + .consumeNextWith(initialTableContentConsumer) + .then(resizeRow) + .consumeNextWith(updatedTableContentConsumer) + .thenCancel() + .verify(Duration.ofSeconds(10)); + } +} diff --git a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/forms/FormWithTableEditingContextDescriptionProvider.java b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/forms/FormWithTableEditingContextDescriptionProvider.java index a1176795ba7..61a2cb242cd 100644 --- a/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/forms/FormWithTableEditingContextDescriptionProvider.java +++ b/packages/sirius-web/backend/sirius-web/src/test/java/org/eclipse/sirius/web/services/forms/FormWithTableEditingContextDescriptionProvider.java @@ -141,6 +141,8 @@ private TableWidgetDescription getTableWidgetDescription() { .headerLabelProvider(variableManager -> "") .headerIconURLsProvider(variableManager -> List.of()) .headerIndexLabelProvider(variableManager -> "") + .isResizablePredicate(variableManager -> false) + .initialHeightProvider(variableManager -> 0) .build(); TableDescription tableDescription = TableDescription.newTableDescription(FORM_WITH_TABLE_ID) diff --git a/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/TableEventProcessor.java b/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/TableEventProcessor.java index 1035499dd81..1c241249610 100644 --- a/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/TableEventProcessor.java +++ b/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/TableEventProcessor.java @@ -164,7 +164,7 @@ private boolean shouldRefresh(ChangeDescription changeDescription) { private IRepresentationRefreshPolicy getDefaultRefreshPolicy() { return changeDescription -> switch (changeDescription.getKind()) { - case ChangeKind.SEMANTIC_CHANGE, ChangeKind.REPRESENTATION_RENAMING, ChangeKind.REPRESENTATION_DELETION, ChangeKind.REPRESENTATION_CREATION, TableChangeKind.TABLE_LAYOUT_CHANGE -> true; + case ChangeKind.SEMANTIC_CHANGE, TableChangeKind.TABLE_LAYOUT_CHANGE -> true; default -> false; }; } diff --git a/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/dto/ResizeTableRowInput.java b/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/dto/ResizeTableRowInput.java new file mode 100644 index 00000000000..5e237498c40 --- /dev/null +++ b/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/dto/ResizeTableRowInput.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.collaborative.tables.dto; + +import java.util.UUID; + +import org.eclipse.sirius.components.collaborative.tables.api.ITableInput; + +/** + * The input object for the resize of a row mutation. + * + * @author Jerome Gout + */ +public record ResizeTableRowInput(UUID id, String editingContextId, String representationId, String tableId, String rowId, int height) implements ITableInput { +} diff --git a/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/handlers/ResizeTableRowEventHandler.java b/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/handlers/ResizeTableRowEventHandler.java new file mode 100644 index 00000000000..48dd49dee10 --- /dev/null +++ b/packages/tables/backend/sirius-components-collaborative-tables/src/main/java/org/eclipse/sirius/components/collaborative/tables/handlers/ResizeTableRowEventHandler.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.collaborative.tables.handlers; + +import java.util.List; +import java.util.Map; + +import org.eclipse.sirius.components.collaborative.api.ChangeDescription; +import org.eclipse.sirius.components.collaborative.api.ChangeKind; +import org.eclipse.sirius.components.collaborative.api.Monitoring; +import org.eclipse.sirius.components.collaborative.tables.TableChangeKind; +import org.eclipse.sirius.components.collaborative.tables.api.ITableContext; +import org.eclipse.sirius.components.collaborative.tables.api.ITableEventHandler; +import org.eclipse.sirius.components.collaborative.tables.api.ITableInput; +import org.eclipse.sirius.components.collaborative.tables.dto.EditTextfieldCellInput; +import org.eclipse.sirius.components.collaborative.tables.dto.ResizeTableRowInput; +import org.eclipse.sirius.components.collaborative.tables.messages.ICollaborativeTableMessageService; +import org.eclipse.sirius.components.core.api.ErrorPayload; +import org.eclipse.sirius.components.core.api.IEditingContext; +import org.eclipse.sirius.components.core.api.IPayload; +import org.eclipse.sirius.components.core.api.SuccessPayload; +import org.eclipse.sirius.components.tables.descriptions.TableDescription; +import org.eclipse.sirius.components.tables.events.ResizeTableRowEvent; +import org.springframework.stereotype.Service; + +import io.micrometer.core.instrument.Counter; +import io.micrometer.core.instrument.MeterRegistry; +import reactor.core.publisher.Sinks; + +/** + * Handle row resize event. + * + * @author Jerome Gout + */ +@Service +public class ResizeTableRowEventHandler implements ITableEventHandler { + + private final ICollaborativeTableMessageService messageService; + + private final Counter counter; + + public ResizeTableRowEventHandler(ICollaborativeTableMessageService messageService, MeterRegistry meterRegistry) { + this.messageService = messageService; + this.counter = Counter.builder(Monitoring.EVENT_HANDLER) + .tag(Monitoring.NAME, this.getClass().getSimpleName()) + .register(meterRegistry); + } + + @Override + public boolean canHandle(ITableInput tableInput) { + return tableInput instanceof ResizeTableRowInput; + } + + @Override + public void handle(Sinks.One payloadSink, Sinks.Many changeDescriptionSink, IEditingContext editingContext, ITableContext tableContext, TableDescription tableDescription, ITableInput tableInput) { + this.counter.increment(); + + ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, tableInput.representationId(), tableInput); + String message = this.messageService.invalidInput(tableInput.getClass().getSimpleName(), EditTextfieldCellInput.class.getSimpleName()); + IPayload payload = new ErrorPayload(tableInput.id(), message); + + if (tableInput instanceof ResizeTableRowInput resizeTableRowInput) { + var resizeTableRowEvent = new ResizeTableRowEvent(resizeTableRowInput.rowId(), resizeTableRowInput.height()); + tableContext.getTableEvents().add(new ResizeTableRowEvent(resizeTableRowInput.rowId(), resizeTableRowInput.height())); + payload = new SuccessPayload(resizeTableRowInput.id()); + changeDescription = new ChangeDescription(TableChangeKind.TABLE_LAYOUT_CHANGE, tableInput.representationId(), tableInput, + Map.of(TableChangeKind.TABLE_EVENTS_PARAM, List.of(resizeTableRowEvent))); + } + + payloadSink.tryEmitValue(payload); + changeDescriptionSink.tryEmitNext(changeDescription); + } +} diff --git a/packages/tables/backend/sirius-components-collaborative-tables/src/main/resources/schema/table.graphqls b/packages/tables/backend/sirius-components-collaborative-tables/src/main/resources/schema/table.graphqls index 0fce774b7bf..c8cb3d3c29a 100644 --- a/packages/tables/backend/sirius-components-collaborative-tables/src/main/resources/schema/table.graphqls +++ b/packages/tables/backend/sirius-components-collaborative-tables/src/main/resources/schema/table.graphqls @@ -46,6 +46,8 @@ type Line { headerLabel: String! headerIconURLs: [String!]! headerIndexLabel: String! + height: Int! + isResizable: Boolean! } type PaginationData { @@ -121,6 +123,7 @@ extend type Mutation { editTextfieldCell(input: EditTextfieldCellInput!): EditTextfieldCellPayload! resizeTableColumn(input: ResizeTableColumnInput!): ResizeTableColumnPayload! changeTableColumnVisibility(input: ChangeTableColumnVisibilityInput!): ChangeTableColumnVisibilityPayload! + resizeTableRow(input: ResizeTableRowInput!): ResizeTableRowPayload! } input EditCheckboxCellInput { @@ -192,3 +195,14 @@ input ColumnVisibility { } union ChangeTableColumnVisibilityPayload = ErrorPayload | SuccessPayload + +input ResizeTableRowInput { + id: ID! + editingContextId: ID! + representationId: ID! + tableId: ID! + rowId: ID! + height: Int! +} + +union ResizeTableRowPayload = ErrorPayload | SuccessPayload \ No newline at end of file diff --git a/packages/tables/backend/sirius-components-tables-graphql/src/main/java/org/eclipse/sirius/components/tables/graphql/datafetchers/mutation/MutationResizeTableRowDataFetcher.java b/packages/tables/backend/sirius-components-tables-graphql/src/main/java/org/eclipse/sirius/components/tables/graphql/datafetchers/mutation/MutationResizeTableRowDataFetcher.java new file mode 100644 index 00000000000..0ff71d81e2c --- /dev/null +++ b/packages/tables/backend/sirius-components-tables-graphql/src/main/java/org/eclipse/sirius/components/tables/graphql/datafetchers/mutation/MutationResizeTableRowDataFetcher.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.mutation; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + +import org.eclipse.sirius.components.annotations.spring.graphql.MutationDataFetcher; +import org.eclipse.sirius.components.collaborative.tables.dto.ResizeTableRowInput; +import org.eclipse.sirius.components.core.api.IPayload; +import org.eclipse.sirius.components.graphql.api.IDataFetcherWithFieldCoordinates; +import org.eclipse.sirius.components.graphql.api.IEditingContextDispatcher; +import org.eclipse.sirius.components.graphql.api.IExceptionWrapper; + +import graphql.schema.DataFetchingEnvironment; + +/** + * Data fetcher used to resize a table row. + * + * @author Jerome Gout + */ +@MutationDataFetcher(type = "Mutation", field = "resizeTableRow") +public class MutationResizeTableRowDataFetcher implements IDataFetcherWithFieldCoordinates> { + + private static final String INPUT_ARGUMENT = "input"; + + private final ObjectMapper objectMapper; + + private final IExceptionWrapper exceptionWrapper; + + private final IEditingContextDispatcher editingContextDispatcher; + + public MutationResizeTableRowDataFetcher(ObjectMapper objectMapper, IExceptionWrapper exceptionWrapper, IEditingContextDispatcher editingContextDispatcher) { + this.objectMapper = Objects.requireNonNull(objectMapper); + this.exceptionWrapper = Objects.requireNonNull(exceptionWrapper); + this.editingContextDispatcher = Objects.requireNonNull(editingContextDispatcher); + } + + @Override + public CompletableFuture get(DataFetchingEnvironment environment) throws Exception { + Object argument = environment.getArgument(INPUT_ARGUMENT); + var input = this.objectMapper.convertValue(argument, ResizeTableRowInput.class); + + return this.exceptionWrapper.wrapMono(() -> this.editingContextDispatcher.dispatchMutation(input.editingContextId(), input), input).toFuture(); + } + +} diff --git a/packages/tables/backend/sirius-components-tables-tests/src/main/java/org/eclipse/sirius/components/tables/tests/graphql/ResizeTableRowMutationRunner.java b/packages/tables/backend/sirius-components-tables-tests/src/main/java/org/eclipse/sirius/components/tables/tests/graphql/ResizeTableRowMutationRunner.java new file mode 100644 index 00000000000..a3975846c89 --- /dev/null +++ b/packages/tables/backend/sirius-components-tables-tests/src/main/java/org/eclipse/sirius/components/tables/tests/graphql/ResizeTableRowMutationRunner.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.tests.graphql; + +import java.util.Objects; + +import org.eclipse.sirius.components.collaborative.tables.dto.ResizeTableRowInput; +import org.eclipse.sirius.components.graphql.tests.api.IGraphQLRequestor; +import org.eclipse.sirius.components.graphql.tests.api.IMutationRunner; +import org.springframework.stereotype.Service; + +/** + * Used to change the row size in table with the GraphQL API. + * + * @author Jerome Gout + */ +@Service +public class ResizeTableRowMutationRunner implements IMutationRunner { + + private static final String RESIZE_ROW_MUTATION = """ + mutation resizeTableRow($input: ResizeTableRowInput!) { + resizeTableRow(input: $input) { + __typename + ... on ErrorPayload { + messages { + body + level + } + } + ... on SuccessPayload { + messages { + body + level + } + } + } + } + """; + + private final IGraphQLRequestor graphQLRequestor; + + public ResizeTableRowMutationRunner(IGraphQLRequestor graphQLRequestor) { + this.graphQLRequestor = Objects.requireNonNull(graphQLRequestor); + } + + @Override + public String run(ResizeTableRowInput input) { + return this.graphQLRequestor.execute(RESIZE_ROW_MUTATION, input); + } +} diff --git a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/Line.java b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/Line.java index 7076119b078..676a351b4ca 100644 --- a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/Line.java +++ b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/Line.java @@ -43,6 +43,10 @@ public final class Line { private String headerIndexLabel; + private int height; + + private boolean resizable; + private Line() { // Prevent instantiation } @@ -79,6 +83,14 @@ public String getHeaderIndexLabel() { return this.headerIndexLabel; } + public int getHeight() { + return this.height; + } + + public boolean isResizable() { + return this.resizable; + } + public static Builder newLine(UUID id) { return new Builder(id); } @@ -113,6 +125,10 @@ public static final class Builder { private String headerIndexLabel; + private int height; + + private boolean resizable; + private Builder(UUID id) { this.id = Objects.requireNonNull(id); } @@ -152,6 +168,16 @@ public Builder headerIndexLabel(String headerIndexLabel) { return this; } + public Builder height(int height) { + this.height = height; + return this; + } + + public Builder resizable(boolean resizable) { + this.resizable = resizable; + return this; + } + public Line build() { Line line = new Line(); line.id = Objects.requireNonNull(this.id); @@ -162,6 +188,8 @@ public Line build() { line.headerLabel = Objects.requireNonNull(this.headerLabel); line.headerIconURLs = Objects.requireNonNull(this.headerIconURLs); line.headerIndexLabel = Objects.requireNonNull(this.headerIndexLabel); + line.height = this.height; + line.resizable = this.resizable; return line; } } diff --git a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/LineComponent.java b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/LineComponent.java index 8988c48677c..f6528d1aeaa 100644 --- a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/LineComponent.java +++ b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/LineComponent.java @@ -34,6 +34,7 @@ import org.eclipse.sirius.components.tables.descriptions.SelectCellDescription; import org.eclipse.sirius.components.tables.descriptions.TextfieldCellDescription; import org.eclipse.sirius.components.tables.elements.LineElementProps; +import org.eclipse.sirius.components.tables.events.ResizeTableRowEvent; /** * The component used to render lines. @@ -78,7 +79,7 @@ public Element render() { private Element doRender(VariableManager lineVariableManager, String targetObjectId, Optional optionalPreviousLine) { LineDescription lineDescription = this.props.lineDescription(); - UUID lineId = optionalPreviousLine.map(Line::getId).orElseGet(() -> this.computeLineId(targetObjectId)); + UUID rowId = optionalPreviousLine.map(Line::getId).orElseGet(() -> this.computeLineId(targetObjectId)); String targetObjectKind = lineDescription.getTargetObjectKindProvider().apply(lineVariableManager); @@ -86,12 +87,25 @@ private Element doRender(VariableManager lineVariableManager, String targetObjec List headerIconURLs = lineDescription.getHeaderIconURLsProvider().apply(lineVariableManager); String headerIndexLabel = lineDescription.getHeaderIndexLabelProvider().apply(lineVariableManager); - var cells = this.getCells(lineVariableManager, lineId); + var cells = this.getCells(lineVariableManager, rowId); + boolean resizable = lineDescription.getIsResizablePredicate().test(lineVariableManager); + Integer initialHeight = lineDescription.getInitialHeightProvider().apply(lineVariableManager); List children = new ArrayList<>(); children.addAll(cells); - var lineElementProps = LineElementProps.newLineElementProps(lineId) + var height = this.props.tableEvents().stream() + .filter(ResizeTableRowEvent.class::isInstance) + .map(ResizeTableRowEvent.class::cast) + .filter(resizeTableRowEvent -> resizeTableRowEvent.rowId().equals(rowId.toString())) + .findFirst() + .map(ResizeTableRowEvent::height) + .orElseGet(() -> optionalPreviousLine.stream() + .map(Line::getHeight) + .findFirst() + .orElse(initialHeight)); + + var rowElementProps = LineElementProps.newLineElementProps(rowId) .descriptionId(lineDescription.getId()) .targetObjectId(targetObjectId) .targetObjectKind(targetObjectKind) @@ -99,9 +113,11 @@ private Element doRender(VariableManager lineVariableManager, String targetObjec .headerIconURLs(headerIconURLs) .headerIndexLabel(headerIndexLabel) .children(children) + .resizable(resizable) + .height(height) .build(); - return new Element(LineElementProps.TYPE, lineElementProps); + return new Element(LineElementProps.TYPE, rowElementProps); } private List getCells(VariableManager lineVariableManager, UUID parentLineId) { diff --git a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/LineComponentProps.java b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/LineComponentProps.java index 58bdee5c206..1d508e2b4e1 100644 --- a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/LineComponentProps.java +++ b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/LineComponentProps.java @@ -19,6 +19,7 @@ import org.eclipse.sirius.components.representations.VariableManager; import org.eclipse.sirius.components.tables.descriptions.ICellDescription; import org.eclipse.sirius.components.tables.descriptions.LineDescription; +import org.eclipse.sirius.components.tables.events.ITableEvent; import org.eclipse.sirius.components.tables.renderer.TableRenderingCache; /** @@ -26,16 +27,24 @@ * * @author arichard */ -public record LineComponentProps(VariableManager variableManager, LineDescription lineDescription, List cellDescriptions, ILinesRequestor linesRequestor, TableRenderingCache cache, - String parentElementId, List semanticRowElements) implements IProps { +public record LineComponentProps( + VariableManager variableManager, + LineDescription lineDescription, + List cellDescriptions, + ILinesRequestor linesRequestor, + TableRenderingCache cache, + String parentElementId, + List semanticRowElements, + List tableEvents) implements IProps { - public LineComponentProps(VariableManager variableManager, LineDescription lineDescription, List cellDescriptions, ILinesRequestor linesRequestor, TableRenderingCache cache, String parentElementId, List semanticRowElements) { - this.variableManager = Objects.requireNonNull(variableManager); - this.lineDescription = Objects.requireNonNull(lineDescription); - this.cellDescriptions = Objects.requireNonNull(cellDescriptions); - this.linesRequestor = Objects.requireNonNull(linesRequestor); - this.cache = Objects.requireNonNull(cache); - this.parentElementId = Objects.requireNonNull(parentElementId); - this.semanticRowElements = Objects.requireNonNull(semanticRowElements); + public LineComponentProps { + Objects.requireNonNull(variableManager); + Objects.requireNonNull(lineDescription); + Objects.requireNonNull(cellDescriptions); + Objects.requireNonNull(linesRequestor); + Objects.requireNonNull(cache); + Objects.requireNonNull(parentElementId); + Objects.requireNonNull(semanticRowElements); + Objects.requireNonNull(tableEvents); } } diff --git a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/TableComponent.java b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/TableComponent.java index 7e6a6548976..20bde4696be 100644 --- a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/TableComponent.java +++ b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/components/TableComponent.java @@ -69,7 +69,7 @@ public Element render() { var previousLines = optionalPreviousTable.map(previousTable -> tableElementRequestor.getRootLines(previousTable, tableDescription.getLineDescription())).orElse(List.of()); ILinesRequestor linesRequestor = new LinesRequestor(previousLines); - var lineComponentProps = new LineComponentProps(variableManager, tableDescription.getLineDescription(), tableDescription.getCellDescriptions(), linesRequestor, cache, id, paginatedData.rows()); + var lineComponentProps = new LineComponentProps(variableManager, tableDescription.getLineDescription(), tableDescription.getCellDescriptions(), linesRequestor, cache, id, paginatedData.rows(), this.props.tableEvents()); var childrenLine = new Element(LineComponent.class, lineComponentProps); List children = new ArrayList<>(childrenColumns); diff --git a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/descriptions/LineDescription.java b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/descriptions/LineDescription.java index 8096b74bc77..2d983d52d5f 100644 --- a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/descriptions/LineDescription.java +++ b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/descriptions/LineDescription.java @@ -45,6 +45,10 @@ public final class LineDescription { private Function headerIndexLabelProvider; + private Function initialHeightProvider; + + private Predicate isResizablePredicate; + private LineDescription() { // Prevent instantiation } @@ -81,6 +85,14 @@ public Function getHeaderIndexLabelProvider() { return this.headerIndexLabelProvider; } + public Function getInitialHeightProvider() { + return this.initialHeightProvider; + } + + public Predicate getIsResizablePredicate() { + return this.isResizablePredicate; + } + public static Builder newLineDescription(String id) { return new Builder(id); } @@ -115,6 +127,10 @@ public static final class Builder { private Function headerIndexLabelProvider; + private Function initialHeightProvider; + + private Predicate isResizablePredicate; + public Builder(String id) { this.id = Objects.requireNonNull(id); } @@ -154,6 +170,16 @@ public Builder headerIndexLabelProvider(Function header return this; } + public Builder initialHeightProvider(Function initialHeightProvider) { + this.initialHeightProvider = Objects.requireNonNull(initialHeightProvider); + return this; + } + + public Builder isResizablePredicate(Predicate isResizablePredicate) { + this.isResizablePredicate = Objects.requireNonNull(isResizablePredicate); + return this; + } + public LineDescription build() { LineDescription lineDescription = new LineDescription(); lineDescription.id = Objects.requireNonNull(this.id); @@ -164,6 +190,8 @@ public LineDescription build() { lineDescription.headerLabelProvider = Objects.requireNonNull(this.headerLabelProvider); lineDescription.headerIconURLsProvider = Objects.requireNonNull(this.headerIconURLsProvider); lineDescription.headerIndexLabelProvider = Objects.requireNonNull(this.headerIndexLabelProvider); + lineDescription.initialHeightProvider = Objects.requireNonNull(this.initialHeightProvider); + lineDescription.isResizablePredicate = Objects.requireNonNull(this.isResizablePredicate); return lineDescription; } } diff --git a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/elements/LineElementProps.java b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/elements/LineElementProps.java index 7f22762b693..b087452266d 100644 --- a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/elements/LineElementProps.java +++ b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/elements/LineElementProps.java @@ -32,7 +32,9 @@ public record LineElementProps( List children, String headerLabel, List headerIconURLs, - String headerIndexLabel) implements IProps { + String headerIndexLabel, + int height, + boolean resizable) implements IProps { public static final String TYPE = "Line"; @@ -80,6 +82,10 @@ public static final class Builder { private String headerIndexLabel; + private int height; + + private boolean resizable; + private Builder(UUID id) { this.id = Objects.requireNonNull(id); } @@ -119,8 +125,19 @@ public Builder headerIndexLabel(String headerIndexLabel) { return this; } + public Builder height(int height) { + this.height = height; + return this; + } + + public Builder resizable(boolean resizable) { + this.resizable = resizable; + return this; + } + + public LineElementProps build() { - return new LineElementProps(this.id, this.descriptionId, this.targetObjectId, this.targetObjectKind, this.children, this.headerLabel, this.headerIconURLs, this.headerIndexLabel); + return new LineElementProps(this.id, this.descriptionId, this.targetObjectId, this.targetObjectKind, this.children, this.headerLabel, this.headerIconURLs, this.headerIndexLabel, this.height, this.resizable); } } } diff --git a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/events/ResizeTableRowEvent.java b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/events/ResizeTableRowEvent.java new file mode 100644 index 00000000000..af987e2a649 --- /dev/null +++ b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/events/ResizeTableRowEvent.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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.events; + +import java.util.Objects; + +/** + * Table Event to handle a row resizing. + * + * @author Jerome Gout + */ +public record ResizeTableRowEvent(String rowId, int height) implements ITableEvent { + + public ResizeTableRowEvent { + Objects.requireNonNull(rowId); + } +} diff --git a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/renderer/TableElementFactory.java b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/renderer/TableElementFactory.java index 3206c859655..b119e3cb1dc 100644 --- a/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/renderer/TableElementFactory.java +++ b/packages/tables/backend/sirius-components-tables/src/main/java/org/eclipse/sirius/components/tables/renderer/TableElementFactory.java @@ -115,6 +115,8 @@ private Line instantiateLine(IProps props, List children) { .headerIconURLs(lineElementProps.headerIconURLs()) .headerIndexLabel(lineElementProps.headerIndexLabel()) .cells(cells) + .resizable(lineElementProps.resizable()) + .height(lineElementProps.height()) .build(); } return null; diff --git a/packages/tables/frontend/sirius-components-tables/src/representation/useTableSubscription.ts b/packages/tables/frontend/sirius-components-tables/src/representation/useTableSubscription.ts index a4ee65abfeb..5c94666020c 100644 --- a/packages/tables/frontend/sirius-components-tables/src/representation/useTableSubscription.ts +++ b/packages/tables/frontend/sirius-components-tables/src/representation/useTableSubscription.ts @@ -55,6 +55,8 @@ export const getTableEventSubscription = ` headerLabel headerIconURLs headerIndexLabel + height + isResizable cells { __typename id diff --git a/packages/tables/frontend/sirius-components-tables/src/rows/ResizeRowHandler.tsx b/packages/tables/frontend/sirius-components-tables/src/rows/ResizeRowHandler.tsx new file mode 100644 index 00000000000..fdf29b12b3c --- /dev/null +++ b/packages/tables/frontend/sirius-components-tables/src/rows/ResizeRowHandler.tsx @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +import { gql, useMutation } from '@apollo/client'; +import { useReporting } from '@eclipse-sirius/sirius-components-core'; +import { memo, useRef } from 'react'; +import { makeStyles } from 'tss-react/mui'; +import { + DragState, + GQLResizeRowData, + GQLResizeRowInput, + GQLResizeRowVariables, + ResizeRowHandlerProps, +} from './ResizeRowHandler.types'; + +const useStyles = makeStyles()(() => ({ + handler: { + position: 'absolute', + margin: 0, + backgroundColor: '#B3BFC5', + borderColor: '#B3BFC5', + borderRadius: '2px', + width: '80%', + height: '4px', + bottom: 0, + left: '15px', + cursor: 'row-resize', + }, +})); + +export const resizeRowMutation = gql` + mutation resizeTableRow($input: ResizeTableRowInput!) { + resizeTableRow(input: $input) { + __typename + ... on ErrorPayload { + messages { + body + level + } + } + ... on SuccessPayload { + messages { + body + level + } + } + } + } +`; + +export const ResizeRowHandler = memo( + ({ editingContextId, representationId, table, readOnly, row }: ResizeRowHandlerProps) => { + const { classes } = useStyles(); + + const [mutationResizeRow, mutationResizeRowResult] = useMutation( + resizeRowMutation + ); + useReporting(mutationResizeRowResult, (data: GQLResizeRowData) => data.resizeTableRow); + + const resizeRow = (rowId: string, height: number) => { + const input: GQLResizeRowInput = { + id: crypto.randomUUID(), + editingContextId, + representationId, + tableId: table.id, + rowId, + height, + }; + + mutationResizeRow({ variables: { input } }); + }; + + const dragState = useRef({ + isDragging: false, + height: 0, + trElement: undefined, + }); + + const handleMouseDown = (e) => { + e.preventDefault(); + + dragState.current = { + isDragging: true, + height: parseInt(window.getComputedStyle(e.target.parentElement.parentElement).height, 10), + trElement: e.target.parentElement.parentElement, + }; + + const handleMouseMove = (e: MouseEvent) => { + if (dragState.current.isDragging) { + if (dragState.current.trElement) { + dragState.current.trElement.style.height = `${dragState.current.height + e.movementY}px`; + dragState.current.height += e.movementY; + } + } + }; + + const handleMouseUp = (_) => { + dragState.current.isDragging = false; + resizeRow(row.id, dragState.current.height); + document.removeEventListener('mousemove', handleMouseMove); + document.removeEventListener('mouseup', handleMouseUp); + }; + + document.addEventListener('mousemove', handleMouseMove); + document.addEventListener('mouseup', handleMouseUp); + }; + + return !readOnly && row.isResizable ?
: null; + } +); diff --git a/packages/tables/frontend/sirius-components-tables/src/rows/ResizeRowHandler.types.ts b/packages/tables/frontend/sirius-components-tables/src/rows/ResizeRowHandler.types.ts new file mode 100644 index 00000000000..41d456b75da --- /dev/null +++ b/packages/tables/frontend/sirius-components-tables/src/rows/ResizeRowHandler.types.ts @@ -0,0 +1,56 @@ +/******************************************************************************* + * 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 + *******************************************************************************/ +import { GQLErrorPayload, GQLSuccessPayload } from '@eclipse-sirius/sirius-components-core'; +import { GQLLine, GQLTable } from '../table/TableContent.types'; + +export interface ResizeRowHandlerProps { + editingContextId: string; + representationId: string; + table: GQLTable; + readOnly: boolean; + row: GQLLine; +} + +export interface DragState { + isDragging: boolean; + height: number; + trElement: HTMLElement | undefined; +} + +export interface GQLResizeColumnInput { + id: string; + editingContextId: string; + representationId: string; + tableId: string; + columnId: string; + width: number; +} + +export interface GQLResizeRowInput { + id: string; + editingContextId: string; + representationId: string; + tableId: string; + rowId: string; + height: number; +} + +export interface GQLResizeRowVariables { + input: GQLResizeRowInput; +} + +export interface GQLResizeRowData { + resizeTableRow: GQLResizeTableRowPayload; +} + +export type GQLResizeTableRowPayload = GQLErrorPayload | GQLSuccessPayload; diff --git a/packages/tables/frontend/sirius-components-tables/src/rows/RowHeader.tsx b/packages/tables/frontend/sirius-components-tables/src/rows/RowHeader.tsx index 3810462269b..ff0dca38c8e 100644 --- a/packages/tables/frontend/sirius-components-tables/src/rows/RowHeader.tsx +++ b/packages/tables/frontend/sirius-components-tables/src/rows/RowHeader.tsx @@ -19,7 +19,7 @@ import { RowHeaderProps } from './RowHeader.types'; export const RowHeader = ({ row }: RowHeaderProps) => { const theme = useTheme(); return ( - + {row.headerIndexLabel} diff --git a/packages/tables/frontend/sirius-components-tables/src/table/TableContent.tsx b/packages/tables/frontend/sirius-components-tables/src/table/TableContent.tsx index 9a07a980def..bf43c0a8d4f 100644 --- a/packages/tables/frontend/sirius-components-tables/src/table/TableContent.tsx +++ b/packages/tables/frontend/sirius-components-tables/src/table/TableContent.tsx @@ -18,6 +18,7 @@ import { CursorBasedPagination } from './CursorBasedPagination'; import { SettingsButton } from '../actions/SettingsButton'; import { useTableColumnSizing } from '../columns/useTableColumnSizing'; import { useTableColumnVisibility } from '../columns/useTableColumnVisibility'; +import { ResizeRowHandler } from '../rows/ResizeRowHandler'; import { RowHeader } from '../rows/RowHeader'; import { GQLLine, TableProps, TablePaginationState } from './TableContent.types'; import { useTableColumns } from './useTableColumns'; @@ -105,6 +106,7 @@ export const TableContent = memo( sx: { backgroundColor: 'transparent', // required to remove the default mui backgroundColor that is defined as !important cursor: 'pointer', + height: row.original.height, }, }; }, @@ -129,13 +131,24 @@ export const TableContent = memo( size: 120, }, }, - renderRowActions: ({ row }) => , + renderRowActions: ({ row }) => ( + <> + + + + ), }; if (table.stripeRow) { tableOptions.muiTableBodyProps = { sx: { - '& tr:nth-of-type(odd) > td': { + '& tr:nth-of-type(odd):not(.Mui-selected) > td': { backgroundColor: '#f5f5f5', }, }, diff --git a/packages/tables/frontend/sirius-components-tables/src/table/TableContent.types.ts b/packages/tables/frontend/sirius-components-tables/src/table/TableContent.types.ts index 768608b174c..4b4e21b0738 100644 --- a/packages/tables/frontend/sirius-components-tables/src/table/TableContent.types.ts +++ b/packages/tables/frontend/sirius-components-tables/src/table/TableContent.types.ts @@ -64,6 +64,8 @@ export interface GQLLine { headerLabel: string; headerIconURLs: string[]; headerIndexLabel: string; + height: number; + isResizable: boolean; } export interface GQLPaginationData { diff --git a/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/table/ViewTableDescriptionConverter.java b/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/table/ViewTableDescriptionConverter.java index d4e204dba57..a96fe8611b9 100644 --- a/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/table/ViewTableDescriptionConverter.java +++ b/packages/view/backend/sirius-components-view-emf/src/main/java/org/eclipse/sirius/components/view/emf/table/ViewTableDescriptionConverter.java @@ -127,6 +127,8 @@ private LineDescription convertRowDescription(org.eclipse.sirius.components.view .headerLabelProvider(variableManager -> this.evaluateString(interpreter, variableManager, rowDescription.getHeaderLabelExpression())) .headerIconURLsProvider(new ViewIconURLsProvider(interpreter, rowDescription.getHeaderIconExpression())) .headerIndexLabelProvider(variableManager -> this.evaluateString(interpreter, variableManager, rowDescription.getHeaderIndexLabelExpression())) + .isResizablePredicate(variableManager -> interpreter.evaluateExpression(variableManager.getVariables(), rowDescription.getIsResizableExpression()).asBoolean().orElse(false)) + .initialHeightProvider(variableManager -> interpreter.evaluateExpression(variableManager.getVariables(), rowDescription.getInitialHeightExpression()).asInt().orElse(-1)) .build(); }