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

fix: DEV-3706: Fix undo with ML backend #999

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 89 additions & 2 deletions e2e/tests/smart-tools.history.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Feature, Scenario */
/* global Feature, Scenario, DataTable, Data */

Feature("Smart tools history");

Expand Down Expand Up @@ -474,6 +474,45 @@ function getRectangleSuggestions(reg, group) {
window.labelStudio.store.loadSuggestions(new Promise((resolve) => resolve(suggestions)), x => x);
}



const createTextConfig = (params = {}) => {
return `
<View>
<Labels name="ner" toName="text" ${paramsToAttrs(params)}>
<Label value="Person"></Label>
<Label value="Words"></Label>
</Labels>
<Text name="text" valueType="url" value="$text" />
</View>
`;
};

const TEXT_URL = "https://htx-pub.s3.amazonaws.com/example.txt";

function getSimpleTextSuggestions(reg, group) {
const allSuggestions = [
{
id: "Hnyt9sO_RX",
from_name: "ner",
to_name: "text",
type: "labels",
origin: "manual",
value: { start: 0, end: 17, labels: ["Person"] },
},
{
id: "tQHRBpvGo0",
from_name: "ner",
to_name: "text",
type: "labels",
origin: "manual",
value: { start: 453, end: 474, labels: ["Words"] },
},
];

window.labelStudio.store.loadSuggestions(new Promise((resolve) => resolve(allSuggestions)), x => x);
}

Scenario("Undo regions auto-annotated from predictions", async function({ I, LabelStudio, AtImageView, AtSidebar }) {
I.amOnPage("/");
LabelStudio.init({
Expand Down Expand Up @@ -585,4 +624,52 @@ Scenario("Undo if there are no regions auto-annotated from predictions", async f
I.say("There should be one history step");
I.seeElement(":not([disabled])[aria-label=\"Undo\"]");
I.seeElement("[disabled][aria-label=\"Redo\"]");
});
});

const forceAutoAcceptSuggestionsTable = new DataTable(["forceAutoAcceptSuggestions"]);

forceAutoAcceptSuggestionsTable.add([true]);
forceAutoAcceptSuggestionsTable.add([false]);

Data(forceAutoAcceptSuggestionsTable).Scenario("Checking that undo does not create new regions", async function({ I, LabelStudio, AtLabels, AtSidebar, AtRichText, current }) {
const { forceAutoAcceptSuggestions } = current;

I.amOnPage("/");
LabelStudio.setFeatureFlags({
fflag_fix_front_dev_1284_auto_detect_undo_281022_short: true,
fflag_fix_front_dev_3706_undo_with_ml_backend_081122_short: true,
});
LabelStudio.init({
config: createTextConfig({
smartonly: true,
}),
data: {
text: TEXT_URL,
},
additionalInterfaces: [
"auto-annotation",
],
events: {
regionFinishedDrawing: getSimpleTextSuggestions,
},
params: {
forceAutoAnnotation: true,
forceAutoAcceptSuggestions,
},
});

I.seeElement("[disabled][aria-label=\"Undo\"]");
I.seeElement("[disabled][aria-label=\"Redo\"]");
AtSidebar.seeRegions(0);

AtLabels.clickLabel("Words");
AtRichText.dblClickOnWord("who");
I.seeElement(":not([disabled])[aria-label=\"Undo\"]");
I.seeElement("[disabled][aria-label=\"Redo\"]");
AtSidebar.seeRegions(3 - forceAutoAcceptSuggestions);

I.pressKey(["ctrl", "z"]);
I.seeElement("[disabled][aria-label=\"Undo\"]");
I.seeElement(":not([disabled])[aria-label=\"Redo\"]");
AtSidebar.seeRegions(0);
});
5 changes: 4 additions & 1 deletion src/mixins/Regions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getEnv, getParent, getRoot, getType, types } from "mobx-state-tree";
import { guidGenerator } from "../core/Helpers";
import { AnnotationMixin } from "./AnnotationMixin";
import { FF_DEV_3706, isFF } from "../utils/feature-flags";

const RegionsMixin = types
.model({
Expand Down Expand Up @@ -97,7 +98,9 @@ const RegionsMixin = types
},

beforeDestroy() {
self.notifyDrawingFinished({ destroy: true });
if (!isFF(FF_DEV_3706)) {
self.notifyDrawingFinished({ destroy: true });
}
},

setLocked(locked) {
Expand Down
9 changes: 7 additions & 2 deletions src/stores/Annotation/Annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { errorBuilder } from "../../core/DataValidator/ConfigValidator";
import Area from "../../regions/Area";
import throttle from "lodash.throttle";
import { UserExtended } from "../UserStore";
import { FF_DEV_1284, FF_DEV_1598, FF_DEV_2100, FF_DEV_2100_A, FF_DEV_2432, isFF } from "../../utils/feature-flags";
import { FF_DEV_1284, FF_DEV_1598, FF_DEV_2100, FF_DEV_2100_A, FF_DEV_2432, FF_DEV_3706, isFF } from "../../utils/feature-flags";
import Result from "../../regions/Result";
import { CommentStore } from "../Comment/CommentStore";

Expand Down Expand Up @@ -441,7 +441,12 @@ export const Annotation = types

children && children.forEach(r => r.setParentID(region.parentID));

if (!region.classification) getEnv(self).events.invoke('entityDelete', region);
if (!region.classification) {
getEnv(self).events.invoke('entityDelete', region);
if (isFF(FF_DEV_3706)) {
region.notifyDrawingFinished({ destroy: true });
}
}

self.relationStore.deleteNodeRelation(region);

Expand Down
6 changes: 6 additions & 0 deletions src/utils/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ export const FF_DEV_3617 = "fflag_fix_front_dev_3617_taxonomy_memory_leaks_fix";
*/
export const FF_DEV_1284 = "fflag_fix_front_dev_1284_auto_detect_undo_281022_short";

/**
* Fixing problem when undo causes request to ML Backend
* @link https://app.launchdarkly.com/default/production/features/fflag_fix_front_dev_3706_undo_with_ml_backend_081122_short
* */
export const FF_DEV_3706 = "fflag_fix_front_dev_3706_undo_with_ml_backend_081122_short";

function getFeatureFlags() {
return {
...(window.APP_SETTINGS?.feature_flags ?? {}),
Expand Down