Skip to content

Commit

Permalink
Merge branch 'master' into wenyluo/fix3395
Browse files Browse the repository at this point in the history
  • Loading branch information
a-b-r-o-w-n authored Jun 16, 2020
2 parents b3b9171 + bac3e28 commit 1967433
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 32 deletions.
1 change: 1 addition & 0 deletions Composer/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
'no-console': 'warn',
'dot-notation': 'error',
yoda: 'error',
'no-bitwise': 'error',
// eqeqeq: 'error',

// plugin: import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ const WelcomeModal = () => {
{stepSets.map(({ steps: { length }, title }, index) => (
<StepStatus
key={index}
isComplete={index < currentSet || (index === currentSet && !~currentStep)}
isComplete={index < currentSet || (index === currentSet && currentStep === -1)}
steps={length}
title={title}
/>
))}
</div>
<div css={footerStyle}>
{!~currentStep && (
{currentStep === -1 && (
<div>
{currentSet + 1 < stepSets.length && (
<PrimaryButton data-testid="onboardingNextSet" text={stepSets[currentSet + 1].title} onClick={nextSet} />
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/src/Onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const Onboarding: React.FC = () => {
!complete && projectId && navigateTo && navigate(navigateTo);
setTeachingBubble({ currentStep, id, location, setLength: steps.length, targetId });

setMinimized(!!~currentStep);
setMinimized(currentStep >= 0);

if (currentSet > -1 && currentSet < stepSets.length) {
onboardingState.setCurrentSet(stepSets[currentSet].id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ExportSkillModal: React.FC<ExportSkillModalProps> = ({ onSubmit, onDismiss

const handleEditJson = () => {
const step = order.findIndex((step) => step === ManifestEditorSteps.MANIFEST_REVIEW);
if (~step) {
if (step >= 0) {
setCurrentStep(step);
setErrors({});
}
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/src/utils/luUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export * from '@bfc/indexers/lib/utils/luUtil';
export function getReferredFiles(luFiles: LuFile[], dialogs: DialogInfo[]) {
return luFiles.filter((file) => {
const idWithOutLocale = getBaseName(file.id);
return !!~dialogs.findIndex((dialog) => dialog.luFile === idWithOutLocale);
return dialogs.some((dialog) => dialog.luFile === idWithOutLocale);
});
}

Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/lib/code-editor/src/LuEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ const LuEditor: React.FC<LULSPEditorProps> = (props) => {

const m = monacoRef.current;
if (m) {
// this is the correct way to combine keycodes in Monaco
// eslint-disable-next-line no-bitwise
editor.addCommand(m.KeyMod.Shift | m.KeyCode.Enter, function () {
const position = editor.getPosition();
SendRequestWithRetry(languageClient, 'labelingExperienceRequest', { uri, position });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const createPath = (path: string, type: string): string => {
if (/\[|\]/.test(x)) {
const reg = /\[.*\]/;
x = x.replace(reg, '');
return ~values(FieldNames).indexOf(x);
return values(FieldNames).includes(x);
}
});

Expand Down
6 changes: 3 additions & 3 deletions Composer/packages/lib/indexers/src/dialogUtils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const isExpression = (value: string | boolean | number, types: string[]): boolea
//TODO: returnType is number, schem type is string, need map or unify
const checkReturnType = (returnType: ReturnType, types: string[]): string => {
return returnType === ReturnType.Object ||
~types.indexOf(ExpressionTypeMapString[returnType]) ||
(returnType === ReturnType.Number && ~types.indexOf(ExpressionType.integer))
types.includes(ExpressionTypeMapString[returnType]) ||
(returnType === ReturnType.Number && types.includes(ExpressionType.integer))
? ''
: formatMessage('the expression type is not match');
: formatMessage('the return type does not match');
};

export const checkExpression = (exp: string | boolean | number, required: boolean, types: string[]): string => {
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export class BotProject {

private getLocale(id: string): string {
const index = id.lastIndexOf('.');
if (~index) return '';
if (index >= 0) return '';
return id.substring(index + 1);
}

Expand Down
46 changes: 24 additions & 22 deletions Composer/packages/server/src/models/bot/luPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class LuPublisher {
public botDir: string;
public dialogsDir: string;
public generatedFolderPath: string;
public interuptionFolderPath: string;
public interruptionFolderPath: string;
public storage: IFileStorage;
public config: ILuisConfig | null = null;
public downSamplingConfig: IDownSamplingConfig = { maxImbalanceRatio: 0, maxUtteranceAllowed: 0 };
Expand All @@ -60,7 +60,7 @@ export class LuPublisher {
this.botDir = path;
this.dialogsDir = this.botDir;
this.generatedFolderPath = Path.join(this.dialogsDir, GENERATEDFOLDER);
this.interuptionFolderPath = Path.join(this.generatedFolderPath, INTERUPTION);
this.interruptionFolderPath = Path.join(this.generatedFolderPath, INTERUPTION);
this.storage = storage;
this._locale = locale;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ export class LuPublisher {
return luObject;
}

private async _downSizeUtterances(luContents: any) {
private async _downsizeUtterances(luContents: any) {
return await Promise.all(
luContents.map(async (luContent) => {
const result = await LuisBuilder.fromLUAsync(luContent.content);
Expand All @@ -147,27 +147,26 @@ export class LuPublisher {
}

private async _writeFiles(crossTrainResult) {
if (!(await this.storage.exists(this.interuptionFolderPath))) {
await this.storage.mkDir(this.interuptionFolderPath);
if (!(await this.storage.exists(this.interruptionFolderPath))) {
await this.storage.mkDir(this.interruptionFolderPath);
}
for (const key of crossTrainResult.keys()) {
const fileName = Path.basename(key);
const newFileId = Path.join(this.interuptionFolderPath, fileName);
const newFileId = Path.join(this.interruptionFolderPath, fileName);
await this.storage.writeFile(newFileId, crossTrainResult.get(key).Content);
}
}

private async _runBuild(files: FileInfo[]) {
const config = await this._getConfig(files);
if (config.models.length === 0) {
throw new Error('No luis file exist');
}
const loadResult = await this._loadLuConatents(config.models);
loadResult.luContents = await this._downSizeUtterances(loadResult.luContents);
let authoringEndpoint = config.authoringEndpoint;
if (!authoringEndpoint) {
authoringEndpoint = `https://${config.region}.api.cognitive.microsoft.com`;
throw new Error('No LUIS files exist');
}

const loadResult = await this._loadLuContents(config.models);
loadResult.luContents = await this._downsizeUtterances(loadResult.luContents);
const authoringEndpoint = config.endpoint ?? `https://${config.region}.api.cognitive.microsoft.com`;

const buildResult = await this.builder.build(
loadResult.luContents,
loadResult.recognizers,
Expand Down Expand Up @@ -201,35 +200,38 @@ export class LuPublisher {

private _getConfig = async (files: FileInfo[]) => {
if (!this.config) {
throw new Error('Please complete your Luis settings');
throw new Error('Please complete your LUIS settings');
}

const luConfig: any = {
const luConfig = {
authoringKey: this.config.authoringKey || '',
region: this.config.authoringRegion || '',
botName: this.config.name || '',
suffix: this.config.environment || '',
fallbackLocal: this.config.defaultLanguage || 'en-us',
endpoint: this.config.endpoint || null,
models: [] as string[],
};

luConfig.models = [];
//add all lu file after cross train
let paths: string[] = [];
if (this._needCrossTrain()) {
paths = await this.storage.glob('**/*.lu', this.interuptionFolderPath);
luConfig.models = paths.map((filePath) => Path.join(this.interuptionFolderPath, filePath));
paths = await this.storage.glob('**/*.lu', this.interruptionFolderPath);
luConfig.models = paths.map((filePath) => Path.join(this.interruptionFolderPath, filePath));
}

//add the lu file that are not in interuption folder.
const pathSet = new Set(paths);

//add the lu file that are not in interruption folder.
files.forEach((file) => {
if (!~paths.indexOf(file.name)) {
if (!pathSet.has(file.name)) {
luConfig.models.push(Path.resolve(this.botDir, file.relativePath));
}
});
return luConfig;
};

private _loadLuConatents = async (paths: string[]) => {
private _loadLuContents = async (paths: string[]) => {
return await this.builder.loadContents(
paths,
this._locale,
Expand All @@ -240,6 +242,6 @@ export class LuPublisher {

private async _cleanCrossTrain() {
if (!this._needCrossTrain()) return;
await this._deleteDir(this.interuptionFolderPath);
await this._deleteDir(this.interruptionFolderPath);
}
}

0 comments on commit 1967433

Please sign in to comment.