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
13 changes: 12 additions & 1 deletion Composer/packages/client/src/TestController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ export const TestController: React.FC = () => {
startBot(false);
}, [toStartBot]);

function isLuisConfigComplete(config) {
let complete = true;
for (const key in LuisConfig) {
if (config && config[LuisConfig[key]] === '') {
complete = false;
break;
}
}
return complete;
}

async function handleClick() {
const dialogErrors = dialogs.reduce<DialogInfo[]>((result, dialog) => {
if (dialog.diagnostics.length !== 0) {
Expand All @@ -78,7 +89,7 @@ export const TestController: React.FC = () => {
const config = settings.luis;

if (!isAbsHosted() && getReferredFiles(luFiles, dialogs).length > 0) {
if (!luisPublishSucceed || (config && config[LuisConfig.AUTHORING_KEY] === '')) {
if (!luisPublishSucceed || !isLuisConfigComplete(config)) {
setModalOpen(true);
} else {
await publishAndReload();
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/client/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export enum LuisConfig {
AUTHORING_KEY = 'authoringKey',
ENVIRONMENT = 'environment',
PROJECT_NAME = 'name',
REGION = 'authoringRegion',
LANGUAGE = 'defaultLanguage',
}

export const FileTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@ const onRenderLabel = info => props => (

const nameRegex = /^[a-zA-Z0-9-_.]+$/;
const validationProperties = ['name', 'authoringKey', 'environment'];
const defaultFields = { authoringRegion: 'westus', defaultLanguage: 'en-us' };
const validateForm = data => {
const errors = {};
const result = { errors: {} };
const dataKeys = keys(data);

dataKeys.forEach(key => {
const value = data[key];
if (validationProperties.indexOf(key) > -1 && (!value || !nameRegex.test(value))) {
errors[key] = formatMessage(
result.errors[key] = formatMessage(
'Spaces and special characters are not allowed. Use letters, numbers, -, or _., numbers, -, and _'
);
} else if (key in defaultFields && value === '') {
result[key] = defaultFields[key];
}
});

return errors;
return result;
};

const DeploySuccess = props => {
Expand Down Expand Up @@ -120,13 +123,13 @@ export const PublishLuis = props => {
const handlePublish = async e => {
e.preventDefault();

const errors = validateForm(formData);
if (keys(errors).length) {
setFormData({ ...formData, errors });
const result = validateForm(formData);
if (keys(result.errors).length) {
setFormData({ ...formData, ...result });
return;
}
// save the settings change to store and persist to server
const newValue = { ...formData };
const newValue = { ...formData, ...result };
delete newValue.errors;
await setSettings(botName, { ...settings, luis: newValue });
await onPublish();
Expand Down Expand Up @@ -168,13 +171,13 @@ export const PublishLuis = props => {
/>
<TextField
label={formatMessage('Authoring Region')}
defaultValue="westus"
defaultValue={defaultFields.authoringRegion}
onRenderLabel={onRenderLabel(Tips.AUTHORING_REGION)}
disabled
/>
<TextField
label={formatMessage('Default Language')}
defaultValue="en-us"
defaultValue={defaultFields.defaultLanguage}
onRenderLabel={onRenderLabel(Tips.DEFAULT_LANGUAGE)}
disabled
/>
Expand Down