Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import React, { useState, useEffect } from 'react';
import { FieldProps, useShellApi, MicrosoftIDialog } from '@bfc/extension-client';
import { RegexRecognizer } from '@bfc/shared';

import { useFormData } from '../../hooks';

import { StringField } from './StringField';

function getRegexIntentPattern(formData: MicrosoftIDialog, intent: string): string {
const recognizer = formData.recognizer as RegexRecognizer;
function getRegexIntentPattern(dialogContent: MicrosoftIDialog, intent: string): string {
const recognizer = dialogContent.recognizer as RegexRecognizer;
let pattern = '';

if (!recognizer) {
Expand All @@ -28,15 +26,14 @@ function getRegexIntentPattern(formData: MicrosoftIDialog, intent: string): stri

const RegexIntentField: React.FC<FieldProps> = ({ value: intentName, ...rest }) => {
const { currentDialog, shellApi } = useShellApi();
const formData = useFormData();
const [localValue, setLocalValue] = useState(getRegexIntentPattern(formData, intentName));
const [localValue, setLocalValue] = useState(getRegexIntentPattern(currentDialog?.content, intentName));

// if the intent name changes or intent names in the regex patterns
// we need to reset the local value
useEffect(() => {
const pattern = getRegexIntentPattern(formData, intentName);
const pattern = getRegexIntentPattern(currentDialog?.content, intentName);
setLocalValue(pattern);
}, [intentName, (formData.recognizer as RegexRecognizer)?.intents.map((i) => i.intent)]);
}, [intentName, currentDialog?.content]);

const handleIntentChange = (pattern?: string) => {
setLocalValue(pattern ?? '');
Expand Down