Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
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 }) => {
Copy link
Contributor

@srinaath srinaath Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This selector reevaluates for every change in the bot asset @benbrown . Is this GetStarted section required only on bot load first up and not required afterwards? Essentially, lets say on startup there is no LUIS,QNA and when we add a dialog which requires LUIS does the GetStarted section update itself to show the need for LUIS or QNA. If thats the case then it makes sense for the selector to reevaluate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should reevaluate if they add LUIS later...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to consider is reusing the logic we have in the DebugPanel to report the error for missing LUIS key, QNA Key. This functionality looks similar

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