Skip to content

Commit

Permalink
KOGITO-8888: Show a message in dashbuilder page when displayer config…
Browse files Browse the repository at this point in the history
…uration is invalid (apache#1569)
  • Loading branch information
kumaradityaraj authored Apr 28, 2023
1 parent d4a7228 commit b757b49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.dashbuilder.displayer.GlobalDisplayerSettings;
import org.dashbuilder.displayer.client.Displayer;
import org.dashbuilder.displayer.client.PerspectiveCoordinator;
import org.dashbuilder.displayer.client.widgets.DisplayerErrorWidget;
import org.dashbuilder.displayer.client.widgets.DisplayerViewer;
import org.dashbuilder.displayer.json.DisplayerSettingsJSONMarshaller;
import org.jboss.errai.ioc.client.container.SyncBeanManager;
Expand All @@ -45,12 +46,15 @@ public class DisplayerDragComponent implements LayoutDragComponent {
DisplayerSettingsJSONMarshaller marshaller;
GlobalDisplayerSettings globalDisplayerSettings;

@Inject
DisplayerErrorWidget displayError;

@Inject
public DisplayerDragComponent(SyncBeanManager beanManager,
DisplayerViewer viewer,
PlaceManager placeManager,
PerspectiveCoordinator perspectiveCoordinator,
GlobalDisplayerSettings globalDisplayerSettings) {
DisplayerViewer viewer,
PlaceManager placeManager,
PerspectiveCoordinator perspectiveCoordinator,
GlobalDisplayerSettings globalDisplayerSettings) {

this.beanManager = beanManager;
this.viewer = viewer;
Expand All @@ -72,7 +76,11 @@ public DisplayerSubType getDisplayerSubType() {
public IsWidget getShowWidget(final RenderingContext ctx) {
var settingsOp = getDisplayerSettings(ctx.getComponent());
return settingsOp.map(settings -> {
perspectiveCoordinator.closeDisplayer(settings.getUUID());
var error = settings.getError();
if (error.isPresent()) {
displayError.show(error.get(), null);
return displayError;
}
viewer.removeFromParent();
viewer.init(settings);
viewer.addAttachHandler(attachEvent -> {
Expand Down Expand Up @@ -115,5 +123,4 @@ private Optional<DisplayerSettings> getDisplayerSettings(LayoutComponent compone

return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,15 @@ private LayoutComponent extractComponent(JsonObject object, int i) {
extractProperties(propertiesObject, component::addProperty);
extractParts(object.getArray(PARTS)).forEach(part -> component.addPartProperties(part.getPartId(), part
.getCssProperties()));

if (settings != null) {
try {
component.setSettings(DisplayerSettingsJSONMarshaller.get().fromJsonObject(settings));
} catch (Exception e) {
// just log the error and let displayers handle missing configuration
LOGGER.warn("Error reading component settings", e);
var _displayer = new DisplayerSettings();
_displayer.setError(e.getMessage());
component.setSettings(_displayer);
}
}
return component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.dashbuilder.dataset.DataColumn;
Expand All @@ -32,6 +33,7 @@
@Portable
public class DisplayerSettings {

private static final String ERROR = "_error";
protected String UUID;
protected DataSet dataSet;
protected DataSetLookup dataSetLookup;
Expand Down Expand Up @@ -824,4 +826,12 @@ public boolean isAttributeDefinedByUser(DisplayerAttributeDef attr) {

}

public Optional<String> getError() {
return Optional.ofNullable(settings.get(ERROR));
}

public void setError(String error) {
settings.put(ERROR, error);
}

}

0 comments on commit b757b49

Please sign in to comment.