diff --git a/Composer/packages/client/src/components/Header.tsx b/Composer/packages/client/src/components/Header.tsx index 8869b38ff0..cae3140192 100644 --- a/Composer/packages/client/src/components/Header.tsx +++ b/Composer/packages/client/src/components/Header.tsx @@ -28,6 +28,7 @@ import { rootBotProjectIdSelector, settingsState, webChatEssentialsSelector, + botProjectSpaceLoadedState, isWebChatPanelVisibleState, allRequiredRecognizersSelector, } from '../recoilModel'; @@ -163,6 +164,7 @@ export const Header = () => { const settings = useRecoilValue(settingsState(projectId)); const schemas = useRecoilValue(schemasState(projectId)); const isWebChatPanelVisible = useRecoilValue(isWebChatPanelVisibleState); + const botProjectSolutionLoaded = useRecoilValue(botProjectSpaceLoadedState); const { languages, defaultLanguage } = settings; const { showing, status } = appUpdate; @@ -173,14 +175,22 @@ export const Header = () => { const [hideBotController, hideBotStartController] = useState(true); const [showGetStarted, setShowGetStarted] = useState(false); const [showTeachingBubble, setShowTeachingBubble] = useState(false); + const [requiresLUIS, setRequiresLUIS] = useState(false); + const [requiresQNA, setRequiresQNA] = useState(false); + const { location } = useLocation(); // These are needed to determine if the bot needs LUIS or QNA // this data is passed into the GetStarted widget // ... if the get started widget moves, this code should too! const requiredStuff = useRecoilValue(allRequiredRecognizersSelector); - const requiresLUIS = requiredStuff.some((p) => p.requiresLUIS); - const requiresQNA = requiredStuff.some((p) => p.requiresQNA); + + useEffect(() => { + if (botProjectSolutionLoaded) { + setRequiresLUIS(requiredStuff.some((p) => p.requiresLUIS)); + setRequiresQNA(requiredStuff.some((p) => p.requiresQNA)); + } + }, [requiredStuff, botProjectSolutionLoaded]); // ... end of get started stuff const isShow = useBotControllerBar(); @@ -412,11 +422,11 @@ export const Header = () => { /> ) : null} { setShowTeachingBubble(true); }} diff --git a/Composer/packages/client/src/recoilModel/selectors/project.ts b/Composer/packages/client/src/recoilModel/selectors/project.ts index 4ec6b81e32..c5d50e11e4 100644 --- a/Composer/packages/client/src/recoilModel/selectors/project.ts +++ b/Composer/packages/client/src/recoilModel/selectors/project.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { BotIndexer } from '@bfc/indexers'; -import { BotAssets, checkForPVASchema, DialogInfo, FormDialogSchema, JsonSchemaFile } from '@bfc/shared'; +import { BotAssets, checkForPVASchema, DialogInfo, FormDialogSchema, JsonSchemaFile, SDKKinds } from '@bfc/shared'; import isEmpty from 'lodash/isEmpty'; import uniqBy from 'lodash/uniqBy'; import { selector, selectorFamily } from 'recoil'; @@ -30,6 +30,7 @@ import { botEndpointsState, localeState, botStatusState, + botProjectSpaceLoadedState, } from '../atoms'; import { dialogsSelectorFamily, @@ -381,16 +382,37 @@ export const webChatEssentialsSelector = selectorFamily { + const luFileId = fileId.replace(/\.lu$/, ''); + return ( + files + .find(({ id }) => getBaseName(id) === luFileId) + ?.content.trim() + .replace(/^>.*$/g, '') + .trim() === '' + ); +}; + export const allRequiredRecognizersSelector = selector({ key: 'allRequiredRecognizersSelector', get: ({ get }) => { const ids = get(botProjectIdsState); + const loaded = get(botProjectSpaceLoadedState); + if (!loaded) return []; + return ids.reduce((result: { projectId: string; requiresLUIS: boolean; requiresQNA: boolean }[], id: string) => { const botAssets = get(botAssetsSelectFamily(id)); if (botAssets) { const { dialogs, luFiles, qnaFiles } = botAssets; - const requiresLUIS = BotIndexer.shouldUseLuis(dialogs, luFiles); - const requiresQNA = BotIndexer.shouldUseQnA(dialogs, qnaFiles); + const requiresLUIS = dialogs.some( + (dialog) => dialog.luProvider === SDKKinds.LuisRecognizer && !isEmptyFile(luFiles, dialog.luFile) + ); + const requiresQNA = qnaFiles.some((file) => file.content.trim().replace(/^>.*$/g, '').trim() !== ''); result.push({ projectId: id, requiresLUIS, requiresQNA }); } return result;