Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
fix: DEV-2408: Regions disappearing from UI (#631)
Browse files Browse the repository at this point in the history
* fix: DEV-2408: Regions disappearing from UI

* test: DEV-2408: Add test for wrong reordered results of per-region textarea and richtext
  • Loading branch information
Gondragos committed May 20, 2022
1 parent c35c48d commit 6ef0657
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
50 changes: 50 additions & 0 deletions e2e/tests/regression-tests/wrong-results-order.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* global Feature, Scenario */

Feature("Wrong ordered results deserialization").tag("@regress");

Scenario("Combining results of per-region textarea and richtext regions.", async ({ I, LabelStudio, AtSidebar }) => {
I.amOnPage("/");

LabelStudio.init({
annotations: [
{
id: "test", result: [

{
id: "id_1",
from_name: "comment",
to_name: "text",
type: "textarea",
value: {
start: 0,
end: 11,
text: ["That's true"],
},
},
{
id: "id_1",
from_name: "labels",
to_name: "text",
type: "labels",
value: {
start: 0,
end: 11,
labels: ["Label 1"],
text: "Just a text",
},
},
],
}],
config: `
<View>
<Labels name="labels" toname="text">
<Label value="Label 1"/>
</Labels>
<Text name="text" value="$text" />
<Textarea name="comment" toname="text" perregion="true"/>
</View>`,
data: { text: "Just a text" },
});

AtSidebar.seeRegions(1);
});
13 changes: 12 additions & 1 deletion src/stores/Annotation/Annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Area from "../../regions/Area";
import throttle from "lodash.throttle";
import { UserExtended } from "../UserStore";
import { FF_DEV_2100, FF_DEV_2100_A, isFF } from "../../utils/feature-flags";
import Result from "../../regions/Result";

const hotkeys = Hotkey("Annotations", "Annotations");

Expand Down Expand Up @@ -951,6 +952,15 @@ export const Annotation = types
const areaId = `${id || guidGenerator()}#${self.id}`;
const resultId = `${data.from_name}@${areaId}`;
const value = self.prepareValue(rawValue, tagType);
// This should fix a problem when the order of results is broken
const omitValueFields = (value) => {
const newValue = { ...value };

Result.properties.value.propertyNames.forEach(propName => {
delete newValue[propName];
});
return newValue;
};

let area = getArea(areaId);

Expand All @@ -959,7 +969,8 @@ export const Annotation = types
id: areaId,
object: data.to_name,
...data,
...value,
// We need to omit value properties due to there may be conflicting property types, for example a text.
...omitValueFields(value),
value,
};

Expand Down

0 comments on commit 6ef0657

Please sign in to comment.