Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Add an ADR on support actions in table row context menu #4394

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

=== Architectural decision records

- [ADR-178] Add support of actions in table row menu

=== Deprecation warning

Expand Down
100 changes: 100 additions & 0 deletions doc/adrs/178_add_support_of_actions_in_table_row_menu.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
= ADR-178 Add support of actions in table row menu

== Context

Currently, there are no actions at the row level in table representations.

== Decision

We need to introduce a general way to handle actions at the table row level.
MUI React Table provides a convenient way to add menu items on each row inside a dedicated column which could be naturally used in the front end part.
As a developer or specifier, we want to be able to specify a list of actions that could be applied on an row description.

=== View DSL

The specifier could add `RowContextMenuEntry` elements under a `RowDescription` element.
`RowContextMenuEntry` has the following properties:

* Label Expression
* Icon URL Expression
* Precondition Expression
* Body Operation

=== Table API

At the API level, we need to introduce a new provider interface `IRowContextMenuEntryProvider` that could be implemented to provide a list of actions at a row level (`RowContextMenuEntry`).

```java
public interface IRowContextMenuEntryProvider {

boolean canHandle(IEditingContext editingContext, TableDescription tableDescription, Table table, Line row);

List<RowContextMenuEntry> getRowContextMenuEntries(IEditingContext editingContext, TableDescription tableDescription, Table table, Line row);
}
```

The `RowContextMenuEntry` class is as simple as:

```java
public record RowContextMenuEntry(String id, String label, List<String> iconURL) { }
```

=== GraphQL

In order to display the content of the context menu in the front end, we need to introduce a GraphQL field to retrieve all context menu entries associated to a given row.
It will behaves the same way as `DiagramDescription#palette`.

```graphQL
type TableDescription implements RepresentationDescription {
...
contextMenu(rowId: ID!): [RowContextMenuEntry!]!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context menu would have a similar behavior as a diagram palette, it should be retrieved using TableDescription#contextMenu. We are always placing those kind of information on the representation description.

See the GraphQL schema of DiagramDescription#palette for example.

...
}

type RowContextMenuEntry {
id: ID!
label: String!
iconURL: [String!]!
}
```

In order to execute a specific action entry, we need to introduce a GraphQL mutation to perform the action itself by the backend.

```graphQL
extend type Mutation {
...
invokeRowContextMenuEntry(input: InvokeRowContextMenuEntryInput!): InvokeRowContextMenuEntryPayload!
...
}

input InvokeRowContextMenuEntryInput {
id: ID!
editingContextId: ID!
representationId: ID!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will also need the tableId here given how tables are working

tableId: ID!
rowId: ID!
menuEntryId: ID!
}
```

=== Back end

As far as the context menu entries retrieval is concerned, the handler has an injected list of implementations of `IRowContextMenuEntryProvider`.
A developer could create directly an implementation of `IRowContextMenuEntryProvider` to use in a row of his/her table.
To manage the view DSL menu entries descriptions, we need to provide an implementation to expose the entries described at the View model level to the DTO element.

For context menu entry execution, we need to introduce a new interface to allow gathering the execution handler `IRowContextMenuEntryExecutor`.
The mutation handler has to select the right executor among the injected list using its `canExecute` method.
Therefore, the `execute` method can be called.
As for the context menu entries collect, we need to provide an implementation of this interface to manage the view DSL cases.

=== Front end

The front end code relies on the GraphQL query `contextMenu` to populate the menu of each table row.
We cannot afford to request all context menu entries for all rows when the component renders, instead, we need to request only the content of the context menu when it is open.

Once an action is triggered, the mutation `invokeRowContextMenuEntry` should be called.

== Status

Work in progress
Loading