Skip to content

Commit

Permalink
[1146] Add an ADR on EditingContext actions
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#1146
Signed-off-by: Raphaël Pagé <raphael.page@obeo.fr>
  • Loading branch information
RaphaelPageObeo committed Apr 11, 2022
1 parent c903ffc commit fb2aefd
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions doc/adrs/051_add_support_for_editing_context_action.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
= ADR-051 - Add Support for EditingContext Action

== Context

Stereotypes descriptions are hard-coded and limited.
The main thing that they can do is to copy JSON into the resource set.
We want to do more things, for example defining when an action is available based on the editing context.
Replacing stereotypes descriptions would also reduce the dependency to the concept of Document.

== Decision

In order to allow for more flexibility, Stereotypes descriptions will be transformed in EditingContext Actions.
There won't be any visible changes for the end user.
They should be supported by both the programmatic API and the GraphQL API.
Every action will not be available all the time. Their availability will be computed and will depend on the editing context.
The actions will be able to manipulate the editing context or contact a remote service.

=== Backend

The actions will be represented by the following POJO which will be sent back to the frontend to be displayed in the user interface :

```java
public class EditingContextAction {
private final String id;
private final String label;
}
```

The following interfaces will need to be implemented in order to contribute new actions :

```java
public interface IEditingContextActionProvider {
List<IEditingContextAction> getEditingContextAction(IEditingContext editingContext);
}
```

```java
public interface IEditingContextAction {
boolean isApplicable(IEditingContext editingContext);

void apply(IEditingContext editingContext);
}
```

An InvokeEditingContextActionEventHandler will be called by the GraphQL data fetcher in order to execute an action selected by the end user :

```java
public class InvokeEditingContextActionEventHandler implements IEditingContextEventHandler {

private final List<IEditingContextActionHandler> editingContextActionHandlers;

public boolean canHandle(IEditingContext editingContext, IInput input) {
return input instanceof InvokeEditingContextActionInput;
}

public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IInput input) {
// Use the relevant editingContextActionHandler to handle the input
}
}
```

This event handler will be used to call the appropriate action handler which will be provided by the same person who has contributed the action :

```java
public interface IEditingContextActionHandler {
boolean canHandle(IEditingContext editingContext, InvokeEditingContextActionInput);

IPayload handle(IEditingContext editingContext, InvokeEditingContextActionInput);
}
```

```java
public final class InvokeEditingContextActionInput implements IInput {
private UUID id;
private String actionId;
}
```

```java
public class InvokeEditingContextActionSuccessPayload implements IPayload {
private UUID id;
}
```

=== GraphQL API

The GraphQL API will look like this :
```
type EditingContext {
actions: EditingContextEditingContextActionsConnection!
}

type EditingContextEditingContextActionsConnection {
edges: [EditingContextEditingContextActionsEdge!]!
pageInfo: PageInfo!
}

type EditingContextEditingContextActionsEdge {
node: EditingContextAction!
}

type EditingContextAction {
id: ID!
label: String!
}

type Mutation {
invokeEditingContextAction(input: InvokeEditingContextActionInput!): InvokeEditingContextActionPayload!
}

input InvokeEditingContextActionInput {
id: ID!
actionId: String!
}

union InvokeEditingContextActionPayload = ErrorPayload | InvokeEditingContextActionSuccessPayload

type InvokeEditingContextActionSuccessPayload {
id: ID!
}
```

== Status

WIP

0 comments on commit fb2aefd

Please sign in to comment.