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

[SIEM] Add toaster logic for Machine Learning #41401

Merged
merged 10 commits into from
Jul 17, 2019
Prev Previous commit
Next Next commit
Cleanups of code not used
FrankHassanabad committed Jul 17, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6fb1cf159b1561cf7f64c47692cd402155bb00e1
Original file line number Diff line number Diff line change
@@ -21,11 +21,6 @@ export interface Body {
maxExamples: number;
}

export const empty: Anomalies = {
anomalies: [],
interval: 'second',
};

export const anomaliesTableData = async (
body: Body,
headers: Record<string, string | undefined>
Original file line number Diff line number Diff line change
@@ -4,26 +4,22 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { isError, isString } from 'lodash/fp';
import { isError } from 'lodash/fp';
import uuid from 'uuid';
import { ActionToaster, AppToast } from '../../toasters';
import { ToasterErrorsType, ToasterErrors } from './throw_if_not_ok';

export type ErrorTypes = Error | string | unknown;

export type ErrorToToasterArgs = Partial<AppToast> & {
error: ErrorTypes;
error: unknown;
Copy link
Member

Choose a reason for hiding this comment

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

++ on the unknown here! And thanks for the reading material -- good stuff!

dispatchToaster: React.Dispatch<ActionToaster>;
additionalErrors?: string[];
};

export const errorToToaster = ({
id = uuid.v4(),
title = 'Data Fetch Failure',
title,
error,
color = 'danger',
iconType = 'alert',
additionalErrors = [],
dispatchToaster,
}: ErrorToToasterArgs) => {
if (isToasterError(error)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, I think that you can simplify it like that

const toast: AppToast = {
  id,
  title,
  color,
  iconType,
  errors: ['Network Error'],
};

if (isToasterError(error)) {
  toast.errors = error.messages;
} else if (isAnError(error)) {
  toast.errors = [error.message];
}

dispatchToaster({
  type: 'addToaster',
  toast,
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Appreciate it, I will try to work it into a follow up PR 🤞 here soon.

Thank you for looking at my PR Xavier and giving me feedback.

@@ -32,7 +28,7 @@ export const errorToToaster = ({
title,
color,
iconType,
errors: [...additionalErrors, ...error.messages],
errors: error.messages,
};
dispatchToaster({
type: 'addToaster',
@@ -44,7 +40,7 @@ export const errorToToaster = ({
title,
color,
iconType,
errors: [...additionalErrors, error.message],
errors: [error.message],
};
dispatchToaster({
type: 'addToaster',
@@ -56,7 +52,7 @@ export const errorToToaster = ({
title,
color,
iconType,
errors: [...additionalErrors, 'Network Error'],
errors: ['Network Error'],
};
dispatchToaster({
type: 'addToaster',
@@ -65,9 +61,6 @@ export const errorToToaster = ({
}
};

// TODO: Use this or delete it
export const isAString = (error: unknown): error is string => isString(error);

export const isAnError = (error: unknown): error is Error => isError(error);

export const isToasterError = (error: unknown): error is ToasterErrorsType =>