Skip to content

Commit

Permalink
fix: Dialog validate throw error when delete an action (microsoft#3537)
Browse files Browse the repository at this point in the history
* fix: Dialog validate throw error when delete an action

* use optional chaining and more explicit length check

* fix lint

Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
Co-authored-by: Andy Brown <asbrown002@gmail.com>
  • Loading branch information
3 people authored Jul 2, 2020
1 parent 7b678bf commit a157b33
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ describe('search lg custom function', () => {
expect(result.length).toEqual(2);
expect(result[0]).toEqual('foo.bar');
expect(result[1]).toEqual('foo.cool');
const lgFilesWithoutOptions = [{ id: 'test.en-us' }];
const result1 = searchLgCustomFunction(lgFilesWithoutOptions as LgFile[]);
expect(result1.length).toEqual(0);
});

it('should return custom functions with namespace', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ const ExportsKey = '@exports';
export const searchLgCustomFunction = (lgFiles: LgFile[]): string[] => {
const customFunctions = lgFiles.reduce((result: string[], lgFile) => {
const { options } = lgFile;
const exports = extractOptionByKey(ExportsKey, options);
let namespace = extractOptionByKey(NamespaceKey, options);
if (!namespace) namespace = lgFile.id; //if namespace doesn't exist, use file name
const funcList = exports.split(',');
funcList.forEach((func) => {
if (func) {
result.push(`${namespace}.${func.trim()}`);
}
});

if (options?.length) {
const exports = extractOptionByKey(ExportsKey, options);
let namespace = extractOptionByKey(NamespaceKey, options);
if (!namespace) namespace = lgFile.id; //if namespace doesn't exist, use file name
const funcList = exports.split(',');
funcList.forEach((func) => {
if (func) {
result.push(`${namespace}.${func.trim()}`);
}
});
}
return result;
}, []);
return customFunctions;
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/lib/shared/src/types/indexers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export interface LgFile {
content: string;
diagnostics: Diagnostic[];
templates: LgTemplate[];
options: string[];
options?: string[];
}

export interface Skill {
Expand Down

0 comments on commit a157b33

Please sign in to comment.