From 676b9af2ce943a512f0e6e422da99924cf47290c Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Thu, 6 Oct 2022 08:28:29 -0400 Subject: [PATCH 01/24] fix: DEV-3341: selected=true attribute is not supported for Taxonomy --- src/stores/Annotation/Annotation.js | 13 +++++++++++-- src/tags/control/Taxonomy.js | 10 +++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/stores/Annotation/Annotation.js b/src/stores/Annotation/Annotation.js index b1ec7edbd..b507a436b 100644 --- a/src/stores/Annotation/Annotation.js +++ b/src/stores/Annotation/Annotation.js @@ -495,9 +495,18 @@ export const Annotation = types setDefaultValues() { self.names.forEach(tag => { - if (isFF(FF_DEV_2100_A) && tag?.type === "choices" && tag.preselectedValues?.length) { + let couldHavePreselectedValues = false; + + if (isFF(FF_DEV_2100_A) && tag?.type === "choices") { // - self.createResult({}, { choices: tag.preselectedValues }, tag, tag.toname); + couldHavePreselectedValues = true; + + } else if (tag?.type === "taxonomy") { + couldHavePreselectedValues = true; + } + + if (couldHavePreselectedValues && tag.preselectedValues?.length) { + self.createResult({}, { [tag.valueType]: tag.preselectedValues }, tag, tag.toname); } }); }, diff --git a/src/tags/control/Taxonomy.js b/src/tags/control/Taxonomy.js index fff43651f..17b6026c8 100644 --- a/src/tags/control/Taxonomy.js +++ b/src/tags/control/Taxonomy.js @@ -14,6 +14,7 @@ import VisibilityMixin from "../../mixins/Visibility"; import ControlBase from "./Base"; import DynamicChildrenMixin from "../../mixins/DynamicChildrenMixin"; import { FF_DEV_2007_DEV_2008, isFF } from "../../utils/feature-flags"; +import Tree from "../../core/Tree"; /** * Use the Taxonomy tag to create one or more hierarchical classifications, storing both choice selections and their ancestors in the results. Use for nested classification tasks with the Choice tag. @@ -160,6 +161,13 @@ const Model = types return fromConfig; }, + get preselectedValues() { + const items = Tree.filterChildrenOfType(self, 'ChoiceModel'); + + console.log("items", items); + return items.filter(c => c.selected).map(c => c.resultValue); + }, + get defaultChildType() { return "choice"; }, @@ -250,7 +258,7 @@ const HtxTaxonomy = observer(({ item }) => {
flatItem.selected).map(flatItem => flatItem.path)} + selected={item.selected} onChange={item.onChange} onAddLabel={item.userLabels && item.onAddLabel} onDeleteLabel={item.userLabels && item.onDeleteLabel} From 8e1a718e16ad60cccce91d5191e63294193a971f Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Thu, 6 Oct 2022 08:30:33 -0400 Subject: [PATCH 02/24] clearing out console.log --- src/tags/control/Taxonomy.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tags/control/Taxonomy.js b/src/tags/control/Taxonomy.js index 17b6026c8..49aa37de5 100644 --- a/src/tags/control/Taxonomy.js +++ b/src/tags/control/Taxonomy.js @@ -164,7 +164,6 @@ const Model = types get preselectedValues() { const items = Tree.filterChildrenOfType(self, 'ChoiceModel'); - console.log("items", items); return items.filter(c => c.selected).map(c => c.resultValue); }, From afdda5185725fd28420cee90c3a10cd5dc6da1a4 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Thu, 6 Oct 2022 18:07:07 -0400 Subject: [PATCH 03/24] toggling visibility only if perRegionVisibile and item is visible --- src/tags/control/Taxonomy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tags/control/Taxonomy.js b/src/tags/control/Taxonomy.js index b478811aa..c913277b8 100644 --- a/src/tags/control/Taxonomy.js +++ b/src/tags/control/Taxonomy.js @@ -231,7 +231,7 @@ const TaxonomyModel = types.compose("TaxonomyModel", const HtxTaxonomy = observer(({ item }) => { const style = { marginTop: "1em", marginBottom: "1em" }; - const visibleStyle = item.perRegionVisible() || item.isVisible ? {} : { display: "none" }; + const visibleStyle = item.perRegionVisible() && item.isVisible ? {} : { display: "none" }; const options = { showFullPath: item.showfullpath, leafsOnly: item.leafsonly, From 04cca628a23605fb1a2654a6d16f59c6fb3e9e7c Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Fri, 7 Oct 2022 09:12:31 -0400 Subject: [PATCH 04/24] adding e2e test --- e2e/tests/taxonomy.test.js | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 e2e/tests/taxonomy.test.js diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js new file mode 100644 index 000000000..c353b6926 --- /dev/null +++ b/e2e/tests/taxonomy.test.js @@ -0,0 +1,71 @@ +/* global Feature, Scenario, locate */ + +const { serialize, selectText } = require("./helpers"); + +const assert = require("assert"); + +Feature("Taxonomy"); + +const config = ` + + + + + + + + + + + + + +`; + + + +const data = { + text: `To have faith is to trust yourself to the water`, +}; + +const annotations = [ + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To' }, +]; + +const params = { config, data }; + +Scenario("Check Taxonomy holds state between annotations and saves result", async function({ I, LabelStudio }) { + + I.amOnPage("/"); + + LabelStudio.init(params); + + annotations.forEach(annotation => { + I.click(locate("span").withText(annotation.label)); + I.executeScript(selectText, { + selector: ".lsf-htx-richtext", + rangeStart: annotation.rangeStart, + rangeEnd: annotation.rangeEnd, + }); + I.click(locate("span").withText(annotation.label)); + I.click(locate("li").withText(annotation.text)); + }); + + annotations.forEach(annotation => { + I.click(locate("li").withText(annotation.text)); + + }); + const results = await I.executeScript(serialize); + + results.filter(result => result.value.labels).forEach((result, index) => { + const input = annotations[index]; + const expected = { end: input.rangeEnd, labels: [input.label], start: input.rangeStart, text: input.text }; + + assert.deepEqual(result.value, expected); + }); + +}); From 7efe2e78298fa6180321a9954035b9dbe7b8a65c Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Fri, 7 Oct 2022 11:06:03 -0400 Subject: [PATCH 05/24] tweaking the new taxonomy e2e test --- e2e/tests/taxonomy.test.js | 93 ++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 33 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index c353b6926..abf1fd6e7 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -25,47 +25,74 @@ const config = ` `; - - - +const configShowFullPath = ` + + + + + + + + + + + + + +`; const data = { text: `To have faith is to trust yourself to the water`, }; - const annotations = [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To' }, + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonmy: ["Eukarya", "Extraterrestial"], taxonomyLabel: "Extraterrestial" }, + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonmy: ["Archaea"], taxonomyLabel: "Archaea" }, +]; +const annotationsShowFullPath = [ + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonmy: ["Eukarya", "Extraterrestial"], taxonomyLabel: "Eukarya / Extraterrestial" }, +]; +const tests = [ + { title: "Check Taxonomy", params: { config, data }, annotations }, + // { title: "Check Taxonomy with showFullPath", params: { configShowFullPath, data }, annotations: annotationsShowFullPath } ]; -const params = { config, data }; - -Scenario("Check Taxonomy holds state between annotations and saves result", async function({ I, LabelStudio }) { - - I.amOnPage("/"); - - LabelStudio.init(params); - - annotations.forEach(annotation => { - I.click(locate("span").withText(annotation.label)); - I.executeScript(selectText, { - selector: ".lsf-htx-richtext", - rangeStart: annotation.rangeStart, - rangeEnd: annotation.rangeEnd, +tests.forEach(t => { + const { title, annotations, params } = t; + + Scenario(title, async ({ I, LabelStudio }) => { + + I.amOnPage("/"); + + LabelStudio.init(params); + + annotations.forEach(annotation => { + I.click(locate("span").withText(annotation.label)); + I.executeScript(selectText, { + selector: ".lsf-htx-richtext", + rangeStart: annotation.rangeStart, + rangeEnd: annotation.rangeEnd, + }); + I.click(locate("span").withText(annotation.label)); + I.click(locate("li").withText(annotation.text)); }); - I.click(locate("span").withText(annotation.label)); - I.click(locate("li").withText(annotation.text)); - }); - annotations.forEach(annotation => { - I.click(locate("li").withText(annotation.text)); + annotations.forEach(annotation => { + I.click(locate("li").withText(annotation.text)); + }); - }); - const results = await I.executeScript(serialize); + const results = await I.executeScript(serialize); + + results.filter(result => result.value.labels).forEach((result, index) => { + const input = annotations[index]; + const expected = { end: input.rangeEnd, labels: [input.label], start: input.rangeStart, text: input.text }; + + assert.deepEqual(result.value, expected); - results.filter(result => result.value.labels).forEach((result, index) => { - const input = annotations[index]; - const expected = { end: input.rangeEnd, labels: [input.label], start: input.rangeStart, text: input.text }; - - assert.deepEqual(result.value, expected); + locate("div").withText(input.taxonomyLabel); + }); + }); - -}); +}); \ No newline at end of file From 8d149fd10e11d216bed9533ac9e28cfb00a7726a Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Fri, 7 Oct 2022 11:33:05 -0400 Subject: [PATCH 06/24] fixing the taxonomy showFullPath e2e test --- e2e/tests/taxonomy.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index abf1fd6e7..f571c90fd 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -33,7 +33,7 @@ const configShowFullPath = ` `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonmy: ["Eukarya", "Extraterrestial"], taxonomyLabel: "Eukarya / Extraterrestial" }, + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [["Eukarya", "Human"]], test: { + assertTrue: [ + "Eukarya / Extraterrestial", + "Eukarya / Human", + ], + assertFalse: [ + "Bacteria", + ], + } }, ], }, }; @@ -69,7 +90,8 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current const Taxonomy = cases[taxnomyName]; const { annotations, config, text } = Taxonomy; - I.amOnPage("/"); + await I.amOnPage("/"); + const isOutliner = await LabelStudio.hasFF("ff_front_1170_outliner_030222_short"); LabelStudio.init({ config, data: { text } }); @@ -81,14 +103,18 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current rangeEnd: annotation.rangeEnd, }); I.click(locate("span").withText(annotation.label)); - I.click(locate("li").withText(annotation.text)); + I.click(isOutliner ? locate(".lsf-outliner-item__title").withText(annotation.text) : locate("li").withText(annotation.text)); }); - annotations.forEach(annotation => { - I.click(locate("li").withText(annotation.text)); + const results = await I.executeScript(serialize); + + annotations.forEach((annotation) => { + const regionEl = isOutliner ? locate(".lsf-outliner-item__title").withText(annotation.text) : locate("li").withText(annotation.text); + + I.seeElement(regionEl); + I.click(regionEl); }); - const results = await I.executeScript(serialize); results.filter(result => result.value.labels).forEach((result, index) => { const annotation = annotations[index]; @@ -96,7 +122,8 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current assert.deepEqual(result.value, expected); - locate("div").withText(annotation.taxonomyLabel); + annotation.test.assertTrue.forEach(label => I.seeElement(locate("div").withText(label))); + annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate("div").withText(label))); }); }); \ No newline at end of file From d8d29a54a8d3860cc74e5a7fb829073469f3458a Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Tue, 18 Oct 2022 17:28:49 -0400 Subject: [PATCH 10/24] trying to fix the e2e test - there appears to be an issue that occurs when clicking the region --- e2e/tests/taxonomy.test.js | 119 ++++++++++++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 16 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index 02b6239cf..3c0d9ae06 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -28,7 +28,7 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [["Eukarya", "Extraterrestial"]], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [[["Eukarya", "Extraterrestial"]]], test: { assertTrue: [ "Extraterrestial", ], @@ -36,7 +36,7 @@ const cases = { "Eukarya", ], } }, - { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [["Archaea"]], test: { + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [[["Archaea"]]], test: { assertTrue: [ "Archaea", "Extraterrestial", @@ -44,6 +44,9 @@ const cases = { assertFalse: [], } }, ], + FF: { + ff_front_1170_outliner_030222_short: false, + }, }, taxonomyWithShowLabels: { config: ` @@ -66,7 +69,7 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [["Eukarya", "Human"]], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [[["Eukarya", "Human"]]], test: { assertTrue: [ "Eukarya / Extraterrestial", "Eukarya / Human", @@ -76,6 +79,85 @@ const cases = { ], } }, ], + FF: { + ff_front_1170_outliner_030222_short: false, + }, + }, + taxonomyOutliner: { + config: ` + + + + + + + + + + + + + `, + text: `To have faith is to trust yourself to the water`, + annotations: [ + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [[["Eukarya", "Extraterrestial"]]], test: { + assertTrue: [ + "Extraterrestial", + ], + assertFalse: [ + "Eukarya", + ], + } }, + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [[["Archaea"]]], test: { + assertTrue: [ + "Archaea", + "Extraterrestial", + ], + assertFalse: [], + } }, + ], + FF: { + ff_front_1170_outliner_030222_short: true, + }, + }, + taxonomyWithShowLabelsWithOuliner: { + config: ` + + + + + + + + + + + + + `, + text: `To have faith is to trust yourself to the water`, + annotations: [ + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [[["Eukarya", "Human"]]], test: { + assertTrue: [ + "Eukarya / Extraterrestial", + "Eukarya / Human", + ], + assertFalse: [ + "Bacteria", + ], + } }, + ], + FF: { + ff_front_1170_outliner_030222_short: true, + }, }, }; @@ -88,33 +170,31 @@ for (const taxonomyName of Object.keys(cases)) { Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current }) => { const { taxnomyName } = current; const Taxonomy = cases[taxnomyName]; - const { annotations, config, text } = Taxonomy; + const { annotations, config, text, FF } = Taxonomy; + const outlinerSelector = ".lsf-outliner-item__title"; + const sideBarRegionSelector = "li"; - await I.amOnPage("/"); - const isOutliner = await LabelStudio.hasFF("ff_front_1170_outliner_030222_short"); + I.amOnPage("/"); + LabelStudio.setFeatureFlags(FF); LabelStudio.init({ config, data: { text } }); + + const isOutliner = FF.ff_front_1170_outliner_030222_short; annotations.forEach(annotation => { - I.click(locate("span").withText(annotation.label)); + I.click(locate(".lsf-label__text").withText(annotation.label)); I.executeScript(selectText, { selector: ".lsf-htx-richtext", rangeStart: annotation.rangeStart, rangeEnd: annotation.rangeEnd, }); - I.click(locate("span").withText(annotation.label)); - I.click(isOutliner ? locate(".lsf-outliner-item__title").withText(annotation.text) : locate("li").withText(annotation.text)); - }); - - const results = await I.executeScript(serialize); - - annotations.forEach((annotation) => { - const regionEl = isOutliner ? locate(".lsf-outliner-item__title").withText(annotation.text) : locate("li").withText(annotation.text); + + const regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); I.seeElement(regionEl); - I.click(regionEl); }); + const results = await I.executeScript(serialize); results.filter(result => result.value.labels).forEach((result, index) => { const annotation = annotations[index]; @@ -122,6 +202,13 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current assert.deepEqual(result.value, expected); + const regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(".lsf-region-item__title").withText(annotation.label); + + I.seeElement(regionEl); + + I.wait(60); + // I.click(regionEl); + annotation.test.assertTrue.forEach(label => I.seeElement(locate("div").withText(label))); annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate("div").withText(label))); }); From efaba5462684441a5f3c3e289647482ed58aa4d1 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Thu, 20 Oct 2022 06:36:42 -0400 Subject: [PATCH 11/24] working on fixing the e2e test --- e2e/tests/taxonomy.test.js | 67 ++++++++++---------- src/components/Taxonomy/Taxonomy.module.scss | 65 ++++++++++--------- src/components/Taxonomy/Taxonomy.tsx | 5 +- src/tags/control/Taxonomy.js | 6 +- 4 files changed, 74 insertions(+), 69 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index 3c0d9ae06..2ac6795c0 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -28,18 +28,19 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [[["Eukarya", "Extraterrestial"]]], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [['Eukarya', 'Extraterrestial'], ['Archaea']], test: { assertTrue: [ - "Extraterrestial", + 'Extraterrestial', + 'Archaea', ], assertFalse: [ - "Eukarya", + 'Eukarya', ], } }, - { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [[["Archaea"]]], test: { + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [['Archaea']], test: { assertTrue: [ - "Archaea", - "Extraterrestial", + 'Archaea', + 'Extraterrestial', ], assertFalse: [], } }, @@ -69,13 +70,13 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [[["Eukarya", "Human"]]], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [['Eukarya', 'Human']], test: { assertTrue: [ - "Eukarya / Extraterrestial", - "Eukarya / Human", + 'Eukarya / Extraterrestial', + 'Eukarya / Human', ], assertFalse: [ - "Bacteria", + 'Bacteria', ], } }, ], @@ -104,18 +105,18 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [[["Eukarya", "Extraterrestial"]]], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [['Eukarya', 'Extraterrestial']], test: { assertTrue: [ - "Extraterrestial", + 'Extraterrestial', ], assertFalse: [ - "Eukarya", + 'Eukarya', ], } }, - { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [[["Archaea"]]], test: { + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [['Archaea']], test: { assertTrue: [ - "Archaea", - "Extraterrestial", + 'Archaea', + 'Extraterrestial', ], assertFalse: [], } }, @@ -145,13 +146,13 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [[["Eukarya", "Human"]]], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [['Eukarya', 'Human']], test: { assertTrue: [ - "Eukarya / Extraterrestial", - "Eukarya / Human", + 'Eukarya / Extraterrestial', + 'Eukarya / Human', ], assertFalse: [ - "Bacteria", + 'Bacteria', ], } }, ], @@ -173,6 +174,7 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current const { annotations, config, text, FF } = Taxonomy; const outlinerSelector = ".lsf-outliner-item__title"; const sideBarRegionSelector = "li"; + const taxonomyLabelSelector = ".lsf-taxonomy__label"; I.amOnPage("/"); @@ -192,25 +194,26 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current const regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); I.seeElement(regionEl); + + I.wait(60); + + I.click(regionEl); + annotation.test.assertTrue.forEach(label => I.seeElement(locate(taxonomyLabelSelector).withText(label))); + annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate(taxonomyLabelSelector).withText(label))); }); const results = await I.executeScript(serialize); results.filter(result => result.value.labels).forEach((result, index) => { const annotation = annotations[index]; - const expected = { end: annotation.rangeEnd, labels: [annotation.label], start: annotation.rangeStart, text: annotation.text }; - - assert.deepEqual(result.value, expected); - - const regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(".lsf-region-item__title").withText(annotation.label); + const expected = { + end: annotation.rangeEnd, + labels: [annotation.label], + start: annotation.rangeStart, + text: annotation.text, + }; - I.seeElement(regionEl); - - I.wait(60); - // I.click(regionEl); - - annotation.test.assertTrue.forEach(label => I.seeElement(locate("div").withText(label))); - annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate("div").withText(label))); + assert.deepEqual(result.value, expected); }); }); \ No newline at end of file diff --git a/src/components/Taxonomy/Taxonomy.module.scss b/src/components/Taxonomy/Taxonomy.module.scss index b769dde6d..30d7b92ff 100644 --- a/src/components/Taxonomy/Taxonomy.module.scss +++ b/src/components/Taxonomy/Taxonomy.module.scss @@ -15,6 +15,38 @@ white-space: nowrap; cursor: pointer; } + &__selected { + display: flex; + flex-wrap: wrap; + min-height: 28px; // 24px button + 4px margin + + div { + margin: 0 2px 4px 0; + background: hsl(0, 0%, 95%); + padding: 0; // all the right space should be a clickable button, so no padding + padding-left: 8px; + border-radius: 4px; + display: flex; + align-items: center; + } + + input[type="button"] { + border: none; + background: none; + cursor: pointer; + width: 24px; + height: 24px; + padding: 0; + line-height: 1; + font-weight: 500; + font-size: 20px; + color: #09f; + + &:hover { + color: red; + } + } + } } .taxonomy > span > svg { @@ -24,39 +56,6 @@ transform: none; } -.taxonomy__selected { - display: flex; - flex-wrap: wrap; - min-height: 28px; // 24px button + 4px margin - - div { - margin: 0 2px 4px 0; - background: hsl(0, 0%, 95%); - padding: 0; // all the right space should be a clickable button, so no padding - padding-left: 8px; - border-radius: 4px; - display: flex; - align-items: center; - } - - input[type="button"] { - border: none; - background: none; - cursor: pointer; - width: 24px; - height: 24px; - padding: 0; - line-height: 1; - font-weight: 500; - font-size: 20px; - color: #09f; - - &:hover { - color: red; - } - } -} - .taxonomy__dropdown { position: absolute; z-index: 10; diff --git a/src/components/Taxonomy/Taxonomy.tsx b/src/components/Taxonomy/Taxonomy.tsx index 15186bafe..b35b11f83 100644 --- a/src/components/Taxonomy/Taxonomy.tsx +++ b/src/components/Taxonomy/Taxonomy.tsx @@ -5,6 +5,7 @@ import { useToggle } from "../../hooks/useToggle"; import { isArraysEqual } from "../../utils/utilities"; import { LsChevron } from "../../assets/icons"; import TreeStructure from "../TreeStructure/TreeStructure"; +import { Elem } from "../../utils/bem"; import styles from "./Taxonomy.module.scss"; @@ -129,12 +130,12 @@ const SelectedList = ({ isReadonly, flatItems } : { isReadonly:boolean, flatItem return (
{selectedLabels.map((path, index) => ( -
+ {showFullPath ? path.join(pathSeparator) : path[path.length - 1]} {!isReadonly && setSelected(selected[index], false)} value="×" /> } -
+ ))}
); diff --git a/src/tags/control/Taxonomy.js b/src/tags/control/Taxonomy.js index 06dcafad8..1bbfe595d 100644 --- a/src/tags/control/Taxonomy.js +++ b/src/tags/control/Taxonomy.js @@ -15,6 +15,7 @@ import ControlBase from "./Base"; import DynamicChildrenMixin from "../../mixins/DynamicChildrenMixin"; import { FF_DEV_2007_DEV_2008, isFF } from "../../utils/feature-flags"; import Tree from "../../core/Tree"; +import { Block } from "../../utils/bem"; /** * Use the Taxonomy tag to create one or more hierarchical classifications, storing both choice selections and their ancestors in the results. Use for nested classification tasks with the Choice tag. @@ -164,6 +165,7 @@ const Model = types get preselectedValues() { const items = Tree.filterChildrenOfType(self, 'ChoiceModel'); + console.log("preselectedValues", items, self, items.filter(c => c.selected).map(c => c.resultValue)); return items.filter(c => c.selected).map(c => c.resultValue); }, @@ -243,7 +245,7 @@ const HtxTaxonomy = observer(({ item }) => { }; return ( -
+ { options={options} isReadonly={item.annotation.readonly} /> -
+ ); }); From f1d80d8510cde52cbd5c9634c26b3d0f91f8ee65 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Thu, 20 Oct 2022 06:58:07 -0400 Subject: [PATCH 12/24] clearing console --- src/tags/control/Taxonomy.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tags/control/Taxonomy.js b/src/tags/control/Taxonomy.js index 1bbfe595d..8af22c107 100644 --- a/src/tags/control/Taxonomy.js +++ b/src/tags/control/Taxonomy.js @@ -164,8 +164,7 @@ const Model = types get preselectedValues() { const items = Tree.filterChildrenOfType(self, 'ChoiceModel'); - - console.log("preselectedValues", items, self, items.filter(c => c.selected).map(c => c.resultValue)); + return items.filter(c => c.selected).map(c => c.resultValue); }, From dac545863dea34a9d6cb03eeb07b3454d87528c6 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Thu, 20 Oct 2022 10:33:38 -0400 Subject: [PATCH 13/24] clean up --- e2e/tests/taxonomy.test.js | 5 ++--- src/tags/control/Taxonomy.js | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index 2ac6795c0..2cf27e369 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -178,7 +178,7 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current I.amOnPage("/"); - LabelStudio.setFeatureFlags(FF); + LabelStudio.setFeatureFlags({ ff_dev_2007_rework_choices_280322_short: true, ...FF }); LabelStudio.init({ config, data: { text } }); const isOutliner = FF.ff_front_1170_outliner_030222_short; @@ -195,9 +195,8 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current I.seeElement(regionEl); - I.wait(60); - I.click(regionEl); + annotation.test.assertTrue.forEach(label => I.seeElement(locate(taxonomyLabelSelector).withText(label))); annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate(taxonomyLabelSelector).withText(label))); }); diff --git a/src/tags/control/Taxonomy.js b/src/tags/control/Taxonomy.js index 8af22c107..615d7e20f 100644 --- a/src/tags/control/Taxonomy.js +++ b/src/tags/control/Taxonomy.js @@ -163,9 +163,10 @@ const Model = types }, get preselectedValues() { - const items = Tree.filterChildrenOfType(self, 'ChoiceModel'); + const items = Tree.filterChildrenOfType(self, ['ChoiceModel']); + const selectedItems = items.filter(c => c.selected); - return items.filter(c => c.selected).map(c => c.resultValue); + return selectedItems.map(c => c.resultValue); }, get defaultChildType() { From 318f4ab44c5233a3e398b8fa2c820e50689e96e4 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Thu, 20 Oct 2022 14:32:53 -0400 Subject: [PATCH 14/24] updating the taxonomy e2e test --- e2e/tests/taxonomy.test.js | 38 ++++++++++++++++++---------- src/components/Taxonomy/Taxonomy.tsx | 6 ++++- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index 2cf27e369..54d8ef998 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -28,16 +28,15 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [['Eukarya', 'Extraterrestial'], ['Archaea']], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: ['Extraterrestial', 'Archaea'], test: { assertTrue: [ - 'Extraterrestial', 'Archaea', ], assertFalse: [ - 'Eukarya', + 'Extraterrestial', ], } }, - { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [['Archaea']], test: { + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', clickTaxonomy: ['Archaea'], test: { assertTrue: [ 'Archaea', 'Extraterrestial', @@ -70,7 +69,7 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [['Eukarya', 'Human']], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: ['Human'], test: { assertTrue: [ 'Eukarya / Extraterrestial', 'Eukarya / Human', @@ -105,15 +104,14 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [['Eukarya', 'Extraterrestial']], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: ['Extraterrestial'], test: { assertTrue: [ - 'Extraterrestial', ], assertFalse: [ - 'Eukarya', + 'Extraterrestial', ], } }, - { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', taxonomy: [['Archaea']], test: { + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', clickTaxonomy: ['Archaea'], test: { assertTrue: [ 'Archaea', 'Extraterrestial', @@ -146,7 +144,7 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', taxonomy: [['Eukarya', 'Human']], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: [['Eukarya', 'Human']], test: { assertTrue: [ 'Eukarya / Extraterrestial', 'Eukarya / Human', @@ -196,9 +194,16 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current I.seeElement(regionEl); I.click(regionEl); - - annotation.test.assertTrue.forEach(label => I.seeElement(locate(taxonomyLabelSelector).withText(label))); - annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate(taxonomyLabelSelector).withText(label))); + I.click(locate("span").withText("Click to add...")); + + I.click(locate(".collapser.collapsed")); + + annotation.clickTaxonomy.forEach(t => I.click(locate("label").withText(t))); + + /* reseting clicks */ + I.click(locate(".collapser.open")); + I.click(regionEl); + I.click(locate(".lsf-label__text").withText(annotation.label)); }); const results = await I.executeScript(serialize); @@ -213,6 +218,13 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current }; assert.deepEqual(result.value, expected); + + const regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); + + I.click(regionEl); + + annotation.test.assertTrue.forEach(label => I.seeElement(locate(taxonomyLabelSelector).withText(label))); + annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate(taxonomyLabelSelector).withText(label))); }); }); \ No newline at end of file diff --git a/src/components/Taxonomy/Taxonomy.tsx b/src/components/Taxonomy/Taxonomy.tsx index b35b11f83..5288a649f 100644 --- a/src/components/Taxonomy/Taxonomy.tsx +++ b/src/components/Taxonomy/Taxonomy.tsx @@ -218,7 +218,11 @@ const Item: React.FC = ({ style, item, dimensionCallback, maxWidth }:
toggle(id)}> - +
Date: Thu, 20 Oct 2022 14:36:09 -0400 Subject: [PATCH 15/24] e2e test finally fixed --- e2e/tests/taxonomy.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index 54d8ef998..735f378b4 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -144,7 +144,7 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: [['Eukarya', 'Human']], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: [['Human']], test: { assertTrue: [ 'Eukarya / Extraterrestial', 'Eukarya / Human', From 0d41b7128ed08394a9df7c766f354661d801d15f Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Fri, 21 Oct 2022 15:48:52 -0400 Subject: [PATCH 16/24] now looking for tags in the appropriate spots --- src/tags/object/RichText/view.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tags/object/RichText/view.js b/src/tags/object/RichText/view.js index 0ea66f56b..2b7c0b178 100644 --- a/src/tags/object/RichText/view.js +++ b/src/tags/object/RichText/view.js @@ -84,10 +84,10 @@ class RichTextPieceView extends Component { normedRange.isText = item.type === "text"; normedRange.dynamic = this.props.store.autoAnnotation; - const perRegionParentWithPreselectedValues = item.parent.filter(parent => parent.perregion && (parent.preselectedValues?.length ?? 0) > 0); + const selectedAnnotation = window.Htx.annotationStore.selected.toNames.get('text').filter(annotation => annotation.perregion && (annotation.preselectedValues?.length ?? 0) > 0); const newRegion = item.addRegion(normedRange, this.doubleClickSelection); - perRegionParentWithPreselectedValues.forEach(parent => newRegion.setDefaultValue(parent)); + selectedAnnotation.forEach(annotation => newRegion.setDefaultValue(annotation)); }, { window: rootEl?.contentWindow ?? window, granularity: label?.granularity ?? item.granularity, From 3d967f24a0f0c77e5893898799dd47f8c3f43953 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Fri, 21 Oct 2022 15:54:16 -0400 Subject: [PATCH 17/24] e2e test cleanup --- e2e/tests/taxonomy.test.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index 735f378b4..c26975d7b 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -28,7 +28,8 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: ['Extraterrestial', 'Archaea'], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', test: { + clickTaxonomy: ['Extraterrestial', 'Archaea'], assertTrue: [ 'Archaea', ], @@ -36,7 +37,8 @@ const cases = { 'Extraterrestial', ], } }, - { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', clickTaxonomy: ['Archaea'], test: { + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', test: { + clickTaxonomy: ['Archaea'], assertTrue: [ 'Archaea', 'Extraterrestial', @@ -69,7 +71,8 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: ['Human'], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', test: { + clickTaxonomy: ['Human'], assertTrue: [ 'Eukarya / Extraterrestial', 'Eukarya / Human', @@ -104,14 +107,16 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: ['Extraterrestial'], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', test: { + clickTaxonomy: ['Extraterrestial'], assertTrue: [ ], assertFalse: [ 'Extraterrestial', ], } }, - { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', clickTaxonomy: ['Archaea'], test: { + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', test: { + clickTaxonomy: ['Archaea'], assertTrue: [ 'Archaea', 'Extraterrestial', @@ -144,7 +149,8 @@ const cases = { `, text: `To have faith is to trust yourself to the water`, annotations: [ - { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', clickTaxonomy: [['Human']], test: { + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', test: { + clickTaxonomy: [['Human']], assertTrue: [ 'Eukarya / Extraterrestial', 'Eukarya / Human', @@ -198,7 +204,7 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current I.click(locate(".collapser.collapsed")); - annotation.clickTaxonomy.forEach(t => I.click(locate("label").withText(t))); + annotation.test.clickTaxonomy.forEach(t => I.click(locate("label").withText(t))); /* reseting clicks */ I.click(locate(".collapser.open")); From e43f9cfb7dccb3b052546d62f4dd3d6cd287558a Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Mon, 24 Oct 2022 07:39:10 -0400 Subject: [PATCH 18/24] fixing e2e test --- e2e/tests/taxonomy.test.js | 98 +++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 18 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index c26975d7b..71c561c68 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -7,7 +7,7 @@ const assert = require("assert"); Feature("Taxonomy"); const cases = { - taxonomy: { + taxonomyPerRegion: { config: ` @@ -46,6 +46,51 @@ const cases = { assertFalse: [], } }, ], + isPerRegion: true, + FF: { + ff_front_1170_outliner_030222_short: false, + }, + }, + taxonomy: { + config: ` + + + + + + + + + + + + + `, + text: `To have faith is to trust yourself to the water`, + annotations: [ + { label: 'PER', rangeStart: 0, rangeEnd: 2, text: 'To', test: { + clickTaxonomy: ['Extraterrestial', 'Archaea'], + assertTrue: [ + 'Archaea', + ], + assertFalse: [ + 'Extraterrestial', + ], + } }, + { label: 'PER', rangeStart: 3, rangeEnd: 7, text: 'have', test: { + clickTaxonomy: ['Archaea'], + assertTrue: [ + 'Archaea', + 'Extraterrestial', + ], + assertFalse: [], + } }, + ], + isPerRegion: false, FF: { ff_front_1170_outliner_030222_short: false, }, @@ -82,6 +127,7 @@ const cases = { ], } }, ], + isPerRegion: true, FF: { ff_front_1170_outliner_030222_short: false, }, @@ -124,6 +170,7 @@ const cases = { assertFalse: [], } }, ], + isPerRegion: true, FF: { ff_front_1170_outliner_030222_short: true, }, @@ -160,6 +207,7 @@ const cases = { ], } }, ], + isPerRegion: true, FF: { ff_front_1170_outliner_030222_short: true, }, @@ -175,7 +223,7 @@ for (const taxonomyName of Object.keys(cases)) { Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current }) => { const { taxnomyName } = current; const Taxonomy = cases[taxnomyName]; - const { annotations, config, text, FF } = Taxonomy; + const { annotations, config, text, isPerRegion, FF } = Taxonomy; const outlinerSelector = ".lsf-outliner-item__title"; const sideBarRegionSelector = "li"; const taxonomyLabelSelector = ".lsf-taxonomy__label"; @@ -188,28 +236,34 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current const isOutliner = FF.ff_front_1170_outliner_030222_short; annotations.forEach(annotation => { - I.click(locate(".lsf-label__text").withText(annotation.label)); - I.executeScript(selectText, { - selector: ".lsf-htx-richtext", - rangeStart: annotation.rangeStart, - rangeEnd: annotation.rangeEnd, - }); - - const regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); + let regionEl; - I.seeElement(regionEl); + if (isPerRegion) { + I.click(locate(".lsf-label__text").withText(annotation.label)); + I.executeScript(selectText, { + selector: ".lsf-htx-richtext", + rangeStart: annotation.rangeStart, + rangeEnd: annotation.rangeEnd, + }); - I.click(regionEl); - I.click(locate("span").withText("Click to add...")); + regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); + + I.seeElement(regionEl); + I.click(regionEl); + } + I.click(locate("span").withText("Click to add...")); I.click(locate(".collapser.collapsed")); - annotation.test.clickTaxonomy.forEach(t => I.click(locate("label").withText(t))); + /* reseting clicks */ I.click(locate(".collapser.open")); - I.click(regionEl); - I.click(locate(".lsf-label__text").withText(annotation.label)); + I.click(locate("span").withText("Click to add...")); + if (isPerRegion) { + I.click(regionEl); + I.click(locate(".lsf-label__text").withText(annotation.label)); + } }); const results = await I.executeScript(serialize); @@ -225,12 +279,20 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current assert.deepEqual(result.value, expected); - const regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); + let regionEl; - I.click(regionEl); + if (isPerRegion) { + regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); + + I.click(regionEl); + } annotation.test.assertTrue.forEach(label => I.seeElement(locate(taxonomyLabelSelector).withText(label))); annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate(taxonomyLabelSelector).withText(label))); + + if (isPerRegion) { + I.click(regionEl); + } }); }); \ No newline at end of file From 1e88a9d12e2b9eaae7af0767e29b42ab01c15529 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Mon, 24 Oct 2022 11:11:19 -0400 Subject: [PATCH 19/24] making sure we pick up outliner just before we use it --- e2e/tests/taxonomy.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index 71c561c68..163516203 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -233,7 +233,6 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current LabelStudio.setFeatureFlags({ ff_dev_2007_rework_choices_280322_short: true, ...FF }); LabelStudio.init({ config, data: { text } }); - const isOutliner = FF.ff_front_1170_outliner_030222_short; annotations.forEach(annotation => { let regionEl; @@ -246,6 +245,8 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current rangeEnd: annotation.rangeEnd, }); + const isOutliner = FF.ff_front_1170_outliner_030222_short; + regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); I.seeElement(regionEl); @@ -282,6 +283,8 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current let regionEl; if (isPerRegion) { + const isOutliner = FF.ff_front_1170_outliner_030222_short; + regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); I.click(regionEl); From 5ae69ecc59d88f6ce87e08cda6a74c8f3a8f136c Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Mon, 24 Oct 2022 14:23:04 -0400 Subject: [PATCH 20/24] fixed e2e test --- e2e/tests/taxonomy.test.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index 163516203..b25288867 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -7,7 +7,7 @@ const assert = require("assert"); Feature("Taxonomy"); const cases = { - taxonomyPerRegion: { + taxonomy: { config: ` @@ -16,7 +16,7 @@ const cases = { - + @@ -46,12 +46,12 @@ const cases = { assertFalse: [], } }, ], - isPerRegion: true, + isPerRegion: false, FF: { ff_front_1170_outliner_030222_short: false, }, }, - taxonomy: { + taxonomyPerRegion: { config: ` @@ -60,7 +60,7 @@ const cases = { - + @@ -90,7 +90,7 @@ const cases = { assertFalse: [], } }, ], - isPerRegion: false, + isPerRegion: true, FF: { ff_front_1170_outliner_030222_short: false, }, @@ -233,6 +233,7 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current LabelStudio.setFeatureFlags({ ff_dev_2007_rework_choices_280322_short: true, ...FF }); LabelStudio.init({ config, data: { text } }); + const isOutliner = FF.ff_front_1170_outliner_030222_short; annotations.forEach(annotation => { let regionEl; @@ -245,8 +246,6 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current rangeEnd: annotation.rangeEnd, }); - const isOutliner = FF.ff_front_1170_outliner_030222_short; - regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); I.seeElement(regionEl); @@ -260,10 +259,11 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current /* reseting clicks */ I.click(locate(".collapser.open")); - I.click(locate("span").withText("Click to add...")); if (isPerRegion) { I.click(regionEl); I.click(locate(".lsf-label__text").withText(annotation.label)); + } else { + I.click(locate("span").withText("Click to add...")); } }); @@ -280,22 +280,14 @@ Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current assert.deepEqual(result.value, expected); - let regionEl; - if (isPerRegion) { - const isOutliner = FF.ff_front_1170_outliner_030222_short; - - regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); + const regionEl = isOutliner ? locate(outlinerSelector).withText(annotation.label) : locate(sideBarRegionSelector).withText(annotation.text); I.click(regionEl); } annotation.test.assertTrue.forEach(label => I.seeElement(locate(taxonomyLabelSelector).withText(label))); annotation.test.assertFalse.forEach(label => I.dontSeeElement(locate(taxonomyLabelSelector).withText(label))); - - if (isPerRegion) { - I.click(regionEl); - } }); }); \ No newline at end of file From 6d9436b37bdc5159905f45da438b089236346063 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Mon, 24 Oct 2022 15:56:49 -0400 Subject: [PATCH 21/24] making the value fix a little more dynamic --- src/tags/object/RichText/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tags/object/RichText/view.js b/src/tags/object/RichText/view.js index 2b7c0b178..6d56b8bd2 100644 --- a/src/tags/object/RichText/view.js +++ b/src/tags/object/RichText/view.js @@ -84,7 +84,7 @@ class RichTextPieceView extends Component { normedRange.isText = item.type === "text"; normedRange.dynamic = this.props.store.autoAnnotation; - const selectedAnnotation = window.Htx.annotationStore.selected.toNames.get('text').filter(annotation => annotation.perregion && (annotation.preselectedValues?.length ?? 0) > 0); + const selectedAnnotation = window.Htx.annotationStore.selected.toNames.get(item.name).toJSON()?.filter(annotation => annotation.perregion && (annotation.preselectedValues?.length ?? 0) > 0); const newRegion = item.addRegion(normedRange, this.doubleClickSelection); selectedAnnotation.forEach(annotation => newRegion.setDefaultValue(annotation)); From 314cd789759cd837dac7dbfb5a71c4fdc3147cce Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Tue, 25 Oct 2022 11:52:46 -0400 Subject: [PATCH 22/24] switching away from Htx.annotationStore --- e2e/tests/taxonomy.test.js | 6 +++--- src/tags/object/RichText/view.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/tests/taxonomy.test.js b/e2e/tests/taxonomy.test.js index b25288867..dabd1553d 100644 --- a/e2e/tests/taxonomy.test.js +++ b/e2e/tests/taxonomy.test.js @@ -214,15 +214,15 @@ const cases = { }, }; -const taxonomyTable = new DataTable(["taxnomyName"]); +const taxonomyTable = new DataTable(["taxonomyName"]); for (const taxonomyName of Object.keys(cases)) { taxonomyTable.add([taxonomyName]); } Data(taxonomyTable).Scenario("Check Taxonomy", async ({ I, LabelStudio, current }) => { - const { taxnomyName } = current; - const Taxonomy = cases[taxnomyName]; + const { taxonomyName } = current; + const Taxonomy = cases[taxonomyName]; const { annotations, config, text, isPerRegion, FF } = Taxonomy; const outlinerSelector = ".lsf-outliner-item__title"; const sideBarRegionSelector = "li"; diff --git a/src/tags/object/RichText/view.js b/src/tags/object/RichText/view.js index 6d56b8bd2..504abeac2 100644 --- a/src/tags/object/RichText/view.js +++ b/src/tags/object/RichText/view.js @@ -84,7 +84,7 @@ class RichTextPieceView extends Component { normedRange.isText = item.type === "text"; normedRange.dynamic = this.props.store.autoAnnotation; - const selectedAnnotation = window.Htx.annotationStore.selected.toNames.get(item.name).toJSON()?.filter(annotation => annotation.perregion && (annotation.preselectedValues?.length ?? 0) > 0); + const selectedAnnotation = item.annotation.toNames.get(item.name).toJSON()?.filter(annotation => annotation.perregion && (annotation.preselectedValues?.length ?? 0) > 0); const newRegion = item.addRegion(normedRange, this.doubleClickSelection); selectedAnnotation.forEach(annotation => newRegion.setDefaultValue(annotation)); From 523da158cfafc3c2168d909fb530887401005408 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Tue, 25 Oct 2022 14:57:35 -0400 Subject: [PATCH 23/24] refactoring the code a bit so heavy lifting happens in createResult instead of richText view --- src/stores/Annotation/Annotation.js | 3 +++ src/tags/object/RichText/view.js | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/stores/Annotation/Annotation.js b/src/stores/Annotation/Annotation.js index 12323810d..ef083ba12 100644 --- a/src/stores/Annotation/Annotation.js +++ b/src/stores/Annotation/Annotation.js @@ -750,6 +750,9 @@ export const Annotation = types }; const area = self.areas.put(areaRaw); + const childrenWithPreselectedValues = self.toNames.get(object?.name ?? object)?.toJSON?.()?.filter(item => item.perregion && (item.preselectedValues?.length ?? 0) > 0); + + childrenWithPreselectedValues?.forEach(item => area.setDefaultValue(item)); if (!area.classification) getEnv(self).events.invoke('entityCreate', area); diff --git a/src/tags/object/RichText/view.js b/src/tags/object/RichText/view.js index 504abeac2..4a4af39e3 100644 --- a/src/tags/object/RichText/view.js +++ b/src/tags/object/RichText/view.js @@ -83,11 +83,7 @@ class RichTextPieceView extends Component { normedRange.text = selectionText; normedRange.isText = item.type === "text"; normedRange.dynamic = this.props.store.autoAnnotation; - - const selectedAnnotation = item.annotation.toNames.get(item.name).toJSON()?.filter(annotation => annotation.perregion && (annotation.preselectedValues?.length ?? 0) > 0); - const newRegion = item.addRegion(normedRange, this.doubleClickSelection); - - selectedAnnotation.forEach(annotation => newRegion.setDefaultValue(annotation)); + item.addRegion(normedRange, this.doubleClickSelection); }, { window: rootEl?.contentWindow ?? window, granularity: label?.granularity ?? item.granularity, From ea426b589d126f9ee3d30703c80b205c7b766954 Mon Sep 17 00:00:00 2001 From: Yousif Yassi Date: Mon, 31 Oct 2022 07:45:11 -0400 Subject: [PATCH 24/24] investigating taxonomy issue --- src/stores/Annotation/Annotation.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/stores/Annotation/Annotation.js b/src/stores/Annotation/Annotation.js index ca92f6365..3de38038b 100644 --- a/src/stores/Annotation/Annotation.js +++ b/src/stores/Annotation/Annotation.js @@ -520,7 +520,7 @@ export const Annotation = types } }); - // @todo deal with `defaultValue`s + // @todo deal with `defaulthttps://github.com/heartexlabs/label-studio-frontend/pull/899/files#diff-54c46de3667aec2ccad8009c8940a5dccba3acd3ba8de3bb3b803842857f922eValue`s }, setDefaultValues() { @@ -536,6 +536,7 @@ export const Annotation = types } if (couldHavePreselectedValues && tag.preselectedValues?.length) { + console.log("setDefaultValues", tag.valueType, tag.preselectedValues, self.selected, self.preselectedValues); self.createResult({}, { [tag.valueType]: tag.preselectedValues }, tag, tag.toname); } }); @@ -774,9 +775,14 @@ export const Annotation = types }; const area = self.areas.put(areaRaw); - const childrenWithPreselectedValues = self.toNames.get(object?.name ?? object)?.toJSON?.()?.filter(item => item.perregion && (item.preselectedValues?.length ?? 0) > 0); - - childrenWithPreselectedValues?.forEach(item => area.setDefaultValue(item)); + const childrenWithPreselectedValues = self.toNames.get(object?.name ?? object)?.toJSON?.()?.filter(item => (item.preselectedValues?.length ?? 0) > 0); + const preRegionChildWithPreselectedValues = childrenWithPreselectedValues.filter(item => item.perregion); + const annotationChildWithPreselectedValues = childrenWithPreselectedValues.filter(item => !item.perregion); + + preRegionChildWithPreselectedValues?.forEach(item => area.setDefaultValue(item)); + annotationChildWithPreselectedValues?.forEach(item => item.selected = item.preselectedValues); + + console.log("annotationChildWithPreselectedValues", annotationChildWithPreselectedValues, self); if (!area.classification) getEnv(self).events.invoke('entityCreate', area); if (!skipAfrerCreate) self.afterCreateResult(area, control); @@ -1075,6 +1081,7 @@ export const Annotation = types }, prepareValue(value, type) { + console.log("prepareValue", value, type); switch (type) { case "text": case "hypertext":