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: UI Schema - Recognizer #4135
Merged
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
197a295
chore: turn RecognizerField to folder
yeze322 48cf2cc
extract 'useMigrationEffect'
yeze322 2dd8607
remove dup & no ref file 'defaultRecognizers'
yeze322 f497f6f
move out complicated selectedType func && var names
yeze322 b7d6755
use 'dropdownOption' to replace 'isCustomType' which is anti-pattern
yeze322 43da36d
add 'default' and 'disabled' to RecognizerSchema
yeze322 a4931f8
set CrossTrain to default, disable Luis
yeze322 47d1ebb
impl 'getRecognizerDefinition()'
yeze322 9aa5694
move DefaultRecognizers to separated file
yeze322 991ba4c
rename: 'editor' -> 'intentEditor'
yeze322 c0b94a0
impl 'recognizerEditor' in Recognizer schema
yeze322 6e1918d
adapt to schema's 'disabled' property
yeze322 de427a8
sort recognizer options
yeze322 eee273a
make renameIntent optional
yeze322 c34971d
make handleRecognizerChange optional & impl fallback submit func
yeze322 19b519e
impl mappers to map among 'schema', 'dropdown', 'value'
yeze322 fd357e3
provide 'findRecognizer' as hook's buitin func
yeze322 5d82982
apply findRecognizer to RecognizerField
yeze322 6ee0b31
mark isSelected optional
yeze322 aacba7d
Merge branch 'main' into uischema/recognizer
yeze322 5d4c89f
add a todo
yeze322 3bf82da
Merge branch 'main' into uischema/recognizer
beyackle d4de656
Merge branch 'main' into uischema/recognizer
yeze322 681ebda
merge 'recognizers' to uiSchema
yeze322 a94cef3
migrate to new RecognizerUISchema
yeze322 0a1ab40
don't show non-recognizer $kinds as dropdown
yeze322 0ba8568
adjust dropdown order
yeze322 2da450e
make the 'Custom Rec' with JSON editor as fallback option
yeze322 6cde9ca
fix tslint error
yeze322 32c35b6
omi RegexRecognizer's `isSelected` option
yeze322 1d82e10
Merge branch 'main' into uischema/recognizer
yeze322 a0ccd13
resolve intentEditor logic leaks
yeze322 d00260b
fix UT
yeze322 87d34bf
fix UT
yeze322 a510c63
impl getDefaultRecognizer()
yeze322 bccc372
create default recognizer when seeding new dialog
yeze322 2165e45
Merge branch 'main' into uischema/recognizer
yeze322 3272ace
fix UT
yeze322 d403252
Merge branch 'main' into uischema/recognizer
yeze322 4726b4c
copyright
yeze322 aadac7a
del 'default' opt from crosstrain plugin
yeze322 7ca0e30
migrate handleRecognizerChange to seedNewRecognizer
yeze322 9075c0b
mark a todo
yeze322 5c4513d
update `seedNewRecongnizer` interface & apply to dialog modal
yeze322 5d01f93
Merge branch 'main' into uischema/recognizer
yeze322 7dd4752
Merge branch 'main' into uischema/recognizer
yeze322 37e8b42
Fix wording issue in comments
yeze322 9e39427
minor fixes on code style & comments
yeze322 ffcfa9a
Merge branch 'uischema/recognizer' of https://github.com/yeze322/BotF…
yeze322 72f3618
type the 'disabled' field strictly
yeze322 1ada824
more strict `isSelected()` method in CrossTrainReocognizer shema
yeze322 0123966
update default recognizer value
yeze322 b53f24d
provide 'current' and 'default' recognizer schema in useRecognizerCon…
yeze322 018cb2c
fix UTs
yeze322 b910d7e
remove custom recognizer template
yeze322 4769cd3
write `displayName` as function to support multi-locale
yeze322 eecb027
Merge branch 'main' into uischema/recognizer
yeze322 7f3c108
Merge branch 'main' into uischema/recognizer
yeze322 196b3af
Merge branch 'main' into uischema/recognizer
a-b-r-o-w-n 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
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
19 changes: 19 additions & 0 deletions
19
Composer/packages/adaptive-form/src/components/fields/CustomRecognizerField.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,19 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import React from 'react'; | ||
| import { FieldProps } from '@bfc/extension-client'; | ||
| import { JsonEditor } from '@bfc/code-editor'; | ||
|
|
||
| export const CustomRecognizerField: React.FC<FieldProps> = (props) => { | ||
| const { value, onChange } = props; | ||
| return ( | ||
| <JsonEditor | ||
| key="customRecognizerField" | ||
| height={200} | ||
| id="customRecognizerField" | ||
| value={value as object} | ||
| onChange={onChange} | ||
| /> | ||
| ); | ||
| }; |
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
129 changes: 0 additions & 129 deletions
129
Composer/packages/adaptive-form/src/components/fields/RecognizerField.tsx
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
Composer/packages/adaptive-form/src/components/fields/RecognizerField/RecognizerField.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,55 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| /** @jsx jsx */ | ||
| import { jsx } from '@emotion/core'; | ||
| import React, { useMemo } from 'react'; | ||
| import { FieldProps, useShellApi, useRecognizerConfig } from '@bfc/extension-client'; | ||
| import { MicrosoftIRecognizer } from '@bfc/shared'; | ||
| import { Dropdown, ResponsiveMode, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown'; | ||
| import formatMessage from 'format-message'; | ||
|
|
||
| import { FieldLabel } from '../../FieldLabel'; | ||
|
|
||
| import { useMigrationEffect } from './useMigrationEffect'; | ||
| import { mapDropdownOptionToRecognizerSchema } from './mappers'; | ||
| import { getDropdownOptions } from './getDropdownOptions'; | ||
|
|
||
| export const RecognizerField: React.FC<FieldProps<MicrosoftIRecognizer>> = (props) => { | ||
| const { value, id, label, description, uiOptions, required, onChange } = props; | ||
| const { shellApi, ...shellData } = useShellApi(); | ||
|
|
||
| useMigrationEffect(value, onChange); | ||
| const { recognizers: recognizerConfigs, currentRecognizer } = useRecognizerConfig(); | ||
| const dropdownOptions = useMemo(() => getDropdownOptions(recognizerConfigs), [recognizerConfigs]); | ||
|
|
||
| const RecognizerEditor = currentRecognizer?.recognizerEditor; | ||
| const widget = RecognizerEditor ? <RecognizerEditor {...props} /> : null; | ||
|
|
||
| const submit = (_, option?: IDropdownOption): void => { | ||
| if (!option) return; | ||
|
|
||
| const recognizerDefinition = mapDropdownOptionToRecognizerSchema(option, recognizerConfigs); | ||
|
|
||
| const seedNewRecognizer = recognizerDefinition?.seedNewRecognizer; | ||
| const recognizerInstance = | ||
| typeof seedNewRecognizer === 'function' | ||
| ? seedNewRecognizer(shellData, shellApi) | ||
| : { $kind: option.key as string, intents: [] }; // fallback to default Recognizer instance; | ||
| onChange(recognizerInstance); | ||
| }; | ||
|
|
||
| return ( | ||
| <React.Fragment> | ||
| <FieldLabel description={description} helpLink={uiOptions?.helpLink} id={id} label={label} required={required} /> | ||
| <Dropdown | ||
| data-testid="recognizerTypeDropdown" | ||
| label={formatMessage('Recognizer Type')} | ||
| options={dropdownOptions} | ||
| responsiveMode={ResponsiveMode.large} | ||
| selectedKey={currentRecognizer?.id} | ||
| onChange={submit} | ||
| /> | ||
| {widget} | ||
| </React.Fragment> | ||
| ); | ||
| }; |
11 changes: 11 additions & 0 deletions
11
...er/packages/adaptive-form/src/components/fields/RecognizerField/defaultRecognizerOrder.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,11 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { SDKKinds } from '@bfc/shared'; | ||
|
|
||
| export const defaultRecognizerOrder = [SDKKinds.CrossTrainedRecognizerSet, SDKKinds.RegexRecognizer]; | ||
|
|
||
| export const recognizerOrderMap: { [$kind: string]: number } = defaultRecognizerOrder.reduce((result, $kind, index) => { | ||
| result[$kind] = index; | ||
| return result; | ||
| }, {}); |
26 changes: 26 additions & 0 deletions
26
Composer/packages/adaptive-form/src/components/fields/RecognizerField/getDropdownOptions.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,26 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { RecognizerSchema, FallbackRecognizerKey } from '@bfc/extension-client'; | ||
|
|
||
| import { recognizerOrderMap } from './defaultRecognizerOrder'; | ||
| import { mapRecognizerSchemaToDropdownOption } from './mappers'; | ||
|
|
||
| const getRankScore = (r: RecognizerSchema) => { | ||
| // Always put disabled recognizer behind. Handle 'disabled' before 'default'. | ||
| if (r.disabled) return Number.MAX_VALUE; | ||
| // Always put default recognzier ahead. | ||
| if (r.default) return -1; | ||
| // Put fallback recognizer behind. | ||
| if (r.id === FallbackRecognizerKey) return Number.MAX_VALUE - 1; | ||
| return recognizerOrderMap[r.id] ?? Number.MAX_VALUE - 1; | ||
| }; | ||
|
|
||
| export const getDropdownOptions = (recognizerConfigs: RecognizerSchema[]) => { | ||
| return recognizerConfigs | ||
| .filter((r) => !r.disabled) | ||
| .sort((r1, r2) => { | ||
| return getRankScore(r1) - getRankScore(r2); | ||
| }) | ||
| .map(mapRecognizerSchemaToDropdownOption); | ||
| }; |
4 changes: 4 additions & 0 deletions
4
Composer/packages/adaptive-form/src/components/fields/RecognizerField/index.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,4 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| export { RecognizerField } from './RecognizerField'; |
15 changes: 15 additions & 0 deletions
15
Composer/packages/adaptive-form/src/components/fields/RecognizerField/mappers.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,15 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { RecognizerSchema } from '@bfc/extension-client'; | ||
| import { IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown'; | ||
|
|
||
| export const mapDropdownOptionToRecognizerSchema = (option: IDropdownOption, recognizerConfigs: RecognizerSchema[]) => { | ||
| return recognizerConfigs.find((r) => r.id === option.key); | ||
| }; | ||
|
|
||
| export const mapRecognizerSchemaToDropdownOption = (recognizerSchema: RecognizerSchema): IDropdownOption => { | ||
| const { id, displayName } = recognizerSchema; | ||
| const recognizerName = typeof displayName === 'function' ? displayName({}) : displayName; | ||
| return { key: id, text: recognizerName || id }; | ||
| }; |
29 changes: 29 additions & 0 deletions
29
Composer/packages/adaptive-form/src/components/fields/RecognizerField/useMigrationEffect.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,29 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import { useShellApi, ChangeHandler } from '@bfc/extension-client'; | ||
| import { useEffect } from 'react'; | ||
| import { MicrosoftIRecognizer } from '@bfc/shared'; | ||
|
|
||
| export const useMigrationEffect = ( | ||
| recognizer: MicrosoftIRecognizer | undefined, | ||
| onChangeRecognizer: ChangeHandler<MicrosoftIRecognizer> | ||
| ) => { | ||
| const { qnaFiles, luFiles, currentDialog, locale } = useShellApi(); | ||
|
|
||
| useEffect(() => { | ||
| // this logic is for handling old bot with `recognizer = undefined' | ||
| if (recognizer === undefined) { | ||
| const qnaFile = qnaFiles.find((f) => f.id === `${currentDialog.id}.${locale}`); | ||
| const luFile = luFiles.find((f) => f.id === `${currentDialog.id}.${locale}`); | ||
| if (qnaFile && luFile) { | ||
| onChangeRecognizer(`${currentDialog.id}.lu.qna`); | ||
| } | ||
| } | ||
|
|
||
| // transform lu recognizer to crosstrained for old bot | ||
| if (recognizer === `${currentDialog.id}.lu`) { | ||
| onChangeRecognizer(`${currentDialog.id}.lu.qna`); | ||
| } | ||
| }, [recognizer]); | ||
| }; | ||
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.