Skip to content

Commit

Permalink
[FIX] TopBar: Remove hidden functions from the insert menu
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rrahir committed Mar 18, 2024
1 parent d86234a commit 6edec77
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/actions/insert_actions.ts
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions tests/menu_items_registry.test.ts
Expand Up @@ -22,6 +22,7 @@ import {
} from "./test_helpers/commands_helpers";
import { getCell, getCellContent, getEvaluatedCell } from "./test_helpers/getters_helpers";
import {
clearFunctions,
doAction,
getName,
getNode,
Expand Down Expand Up @@ -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"]);
Expand Down

0 comments on commit 6edec77

Please sign in to comment.