-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1912] Add the possibility to send feedback messages to the frontend
Bug: #1912 Signed-off-by: Florian Rouëné <florian.rouene@obeosoft.com>
- Loading branch information
Showing
75 changed files
with
601 additions
and
1,068 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
= ADR-101 - Add the possibility to send feedback messages to the frontend after an action | ||
|
||
== Context | ||
|
||
After an action, only technical error messages can be displayed on the UI. | ||
We want to offer the specifier the ability to send back custom return messages to the end user. | ||
|
||
== Decision | ||
|
||
We will provide a new Java service that specifiers can invoke during the execution of their actions (tools behaviors) to stack messages. | ||
These messages will be displayed on the UI after the action resolution. | ||
|
||
=== Backend | ||
|
||
The interface will provide the following method : | ||
|
||
[source,java] | ||
---- | ||
interface IFeedbackMessageService { | ||
void addFeedbackMessage(String message, FeedbackLevel level); | ||
} | ||
---- | ||
with | ||
[source,java] | ||
---- | ||
enum FeedbackLevel { | ||
DEBUG, | ||
INFO, | ||
WARNING, | ||
ERROR, | ||
} | ||
---- | ||
|
||
The implementation must have a scope to limit the _bean_ life cycle to the action only, in order to just return at the end of the action the messages stacked by the services called by the action. | ||
The spring scope of type _request_ provides this limitation. | ||
|
||
At first, we will join all the _string messages_ stacked in a single string, and append it to the existing `Failure` (`IStatus` implementation) _message_ parameter. | ||
In doing so, we can keep the actual _frontend_ representation for this message. | ||
|
||
To differentiate the level applied to the message, we will prefix it with an emoji representing this level. | ||
|
||
=== Frontend | ||
|
||
To begin, we will not change the actual representation for an action error message. | ||
But in order to facilitate the maintenance and the evolutions, we will mutualize all these representations in a single custom component `Toast`. | ||
|
||
with | ||
|
||
[source,typescript] | ||
---- | ||
export interface ToastProps { | ||
message?: string; | ||
open?: boolean; | ||
onClose?: () => void; | ||
} | ||
---- | ||
|
||
Next, we will change this representation to display, for each stacked message, a unique _notification_ with a style depending on the chosen level. | ||
|
||
== Status | ||
|
||
Accepted. |
22 changes: 22 additions & 0 deletions
22
...s-components-core/src/main/java/org/eclipse/sirius/components/core/api/FeedbackLevel.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,22 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 | ||
* 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.core.api; | ||
|
||
/** | ||
* Enumeration used to indicate the feedback message level. | ||
* | ||
* @author frouene | ||
*/ | ||
public enum FeedbackLevel { | ||
DEBUG, INFO, WARNING, ERROR, | ||
} |
29 changes: 29 additions & 0 deletions
29
...components-core/src/main/java/org/eclipse/sirius/components/core/api/FeedbackMessage.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,29 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 | ||
* 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.core.api; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Record used to represent a feedback message. | ||
* | ||
* @author frouene | ||
*/ | ||
public record FeedbackMessage(String message, FeedbackLevel level) { | ||
|
||
public FeedbackMessage { | ||
Objects.requireNonNull(message); | ||
Objects.requireNonNull(level); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
...ts-core/src/main/java/org/eclipse/sirius/components/core/api/IFeedbackMessageService.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,45 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 | ||
* 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.core.api; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Interface of the service interacting with the list of stacked feedback messages. | ||
* | ||
* @author frouene | ||
*/ | ||
public interface IFeedbackMessageService { | ||
|
||
void addFeedbackMessage(String message, FeedbackLevel level); | ||
|
||
List<String> getFeedbackMessages(); | ||
|
||
/** | ||
* Implementation which does nothing, used for mocks in unit tests. | ||
* | ||
* @author frouene | ||
*/ | ||
class NoOp implements IFeedbackMessageService { | ||
|
||
@Override | ||
public void addFeedbackMessage(String message, FeedbackLevel level) { | ||
|
||
} | ||
|
||
@Override | ||
public List<String> getFeedbackMessages() { | ||
return List.of(); | ||
} | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
packages/core/frontend/sirius-components-core/src/workbench/Toast.tsx
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,37 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import Snackbar from '@material-ui/core/Snackbar'; | ||
import CloseIcon from '@material-ui/icons/Close'; | ||
import { ToastProps } from './Toast.types'; | ||
|
||
export const Toast = ({ message, open, onClose }: ToastProps) => { | ||
return ( | ||
<Snackbar | ||
anchorOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: 'right', | ||
}} | ||
open={open} | ||
autoHideDuration={3000} | ||
onClose={onClose} | ||
message={message} | ||
action={ | ||
<IconButton size="small" aria-label="close" color="inherit" onClick={() => onClose()}> | ||
<CloseIcon fontSize="small" /> | ||
</IconButton> | ||
} | ||
data-testid="toast" | ||
/> | ||
); | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/core/frontend/sirius-components-core/src/workbench/Toast.types.ts
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,18 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
export interface ToastProps { | ||
message?: string; | ||
open?: boolean; | ||
onClose?: () => void; | ||
} |
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
Oops, something went wrong.