Skip to content

Commit

Permalink
fix: No exception thrown when unsupported locale is set for Luis publ…
Browse files Browse the repository at this point in the history
…ish (microsoft#5688)

* fix: No exception thrown when unsupported locale is set for Luis publish

* fix unit tests

* filter unsupport language when create cross train config

Co-authored-by: Dong Lei <[email protected]>
  • Loading branch information
lei9444 and boydc2014 authored Feb 7, 2021
1 parent 2010f0f commit b83c152
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const state = {
name: 'Email-Skill',
},
},
languages: ['en-us'],
},
formDialogSchemas: [{ id: '1', content: '{}' }],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { jsx, css, keyframes } from '@emotion/core';
import React, { useState } from 'react';
import { IconButton, ActionButton } from 'office-ui-fabric-react/lib/Button';
import { useRef } from 'react';
import { FontSizes } from '@uifabric/fluent-theme';
import { FontSizes, SharedColors } from '@uifabric/fluent-theme';
import { Shimmer, ShimmerElementType } from 'office-ui-fabric-react/lib/Shimmer';
import { Icon } from 'office-ui-fabric-react/lib/Icon';
import formatMessage from 'format-message';
Expand Down Expand Up @@ -76,6 +76,11 @@ const successType = css`
color: #27ae60;
`;

const warningType = css`
margin-top: 4px;
color: ${SharedColors.yellow10};
`;

const cardTitle = css`
font-size: ${FontSizes.size16};
lint-height: 22px;
Expand Down Expand Up @@ -147,6 +152,7 @@ const defaultCardContentRenderer = (props: CardProps) => {
<div css={cardContent}>
{type === 'error' && <Icon css={errorType} iconName="ErrorBadge" />}
{type === 'success' && <Icon css={successType} iconName="Completed" />}
{type === 'warning' && <Icon css={warningType} iconName="Warning" />}
<div css={cardDetail}>
<div css={cardTitle}>{title}</div>
{description && <div css={cardDescription}>{description}</div>}
Expand Down
27 changes: 23 additions & 4 deletions Composer/packages/client/src/recoilModel/dispatchers/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,52 @@
/* eslint-disable react-hooks/rules-of-hooks */

import { useRecoilCallback, CallbackInterface } from 'recoil';
import { ILuisConfig, IQnAConfig } from '@bfc/shared';
import { ILuisConfig, IQnAConfig, LUISLocales } from '@bfc/shared';
import formatMessage from 'format-message';
import difference from 'lodash/difference';

import * as luUtil from '../../utils/luUtil';
import { Text, BotStatus } from '../../constants';
import httpClient from '../../utils/httpUtil';
import luFileStatusStorage from '../../utils/luFileStatusStorage';
import qnaFileStatusStorage from '../../utils/qnaFileStatusStorage';
import { luFilesState, qnaFilesState, botStatusState, botRuntimeErrorState } from '../atoms';
import { luFilesState, qnaFilesState, botStatusState, botRuntimeErrorState, settingsState } from '../atoms';
import { dialogsSelectorFamily } from '../selectors';
import { getReferredQnaFiles } from '../../utils/qnaUtil';

import { addNotificationInternal, createNotification } from './notification';

const checkEmptyQuestionOrAnswerInQnAFile = (sections) => {
return sections.some((s) => !s.Answer || s.Questions.some((q) => !q.content));
};

const setLuisBuildNotification = (callbackHelpers: CallbackInterface, unsupportedLocales: string[]) => {
if (!unsupportedLocales.length) return;
const notification = createNotification({
title: formatMessage('Luis build warning'),
description: formatMessage('locale "{locale}" is not supported by LUIS', { locale: unsupportedLocales.join(' ') }),
type: 'warning',
retentionTime: 5000,
});
addNotificationInternal(callbackHelpers, notification);
};

export const builderDispatcher = () => {
const build = useRecoilCallback(
({ set, snapshot }: CallbackInterface) => async (
(callbackHelpers: CallbackInterface) => async (
projectId: string,
luisConfig: ILuisConfig,
qnaConfig: IQnAConfig
) => {
const { set, snapshot } = callbackHelpers;
const dialogs = await snapshot.getPromise(dialogsSelectorFamily(projectId));
const luFiles = await snapshot.getPromise(luFilesState(projectId));
const qnaFiles = await snapshot.getPromise(qnaFilesState(projectId));
const { languages } = await snapshot.getPromise(settingsState(projectId));
const referredLuFiles = luUtil.checkLuisBuild(luFiles, dialogs);
const referredQnaFiles = getReferredQnaFiles(qnaFiles, dialogs);
const referredQnaFiles = getReferredQnaFiles(qnaFiles, dialogs, false);
const unsupportedLocales = difference<string>(languages, LUISLocales);
setLuisBuildNotification(callbackHelpers, unsupportedLocales);
const errorMsg = referredQnaFiles.reduce(
(result, file) => {
if (
Expand Down
26 changes: 14 additions & 12 deletions Composer/packages/client/src/utils/buildUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { DialogInfo, LuFile, QnAFile, SDKKinds } from '@bfc/shared';
import { DialogInfo, LuFile, LUISLocales, QnAFile, SDKKinds } from '@bfc/shared';

import { LuisConfig, QnaConfig } from '../constants';

Expand All @@ -25,17 +25,19 @@ export function createCrossTrainConfig(dialogs: DialogInfo[], luFiles: LuFile[],

if (!filtered.length) return result;

languages.forEach((language) => {
const triggers = filtered.reduce((result, { intent, dialogs }) => {
const ids = dialogs
.map((dialog) => createConfigId(dialog, language))
.filter((id) => luFiles.some((file) => `${file.id}` === id));
if (!ids.length && dialogs.length) return result;
result[intent] = ids;
return result;
}, {});
result[createConfigId(id, language)] = { rootDialog, triggers };
});
languages
.filter((item) => LUISLocales.includes(item))
.forEach((language) => {
const triggers = filtered.reduce((result, { intent, dialogs }) => {
const ids = dialogs
.map((dialog) => createConfigId(dialog, language))
.filter((id) => luFiles.some((file) => `${file.id}` === id));
if (!ids.length && dialogs.length) return result;
result[intent] = ids;
return result;
}, {});
result[createConfigId(id, language)] = { rootDialog, triggers };
});

return result;
}, {});
Expand Down
6 changes: 5 additions & 1 deletion Composer/packages/lib/indexers/src/botIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ const checkLUISLocales = (assets: { dialogs: DialogInfo[]; setting: DialogSettin
if (!useLUIS) return [];

const unsupportedLocales = difference(languages, LUISLocales);

const severity =
unsupportedLocales.length === languages.length ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning;

return unsupportedLocales.map((locale) => {
return new Diagnostic(`locale ${locale} is not supported by LUIS`, 'appsettings.json', DiagnosticSeverity.Warning);
return new Diagnostic(`locale ${locale} is not supported by LUIS`, 'appsettings.json', severity);
});
};

Expand Down

0 comments on commit b83c152

Please sign in to comment.