Skip to content

Commit

Permalink
review III
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Jan 3, 2020
1 parent 2fd5114 commit d36963d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const EmptyPage = React.memo<EmptyPageProps>(
title={<h2>{title}</h2>}
body={message && <p>{message}</p>}
actions={
<EuiFlexGroup>
<EuiFlexItem>
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiButton
fill
href={actionPrimaryUrl}
Expand All @@ -59,7 +59,7 @@ export const EmptyPage = React.memo<EmptyPageProps>(
</EuiFlexItem>

{actionSecondaryLabel && actionSecondaryUrl && (
<EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
href={actionSecondaryUrl}
iconType={actionSecondaryIcon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import * as i18n from './translations';
import { MlError } from '../types';
import { SetupMlResponse } from '../../ml_popover/types';

export interface MessageBody {
error?: string;
message?: string;
statusCode?: number;
}
export { MessageBody, parseJsonFromBody } from '../../../utils/api';

export interface MlStartJobError {
error: MlError;
Expand All @@ -35,15 +31,6 @@ export class ToasterErrors extends Error implements ToasterErrorsType {
}
}

export const parseJsonFromBody = async (response: Response): Promise<MessageBody | null> => {
try {
const text = await response.text();
return JSON.parse(text);
} catch (error) {
return null;
}
};

export const tryParseResponse = (response: string): string => {
try {
return JSON.stringify(JSON.parse(response), null, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import {
PostSignalError,
BasicSignals,
} from './types';
import { parseJsonFromBody } from '../../../components/ml/api/throw_if_not_ok';
import { parseJsonFromBody } from '../../../utils/api';

/**
* Fetch Signals by providing a query
*
* @param query String to match a dsl
* @param kbnVersion current Kibana Version to use for headers
* @param signal AbortSignal for cancelling request
*/
export const fetchQuerySignals = async <Hit, Aggregations>({
query,
Expand Down Expand Up @@ -58,7 +59,7 @@ export const fetchQuerySignals = async <Hit, Aggregations>({
* @param query of signals to update
* @param status to update to('open' / 'closed')
* @param kbnVersion current Kibana Version to use for headers
* @param signal to cancel request
* @param signal AbortSignal for cancelling request
*/
export const updateSignalStatus = async ({
query,
Expand Down Expand Up @@ -86,6 +87,7 @@ export const updateSignalStatus = async ({
* Fetch Signal Index
*
* @param kbnVersion current Kibana Version to use for headers
* @param signal AbortSignal for cancelling request
*/
export const getSignalIndex = async ({
kbnVersion,
Expand Down Expand Up @@ -116,6 +118,7 @@ export const getSignalIndex = async ({
* Get User Privileges
*
* @param kbnVersion current Kibana Version to use for headers
* @param signal AbortSignal for cancelling request
*/
export const getUserPrivilege = async ({
kbnVersion,
Expand All @@ -140,6 +143,7 @@ export const getUserPrivilege = async ({
* Create Signal Index if needed it
*
* @param kbnVersion current Kibana Version to use for headers
* @param signal AbortSignal for cancelling request
*/
export const createSignalIndex = async ({
kbnVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class SignalIndexError extends Error {
this.message = errObj.message ?? '';
this.statusCode = errObj.statusCode ?? -1;
this.error = errObj.error ?? '';
this.name = 'SignalIndexError';

// Set the prototype explicitly.
Object.setPrototypeOf(this, SignalIndexError.prototype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class PostSignalError extends Error {
this.message = errObj.message ?? '';
this.statusCode = errObj.statusCode ?? -1;
this.error = errObj.error ?? '';
this.name = 'PostSignalError';

// Set the prototype explicitly.
Object.setPrototypeOf(this, PostSignalError.prototype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class PrivilegeUserError extends Error {
this.message = errObj.message ?? '';
this.statusCode = errObj.statusCode ?? -1;
this.error = errObj.error ?? '';
this.name = 'PrivilegeUserError';

// Set the prototype explicitly.
Object.setPrototypeOf(this, PrivilegeUserError.prototype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ export interface UpdateSignalStatusProps {
signal?: AbortSignal; // TODO: implement cancelling
}

// export class PostSignalsError extends Error {
// constructor(m: string) {
// super(m);
// // Set the prototype explicitly.
// Object.setPrototypeOf(this, SignalsIndexError.prototype);
// }
// }

export interface SignalsIndex {
name: string;
}
Expand Down Expand Up @@ -105,5 +97,5 @@ export interface Privilege {
write: boolean;
};
};
isAuthenticated: true;
isAuthenticated: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ type Return = [boolean, boolean | null, boolean | null];
/**
* Hook to get user privilege from
*
* @param query convert a dsl into string
*
*/
export const usePrivilegeUser = (): Return => {
const [loading, setLoading] = useState(true);
Expand Down
20 changes: 20 additions & 0 deletions x-pack/legacy/plugins/siem/public/utils/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export interface MessageBody {
error?: string;
message?: string;
statusCode?: number;
}

export const parseJsonFromBody = async (response: Response): Promise<MessageBody | null> => {
try {
const text = await response.text();
return JSON.parse(text);
} catch (error) {
return null;
}
};

0 comments on commit d36963d

Please sign in to comment.