Skip to content

Commit

Permalink
#1712 fix patching a thing, removing items did not correctly upgrade …
Browse files Browse the repository at this point in the history
…the thing on the UI

* fixed by solving the merge on Ditto server side, selecting all "extraFields" for each change .. that way, the complete updated thing is emitted via the SSE instead only the diff
* as a result, also deleted the "merge" functionality of the UI, also removed no-longer needed "lodash" dependency

Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
  • Loading branch information
thjaeckle committed Oct 15, 2023
1 parent f54eed2 commit 9c76cd3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 30 deletions.
Expand Up @@ -18,6 +18,7 @@

import javax.annotation.Nullable;

import org.apache.pekko.actor.ActorSystem;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.headers.contenttype.ContentType;
import org.eclipse.ditto.connectivity.api.ExternalMessage;
Expand All @@ -43,8 +44,6 @@

import com.typesafe.config.Config;

import org.apache.pekko.actor.ActorSystem;

/**
* A message mapper implementation for normalized changes.
* Create-, modify- and merged-events are mapped to nested sparse JSON.
Expand Down Expand Up @@ -181,6 +180,7 @@ private static JsonObject abridgeMessage(final Adaptable adaptable) {
// add fields of an event protocol message excluding "value" and "status"
builder.set(JsonifiableAdaptable.JsonFields.TOPIC, adaptable.getTopicPath().getPath());
builder.set(Payload.JsonFields.PATH, payload.getPath().toString());
builder.set(Payload.JsonFields.VALUE, adaptable.getPayload().getValue().orElse(JsonValue.nullLiteral()));
payload.getFields().ifPresent(fields -> builder.set(Payload.JsonFields.FIELDS, fields.toString()));
builder.set(JsonifiableAdaptable.JsonFields.HEADERS, dittoHeadersToJson(dittoHeaders));

Expand Down
Expand Up @@ -786,6 +786,7 @@ private JsonObject addContext(final JsonObjectBuilder objectBuilder,
objectBuilder.set(CONTEXT, JsonObject.newBuilder()
.set(JsonifiableAdaptable.JsonFields.TOPIC, adaptable.getTopicPath().getPath())
.set(Payload.JsonFields.PATH, adaptable.getPayload().getPath().toString())
.set(Payload.JsonFields.VALUE, adaptable.getPayload().getValue().orElse(JsonValue.nullLiteral()))
.set(JsonifiableAdaptable.JsonFields.HEADERS, dittoHeadersToJson(thingEvent.getDittoHeaders()))
.build()
);
Expand Down
2 changes: 1 addition & 1 deletion ui/modules/things/messagesIncoming.html
Expand Up @@ -28,7 +28,7 @@ <h5 data-bs-toggle="collapse" data-bs-target="#collapseMessages">
<thead>
<tr>
<th>Revision</th>
<th>Field</th>
<th>Field(s)</th>
<th>Modified</th>
</tr>
</thead>
Expand Down
6 changes: 3 additions & 3 deletions ui/modules/things/messagesIncoming.ts
Expand Up @@ -12,9 +12,9 @@
*/

import * as Utils from '../utils.js';
import messagesIncomingHTML from './messagesIncoming.html';
import * as Things from './things.js';
import * as ThingsSSE from './thingsSSE.js';
import messagesIncomingHTML from './messagesIncoming.html';
/* eslint-disable prefer-const */
/* eslint-disable max-len */
/* eslint-disable no-invalid-this */
Expand Down Expand Up @@ -64,8 +64,8 @@ function onMessage(messageData) {
Utils.addTableRow(
dom.tbodyMessagesIncoming,
messageData._revision, false, false,
[...messageData['features'] ? Object.keys(messageData.features) : [],
...messageData['attributes'] ? Object.keys(messageData.attributes) : []],
[...messageData['_context'].value.features ? Object.keys(messageData['_context'].value.features) : [],
...messageData['_context'].value.attributes ? Object.keys(messageData['_context'].value.attributes) : []],
Utils.formatDate(messageData._modified, true),
);
}
Expand Down
30 changes: 15 additions & 15 deletions ui/modules/things/thingsSSE.ts
@@ -1,15 +1,15 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
/* eslint-disable require-jsdoc */
/* eslint-disable arrow-parens */
// @ts-check
Expand All @@ -18,7 +18,6 @@ import * as Environments from '../environments/environments.js';

import * as Things from './things.js';
import * as ThingsSearch from './thingsSearch.js';
import merge from 'lodash/merge';

let selectedThingEventSource;
let thingsTableEventSource;
Expand Down Expand Up @@ -57,7 +56,8 @@ function onSelectedThingChanged(newThingJson, isNewThingId) {
selectedThingEventSource && selectedThingEventSource.close();
console.log('SSE Start: SELECTED THING : ' + newThingJson.thingId);
selectedThingEventSource = API.getEventSource(newThingJson.thingId,
'fields=thingId,attributes,features,_revision,_modified');
'fields=thingId,policyId,definition,attributes,features,_revision,_created,_modified,_metadata,_context/topic,_context/path,_context/value' +
'&extraFields=thingId,policyId,definition,attributes,features,_revision,_created,_modified,_metadata');
selectedThingEventSource.onmessage = onMessageSelectedThing;
}
}
Expand All @@ -78,8 +78,8 @@ function onEnvironmentChanged(modifiedField) {

function onMessageSelectedThing(event) {
if (event.data && event.data !== '') {
const merged = merge(Things.theThing, JSON.parse(event.data));
Things.setTheThing(merged);
const completeChangedThing = JSON.parse(event.data);
Things.setTheThing(completeChangedThing);
notifyAll(JSON.parse(event.data));
}
}
Expand Down
8 changes: 1 addition & 7 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions ui/package.json
Expand Up @@ -28,7 +28,6 @@
"bootstrap": "^5.2.3",
"bootstrap-icons": "^1.10.5",
"event-source-polyfill": "^1.0.31",
"jsonpath-plus": "^7.2.0",
"lodash": "^4.17.21"
"jsonpath-plus": "^7.2.0"
}
}

0 comments on commit 9c76cd3

Please sign in to comment.