Skip to content

Commit

Permalink
fix: reset errors when switching between bots (#6235)
Browse files Browse the repository at this point in the history
* reset errors when switching between bots

* remove typos

* lint fix

* handle comments

Co-authored-by: Dong Lei <donglei@microsoft.com>
  • Loading branch information
liweitian and boydc2014 authored Mar 8, 2021
1 parent cfdc8bb commit 215af1a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ type Props = {
const errorElement = (errorText: string) => {
if (!errorText) return '';
return (
<div css={errorContainer}>
<span css={errorContainer}>
<Icon iconName="ErrorBadge" styles={errorIcon} />
<div css={errorTextStyle}>{errorText}</div>
</div>
<span css={errorTextStyle}>{errorText}</span>
</span>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ const onRenderLabel = (props) => {
const errorElement = (errorText: string) => {
if (!errorText) return '';
return (
<div css={errorContainer}>
<span css={errorContainer}>
<Icon iconName="ErrorBadge" styles={errorIcon} />
<div css={errorTextStyle}>{errorText}</div>
</div>
<span css={errorTextStyle}>{errorText}</span>
</span>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from '../../../recoilModel';
import { LoadingSpinner } from '../../../components/LoadingSpinner';
import TelemetryClient from '../../../telemetry/TelemetryClient';
import { subtitle } from '../styles';
import { subtitle, errorContainer, errorTextStyle, errorIcon, customError } from '../styles';

import { EjectModal } from './ejectModal';
import { WorkingModal } from './workingModal';
Expand Down Expand Up @@ -78,6 +78,15 @@ export const RuntimeSettings: React.FC<RouteComponentProps<{ projectId: string }
setRuntimePath(settings.runtime?.path ?? '');
setRuntimeCommand(settings.runtime?.command ?? '');
setUsingCustomRuntime(settings.runtime?.customRuntime ?? false);
const errorMessage = formatMessage('This is a required field.');
const errors = { command: '', path: '' };
if (!settings.runtime?.path && settings.runtime?.customRuntime) {
errors.path = errorMessage;
}
if (!settings.runtime?.command && settings.runtime?.customRuntime) {
errors.command = errorMessage;
}
setFormDataErrors(errors);
}, [settings, projectId]);

useEffect(() => {
Expand Down Expand Up @@ -203,6 +212,16 @@ export const RuntimeSettings: React.FC<RouteComponentProps<{ projectId: string }
);
};

const errorElement = (errorText: string) => {
if (!errorText) return '';
return (
<span css={errorContainer}>
<Icon iconName="ErrorBadge" styles={errorIcon} />
<span css={errorTextStyle}>{errorText}</span>
</span>
);
};

return botName ? (
<div css={runtimeSettingsStyle} id="runtimeSettings">
{header()}
Expand All @@ -212,9 +231,9 @@ export const RuntimeSettings: React.FC<RouteComponentProps<{ projectId: string }
required
data-testid="runtimeCodeLocation"
disabled={!settings.runtime || !settings.runtime.customRuntime}
errorMessage={formDataErrors.path}
errorMessage={errorElement(formDataErrors.path)}
label={formatMessage('Runtime code location')}
styles={name}
styles={customError}
value={runtimePath}
onBlur={() => handleRuntimeSettingOnBlur('path')}
onChange={handleRuntimeSettingOnChange('path')}
Expand All @@ -233,9 +252,9 @@ export const RuntimeSettings: React.FC<RouteComponentProps<{ projectId: string }
required
data-testid="runtimeCommand"
disabled={!settings.runtime || !settings.runtime.customRuntime}
errorMessage={formDataErrors.command}
errorMessage={errorElement(formDataErrors.command)}
label={formatMessage('Start command')}
styles={name}
styles={customError}
value={runtimeCommand}
onBlur={() => handleRuntimeSettingOnBlur('command')}
onChange={handleRuntimeSettingOnChange('command')}
Expand Down
14 changes: 12 additions & 2 deletions Composer/packages/client/src/pages/botProject/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,27 @@ export const customerLabel = css`
margin-right: 5px;
`;

export const customError = {
root: {
selectors: {
'p > span': {
width: '100%',
},
},
},
};

// These bg and icon colors are the standard Fluent ones for Messaging, which
// aren't exported anywhere they can easily be reached
// Docs: https://developer.microsoft.com/en-us/fluentui#/styles/web/colors/messaging

export const errorContainer = css`
display: flex;
width: 100%;
line-height: 24px;
line-height: 20px;
padding-top: 12px;
padding-bottom: 12px;
background: '#fde7e9';
background: #fed9cc;
color: ${NeutralColors.black};
`;

Expand Down

0 comments on commit 215af1a

Please sign in to comment.