Skip to content

Commit

Permalink
fix: adjust mechanism used to determine if/when luis and qna teaching…
Browse files Browse the repository at this point in the history
… bubbles should pop out (#6973)

* adjust mechnaism used to determine if luis and qna bubbs should pop

* change name of variable

Co-authored-by: Srinaath Ravichandran <srinaath27@gmail.com>
Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
  • Loading branch information
3 people authored Apr 15, 2021
1 parent 64884d0 commit 611629b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
18 changes: 14 additions & 4 deletions Composer/packages/client/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
rootBotProjectIdSelector,
settingsState,
webChatEssentialsSelector,
botProjectSpaceLoadedState,
isWebChatPanelVisibleState,
allRequiredRecognizersSelector,
} from '../recoilModel';
Expand Down Expand Up @@ -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;
Expand All @@ -173,14 +175,22 @@ export const Header = () => {
const [hideBotController, hideBotStartController] = useState(true);
const [showGetStarted, setShowGetStarted] = useState<boolean>(false);
const [showTeachingBubble, setShowTeachingBubble] = useState<boolean>(false);
const [requiresLUIS, setRequiresLUIS] = useState<boolean>(false);
const [requiresQNA, setRequiresQNA] = useState<boolean>(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();
Expand Down Expand Up @@ -412,11 +422,11 @@ export const Header = () => {
/>
) : null}
<GetStarted
isOpen={showGetStarted}
isOpen={botProjectSolutionLoaded && showGetStarted}
projectId={rootBotProjectId}
requiresLUIS={requiresLUIS}
requiresQNA={requiresQNA}
showTeachingBubble={showGetStartedTeachingBubble}
showTeachingBubble={botProjectSolutionLoaded && showGetStartedTeachingBubble}
onBotReady={() => {
setShowTeachingBubble(true);
}}
Expand Down
28 changes: 25 additions & 3 deletions Composer/packages/client/src/recoilModel/selectors/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -30,6 +30,7 @@ import {
botEndpointsState,
localeState,
botStatusState,
botProjectSpaceLoadedState,
} from '../atoms';
import {
dialogsSelectorFamily,
Expand Down Expand Up @@ -381,16 +382,37 @@ export const webChatEssentialsSelector = selectorFamily<WebChatEssentials, strin
},
});

function getBaseName(filename: string, sep?: string): string {
if (sep) return filename.substr(0, filename.lastIndexOf(sep));
return filename.substring(0, filename.lastIndexOf('.')) || filename;
}

const isEmptyFile = (files, fileId) => {
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;
Expand Down

0 comments on commit 611629b

Please sign in to comment.