-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into notification
- Loading branch information
Showing
49 changed files
with
1,203 additions
and
863 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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.