Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Alerting UI] Fix console error when setting connector params #83333

Merged
merged 11 commits into from
Nov 17, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ describe('validateParams()', () => {
expect(validateParams(actionType, params)).toEqual(params);
});

test('should validate and pass when params is valid and optional timestamp is empty string', () => {
expect(validateParams(actionType, {})).toEqual({});

const params = {
eventAction: 'trigger',
dedupKey: 'a dedupKey',
summary: 'a summary',
source: 'a source',
severity: 'critical',
timestamp: '',
component: 'a component',
group: 'a group',
class: 'a class',
};
expect(validateParams(actionType, params)).toEqual(params);
});

test('should validate and pass when params is valid and optional timestamp is null', () => {
expect(validateParams(actionType, {})).toEqual({});

const params = {
eventAction: 'trigger',
dedupKey: 'a dedupKey',
summary: 'a summary',
source: 'a source',
severity: 'critical',
timestamp: null,
component: 'a component',
group: 'a group',
class: 'a class',
};
expect(validateParams(actionType, params)).toEqual(params);
});

test('should validate and throw error when params is invalid', () => {
expect(() => {
validateParams(actionType, { eventAction: 'ackynollage' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const ParamsSchema = schema.object(

function validateParams(paramsObject: unknown): string | void {
const { timestamp, eventAction, dedupKey } = paramsObject as ActionParamsType;
if (timestamp != null) {
if (timestamp != null && timestamp.length > 0) {
try {
const date = Date.parse(timestamp);
if (isNaN(date)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const TextAreaWithMessageVariables: React.FunctionComponent<Props> = ({
fullWidth
isInvalid={errors && errors.length > 0 && inputTargetValue !== undefined}
name={paramsProperty}
value={inputTargetValue}
value={inputTargetValue || ''}
data-test-subj={`${paramsProperty}TextArea`}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => onChangeWithMessageVariable(e)}
onFocus={(e: React.FocusEvent<HTMLTextAreaElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const TextFieldWithMessageVariables: React.FunctionComponent<Props> = ({
id={`${paramsProperty}Id`}
isInvalid={errors && errors.length > 0 && inputTargetValue !== undefined}
data-test-subj={`${paramsProperty}Input`}
value={inputTargetValue}
value={inputTargetValue || ''}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => onChangeWithMessageVariable(e)}
onFocus={(e: React.FocusEvent<HTMLInputElement>) => {
setCurrentTextElement(e.target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ export const ConnectorAddFlyout = ({
const [isSaving, setIsSaving] = useState<boolean>(false);

const closeFlyout = useCallback(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the following lines because I was seeing another console error when saving a connector. With this PR #82126, the connector flyouts are destroyed when closed instead of hidden, so setting these states on closing was causing a Warning: Can't perform a React state update on an unmounted component. browser error.

setActionType(undefined);
setConnector(initialConnector);
onClose();
}, [onClose, initialConnector]);
}, [onClose]);

const canSave = hasSaveActionsCapability(capabilities);

Expand Down