-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4335] Add support of column reordering in table representation
Bug: #4335 Signed-off-by: Jerome Gout <[email protected]>
- Loading branch information
1 parent
5eadddf
commit 4fe74bc
Showing
20 changed files
with
533 additions
and
21 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
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
27 changes: 27 additions & 0 deletions
27
...java/org/eclipse/sirius/components/collaborative/tables/dto/ReorderTableColumnsInput.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,27 @@ | ||
/******************************************************************************* | ||
* 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 | ||
* 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.List; | ||
import java.util.UUID; | ||
|
||
import org.eclipse.sirius.components.collaborative.tables.api.ITableInput; | ||
|
||
/** | ||
* The input object for the reorder of columns mutation. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
public record ReorderTableColumnsInput(UUID id, String editingContextId, String representationId, String tableId, List<String> reorderedColumnIds) implements ITableInput { | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...ipse/sirius/components/collaborative/tables/handlers/ReorderTableColumnsEventHandler.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,78 @@ | ||
/******************************************************************************* | ||
* 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 | ||
* 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 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.ReorderTableColumnsInput; | ||
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.ReorderTableColumnsEvent; | ||
import org.springframework.stereotype.Service; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import reactor.core.publisher.Sinks; | ||
|
||
/** | ||
* Handle columns reorder event. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Service | ||
public class ReorderTableColumnsEventHandler implements ITableEventHandler { | ||
|
||
private final ICollaborativeTableMessageService messageService; | ||
|
||
private final Counter counter; | ||
|
||
public ReorderTableColumnsEventHandler(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 ReorderTableColumnsInput; | ||
} | ||
|
||
@Override | ||
public void handle(Sinks.One<IPayload> payloadSink, Sinks.Many<ChangeDescription> 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 ReorderTableColumnsInput reorderTableColumnsInput) { | ||
tableContext.getTableEvents().add(new ReorderTableColumnsEvent(reorderTableColumnsInput.reorderedColumnIds())); | ||
payload = new SuccessPayload(reorderTableColumnsInput.id()); | ||
changeDescription = new ChangeDescription(TableChangeKind.TABLE_LAYOUT_CHANGE, tableInput.representationId(), tableInput); | ||
} | ||
|
||
payloadSink.tryEmitValue(payload); | ||
changeDescriptionSink.tryEmitNext(changeDescription); | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...mponents/tables/graphql/datafetchers/mutation/MutationReorderTableColumnsDataFetcher.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,59 @@ | ||
/******************************************************************************* | ||
* 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 | ||
* 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.ReorderTableColumnsInput; | ||
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 reorder the columns of a table. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@MutationDataFetcher(type = "Mutation", field = "reorderTableColumns") | ||
public class MutationReorderTableColumnsDataFetcher implements IDataFetcherWithFieldCoordinates<CompletableFuture<IPayload>> { | ||
|
||
private static final String INPUT_ARGUMENT = "input"; | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
private final IExceptionWrapper exceptionWrapper; | ||
|
||
private final IEditingContextDispatcher editingContextDispatcher; | ||
|
||
public MutationReorderTableColumnsDataFetcher(ObjectMapper objectMapper, IExceptionWrapper exceptionWrapper, IEditingContextDispatcher editingContextDispatcher) { | ||
this.objectMapper = Objects.requireNonNull(objectMapper); | ||
this.exceptionWrapper = Objects.requireNonNull(exceptionWrapper); | ||
this.editingContextDispatcher = Objects.requireNonNull(editingContextDispatcher); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<IPayload> get(DataFetchingEnvironment environment) throws Exception { | ||
Object argument = environment.getArgument(INPUT_ARGUMENT); | ||
var input = this.objectMapper.convertValue(argument, ReorderTableColumnsInput.class); | ||
|
||
return this.exceptionWrapper.wrapMono(() -> this.editingContextDispatcher.dispatchMutation(input.editingContextId(), input), input).toFuture(); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
...org/eclipse/sirius/components/tables/tests/graphql/ReorderTableColumnsMutationRunner.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,60 @@ | ||
/******************************************************************************* | ||
* 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 | ||
* 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.ReorderTableColumnsInput; | ||
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 order of columns in table with the GraphQL API. | ||
* | ||
* @author Jerome Gout | ||
*/ | ||
@Service | ||
public class ReorderTableColumnsMutationRunner implements IMutationRunner<ReorderTableColumnsInput> { | ||
|
||
private static final String REORDER_COLUMNS_MUTATION = """ | ||
mutation reorderTableColumns($input: ReorderTableColumnsInput!) { | ||
reorderTableColumns(input: $input) { | ||
__typename | ||
... on ErrorPayload { | ||
messages { | ||
body | ||
level | ||
} | ||
} | ||
... on SuccessPayload { | ||
messages { | ||
body | ||
level | ||
} | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
private final IGraphQLRequestor graphQLRequestor; | ||
|
||
public ReorderTableColumnsMutationRunner(IGraphQLRequestor graphQLRequestor) { | ||
this.graphQLRequestor = Objects.requireNonNull(graphQLRequestor); | ||
} | ||
|
||
@Override | ||
public String run(ReorderTableColumnsInput input) { | ||
return this.graphQLRequestor.execute(REORDER_COLUMNS_MUTATION, input); | ||
} | ||
} |
Oops, something went wrong.