Skip to content

Commit 1929ea9

Browse files
committed
[IMP] add_dimension_button: allow to fuzzy search on technical names
This commit adds the technical names of fields to the fuzzy search keys. Task: 5226786
1 parent 3cd5eee commit 1929ea9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/components/side_panel/pivot/pivot_layout_configurator/add_dimension_button/add_dimension_button.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export class AddDimensionButton extends Component<Props, SpreadsheetChildEnv> {
6161
get proposals(): AutoCompleteProposal[] {
6262
let fields: PivotField[];
6363
if (this.search.input) {
64-
fields = fuzzyLookup(this.search.input, this.props.fields, (field) => field.string);
64+
fields = fuzzyLookup(this.search.input, this.props.fields, (field) =>
65+
field.string === field.name ? field.string : field.string + field.name
66+
);
6567
} else {
6668
fields = this.props.fields;
6769
}

tests/pivots/add_dimension_button.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AddDimensionButton } from "../../src/components/side_panel/pivot/pivot_layout_configurator/add_dimension_button/add_dimension_button";
2-
import { click, keyDown } from "../test_helpers/dom_helper";
2+
import { click, keyDown, setInputValueAndTrigger } from "../test_helpers/dom_helper";
33
import { mountComponentWithPortalTarget } from "../test_helpers/helpers";
44

55
async function mountAddDimensionButton(
@@ -48,4 +48,20 @@ describe("Add dimension button", () => {
4848
await keyDown({ key: "Enter" });
4949
expect(onFieldPicked).toHaveBeenCalledWith("Amount");
5050
});
51+
52+
test("Can fuzzy lookup on name and string", async () => {
53+
const onFieldPicked = jest.fn();
54+
const { fixture } = await mountAddDimensionButton({
55+
fields: [
56+
{ name: "technical", type: "integer", string: "Amount" },
57+
{ name: "Product", type: "char", string: "Product" },
58+
],
59+
onFieldPicked,
60+
});
61+
await click(fixture.querySelector(".add-dimension")!);
62+
await setInputValueAndTrigger(fixture.querySelector("input")!, "tech");
63+
const options = [...fixture.querySelectorAll(".o-popover .o-autocomplete-dropdown > div")];
64+
expect(options.length).toBe(1);
65+
expect(options[0].textContent?.trim()).toBe("Amount");
66+
});
5167
});

0 commit comments

Comments
 (0)