diff --git a/v3/cypress/e2e/formula/formula-component.spec.ts b/v3/cypress/e2e/formula/formula-component.spec.ts index 76ae5b93e8..0f517d7b6e 100644 --- a/v3/cypress/e2e/formula/formula-component.spec.ts +++ b/v3/cypress/e2e/formula/formula-component.spec.ts @@ -1,80 +1,81 @@ import { FormulaHelper as fh } from "../../support/helpers/formula-helper" import { TableTileElements as table } from "../../support/elements/table-tile" +import { SliderTileElements as slider } from "../../support/elements/slider-tile" context("Formula Engine", () => { describe("Component Formula Tests", () => { it("Add and edit formula for a new attribute", () => { fh.visitURL("?sample=four&dashboard") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") - fh.addFormula("Formula", "a+1") - fh.verifyValues("Formula", [2, 3, 4, 4, 1]) - fh.checkFormulaExists("Formula", "a+1") - fh.editFormula("Formula", "a+2") - fh.verifyValues("Formula", [3, 4, 5, 5, 2]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") + table.addFormula("Formula", "a+1") + table.verifyFormulaValues("Formula", [2, 3, 4, 4, 1]) + table.checkFormulaExists("Formula", "a+1") + table.editFormula("Formula", "a+2") + table.verifyFormulaValues("Formula", [3, 4, 5, 5, 2]) }) it("Add and edit formula for an existing attribute", () => { fh.visitURL("?sample=four&dashboard") - fh.addFormula("b", "count(a)") - fh.verifyValues("b", [4, 4, 4, 4, 4]) - fh.checkFormulaExists("b", "count(a)") - fh.editFormula("b", "mean(a)") - fh.verifyValues("b", [2.25, 2.25, 2.25, 2.25, 2.25]) + table.addFormula("b", "count(a)") + table.verifyFormulaValues("b", [4, 4, 4, 4, 4]) + table.checkFormulaExists("b", "count(a)") + table.editFormula("b", "mean(a)") + table.verifyFormulaValues("b", [2.25, 2.25, 2.25, 2.25, 2.25]) }) it("Rename attribute and make sure formula updates", () => { fh.visitURL("?sample=four&dashboard") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") - fh.addFormula("Formula", "count(a)") - fh.verifyValues("Formula", [4, 4, 4, 4, 4]) - fh.renameAttribute("a", "x") - fh.checkFormulaExists("Formula", "count(x)") - fh.verifyValues("Formula", [4, 4, 4, 4, 4]) - fh.editFormula("Formula", "mean(x)") - fh.verifyValues("Formula", [2.25, 2.25, 2.25, 2.25, 2.25]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") + table.addFormula("Formula", "count(a)") + table.verifyFormulaValues("Formula", [4, 4, 4, 4, 4]) + table.renameAttribute("a", "x") + table.checkFormulaExists("Formula", "count(x)") + table.verifyFormulaValues("Formula", [4, 4, 4, 4, 4]) + table.editFormula("Formula", "mean(x)") + table.verifyFormulaValues("Formula", [2.25, 2.25, 2.25, 2.25, 2.25]) }) it("Delete attribute that a formula uses", () => { fh.visitURL("?sample=four&dashboard") - fh.addFormula("b", "count(a)") - fh.deleteAttribute("a") - fh.checkFormulaExists("b", "count(a)") - fh.verifyValues("b", [ + table.addFormula("b", "count(a)") + table.deleteAttribute("a") + table.checkFormulaExists("b", "count(a)") + table.verifyFormulaValues("b", [ "❌ Undefined symbol a", "❌ Undefined symbol a", "❌ Undefined symbol a", "❌ Undefined symbol a", "❌ Undefined symbol a" ]) - fh.editFormula("b", "5") - fh.verifyValues("b", [5, 5, 5, 5, 5]) + table.editFormula("b", "5") + table.verifyFormulaValues("b", [5, 5, 5, 5, 5]) }) it("Use slider variable with formula", () => { fh.visitURL("?sample=four&dashboard") - fh.addFormula("b", "count(a) + v1") - fh.verifyValues("b", [4.5, 4.5, 4.5, 4.5, 4.5]) - fh.changeSliderVariableName("v2") - fh.checkFormulaExists("b", "count(a) + v2") - fh.verifyValues("b", [4.5, 4.5, 4.5, 4.5, 4.5]) - fh.changeSliderValue("10") - fh.verifyValues("b", [14, 14, 14, 14, 14]) - fh.deleteSlider() - fh.checkFormulaExists("b", "count(a) + v2") + table.addFormula("b", "count(a) + v1") + table.verifyFormulaValues("b", [4.5, 4.5, 4.5, 4.5, 4.5]) + slider.changeVariableName("v2") + table.checkFormulaExists("b", "count(a) + v2") + table.verifyFormulaValues("b", [4.5, 4.5, 4.5, 4.5, 4.5]) + slider.changeVariableValue("10") + table.verifyFormulaValues("b", [14, 14, 14, 14, 14]) + slider.deleteSlider() + table.checkFormulaExists("b", "count(a) + v2") }) it("Add slider after using it in formula", () => { fh.visitURL("?sample=four") - fh.addFormula("b", "count(a) + v1") - fh.verifyValues("b", [ + table.addFormula("b", "count(a) + v1") + table.verifyFormulaValues("b", [ "❌ Undefined symbol v1", "❌ Undefined symbol v1", "❌ Undefined symbol v1", "❌ Undefined symbol v1", "❌ Undefined symbol v1" ]) - fh.addSlider() - fh.checkFormulaExists("b", "count(a) + v1") - fh.verifyValues("b", [4.5, 4.5, 4.5, 4.5, 4.5]) - fh.deleteSlider() - fh.verifyValues("b", [ + slider.addSlider() + table.checkFormulaExists("b", "count(a) + v1") + table.verifyFormulaValues("b", [4.5, 4.5, 4.5, 4.5, 4.5]) + slider.deleteSlider() + table.verifyFormulaValues("b", [ "❌ Undefined symbol v1", "❌ Undefined symbol v1", "❌ Undefined symbol v1", @@ -84,13 +85,14 @@ context("Formula Engine", () => { }) it("Formula in a new dataset", () => { fh.visitURL("") - fh.createNewDataset() - fh.insertCases(2, 4) - fh.addFormula("AttributeName", "10*10") - fh.verifyValues("AttributeName", [100, 100, 100, 100, 100]) - fh.addNewAttribute() - fh.addFormula("newAttr", "AttributeName+2") - fh.verifyValues("newAttr", [102, 102, 102, 102, 102]) + table.createNewTableFromToolShelf() + table.openIndexMenuForRow(2) + table.insertCases(4, "after") + table.addFormula("AttributeName", "10*10") + table.verifyFormulaValues("AttributeName", [100, 100, 100, 100, 100]) + table.addNewAttribute() + table.addFormula("newAttr", "AttributeName+2") + table.verifyFormulaValues("newAttr", [102, 102, 102, 102, 102]) }) }) describe("Add functions and values from Insert buttons", () => { @@ -98,8 +100,8 @@ context("Formula Engine", () => { const func = "abs" const funcCategory = "Arithmetic" fh.visitURL("?sample=four&dashboard") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") table.openAttributeMenu("Formula") table.selectMenuItemFromAttributeMenu("Edit Formula...") cy.get("[data-testid=formula-insert-function-button]").click() @@ -121,8 +123,8 @@ context("Formula Engine", () => { const func = "abs" const funcCategory = "Arithmetic" fh.visitURL("?sample=four&dashboard") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") table.openAttributeMenu("Formula") table.selectMenuItemFromAttributeMenu("Edit Formula...") cy.get("[data-testid=formula-insert-function-button]").click() @@ -139,8 +141,8 @@ context("Formula Engine", () => { it("Insert value into formula", () => { const value = "b" fh.visitURL("?sample=four&dashboard") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") table.openAttributeMenu("Formula") table.selectMenuItemFromAttributeMenu("Edit Formula...") cy.get("[data-testid=formula-insert-value-button]").click() diff --git a/v3/cypress/e2e/formula/formula-errors.spec.ts b/v3/cypress/e2e/formula/formula-errors.spec.ts index c1d27b5014..e0c0e22916 100644 --- a/v3/cypress/e2e/formula/formula-errors.spec.ts +++ b/v3/cypress/e2e/formula/formula-errors.spec.ts @@ -1,21 +1,22 @@ import { FormulaHelper as fh } from "../../support/helpers/formula-helper" +import { TableTileElements as table } from "../../support/elements/table-tile" context("Formula Engine", () => { describe("Errors Formula Tests", () => { it("Check invalid functions", () => { fh.visitURL("?sample=four") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") - fh.addFormula("Formula", "count(aaa)") - fh.verifyValues("Formula", [ + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") + table.addFormula("Formula", "count(aaa)") + table.verifyFormulaValues("Formula", [ "❌ Undefined symbol aaa", "❌ Undefined symbol aaa", "❌ Undefined symbol aaa", "❌ Undefined symbol aaa", "❌ Undefined symbol aaa" ]) - fh.editFormula("Formula", "c(aaa)") - fh.verifyValues("Formula", [ + table.editFormula("Formula", "c(aaa)") + table.verifyFormulaValues("Formula", [ "❌ Undefined function c", "❌ Undefined function c", "❌ Undefined function c", @@ -23,16 +24,16 @@ context("Formula Engine", () => { "❌ Undefined function c" ]) // need to add {del} because CodeMirror auto-matches parentheses - fh.editFormula("Formula", "count(a{del}") - fh.verifyValues("Formula", [ + table.editFormula("Formula", "count(a{del}") + table.verifyFormulaValues("Formula", [ "❌ Syntax error: 'Parenthesis ) expected (char 8)'", "❌ Syntax error: 'Parenthesis ) expected (char 8)'", "❌ Syntax error: 'Parenthesis ) expected (char 8)'", "❌ Syntax error: 'Parenthesis ) expected (char 8)'", "❌ Syntax error: 'Parenthesis ) expected (char 8)'" ]) - fh.editFormula("Formula", "count(a)") - fh.verifyValues("Formula", [4, 4, 4, 4, 4]) + table.editFormula("Formula", "count(a)") + table.verifyFormulaValues("Formula", [4, 4, 4, 4, 4]) }) }) }) diff --git a/v3/cypress/e2e/formula/formula-functions.spec.ts b/v3/cypress/e2e/formula/formula-functions.spec.ts index c7d50976d8..6e767bfdc5 100644 --- a/v3/cypress/e2e/formula/formula-functions.spec.ts +++ b/v3/cypress/e2e/formula/formula-functions.spec.ts @@ -1,69 +1,70 @@ import { FormulaHelper as fh } from "../../support/helpers/formula-helper" +import { TableTileElements as table } from "../../support/elements/table-tile" context("Formula Engine", () => { it("Check arithmetic functions", () => { fh.visitURL("") fh.importFile("cypress/fixtures/formula.codap3") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "abs") - fh.addFormula("abs", "abs(num)") - fh.verifyValues("abs", [2, 1, 0, 2, 0.147, 0.976, 1.571, "Infinity", "Infinity", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "ceil") - fh.addFormula("ceil", "ceil(num)") - fh.verifyValues("ceil", [2, 1, 0, "−2", 0, 1, "−1", "Infinity", "-Infinity", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "exp") - fh.addFormula("exp", "exp(num)") - fh.verifyValues("exp", [7.389, 2.718, 1, 0.135, 0.864, 2.655, 0.208, "Infinity", 0, "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "floor") - fh.addFormula("floor", "floor(num)") - fh.verifyValues("floor", [2, 1, 0, "−2", "−1", 0, "−2", "Infinity", "-Infinity", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "frac") - fh.addFormula("frac", "frac(num)") - fh.verifyValues("frac", [0, 0, 0, 0, "−0.147", 0.976, "−0.571", "NaN", "NaN", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "ln") - fh.addFormula("ln", "ln(num)") - fh.verifyValues("ln", [0.693, 0, "-Infinity", "NaN", "NaN", "−0.024", "NaN", "Infinity", "NaN", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "log") - fh.addFormula("log", "log(num)") - fh.verifyValues("log", [0.301, 0, "-Infinity", "NaN", "NaN", "−0.01", "NaN", "Infinity", "NaN", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "pow") - fh.addFormula("pow", "pow(num, 2)") - fh.verifyValues("pow", [4, 1, 0, 4, 0.021, 0.953, 2.468, "Infinity", "Infinity", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "round") - fh.addFormula("round", "round(num)") - fh.verifyValues("round", [2, 1, 0, "−2", 0, 1, "−2", "Infinity", "-Infinity", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "sqrt") - fh.addFormula("sqrt", "sqrt(num)") - fh.verifyValues("sqrt", [1.414, 1, 0, "NaN", "NaN", 0.988, "NaN", "Infinity", "NaN", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "trunc") - fh.addFormula("trunc", "trunc(num)") - fh.verifyValues("trunc", [2, 1, 0, "−2", 0, 0, "−1", "Infinity", "-Infinity", "", ""]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "combinations") - fh.addFormula("combinations", "combinations(num, 1)") - fh.verifyValues("combinations", [2, 1, + table.addNewAttribute() + table.renameAttribute("newAttr", "abs") + table.addFormula("abs", "abs(num)") + table.verifyFormulaValues("abs", [2, 1, 0, 2, 0.147, 0.976, 1.571, "Infinity", "Infinity", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "ceil") + table.addFormula("ceil", "ceil(num)") + table.verifyFormulaValues("ceil", [2, 1, 0, "−2", 0, 1, "−1", "Infinity", "-Infinity", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "exp") + table.addFormula("exp", "exp(num)") + table.verifyFormulaValues("exp", [7.389, 2.718, 1, 0.135, 0.864, 2.655, 0.208, "Infinity", 0, "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "floor") + table.addFormula("floor", "floor(num)") + table.verifyFormulaValues("floor", [2, 1, 0, "−2", "−1", 0, "−2", "Infinity", "-Infinity", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "frac") + table.addFormula("frac", "frac(num)") + table.verifyFormulaValues("frac", [0, 0, 0, 0, "−0.147", 0.976, "−0.571", "NaN", "NaN", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "ln") + table.addFormula("ln", "ln(num)") + table.verifyFormulaValues("ln", [0.693, 0, "-Infinity", "NaN", "NaN", "−0.024", "NaN", "Infinity", "NaN", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "log") + table.addFormula("log", "log(num)") + table.verifyFormulaValues("log", [0.301, 0, "-Infinity", "NaN", "NaN", "−0.01", "NaN", "Infinity", "NaN", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "pow") + table.addFormula("pow", "pow(num, 2)") + table.verifyFormulaValues("pow", [4, 1, 0, 4, 0.021, 0.953, 2.468, "Infinity", "Infinity", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "round") + table.addFormula("round", "round(num)") + table.verifyFormulaValues("round", [2, 1, 0, "−2", 0, 1, "−2", "Infinity", "-Infinity", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "sqrt") + table.addFormula("sqrt", "sqrt(num)") + table.verifyFormulaValues("sqrt", [1.414, 1, 0, "NaN", "NaN", 0.988, "NaN", "Infinity", "NaN", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "trunc") + table.addFormula("trunc", "trunc(num)") + table.verifyFormulaValues("trunc", [2, 1, 0, "−2", 0, 0, "−1", "Infinity", "-Infinity", "", ""]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "combinations") + table.addFormula("combinations", "combinations(num, 1)") + table.verifyFormulaValues("combinations", [2, 1, "❌ k must be less than or equal to n", "❌ Positive integer value expected in function combinations", "❌ Positive integer value expected in function combinations", @@ -78,54 +79,56 @@ context("Formula Engine", () => { fh.visitURL("") fh.importFile("cypress/fixtures/formula.codap3") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "prev") - fh.addFormula("prev", "prev(num, 1)") - fh.verifyValues("prev", [1, 2, 1, 0, "−2", "−0.147", 0.976, "−1.571", "Infinity", "-Infinity", "foo"]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "next") - fh.addFormula("next", "next(num, 1)") - fh.verifyValues("next", [1, 0, "−2", "−0.147", 0.976, "−1.571", "Infinity", "-Infinity", "foo", "", 1]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "lookupByIndex") - fh.addFormula("lookupByIndex", `lookupByIndex("Formula", "num", 1)`) - fh.verifyValues("lookupByIndex", [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) - - fh.addNewAttribute() - fh.renameAttribute("newAttr", "lookupByKey") - fh.addFormula("lookupByKey", `lookupByKey("Formula", "num", "prev",1)`) - fh.verifyValues("lookupByKey", [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) + table.addNewAttribute() + table.renameAttribute("newAttr", "prev") + table.addFormula("prev", "prev(num, 1)") + table.verifyFormulaValues("prev", [1, 2, 1, 0, "−2", "−0.147", 0.976, "−1.571", "Infinity", "-Infinity", "foo"]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "next") + table.addFormula("next", "next(num, 1)") + table.verifyFormulaValues("next", [1, 0, "−2", "−0.147", 0.976, "−1.571", "Infinity", "-Infinity", "foo", "", 1]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "lookupByIndex") + table.addFormula("lookupByIndex", `lookupByIndex("Formula", "num", 1)`) + table.verifyFormulaValues("lookupByIndex", [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) + + table.addNewAttribute() + table.renameAttribute("newAttr", "lookupByKey") + table.addFormula("lookupByKey", `lookupByKey("Formula", "num", "prev",1)`) + table.verifyFormulaValues("lookupByKey", [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]) }) it("Check logic functions", () => { fh.visitURL("") fh.importFile("cypress/fixtures/formula.codap3") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "boolean") - fh.addFormula("boolean", "boolean(3+4=7)") - fh.verifyValues("boolean", ["true", "true", "true", "true", "true", "true", "true", "true", "true", "true", "true"]) + table.addNewAttribute() + table.renameAttribute("newAttr", "boolean") + table.addFormula("boolean", "boolean(3+4=7)") + table.verifyFormulaValues("boolean", + ["true", "true", "true", "true", "true", "true", "true", "true", "true", "true", "true"]) }) it("Check other functions", () => { fh.visitURL("") fh.importFile("cypress/fixtures/formula.codap3") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "number") - fh.addFormula("number", `number("45")`) - fh.verifyValues("number", [45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]) + table.addNewAttribute() + table.renameAttribute("newAttr", "number") + table.addFormula("number", `number("45")`) + table.verifyFormulaValues("number", [45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]) - fh.addNewAttribute() - fh.renameAttribute("newAttr", "random") - fh.addFormula("random", `if("random(1, 5) > 0 AND random(1, 5) < 6", "true", "false")`) - fh.verifyValues("random", ["true", "true", "true", "true", "true", "true", "true", "true", "true", "true", "true"]) + table.addNewAttribute() + table.renameAttribute("newAttr", "random") + table.addFormula("random", `if("random(1, 5) > 0 AND random(1, 5) < 6", "true", "false")`) + table.verifyFormulaValues("random", + ["true", "true", "true", "true", "true", "true", "true", "true", "true", "true", "true"]) - fh.addNewAttribute() - fh.renameAttribute("newAttr", "randomPick") - fh.addFormula("randomPick", `if("randomPick(1, 2, 3, 4, 5) > 0 AND randomPick(1, 2, 3, 4, 5) < 6", + table.addNewAttribute() + table.renameAttribute("newAttr", "randomPick") + table.addFormula("randomPick", `if("randomPick(1, 2, 3, 4, 5) > 0 AND randomPick(1, 2, 3, 4, 5) < 6", "true", "false")`) - fh.verifyValues("randomPick", ["true", "true", "true", "true", "true", "true", "true", "true", "true", + table.verifyFormulaValues("randomPick", ["true", "true", "true", "true", "true", "true", "true", "true", "true", "true", "true"]) }) }) diff --git a/v3/cypress/e2e/formula/formula-hierarchical-tables.spec.ts b/v3/cypress/e2e/formula/formula-hierarchical-tables.spec.ts index cddf68e433..b0891b1f35 100644 --- a/v3/cypress/e2e/formula/formula-hierarchical-tables.spec.ts +++ b/v3/cypress/e2e/formula/formula-hierarchical-tables.spec.ts @@ -1,55 +1,56 @@ import { FormulaHelper as fh } from "../../support/helpers/formula-helper" +import { TableTileElements as table } from "../../support/elements/table-tile" context("Formula Engine", () => { describe("Hierarchical Case Tables Formula Tests", () => { it("Check aggregate and non-aggregate formulae referencing a parent attribute in child collection", () => { fh.visitURL("") fh.importFile("cypress/fixtures/hierarchical-four.codap3") - fh.addNewAttribute(2) - fh.renameAttribute("newAttr", "Formula", 2) - fh.addFormula("Formula", "count(b)", 2) - fh.verifyValues("Formula", [ + table.addNewAttribute(2) + table.renameAttribute("newAttr", "Formula", 2) + table.addFormula("Formula", "count(b)", 2) + table.verifyFormulaValues("Formula", [ "❌ invalid reference to parent attribute 'b' within aggregate function", "❌ invalid reference to parent attribute 'b' within aggregate function", "❌ invalid reference to parent attribute 'b' within aggregate function", "❌ invalid reference to parent attribute 'b' within aggregate function", "❌ invalid reference to parent attribute 'b' within aggregate function" ], 2) - fh.editFormula("Formula", "b+1", 2) - fh.verifyValues("Formula", [2, 2, 2, 1, 1], 2) + table.editFormula("Formula", "b+1", 2) + table.verifyFormulaValues("Formula", [2, 2, 2, 1, 1], 2) }) it("Check aggregate and non-aggregate formulae referencing a child attribute in child collection", () => { fh.visitURL("") fh.importFile("cypress/fixtures/hierarchical-four.codap3") - fh.addNewAttribute(2) - fh.renameAttribute("newAttr", "Formula", 2) - fh.addFormula("Formula", "count(a)", 2) - fh.verifyValues("Formula", [3, 3, 3, 1, 1], 2) - fh.editFormula("Formula", "a+1", 2) - fh.verifyValues("Formula", [2, 3, 4, 4, 1], 2) + table.addNewAttribute(2) + table.renameAttribute("newAttr", "Formula", 2) + table.addFormula("Formula", "count(a)", 2) + table.verifyFormulaValues("Formula", [3, 3, 3, 1, 1], 2) + table.editFormula("Formula", "a+1", 2) + table.verifyFormulaValues("Formula", [2, 3, 4, 4, 1], 2) }) it("Check aggregate and non-aggregate formulae referencing a parent attribute in parent collection", () => { fh.visitURL("") fh.importFile("cypress/fixtures/hierarchical-four.codap3") - fh.addNewAttribute(1) - fh.renameAttribute("newAttr", "Formula", 1) - fh.addFormula("Formula", "count(b)", 1) - fh.verifyValues("Formula", [1, 1], 1) - fh.editFormula("Formula", "b+1", 1) - fh.verifyValues("Formula", [2, 1], 1) + table.addNewAttribute(1) + table.renameAttribute("newAttr", "Formula", 1) + table.addFormula("Formula", "count(b)", 1) + table.verifyFormulaValues("Formula", [1, 1], 1) + table.editFormula("Formula", "b+1", 1) + table.verifyFormulaValues("Formula", [2, 1], 1) }) it("Check aggregate and non-aggregate formulae referencing a child attribute in parent collection", () => { fh.visitURL("") fh.importFile("cypress/fixtures/hierarchical-four.codap3") - fh.addNewAttribute(1) - fh.renameAttribute("newAttr", "Formula", 1) - fh.addFormula("Formula", "a+1", 1) - fh.verifyValues("Formula", [ + table.addNewAttribute(1) + table.renameAttribute("newAttr", "Formula", 1) + table.addFormula("Formula", "a+1", 1) + table.verifyFormulaValues("Formula", [ "❌ invalid reference to child attribute 'a'", "❌ invalid reference to child attribute 'a'" ], 1) - fh.editFormula("Formula", "count(a)", 1) - fh.verifyValues("Formula", [3, 1], 1) + table.editFormula("Formula", "count(a)", 1) + table.verifyFormulaValues("Formula", [3, 1], 1) }) }) }) diff --git a/v3/cypress/e2e/formula/formula-special-characters.spec.ts b/v3/cypress/e2e/formula/formula-special-characters.spec.ts index bbe88a1ee4..64a651dd1a 100644 --- a/v3/cypress/e2e/formula/formula-special-characters.spec.ts +++ b/v3/cypress/e2e/formula/formula-special-characters.spec.ts @@ -1,150 +1,151 @@ import { FormulaHelper as fh } from "../../support/helpers/formula-helper" +import { TableTileElements as table } from "../../support/elements/table-tile" context("Formula Engine", () => { describe("Special Characters in Formula Tests", () => { it("Check backtick in symbol name", () => { fh.visitURL("?sample=four") - fh.renameAttribute("b", "x`yz") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula1") - fh.addFormula("Formula1", "`x\\`yz`+1") - fh.verifyValues("Formula1", [2, 2, 2, 1, 1]) - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula2") - fh.addFormula("Formula2", "Formula1+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) - fh.renameAttribute("Formula1", "Formula`1") - fh.checkFormulaExists("Formula2", "`Formula\\`1`+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("b", "x`yz") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula1") + table.addFormula("Formula1", "`x\\`yz`+1") + table.verifyFormulaValues("Formula1", [2, 2, 2, 1, 1]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula2") + table.addFormula("Formula2", "Formula1+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("Formula1", "Formula`1") + table.checkFormulaExists("Formula2", "`Formula\\`1`+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) }) it("Check backslash symbol in attribute", () => { fh.visitURL("?sample=four") - fh.renameAttribute("b", "x\\yz") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula1") - fh.addFormula("Formula1", "`x\\yz`+1") - fh.verifyValues("Formula1", [2, 2, 2, 1, 1]) - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula2") - fh.addFormula("Formula2", "Formula1+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) - fh.renameAttribute("Formula1", "Formula\\1") - fh.checkFormulaExists("Formula2", "`Formula\\\\1`+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("b", "x\\yz") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula1") + table.addFormula("Formula1", "`x\\yz`+1") + table.verifyFormulaValues("Formula1", [2, 2, 2, 1, 1]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula2") + table.addFormula("Formula2", "Formula1+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("Formula1", "Formula\\1") + table.checkFormulaExists("Formula2", "`Formula\\\\1`+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) }) it("Check backslash and backtick symbols in attribute", () => { fh.visitURL("?sample=four") - fh.renameAttribute("b", "x\\`yz") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula1") - fh.addFormula("Formula1", "`x\\\\\\`yz`+1") - fh.verifyValues("Formula1", [2, 2, 2, 1, 1]) - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula2") - fh.addFormula("Formula2", "Formula1+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) - fh.renameAttribute("Formula1", "Formula\\`1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("b", "x\\`yz") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula1") + table.addFormula("Formula1", "`x\\\\\\`yz`+1") + table.verifyFormulaValues("Formula1", [2, 2, 2, 1, 1]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula2") + table.addFormula("Formula2", "Formula1+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("Formula1", "Formula\\`1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) }) it("Check single quote symbol in attribute", () => { fh.visitURL("?sample=four") - fh.renameAttribute("b", "x'yz") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula1") - fh.addFormula("Formula1", "`x'yz`+1") - fh.verifyValues("Formula1", [2, 2, 2, 1, 1]) - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula2") - fh.addFormula("Formula2", "Formula1+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) - fh.renameAttribute("Formula1", "Formula'1") - fh.checkFormulaExists("Formula2", "`Formula'1`+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("b", "x'yz") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula1") + table.addFormula("Formula1", "`x'yz`+1") + table.verifyFormulaValues("Formula1", [2, 2, 2, 1, 1]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula2") + table.addFormula("Formula2", "Formula1+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("Formula1", "Formula'1") + table.checkFormulaExists("Formula2", "`Formula'1`+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) }) it("Check double quotes symbol in attribute", () => { fh.visitURL("?sample=four") - fh.renameAttribute("b", "x\"yz") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula1") - fh.addFormula("Formula1", "`x\"yz`+1") - fh.verifyValues("Formula1", [2, 2, 2, 1, 1]) - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula2") - fh.addFormula("Formula2", "Formula1+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) - fh.renameAttribute("Formula1", "Formula\"1") - fh.checkFormulaExists("Formula2", "`Formula\"1`+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("b", "x\"yz") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula1") + table.addFormula("Formula1", "`x\"yz`+1") + table.verifyFormulaValues("Formula1", [2, 2, 2, 1, 1]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula2") + table.addFormula("Formula2", "Formula1+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("Formula1", "Formula\"1") + table.checkFormulaExists("Formula2", "`Formula\"1`+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) }) it("Check backslash and double quotes symbols in attribute", () => { fh.visitURL("?sample=four") - fh.renameAttribute("b", "x\\\"yz") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula1") + table.renameAttribute("b", "x\\\"yz") + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula1") // must add {del} to delete auto-matched (in error) closing quote - fh.addFormula("Formula1", "`x\\\"yz`+1{del}") - fh.verifyValues("Formula1", [2, 2, 2, 1, 1]) - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula2") - fh.addFormula("Formula2", "Formula1+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) - fh.renameAttribute("Formula1", "Formula\\\"1") - fh.checkFormulaExists("Formula2", "`Formula\\\\\"1`+1") - fh.verifyValues("Formula2", [3, 3, 3, 2, 2]) + table.addFormula("Formula1", "`x\\\"yz`+1{del}") + table.verifyFormulaValues("Formula1", [2, 2, 2, 1, 1]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula2") + table.addFormula("Formula2", "Formula1+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) + table.renameAttribute("Formula1", "Formula\\\"1") + table.checkFormulaExists("Formula2", "`Formula\\\\\"1`+1") + table.verifyFormulaValues("Formula2", [3, 3, 3, 2, 2]) }) it("Check double quote in string constant", () => { fh.visitURL("?sample=four") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") - fh.addFormula("Formula", "if(b = 1, \"o\\\"k\", \"ok\")") - fh.verifyValues("Formula", ["o\"k", "o\"k", "o\"k", "ok", "ok"]) - fh.editFormula("Formula", "if(b = 1, \"o\\\\k\", \"ok\")") - fh.verifyValues("Formula", ["o\\k", "o\\k", "o\\k", "ok", "ok"]) - fh.editFormula("Formula", "if(b = 1, \"o\\\\\\\"k\", \"ok\")") - fh.verifyValues("Formula", ["o\\\"k", "o\\\"k", "o\\\"k", "ok", "ok"]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") + table.addFormula("Formula", "if(b = 1, \"o\\\"k\", \"ok\")") + table.verifyFormulaValues("Formula", ["o\"k", "o\"k", "o\"k", "ok", "ok"]) + table.editFormula("Formula", "if(b = 1, \"o\\\\k\", \"ok\")") + table.verifyFormulaValues("Formula", ["o\\k", "o\\k", "o\\k", "ok", "ok"]) + table.editFormula("Formula", "if(b = 1, \"o\\\\\\\"k\", \"ok\")") + table.verifyFormulaValues("Formula", ["o\\\"k", "o\\\"k", "o\\\"k", "ok", "ok"]) }) it("Check double quote in symbol name", () => { fh.visitURL("?sample=four") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") - fh.addFormula("Formula", "lookupByIndex(\"Four\", \"b\", caseIndex)") - fh.renameAttribute("b", "x'yz") - fh.checkFormulaExists("Formula", "lookupByIndex(\"Four\", \"x'yz\", caseIndex)") - fh.verifyValues("Formula", [1, 1, 1, "", ""]) - fh.renameAttribute("x'yz", "x\"yz") - fh.checkFormulaExists("Formula", "lookupByIndex(\"Four\", \"x\\\"yz\", caseIndex)") - fh.verifyValues("Formula", [1, 1, 1, "", ""]) - fh.renameAttribute("x\\\"yz", "x\\yz") - fh.checkFormulaExists("Formula", "lookupByIndex(\"Four\", \"x\\\\yz\", caseIndex)") - fh.verifyValues("Formula", [1, 1, 1, "", ""]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") + table.addFormula("Formula", "lookupByIndex(\"Four\", \"b\", caseIndex)") + table.renameAttribute("b", "x'yz") + table.checkFormulaExists("Formula", "lookupByIndex(\"Four\", \"x'yz\", caseIndex)") + table.verifyFormulaValues("Formula", [1, 1, 1, "", ""]) + table.renameAttribute("x'yz", "x\"yz") + table.checkFormulaExists("Formula", "lookupByIndex(\"Four\", \"x\\\"yz\", caseIndex)") + table.verifyFormulaValues("Formula", [1, 1, 1, "", ""]) + table.renameAttribute("x\\\"yz", "x\\yz") + table.checkFormulaExists("Formula", "lookupByIndex(\"Four\", \"x\\\\yz\", caseIndex)") + table.verifyFormulaValues("Formula", [1, 1, 1, "", ""]) }) it("Check single quote in string constant", () => { fh.visitURL("?sample=four") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") - fh.addFormula("Formula", "if(b = 1, 'ok', 'not ok')") - fh.verifyValues("Formula", ["ok", "ok", "ok", "not ok", "not ok"]) - fh.editFormula("Formula", "if(b = 1, 'o\"k', 'not ok')") - fh.verifyValues("Formula", ["o\"k", "o\"k", "o\"k", "not ok", "not ok"]) - fh.editFormula("Formula", "if(b = 1, 'o\\'k', 'not ok')") - fh.verifyValues("Formula", ["o'k", "o'k", "o'k", "not ok", "not ok"]) - fh.editFormula("Formula", "if(b = 1, 'o\\\\k', 'not ok')") - fh.verifyValues("Formula", ["o\\k", "o\\k", "o\\k", "not ok", "not ok"]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") + table.addFormula("Formula", "if(b = 1, 'ok', 'not ok')") + table.verifyFormulaValues("Formula", ["ok", "ok", "ok", "not ok", "not ok"]) + table.editFormula("Formula", "if(b = 1, 'o\"k', 'not ok')") + table.verifyFormulaValues("Formula", ["o\"k", "o\"k", "o\"k", "not ok", "not ok"]) + table.editFormula("Formula", "if(b = 1, 'o\\'k', 'not ok')") + table.verifyFormulaValues("Formula", ["o'k", "o'k", "o'k", "not ok", "not ok"]) + table.editFormula("Formula", "if(b = 1, 'o\\\\k', 'not ok')") + table.verifyFormulaValues("Formula", ["o\\k", "o\\k", "o\\k", "not ok", "not ok"]) }) it("Check single quote in symbol name", () => { fh.visitURL("?sample=four") - fh.addNewAttribute() - fh.renameAttribute("newAttr", "Formula") - fh.addFormula("Formula", "lookupByIndex('Four', 'b', caseIndex)") - fh.renameAttribute("b", "x'yz") - fh.checkFormulaExists("Formula", "lookupByIndex('Four', 'x\\'yz', caseIndex)") - fh.verifyValues("Formula", [1, 1, 1, "", ""]) - fh.renameAttribute("x'yz", "x\"yz") - fh.checkFormulaExists("Formula", "lookupByIndex('Four', 'x\"yz', caseIndex)") - fh.verifyValues("Formula", [1, 1, 1, "", ""]) - fh.renameAttribute("x\\\"yz", "x\\yz") - fh.checkFormulaExists("Formula", "lookupByIndex('Four', 'x\\\\yz', caseIndex)") - fh.verifyValues("Formula", [1, 1, 1, "", ""]) + table.addNewAttribute() + table.renameAttribute("newAttr", "Formula") + table.addFormula("Formula", "lookupByIndex('Four', 'b', caseIndex)") + table.renameAttribute("b", "x'yz") + table.checkFormulaExists("Formula", "lookupByIndex('Four', 'x\\'yz', caseIndex)") + table.verifyFormulaValues("Formula", [1, 1, 1, "", ""]) + table.renameAttribute("x'yz", "x\"yz") + table.checkFormulaExists("Formula", "lookupByIndex('Four', 'x\"yz', caseIndex)") + table.verifyFormulaValues("Formula", [1, 1, 1, "", ""]) + table.renameAttribute("x\\\"yz", "x\\yz") + table.checkFormulaExists("Formula", "lookupByIndex('Four', 'x\\\\yz', caseIndex)") + table.verifyFormulaValues("Formula", [1, 1, 1, "", ""]) }) }) }) diff --git a/v3/cypress/e2e/table.spec.ts b/v3/cypress/e2e/table.spec.ts index b34171c497..a305a33176 100644 --- a/v3/cypress/e2e/table.spec.ts +++ b/v3/cypress/e2e/table.spec.ts @@ -1,7 +1,6 @@ import { TableTileElements as table } from "../support/elements/table-tile" import { ComponentElements as c } from "../support/elements/component-elements" import { ToolbarElements as toolbar } from "../support/elements/toolbar-elements" -import { FormulaHelper as fh } from "../support/helpers/formula-helper" import { ColorPickerPaletteElements as cpp } from "../support/elements/color-picker-palette" context("case table ui", () => { @@ -417,7 +416,7 @@ context("case table ui", () => { describe("case table header attribute menu", () => { it("verify add attribute with undo and redo", ()=>{ // Add new attribute using Add New Attribute button (+) - fh.addNewAttribute() + table.addNewAttribute() // verify new attribute exists table.getColumnHeaders().should("have.length.be.within", 10, 11) diff --git a/v3/cypress/support/elements/slider-tile.ts b/v3/cypress/support/elements/slider-tile.ts index b18f9ab848..08301322e9 100644 --- a/v3/cypress/support/elements/slider-tile.ts +++ b/v3/cypress/support/elements/slider-tile.ts @@ -126,5 +126,11 @@ export const SliderTileElements = { // Choose either Numeric or Date-Time based on the provided scaleType cy.clickWhenClickable(`[data-testid="slider-scale-${scaleType}"]`) // cy.get('[data-testid="slider-date-display"]').should("have.text", today) - } + }, + addSlider() { + c.getIconFromToolShelf("slider").click() + }, + deleteSlider() { + c.closeComponent("slider") + }, } diff --git a/v3/cypress/support/elements/table-tile.ts b/v3/cypress/support/elements/table-tile.ts index d0b4fbd49e..7f4471038e 100644 --- a/v3/cypress/support/elements/table-tile.ts +++ b/v3/cypress/support/elements/table-tile.ts @@ -1,4 +1,6 @@ import { ComponentElements as c } from "./component-elements" +import { FormulaHelper as fh } from "../helpers/formula-helper" + type TestAttributes = Array<{ name: string, move: string }> type TestValues = Record @@ -415,7 +417,8 @@ export const TableTileElements = { addFilterFormulaInModal(formula: string) { this.getHideShowButton().click() this.getHideShowMenuItem(/(Add|Edit) Filter Formula.../).click() - cy.get(".codap-modal-content [data-testid=attr-formula-input]").type(`{selectAll}{del}${formula}`) + fh.clearFormulaInput() + fh.addFilterFormula(formula) cy.get(".codap-modal-content [data-testid=Apply-button]").should("be.visible").click() cy.get("[data-testid=Apply-button]").click() }, diff --git a/v3/cypress/support/helpers/formula-helper.ts b/v3/cypress/support/helpers/formula-helper.ts index 5b9c64ea59..8f356ab04c 100644 --- a/v3/cypress/support/helpers/formula-helper.ts +++ b/v3/cypress/support/helpers/formula-helper.ts @@ -1,6 +1,3 @@ -import { ComponentElements as c } from "../elements/component-elements" -import { TableTileElements as table } from "../elements/table-tile" -import { SliderTileElements as slider } from "../elements/slider-tile" import { CfmElements as cfm } from "../elements/cfm" const isMac = navigator.platform.toLowerCase().includes("mac") @@ -16,46 +13,6 @@ export const FormulaHelper = { cfm.openLocalDoc(file) cy.wait(1000) }, - addNewAttribute(collectionIndex = 1) { - table.addNewAttribute(collectionIndex) - }, - renameAttribute(currentAttributeName: string, newAttributeName: string, collectionIndex = 1) { - table.renameAttribute(currentAttributeName, newAttributeName, collectionIndex) - }, - deleteAttribute(attributeName: string, collectionIndex = 1) { - table.deleteAttribute(attributeName, collectionIndex) - }, - addFormula(attributeName: string, formula: string, collectionIndex = 1) { - table.addFormula(attributeName, formula, collectionIndex) - }, - verifyValues(attributeName: string, values: Array, collectionIndex = 1) { - table.verifyFormulaValues(attributeName, values, collectionIndex) - }, - checkFormulaExists(attributeName: string, formula: string, collectionIndex = 1) { - table.checkFormulaExists(attributeName, formula, collectionIndex) - }, - editFormula(attributeName: string, formula: string, collectionIndex = 1) { - table.editFormula(attributeName, formula, collectionIndex) - }, - createNewDataset() { - table.createNewTableFromToolShelf() - }, - insertCases(rowIndex: number, numOfCases: number) { - table.openIndexMenuForRow(rowIndex) - table.insertCases(numOfCases, "after") - }, - changeSliderVariableName(sliderVariableName: string) { - slider.changeVariableName(sliderVariableName) - }, - changeSliderValue(sliderValue: string) { - slider.changeVariableValue(sliderValue) - }, - addSlider() { - c.getIconFromToolShelf("slider").click() - }, - deleteSlider() { - c.closeComponent("slider") - }, clearFormulaInput() { cy.get("[data-testid=formula-editor-input] .cm-content").should("be.visible").and("have.focus") cy.get("[data-testid=formula-editor-input] .cm-content").realPress([metaCtrlKey, "A"]) diff --git a/v3/src/components/case-tile-common/hide-show-menu-list.tsx b/v3/src/components/case-tile-common/hide-show-menu-list.tsx index ca7714927e..1f388530ee 100644 --- a/v3/src/components/case-tile-common/hide-show-menu-list.tsx +++ b/v3/src/components/case-tile-common/hide-show-menu-list.tsx @@ -7,8 +7,8 @@ import { useDataSetContext } from "../../hooks/use-data-set-context" import { hideAttributeNotification } from "../../models/data/data-set-notifications" import { addSetAsideCases, restoreSetAsideCases } from "../../models/data/data-set-utils" import { t } from "../../utilities/translation/translate" -import { EditFilterFormulaModal } from "../common/edit-filter-formula-modal" import { IMenuItem, StdMenuList } from "./std-menu-list" +import { EditFormulaModal } from "../common/edit-formula-modal" export const HideShowMenuList = observer(function HideShowMenuList() { const data = useDataSetContext() @@ -104,7 +104,13 @@ export const HideShowMenuList = observer(function HideShowMenuList() { { data && - + } ) diff --git a/v3/src/components/common/edit-filter-formula-modal.tsx b/v3/src/components/common/edit-filter-formula-modal.tsx deleted file mode 100644 index 5f7cb5fe9a..0000000000 --- a/v3/src/components/common/edit-filter-formula-modal.tsx +++ /dev/null @@ -1,101 +0,0 @@ -import { - Button, FormControl, FormLabel, ModalBody, ModalCloseButton, ModalFooter, ModalHeader, - Textarea, Tooltip -} from "@chakra-ui/react" -import { observer } from "mobx-react-lite" -import React, { useEffect, useState } from "react" -import { IFormula } from "../../models/formula/formula" -import { t } from "../../utilities/translation/translate" -import { CodapModal } from "../codap-modal" - -interface IFormulaSource { - filterFormula?: IFormula - filterFormulaError: string - setFilterFormula: (formula: string) => void - applyModelChange: (change: () => void, options: { undoStringKey: string, redoStringKey: string }) => void -} -interface IProps { - formulaSource: IFormulaSource - isOpen: boolean - onClose: () => void -} - -export const EditFilterFormulaModal = observer(function EditFormulaModal({ formulaSource, isOpen, onClose }: IProps) { - const [formula, setFormula] = useState("") - - useEffect(() => { - setFormula(formulaSource.filterFormula?.display || "") - }, [formulaSource.filterFormula?.display]) - - const closeModal = () => { - onClose() - } - - function applyFilterFormula() { - formulaSource.applyModelChange(() => { - formulaSource.setFilterFormula(formula) - }, { - undoStringKey: "V3.Undo.hideShowMenu.changeFilterFormula", - redoStringKey: "V3.Redo.hideShowMenu.changeFilterFormula" - }) - closeModal() - } - - const handleFormulaChange = (e: React.ChangeEvent) => setFormula(e.target.value) - - const buttons = [{ - label: t("DG.AttrFormView.cancelBtnTitle"), - tooltip: t("DG.AttrFormView.cancelBtnTooltip"), - onClick: closeModal - }, { - label: t("DG.AttrFormView.applyBtnTitle"), - onClick: applyFilterFormula, - default: true - }] - - return ( - - -
-
- - - - { - formulaSource.filterFormulaError && -
- {formulaSource.filterFormulaError} -
- } - - {t("DG.AttrFormView.formulaPrompt")} -