Skip to content

Commit

Permalink
Fix changing widget types (#207)
Browse files Browse the repository at this point in the history
* Instantiate WhiteSpaceWidget and send clearing event

* Clearing old status and old error message moved to frontend

* Added condition for first time addition of widget

* Removing example Endpoint

* favicon.ico

* better screen for docks

Co-authored-by: Stanislaw <[email protected]>
Co-authored-by: Szymon Owczarzak <[email protected]>
  • Loading branch information
szymon-owczarzak and staszke authored Jan 14, 2020
2 parents 4c134f1 + f2de42a commit eb71c38
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ class WidgetRuntimeService(
}

fun createOrUpdateWidget(widgetConfig: JsonObject) {
var newConfig = widgetConfig
val id = widgetConfig.getId()

if (id != null) {
widgets[id]?.let {
it.stop()
newConfig = it.config().mergeIn(widgetConfig, true)
}
newConfig.attachEndpoint()
widgets[id] = WidgetIndex.create(newConfig, vertx).start()
widgets[id]?.stop()

widgetConfig.attachEndpoint()
widgets[id] = WidgetIndex.create(widgetConfig, vertx).start()
} else {
LOGGER.error("Widget Update / Create | " +
"There is no widget with given ID in configuration: $widgetConfig")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ abstract class BaseWidget(
return this.getJsonObject(CC.PROP_ENDPOINT)?.getString(prop) ?: ""
}

protected fun JsonObject.clearErrorMessageAndErrorCause() {
map[CC.PROP_ERROR_MESSAGE] = ""
map[CC.PROP_ERROR_CAUSE] = ""
}

companion object {
const val PROP_EVENT_TYPE_WIDGET_UPDATE = "widget-update"
const val TO_SECONDS = 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WidgetIndex {
PersonDrawWidget::class.java.simpleName -> PersonDrawWidget(vertx, config)
AemBundleInfoWidget::class.java.simpleName -> AemBundleInfoWidget(vertx, config)
// add here
else -> WhiteSpaceWidget.INSTANCE
else -> WhiteSpaceWidget(vertx, config)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class AemBundleInfoWidget(vertx: Vertx, config: JsonObject) : AsyncWidget(vertx,
}

private fun sendSuccess(content: JsonObject) {
content.put(CC.PROP_ERROR_MESSAGE, "")

send(JsonObject().put(CC.PROP_CONTENT, content))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class AemHealthcheckWidget(vertx: Vertx, config: JsonObject) : AsyncWidget(vertx
var widgetStatus = OK
val overviewUrl = "$publicUrl/$OVERVIEW_PATH"
val result = JsonObject()
content.put(CogboardConstants.PROP_ERROR_MESSAGE, "")
content.put(CogboardConstants.PROP_URL, overviewUrl)
content.put("healthChecks", result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class BambooDeploymentWidget(
val deploymentVersionName = result.getJsonObject("deploymentVersion").getString("name")
val deploymentResultId = result.getInteger("id")

result.put(CC.PROP_ERROR_MESSAGE, "")
.put(CC.PROP_URL, constructUrl(deploymentResultId))
.put(CC.PROP_RELEASE_NAME, deploymentVersionName)
.put(CC.PROP_WIDGET_STATUS, getStatus(result))

result.remove("items")
result.apply {
put(CC.PROP_URL, constructUrl(deploymentResultId))
put(CC.PROP_RELEASE_NAME, deploymentVersionName)
put(CC.PROP_WIDGET_STATUS, getStatus(result))
remove("items")
}

send(JsonObject()
.put(CC.PROP_CONTENT, result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class BambooPlanWidget(vertx: Vertx, config: JsonObject) : AsyncWidget(vertx, co
results.getJsonArray("result")?.first().let {
val result = it as JsonObject

result.put(CC.PROP_ERROR_MESSAGE, "")
.put(CC.PROP_URL, extractUrl(result.getString("buildResultKey")))
result.put(CC.PROP_URL, extractUrl(result.getString("buildResultKey")))
.put(CC.PROP_WIDGET_STATUS, Widget.Status.from(result.getString("state")))

send(JsonObject().put(CC.PROP_CONTENT, result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class JenkinsJobWidget(
val status = if (lastBuild.getBoolean("building", false)) Widget.Status.IN_PROGRESS
else Widget.Status.from(lastBuild.getString("result", ""))

lastBuild.put(CC.PROP_ERROR_MESSAGE, "")
.put("branch", extractBranchInfo(lastBuild))
lastBuild.put("branch", extractBranchInfo(lastBuild))
.put(CC.PROP_URL, makePublic(lastBuild.getString(CC.PROP_URL, "")))
.put(CC.PROP_WIDGET_STATUS, status)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cognifide.cogboard.widget.type

import com.cognifide.cogboard.CogboardConstants
import com.cognifide.cogboard.CogboardConstants.Companion.PROP_BODY
import com.cognifide.cogboard.CogboardConstants.Companion.PROP_CONTENT
import com.cognifide.cogboard.CogboardConstants.Companion.PROP_EXPECTED_RESPONSE_BODY
Expand Down Expand Up @@ -61,7 +60,6 @@ class ServiceCheckWidget(vertx: Vertx, config: JsonObject) : AsyncWidget(vertx,

override fun handleResponse(responseBody: JsonObject) {
responseBody.put(PROP_URL, urlToCheck)
.put(CogboardConstants.PROP_ERROR_MESSAGE, "")
.put(PROP_EXPECTED_RESPONSE_BODY, expectedResponseBody)
.put(PROP_EXPECTED_STATUS_CODE, expectedStatusCode)
.put(PROP_WIDGET_STATUS, getStatusResponse(responseBody))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
package com.cognifide.cogboard.widget.type

import com.cognifide.cogboard.widget.Widget
import com.cognifide.cogboard.CogboardConstants
import com.cognifide.cogboard.widget.BaseWidget
import io.vertx.core.Vertx
import io.vertx.core.json.JsonObject

/**
* Use this for all widgets that don't require backend code
*/
class WhiteSpaceWidget : Widget {

override val id: String
get() = "unknown"

override val type: String
get() = "WhiteSpaceWidget"

override fun start(): Widget {
return this
}

override fun stop(): Widget {
return this
}

override fun send(state: JsonObject) {
// do nothing
}
class WhiteSpaceWidget(vertx: Vertx, config: JsonObject) : BaseWidget(vertx, config) {

override fun updateState() {
// do nothing
}

override fun config(): JsonObject {
return JsonObject()
}

companion object {
val INSTANCE = WhiteSpaceWidget()
send(JsonObject()
.put(CogboardConstants.PROP_CONTENT, JsonObject()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class SonarQubeWidget(vertx: Vertx, config: JsonObject) : AsyncWidget(vertx, con
content.put(CogboardConstants.PROP_URL, version.getDashboardUrl(publicUrl, key, idNumber))
.put(CogboardConstants.PROP_WIDGET_STATUS, extractStatus(it))

content.clearErrorMessageAndErrorCause()

send(JsonObject()
.put(CogboardConstants.PROP_CONTENT, content))
}
Expand Down
7 changes: 0 additions & 7 deletions cogboard-app/src/main/resources/initData/endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
"label": "API Mocks Endpoint",
"publicUrl": "http://api-mocks:8080",
"url": "http://api-mocks:8080"
},
{
"credentials": "credentials1",
"id": "endpoint2",
"label": "Example Endpoint",
"publicUrl": "http://example.com",
"url": "http://internal.example.com"
}
]
}
Binary file modified cogboard-webapp/public/favicon.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions cogboard-webapp/src/reducers/widgets/widgetsById.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const updateWidget = (state, { payload }) => {
const { id, content, ...other } = payload;
const widget = state[id];
const prevContent = widget.content;
if (prevContent) {
prevContent.widgetStatus = null;
prevContent.errorMessage = null;
prevContent.errorCause = null;
}

return {
...state,
Expand Down
Binary file modified docs/images/Cogboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit eb71c38

Please sign in to comment.