Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] TopBar: Remove hidden functions from the insert menu #3842

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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