Skip to content

Commit

Permalink
fix: various template bugs (#7378)
Browse files Browse the repository at this point in the history
* Fix qna template name and prepare sort order for new package names

* Fixing default proj name logic and minor cleaning up

* Partially fix initial template selection bug

* Add timeout to fully fix initial template selection UI bug

* fix qna read me bug

* fix backup sort order

* Adding new templates to sort template unit test

* Fix creation unit test to account for new template name

* Adjusting unit test to check for default name derived by display name vs template package name
  • Loading branch information
pavolum authored Apr 27, 2021
1 parent e3e1b3e commit c064006
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
creationFlowStatusState,
dispatcherState,
featureFlagsState,
templateProjectsState,
} from '../../../src/recoilModel';
import { CreationFlowStatus } from '../../../src/constants';
import CreationFlowV2 from '../../../src/components/CreationFlow/v2/CreationFlow';
Expand All @@ -36,6 +37,17 @@ describe('<CreationFlowV2/>', () => {
});
set(creationFlowStatusState, CreationFlowStatus.NEW_FROM_TEMPLATE);
set(featureFlagsState, getDefaultFeatureFlags());
set(templateProjectsState, [
{
id: '@microsoft/generator-bot-empty',
name: 'Empty Bot',
description: 'Yeoman generator for creating an empty bot built on the Azure Bot Framework.',
package: { packageName: '@microsoft/generator-bot-empty', packageSource: 'npm', packageVersion: '1.0.0' },
dotnetSupport: { functionsSupported: true, webAppSupported: true },
nodeSupport: { functionsSupported: true, webAppSupported: true },
},
]);

set(focusedStorageFolderState, {
name: 'Desktop',
parent: '/test-folder',
Expand Down Expand Up @@ -73,7 +85,7 @@ describe('<CreationFlowV2/>', () => {
</RecoilRoot>
);

navigate('create/dotnet/generator-conversational-core');
navigate('create/dotnet/%40microsoft%2Fgenerator-bot-empty');
const node = await findByText('OK');

act(() => {
Expand All @@ -88,10 +100,10 @@ describe('<CreationFlowV2/>', () => {
appLocale: 'en-US',
description: '',
location: expectedLocation,
name: 'conversational_core',
name: 'empty_bot',
schemaUrl: '',
templateId: 'generator-conversational-core',
templateVersion: '',
templateId: '@microsoft/generator-bot-empty',
templateVersion: '1.0.0',
alias: undefined,
eTag: undefined,
preserveRoot: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ export function CreateBotV2(props: CreateBotProps) {
useEffect(() => {
if (displayedTemplates?.[0]?.id) {
setCurrentTemplateId(displayedTemplates[0].id);
setTimeout(() => {
selectedTemplate.setIndexSelected(0, true, false);
}, 0);
}
}, [displayedTemplates]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,23 @@ const DefineConversationV2: React.FC<DefineConversationProps> = (props) => {
const writable = focusedStorageFolder.writable;
const runtimeLanguage = props.runtimeLanguage ? props.runtimeLanguage : csharpFeedKey;
const templateProjects = useRecoilValue(templateProjectsState);
const currentTemplate = templateProjects.find((t) => {
if (t?.id) {
return t.id === templateId;
}
});

// template ID is populated by npm package name which needs to be formatted
const normalizeTemplateId = (templateId?: string) => {
if (templateId) {
const normalizeTemplateId = () => {
if (currentTemplate) {
// use almost the same patterns as in assetManager.ts
return templateId
.replace(/^@microsoft\/generator-bot-/, '') // clean up our complex package names
.replace(/^generator-/, '') // clean up other package names too
.trim()
.replace(/-/, '_')
.toLocaleLowerCase();
return currentTemplate.name.trim().replace(/[-\s]/g, '_').toLocaleLowerCase();
}
};

const getDefaultName = () => {
let i = 0;
const bot = normalizeTemplateId(templateId);
const bot = normalizeTemplateId();
let defaultName = `${bot}`;
while (
files.some((file) => {
Expand Down Expand Up @@ -295,11 +295,6 @@ const DefineConversationV2: React.FC<DefineConversationProps> = (props) => {

const getSupportedRuntimesForTemplate = (): IDropdownOption[] => {
const result: IDropdownOption[] = [];
const currentTemplate = templateProjects.find((t) => {
if (t?.id) {
return t.id === templateId;
}
});

if (currentTemplate) {
if (runtimeLanguage === csharpFeedKey) {
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/server/src/controllers/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function getTemplateReadMe(req: any, res: any) {
'microsoft',
'botframework-components',
'main',
'generators/generator-bot-qna-maker/README.md'
'generators/generator-bot-core-qna/README.md'
);
res.status(200).json(qnaReadMe);
} else {
Expand Down
26 changes: 23 additions & 3 deletions Composer/packages/server/src/utility/__tests__/creation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jest.mock('../../models/asset/assetManager', () => ({
describe('templateSort', () => {
const templates: BotTemplate[] = [
{
id: '@microsoft/generator-bot-assistant-core',
id: '@microsoft/generator-bot-core-language',
name: ' Calendar Assistant',
description: 'Preview Calendar Assistant template for TESTING ONLY',
package: {
Expand All @@ -33,7 +33,7 @@ describe('templateSort', () => {
},
},
{
id: '@microsoft/generator-bot-people',
id: '@microsoft/generator-bot-enterprise-people',
name: ' Calendar Assistant',
description: 'Preview Calendar Assistant template for TESTING ONLY',
package: {
Expand All @@ -43,7 +43,7 @@ describe('templateSort', () => {
},
},
{
id: '@microsoft/generator-bot-calendar',
id: '@microsoft/generator-bot-enterprise-calendar',
name: ' Calendar',
description: 'Preview calendar bot for TESTING ONLY',
package: {
Expand Down Expand Up @@ -83,6 +83,26 @@ describe('templateSort', () => {
packageVersion: '0.0.1',
},
},
{
id: '@microsoft/generator-bot-core-qna',
name: 'generator-qna-bot',
description: 'Empty bot template that routes to qna configuration',
package: {
packageName: 'generator-empty-bot',
packageSource: 'npm',
packageVersion: '0.0.1',
},
},
{
id: '@microsoft/generator-bot-core-assistant',
name: 'generator-qna-bot',
description: 'Empty bot template that routes to qna configuration',
package: {
packageName: 'generator-empty-bot',
packageSource: 'npm',
packageVersion: '0.0.1',
},
},
];

it('should return sorted templates per sortOrder obj', async () => {
Expand Down
15 changes: 8 additions & 7 deletions Composer/packages/server/src/utility/creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import logger from '../logger';
import AssetService from '../services/asset';

export const defaultSortOrder = [
{ generatorName: '@microsoft/generator-bot-empty', displayName: 'Blank bot' },
{ generatorName: '@microsoft/generator-bot-conversational-core', displayName: 'Basic bot' },
{ generatorName: '@microsoft/generator-bot-assistant-core', displayName: 'Basic assistant' },
{ generatorName: '@microsoft/generator-bot-enterprise-assistant', displayName: 'Enterprise assistant' },
{ generatorName: '@microsoft/generator-bot-people', displayName: 'People' },
{ generatorName: '@microsoft/generator-bot-calendar', displayName: 'Calendar' },
{ generatorName: QnABotTemplateId, displayName: 'QnAMaker bot' },
{ generatorName: '@microsoft/generator-bot-empty', displayName: 'Empty Bot' },
{ generatorName: '@microsoft/generator-bot-core-language', displayName: 'Core Bot with Language' },
{ generatorName: '@microsoft/generator-bot-core-qna', displayName: 'Core Bot with QnA Maker' },
{ generatorName: QnABotTemplateId, displayName: 'Core Bot with QnA Maker' },
{ generatorName: '@microsoft/generator-bot-core-assistant', displayName: 'Core Assistant Bot' },
{ generatorName: '@microsoft/generator-bot-enterprise-assistant', displayName: 'Enterprise Assistant Bot' },
{ generatorName: '@microsoft/generator-bot-enterprise-calendar', displayName: 'Enterprise Calendar Bot' },
{ generatorName: '@microsoft/generator-bot-enterprise-people', displayName: 'Enterprise People Bot' },
];

export const sortTemplates = async (templates: BotTemplate[]): Promise<BotTemplate[]> => {
Expand Down

0 comments on commit c064006

Please sign in to comment.