Skip to content

Commit

Permalink
feat(formula): select function, show description, select all functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dushusir committed Nov 16, 2023
1 parent 1a793e5 commit 8ccc1d6
Show file tree
Hide file tree
Showing 70 changed files with 718 additions and 215 deletions.
6 changes: 0 additions & 6 deletions packages/base-formula-engine/src/basics/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ export interface IFunctionInfo {
*/
abstract: string;

/**
* [Minimum number of parameters, maximum number of parameters]
* Detected before each calculation of the function
*/
parameterRange: [min: number, max: number];

/**
* Function params
*/
Expand Down
1 change: 1 addition & 0 deletions packages/base-ui/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './custom-label';
export * from './menu';
export * from './range-selector/RangeSelector';
11 changes: 11 additions & 0 deletions packages/base-ui/src/components/range-selector/RangeSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Input } from '@univerjs/design';

import styles from './index.module.less';

export function RangeSelector() {
return (
<div className={styles.rangeSelector}>
<Input placeholder="Select range or input value"></Input>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.range-selector {
display: flex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ISelectEditorFormulaOperationParam {
}

export const SelectEditorFormluaOperation: IOperation<ISelectEditorFormulaOperationParam> = {
id: 'formula.operation.select-editor-formula',
id: 'formula-ui.operation.select-editor-formula',
type: CommandType.OPERATION,
handler: (accessor, params) => {
const { eventType, keycode } = params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IAccessor } from '@wendellhu/redi';
import { IFormulaPromptService, IHelpFunctionCommandParams } from '../../services/prompt.service';

export const HelpFunctionOperation: ICommand = {
id: 'formula.operation.help-function',
id: 'formula-ui.operation.help-function',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor, params: IHelpFunctionCommandParams) => {
const promptService = accessor.get(IFormulaPromptService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IInsertFunctionCommandParams {
}

export const InsertFunctionOperation: ICommand = {
id: 'formula.operation.insert-function',
id: 'formula-ui.operation.insert-function',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor, params: IInsertFunctionCommandParams) => true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IAccessor } from '@wendellhu/redi';
import { MORE_FUNCTIONS_COMPONENT } from '../../views/more-functions/interface';

export const MoreFunctionsOperation: ICommand = {
id: 'formula.operation.more-functions',
id: 'formula-ui.operation.more-functions',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor) => {
const sidebarService = accessor.get(ISidebarService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IAccessor } from '@wendellhu/redi';
import { IFormulaPromptService, ISearchFunctionParams } from '../../services/prompt.service';

export const SearchFunctionOperation: ICommand = {
id: 'formula.operation.search-function',
id: 'formula-ui.operation.search-function',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor, params: ISearchFunctionParams) => {
const promptService = accessor.get(IFormulaPromptService);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TextSelectionManagerService } from '@univerjs/base-docs';
import { FormulaEngineService, IFunctionInfo, ISequenceNode, sequenceNodeType } from '@univerjs/base-formula-engine';
import {
DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
IRenderManagerService,
ITextSelectionRenderManager,
} from '@univerjs/base-render';
import { ISelectionWithStyle, NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '@univerjs/base-sheets';
import {
Expand Down Expand Up @@ -36,9 +36,8 @@ import { Inject } from '@wendellhu/redi';
import { HelpFunctionOperation } from '../commands/operations/help-function.operation';
import { SearchFunctionOperation } from '../commands/operations/search-function.operation';
import { FORMULA_REF_SELECTION_PLUGIN_NAME, getFormulaRefSelectionStyle } from '../common/selection';
import { FUNCTION_LIST } from '../services/function-list/function-list';
import { IFormulaPromptService, ISearchItem } from '../services/prompt.service';
import { getFunctionName } from './util';
import { IDescriptionService, ISearchItem } from '../services/description.service';
import { IFormulaPromptService } from '../services/prompt.service';

interface IFunctionPanelParam {
visibleSearch: boolean;
Expand Down Expand Up @@ -69,7 +68,7 @@ export class PromptController extends Disposable {
@ICommandService private readonly _commandService: ICommandService,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@IContextService private readonly _contextService: IContextService,
@Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
@ITextSelectionRenderManager private readonly _textSelectionRenderManager: ITextSelectionRenderManager,
@Inject(IEditorBridgeService) private readonly _editorBridgeService: EditorBridgeService,
@Inject(IFormulaPromptService) private readonly _formulaPromptService: IFormulaPromptService,
@Inject(FormulaEngineService) private readonly _formulaEngineService: FormulaEngineService,
Expand All @@ -78,7 +77,8 @@ export class PromptController extends Disposable {
@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
@Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
@Inject(ISelectionRenderService) private readonly _selectionRenderService: ISelectionRenderService
@Inject(ISelectionRenderService) private readonly _selectionRenderService: ISelectionRenderService,
@Inject(IDescriptionService) private readonly _descriptionService: IDescriptionService
) {
super();

Expand Down Expand Up @@ -126,7 +126,7 @@ export class PromptController extends Disposable {
private _initialCursorSync() {
this.disposeWithMe(
toDisposable(
this._textSelectionManagerService.textSelectionInfo$.subscribe(() => {
this._textSelectionRenderManager.textSelection$.subscribe(() => {
if (this._editorBridgeService.isVisible().visible === false) {
return;
}
Expand Down Expand Up @@ -194,31 +194,30 @@ export class PromptController extends Disposable {
const searchText = currentInputValue.substring(1);

// TODO@Dushusir: remove after use real text info
const matchList = ['SUMIF', 'TAN', 'TANH'];
const matchList = ['SUM', 'AVERAGE'];

// help function
if (matchList.includes(searchText)) {
const paramIndex = Math.random() > 0.5 ? 0 : 1;

const functionInfo = this._getFunctionInfo(searchText);

const functionInfo = this._descriptionService.getFunctionInfo(searchText);
param = {
visibleSearch: false,
visibleHelp: !!functionInfo,
searchText,
paramIndex,
functionInfo,
};
} else {
const searchList = this._descriptionService.getSearchListByName(searchText);
param = {
visibleSearch: searchList.length > 0,
visibleHelp: false,
searchText,
paramIndex: 0,
searchList,
};
}

const searchList = this._getSearchList(searchText);
param = {
visibleSearch: searchList.length > 0,
visibleHelp: false,
searchText,
paramIndex: 0,
searchList,
};
}

this._commandService.executeCommand(SearchFunctionOperation.id, {
Expand All @@ -239,22 +238,6 @@ export class PromptController extends Disposable {
});
}

private _getSearchList(searchText: string) {
const searchList: ISearchItem[] = [];
FUNCTION_LIST.forEach((item) => {
const functionName = getFunctionName(item, this._localeService);
if (functionName.indexOf(searchText) > -1) {
searchList.push({ name: functionName, desc: this._localeService.t(item.abstract) as string });
}
});

return searchList;
}

private _getFunctionInfo(searchText: string) {
return FUNCTION_LIST.find((item) => getFunctionName(item, this._localeService) === searchText);
}

/**
*
* @param body the body object of the current input box
Expand Down
18 changes: 0 additions & 18 deletions packages/sheets-plugin-formula-ui/src/controllers/util.ts

This file was deleted.

54 changes: 36 additions & 18 deletions packages/sheets-plugin-formula-ui/src/locale/en-US.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import arrayEnUS from './function-list/array/en-US';
import compatibilityEnUS from './function-list/compatibility/en-US';
import cubeEnUS from './function-list/cube/en-US';
import databaseEnUS from './function-list/database/en-US';
import dateEnUS from './function-list/date/en-US';
import engineeringEnUS from './function-list/engineering/en-US';
import financialEnUS from './function-list/financial/en-US';
import informationEnUS from './function-list/information/en-US';
import logicalEnUS from './function-list/logical/en-US';
import lookupEnUS from './function-list/lookup/en-US';
import mathEnUS from './function-list/math/en-US';
import statisticalEnUS from './function-list/statistical/en-US';
import textEnUS from './function-list/text/en-US';
import univerEnUS from './function-list/univer/en-US';
import webEnUS from './function-list/web/en-US';

export default {
formula: {
Expand All @@ -12,26 +26,29 @@ export default {
more: 'More Functions...',
},
functionList: {
AVERAGE: {
description: 'Returns the average (arithmetic mean) of the arguments.',
abstract: 'Returns the average of the arguments.',
functionParameter: {
number1: {
name: 'number1',
detail: 'The first number, cell reference, or range for which you want the average.',
},
number2: {
name: 'number2',
detail: 'Additional numbers, cell references or ranges for which you want the average, up to a maximum of 255.',
},
},
},
...financialEnUS,
...dateEnUS,
...mathEnUS,
...statisticalEnUS,
...lookupEnUS,
...databaseEnUS,
...textEnUS,
...logicalEnUS,
...informationEnUS,
...engineeringEnUS,
...cubeEnUS,
...compatibilityEnUS,
...webEnUS,
...arrayEnUS,
...univerEnUS,
},
formulaMore: {
prompt: {
helpExample: 'EXAMPLE',
helpAbstract: 'ABOUT',

required: 'Required.',
optional: 'Optional.',
},
functionType: {
financial: 'Financial',
date: 'Date & Time',
math: 'Math & Trig',
Expand All @@ -47,13 +64,14 @@ export default {
web: 'Web',
array: 'Array',
univer: 'Univer',

searchFunctionPlaceholder: 'Search function',
},
moreFunctions: {
confirm: 'Confirm',
prev: 'Previous',
next: 'Next',
searchFunctionPlaceholder: 'Search function',
allFunctions: 'All Functions',
syntax: 'SYNTAX',
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
SUM: {
description: 'You can add individual values, cell references or ranges or a mix of all three.',
abstract: 'You can add individual values, cell references or ranges or a mix of all three.',
abstract: 'Adds its arguments',
functionParameter: {
number1: {
name: 'number1',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
SUM: {
description: '将单个值、单元格引用或是区域相加,或者将三者的组合相加。',
abstract: '将单个值、单元格引用或是区域相加。',
abstract: '求参数的和',
functionParameter: {
number1: {
name: '数值1',
Expand Down
Loading

0 comments on commit 8ccc1d6

Please sign in to comment.