This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 374
feat: adaptive expression functions menu #5015
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3ee4c90
expressions menu
LouisEugeneMSFT 5854ad4
Merge branch 'main' into leugene/expressionsMenu
LouisEugeneMSFT e63e57b
Fixing aligment of menu
LouisEugeneMSFT 05a17da
PR comments
LouisEugeneMSFT 3070d61
Merge branch 'main' into leugene/expressionMenu
hatpick 45ec313
Merge branch 'main' into leugene/expressionMenu
LouisEugeneMSFT 5fa44bd
Merge branch 'main' into leugene/expressionMenu
LouisEugeneMSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
62 changes: 62 additions & 0 deletions
62
Composer/packages/adaptive-form/src/components/expressions/ExpressionsListMenu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { ContextualMenu, DirectionalHint } from 'office-ui-fabric-react/lib/ContextualMenu'; | ||
| import React, { useCallback, useMemo } from 'react'; | ||
| import { builtInFunctionsGrouping, getBuiltInFunctionInsertText } from '@bfc/built-in-functions'; | ||
|
|
||
| import { expressionGroupingsToMenuItems } from './utils/expressionsListMenuUtils'; | ||
|
|
||
| const componentMaxHeight = 400; | ||
|
|
||
| type ExpressionsListMenuProps = { | ||
| onExpressionSelected: (expression: string) => void; | ||
| onMenuMount: (menuContainerElms: HTMLDivElement[]) => void; | ||
| }; | ||
| export const ExpressionsListMenu = (props: ExpressionsListMenuProps) => { | ||
| const { onExpressionSelected, onMenuMount } = props; | ||
|
|
||
| const containerRef = React.createRef<HTMLDivElement>(); | ||
|
|
||
| const onExpressionKeySelected = useCallback( | ||
| (key) => { | ||
| const insertText = getBuiltInFunctionInsertText(key); | ||
| onExpressionSelected('= ' + insertText); | ||
| }, | ||
| [onExpressionSelected] | ||
| ); | ||
|
|
||
| const onLayerMounted = useCallback(() => { | ||
| const elms = document.querySelectorAll<HTMLDivElement>('.ms-ContextualMenu-Callout'); | ||
| onMenuMount(Array.prototype.slice.call(elms)); | ||
| }, [onMenuMount]); | ||
|
|
||
| const menuItems = useMemo( | ||
| () => | ||
| expressionGroupingsToMenuItems( | ||
| builtInFunctionsGrouping, | ||
| onExpressionKeySelected, | ||
| onLayerMounted, | ||
| componentMaxHeight | ||
| ), | ||
| [onExpressionKeySelected, onLayerMounted] | ||
| ); | ||
|
|
||
| return ( | ||
| <div ref={containerRef}> | ||
| <ContextualMenu | ||
| calloutProps={{ | ||
| onLayerMounted: onLayerMounted, | ||
| }} | ||
| directionalHint={DirectionalHint.bottomLeftEdge} | ||
| hidden={false} | ||
| items={menuItems} | ||
| shouldFocusOnMount={false} | ||
| styles={{ | ||
| container: { maxHeight: componentMaxHeight }, | ||
| }} | ||
| target={containerRef} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
48 changes: 48 additions & 0 deletions
48
Composer/packages/adaptive-form/src/components/expressions/utils/expressionsListMenuUtils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { ContextualMenuItemType, IContextualMenuItem } from 'office-ui-fabric-react/lib/ContextualMenu'; | ||
|
|
||
| type ExpressionGroupingType = { | ||
| key: string; | ||
| name: string; | ||
| children: string[]; | ||
| }; | ||
|
|
||
| export const expressionGroupingsToMenuItems = ( | ||
| expressionGroupings: ExpressionGroupingType[], | ||
| menuItemSelectedHandler: (key: string) => void, | ||
| onLayerMounted: () => void, | ||
| maxHeight?: number | ||
| ): IContextualMenuItem[] => { | ||
| const menuItems: IContextualMenuItem[] = | ||
| expressionGroupings?.map((grouping: ExpressionGroupingType) => { | ||
| return { | ||
| key: grouping.key, | ||
| text: grouping.name, | ||
| target: '_blank', | ||
| subMenuProps: { | ||
| calloutProps: { onLayerMounted: onLayerMounted }, | ||
| items: grouping.children.map((key: string) => { | ||
| return { | ||
| key: key, | ||
| text: key, | ||
| onClick: () => menuItemSelectedHandler(key), | ||
| }; | ||
| }), | ||
| styles: { container: { maxHeight } }, | ||
| }, | ||
| }; | ||
| }) || []; | ||
|
|
||
| const header = { | ||
| key: 'header', | ||
| itemType: ContextualMenuItemType.Header, | ||
| text: 'Pre-built functions', | ||
| itemProps: { lang: 'en-us' }, | ||
| }; | ||
|
|
||
| menuItems.unshift(header); | ||
LouisEugeneMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return menuItems; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
Composer/packages/tools/built-in-functions/src/builtInFunctionsGrouping.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // This is the grouping of adaptive expression functions by type as seen on: | ||
| // https://docs.microsoft.com/en-us/azure/bot-service/adaptive-expressions/adaptive-expressions-prebuilt-functions?view=azure-bot-service-4.0 | ||
|
|
||
| export const builtInFunctionsGrouping = [ | ||
LouisEugeneMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| key: 'string', | ||
| name: 'String', | ||
| children: [ | ||
| 'length', | ||
| 'replace', | ||
| 'replaceIgnoreCase', | ||
| 'split', | ||
| 'substring', | ||
| 'toLower', | ||
| 'toUpper', | ||
| 'trim', | ||
| 'addOrdinal', | ||
| 'endsWith', | ||
| 'startsWith', | ||
| 'countWord', | ||
| 'concat', | ||
| 'newGuid', | ||
| 'indexOf', | ||
| 'lastIndexOf', | ||
| 'sentenceCase', | ||
| 'titleCase', | ||
| ], | ||
| }, | ||
| { | ||
| key: 'collection', | ||
| name: 'Collection', | ||
| children: [ | ||
| 'contains', | ||
| 'first', | ||
| 'join', | ||
| 'last', | ||
| 'count', | ||
| 'foreach', | ||
| 'union', | ||
| 'skip', | ||
| 'take', | ||
| 'intersection', | ||
| 'subArray', | ||
| 'select', | ||
| 'where', | ||
| 'sortBy', | ||
| 'sortByDescending', | ||
| 'indicesAndValues', | ||
| 'flatten', | ||
| 'unique', | ||
| ], | ||
| }, | ||
| { | ||
| key: 'logicalComparison', | ||
| name: 'Logical comparison', | ||
| children: [ | ||
| 'and', | ||
| 'equals', | ||
| 'empty', | ||
| 'greater', | ||
| 'greaterOrEquals', | ||
| 'if', | ||
| 'less', | ||
| 'lessOrEquals', | ||
| 'not', | ||
| 'or', | ||
| 'exists', | ||
| ], | ||
| }, | ||
| { | ||
| key: 'conversion', | ||
| name: 'Conversion', | ||
| children: [ | ||
| 'float', | ||
| 'int', | ||
| 'string', | ||
| 'bool', | ||
| 'createArray', | ||
| 'json', | ||
| 'base64', | ||
| 'base64ToBinary', | ||
| 'base64ToString', | ||
| 'binary', | ||
| 'dataUri', | ||
| 'dataUriToBinary', | ||
| 'dataUriToString', | ||
| 'uriComponent', | ||
| 'uriComponentToString', | ||
| 'xml', | ||
| 'formatNumber', | ||
| ], | ||
| }, | ||
| { | ||
| key: 'math', | ||
| name: 'Math', | ||
| children: [ | ||
| 'add', | ||
| 'div', | ||
| 'max', | ||
| 'min', | ||
| 'mod', | ||
| 'mul', | ||
| 'rand', | ||
| 'sub', | ||
| 'sum', | ||
| 'range', | ||
| 'exp', | ||
| 'average', | ||
| 'floor', | ||
| 'ceiling', | ||
| 'round', | ||
| ], | ||
| }, | ||
| { | ||
| key: 'dateAndTime', | ||
| name: 'Date and time', | ||
| children: [ | ||
| 'addDays', | ||
| 'addHours', | ||
| 'addMinutes', | ||
| 'addSeconds', | ||
| 'dayOfMonth', | ||
| 'dayOfWeek', | ||
| 'dayOfYear', | ||
| 'formatDateTime', | ||
| 'formatEpoch', | ||
| 'formatTicks', | ||
| 'subtractFromTime', | ||
| 'utcNow', | ||
| 'dateReadBack', | ||
| 'month', | ||
| 'date', | ||
| 'year', | ||
| 'getTimeOfDay', | ||
| 'getFutureTime', | ||
| 'getPastTime', | ||
| 'addToTime', | ||
| 'convertFromUTC', | ||
| 'convertToUTC', | ||
| 'startOfDay', | ||
| 'startOfHour', | ||
| 'startOfMonth', | ||
| 'ticks', | ||
| 'ticksToDays', | ||
| 'ticksToHours', | ||
| 'ticksToMinutes', | ||
| 'dateTimeDiff', | ||
| 'getPreviousViableDate', | ||
| 'getNextViableDate', | ||
| 'getPreviousViableTime', | ||
| 'getNextViableTime', | ||
| ], | ||
| }, | ||
| { | ||
| key: 'timex', | ||
| name: 'Timex', | ||
| children: ['isPresent', 'isDuration', 'isTime', 'isDate', 'isTimeRange', 'isDateRange', 'isDefinite'], | ||
| }, | ||
| { | ||
| key: 'uriParsing', | ||
| name: 'URI parsing', | ||
| children: ['uriHost', 'uriPath', 'uriPathAndQuery', 'uriPort', 'uriQuery', 'uriScheme'], | ||
| }, | ||
| { | ||
| key: 'objectManipulationAndConstruction', | ||
| name: 'Object manipulation and construction', | ||
| children: [ | ||
| 'addProperty', | ||
| 'removeProperty', | ||
| 'setProperty', | ||
| 'getProperty', | ||
| 'coalesce', | ||
| 'xPath', | ||
| 'jPath', | ||
| 'setPathToValue', | ||
| ], | ||
| }, | ||
| { | ||
| key: 'regularExpression', | ||
| name: 'Regular expression', | ||
| children: ['isMatch'], | ||
| }, | ||
| { | ||
| key: 'typeChecking', | ||
| name: 'Type checking', | ||
| children: ['EOL', 'isInteger', 'isFloat', 'isBoolean', 'isArray', 'isObject', 'isDateTime', 'isString'], | ||
| }, | ||
| ]; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.