Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheets-formula-ui): hide empty function list of SelectFunction (#6545)

白熱9a9685345a51
diff --git a/packages/sheets-formula-ui/src/services/utils.ts b/packages/sheets-formula-ui/src/services/utils.ts
index d374cce9b0..cc9b676ab0 100644
--- a/packages/sheets-formula-ui/src/services/utils.ts
+++ b/packages/sheets-formula-ui/src/services/utils.ts
@@ -15,19 +15,19 @@
*/
import type { LocaleService } from '@univerjs/core';
-import type { FunctionType, IFunctionInfo, IFunctionParam } from '@univerjs/engine-formula';
+import type { IFunctionInfo, IFunctionParam } from '@univerjs/engine-formula';
+import { FunctionType } from '@univerjs/engine-formula';
export function getFunctionTypeValues(
- enumObj: typeof FunctionType,
localeService: LocaleService,
customFormula: boolean
): Array<{ label: string; value: string }> {
// Exclude the DefinedName key
- return Object.keys(enumObj)
+ return Object.keys(FunctionType)
.filter((key) => isNaN(Number(key)) && key !== 'DefinedName' && key !== 'Table' && (customFormula || key !== 'User'))
.map((key) => ({
label: localeService.t(`formula.functionType.${key.toLocaleLowerCase()}`),
- value: `${enumObj[key as keyof typeof FunctionType]}`,
+ value: `${FunctionType[key as keyof typeof FunctionType]}`,
}));
}
diff --git a/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx b/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
index 0fc5e09fa4..293aebd9b3 100644
--- a/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
+++ b/packages/sheets-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx
@@ -20,7 +20,6 @@ import type { ISidebarMethodOptions } from '@univerjs/ui';
import type { KeyboardEvent } from 'react';
import { IConfigService, LocaleService } from '@univerjs/core';
import { borderClassName, clsx, Input, scrollbarClassName, Select } from '@univerjs/design';
-import { FunctionType } from '@univerjs/engine-formula';
import { CheckMarkIcon } from '@univerjs/icons';
import { IDescriptionService, PLUGIN_CONFIG_KEY_BASE } from '@univerjs/sheets-formula';
import { ISidebarService, useDependency, useObservable } from '@univerjs/ui';
@@ -51,7 +50,11 @@ export function SelectFunction(props: ISelectFunctionProps) {
const sidebarService = useDependency(ISidebarService);
const sidebarOptions = useObservable<ISidebarMethodOptions>(sidebarService.sidebarOptions$);
- const options = getFunctionTypeValues(FunctionType, localeService, Boolean(customFunction));
+ const options = getFunctionTypeValues(localeService, Boolean(customFunction))
+ .filter(
+ (option) => descriptionService.getSearchListByType(Number(option.value)).length > 0
+ );
+
options.unshift({
label: localeService.t('formula.moreFunctions.allFunctions'),
value: allTypeValue,