From 6edec7773b9a743520f66f7bc0cdc5e589a9f85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Fri, 15 Mar 2024 11:16:45 +0100 Subject: [PATCH] [FIX] TopBar: Remove hidden functions from the `insert` menu The introduction of the `hidden` tag of functions in pr #1928 did not account for the `insert function` menu of the top bar that was developped at the same time. This revision ensures that the functions marked as `hidden` do not appear in the top bar menu, similarly to their behaviour in the composer formula autocomplete assistant. Task: 3810284 --- src/actions/insert_actions.ts | 15 ++++++++++----- tests/menu_items_registry.test.ts | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/actions/insert_actions.ts b/src/actions/insert_actions.ts index a0b011da9..a568874d2 100644 --- a/src/actions/insert_actions.ts +++ b/src/actions/insert_actions.ts @@ -154,19 +154,24 @@ export const categorieFunctionAll: ActionSpec = { }; function allFunctionListMenuBuilder(): ActionSpec[] { - const fnNames = functionRegistry.getKeys(); + const fnNames = functionRegistry.getKeys().filter((key) => !functionRegistry.get(key).hidden); return createFormulaFunctions(fnNames); } export const categoriesFunctionListMenuBuilder: ActionBuilder = () => { const functions = functionRegistry.content; - const categories = [...new Set(functionRegistry.getAll().map((fn) => fn.category))].filter( - isDefined - ); + const categories = [ + ...new Set( + functionRegistry + .getAll() + .filter((fn) => !fn.hidden) + .map((fn) => fn.category) + ), + ].filter(isDefined); return categories.sort().map((category, i) => { const functionsInCategory = Object.keys(functions).filter( - (key) => functions[key].category === category + (key) => functions[key].category === category && !functions[key].hidden ); return { name: category, diff --git a/tests/menu_items_registry.test.ts b/tests/menu_items_registry.test.ts index 311b8ff54..a8b5cb006 100644 --- a/tests/menu_items_registry.test.ts +++ b/tests/menu_items_registry.test.ts @@ -22,6 +22,7 @@ import { } from "./test_helpers/commands_helpers"; import { getCell, getCellContent, getEvaluatedCell } from "./test_helpers/getters_helpers"; import { + clearFunctions, doAction, getName, getNode, @@ -859,6 +860,26 @@ describe("Menu Item actions", () => { restoreDefaultFunctions(); }); + test("Insert -> Function -> hidden formulas are filtered out", () => { + clearFunctions(); + functionRegistry.add("HIDDEN.FUNC", { + args: [], + compute: () => 42, + description: "Test function", + returns: ["NUMBER"], + hidden: true, + category: "hidden", + }); + const env = makeTestEnv(); + const functionCategories = getNode(["insert", "insert_function"]).children(env); + expect(functionCategories.map((f) => f.name(env))).not.toContain("hidden"); + const allFunctions = getNode(["insert", "insert_function", "categorie_function_all"]).children( + env + ); + expect(allFunctions.map((f) => f.name(env))).not.toContain("HIDDEN.FUNC"); + restoreDefaultFunctions(); + }); + describe("Format -> numbers", () => { test("Automatic", () => { const action = getNode(["format", "format_number", "format_number_automatic"]);