Skip to content

Commit

Permalink
fixing eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed May 29, 2020
1 parent 1aaeb79 commit f60716d
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 60 deletions.
9 changes: 1 addition & 8 deletions x-pack/plugins/observability/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@
*/
import React from 'react';
import ReactDOM from 'react-dom';
import { ConfigSchema } from '../';
import { AppMountParameters, CoreStart } from '../../../../../src/core/public';
import { PluginSetupDeps } from '../plugin';
import { Home } from '../pages/home';

export const renderApp = (
core: CoreStart,
deps: PluginSetupDeps,
{ element }: AppMountParameters,
config: ConfigSchema
) => {
export const renderApp = (core: CoreStart, { element }: AppMountParameters) => {
ReactDOM.render(<Home core={core} />, element);
return () => {
ReactDOM.unmountComponentAtNode(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const SectionLink: React.FC<EuiListGroupItemProps> = (props) => (
<EuiListGroupItem style={{ padding: 0 }} size={'s'} {...props} />
);

export const ActionMenuDivider: React.FC<{}> = (props) => <EuiHorizontalRule margin={'s'} />;
export const ActionMenuDivider: React.FC<{}> = (props) => (
<EuiHorizontalRule margin={'s'} />
);

export const ActionMenu: React.FC<Props> = (props) => <EuiPopover {...props} ownFocus={true} />;
export const ActionMenu: React.FC<Props> = (props) => (
<EuiPopover {...props} ownFocus={true} />
);
24 changes: 19 additions & 5 deletions x-pack/plugins/observability/public/hooks/use_track_metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ export { METRIC_TYPE };
export function useUiTracker<Services extends ServiceDeps>({
app: defaultApp,
}: { app?: ObservabilityApp } = {}) {
const reportUiStats = useKibana<Services>().services?.usageCollection?.reportUiStats;
const reportUiStats = useKibana<Services>().services?.usageCollection
?.reportUiStats;
const trackEvent = useMemo(() => {
return ({ app = defaultApp, metric, metricType = METRIC_TYPE.COUNT }: TrackMetricOptions) => {
return ({
app = defaultApp,
metric,
metricType = METRIC_TYPE.COUNT,
}: TrackMetricOptions) => {
if (reportUiStats) {
reportUiStats(app as string, metricType, metric);
}
Expand All @@ -50,10 +55,16 @@ export function useUiTracker<Services extends ServiceDeps>({
}

export function useTrackMetric<Services extends ServiceDeps>(
{ app, metric, metricType = METRIC_TYPE.COUNT, delay = 0 }: TrackMetricOptions,
{
app,
metric,
metricType = METRIC_TYPE.COUNT,
delay = 0,
}: TrackMetricOptions,
effectDependencies: EffectDeps = []
) {
const reportUiStats = useKibana<Services>().services?.usageCollection?.reportUiStats;
const reportUiStats = useKibana<Services>().services?.usageCollection
?.reportUiStats;

useEffect(() => {
if (!reportUiStats) {
Expand Down Expand Up @@ -88,5 +99,8 @@ export function useTrackPageview<Services extends ServiceDeps>(
{ path, ...rest }: TrackPageviewProps,
effectDependencies: EffectDeps = []
) {
useTrackMetric<Services>({ ...rest, metric: `pageview__${path}` }, effectDependencies);
useTrackMetric<Services>(
{ ...rest, metric: `pageview__${path}` },
effectDependencies
);
}
6 changes: 0 additions & 6 deletions x-pack/plugins/observability/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
import { PluginInitializerContext, PluginInitializer } from 'kibana/public';
import { Plugin, ClientSetup, ClientStart } from './plugin';

export interface ConfigSchema {
ui: {
enabled: boolean;
};
}

export const plugin: PluginInitializer<ClientSetup, ClientStart> = (
context: PluginInitializerContext
) => {
Expand Down
18 changes: 3 additions & 15 deletions x-pack/plugins/observability/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,21 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { ConfigSchema } from '.';
import {
AppMountParameters,
CoreSetup,
DEFAULT_APP_CATEGORIES,
// CoreStart,
Plugin as PluginClass,
PluginInitializerContext,
} from '../../../../src/core/public';

export type ClientSetup = void;
export type ClientStart = void;

// eslint-disable-next-line
export interface PluginSetupDeps {
}

export class Plugin implements PluginClass<ClientSetup, ClientStart> {
private readonly initializerContext: PluginInitializerContext<ConfigSchema>;
constructor(initializerContext: PluginInitializerContext<ConfigSchema>) {
this.initializerContext = initializerContext;
}

public setup(core: CoreSetup, plugins: PluginSetupDeps) {
const config = this.initializerContext.config.get();
const pluginSetupDeps = plugins;
constructor(context: PluginInitializerContext) {}

public setup(core: CoreSetup) {
core.application.register({
id: 'observability-overview',
title: 'Overview',
Expand All @@ -43,7 +31,7 @@ export class Plugin implements PluginClass<ClientSetup, ClientStart> {
// Get start services
const [coreStart] = await core.getStartServices();

return renderApp(coreStart, pluginSetupDeps, params, config);
return renderApp(coreStart, params);
},
});
}
Expand Down
13 changes: 10 additions & 3 deletions x-pack/plugins/observability/public/typings/eui_draggable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
import React from 'react';
import { EuiDraggable, EuiDragDropContext } from '@elastic/eui';

type PropsOf<T> = T extends React.ComponentType<infer ComponentProps> ? ComponentProps : never;
type FirstArgumentOf<Func> = Func extends (arg1: infer FirstArgument, ...rest: any[]) => any
type PropsOf<T> = T extends React.ComponentType<infer ComponentProps>
? ComponentProps
: never;
type FirstArgumentOf<Func> = Func extends (
arg1: infer FirstArgument,
...rest: any[]
) => any
? FirstArgument
: never;
export type DragHandleProps = FirstArgumentOf<
Exclude<PropsOf<typeof EuiDraggable>['children'], React.ReactElement>
>['dragHandleProps'];
export type DropResult = FirstArgumentOf<FirstArgumentOf<typeof EuiDragDropContext>['onDragEnd']>;
export type DropResult = FirstArgumentOf<
FirstArgumentOf<typeof EuiDragDropContext>['onDragEnd']
>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

import React from 'react';
import * as styledComponents from 'styled-components';
import { ThemedStyledComponentsModule, ThemeProvider, ThemeProviderProps } from 'styled-components';
import {
ThemedStyledComponentsModule,
ThemeProvider,
ThemeProviderProps,
} from 'styled-components';

import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
Expand Down Expand Up @@ -42,4 +46,11 @@ const {
withTheme,
} = (styledComponents as unknown) as ThemedStyledComponentsModule<EuiTheme>;

export { css, euiStyled, EuiThemeProvider, createGlobalStyle, keyframes, withTheme };
export {
css,
euiStyled,
EuiThemeProvider,
createGlobalStyle,
keyframes,
withTheme,
};
5 changes: 4 additions & 1 deletion x-pack/plugins/observability/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import { schema, TypeOf } from '@kbn/config-schema';
import { PluginInitializerContext } from 'src/core/server';
import { ObservabilityPlugin, ObservabilityPluginSetup } from './plugin';
import { createOrUpdateIndex, MappingsDefinition } from './utils/create_or_update_index';
import {
createOrUpdateIndex,
MappingsDefinition,
} from './utils/create_or_update_index';
import { ScopedAnnotationsClient } from './lib/annotations/bootstrap_annotations';

export const config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export type ScopedAnnotationsClientFactory = PromiseReturnType<
typeof bootstrapAnnotations
>['getScopedAnnotationsClient'];

export type ScopedAnnotationsClient = ReturnType<ScopedAnnotationsClientFactory>;
export type ScopedAnnotationsClient = ReturnType<
ScopedAnnotationsClientFactory
>;
export type AnnotationsAPI = PromiseReturnType<typeof bootstrapAnnotations>;

export async function bootstrapAnnotations({ index, core, context }: Params) {
Expand All @@ -36,10 +38,14 @@ export async function bootstrapAnnotations({ index, core, context }: Params) {
});

return {
getScopedAnnotationsClient: (requestContext: RequestHandlerContext, request: KibanaRequest) => {
getScopedAnnotationsClient: (
requestContext: RequestHandlerContext,
request: KibanaRequest
) => {
return createAnnotationsClient({
index,
apiCaller: requestContext.core.elasticsearch.legacy.client.callAsCurrentUser,
apiCaller:
requestContext.core.elasticsearch.dataClient.callAsCurrentUser,
logger,
license: requestContext.licensing?.license,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export function createAnnotationsClient(params: {
function ensureGoldLicense<T extends (...args: any[]) => any>(fn: T): T {
return ((...args) => {
if (!license?.hasAtLeast('gold')) {
throw Boom.forbidden('Annotations require at least a gold license or a trial license.');
throw Boom.forbidden(
'Annotations require at least a gold license or a trial license.'
);
}
return fn(...args);
}) as T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export function registerAnnotationAPIs({
}) {
function wrapRouteHandler<TType extends t.Type<any>>(
types: TType,
handler: (params: { data: t.TypeOf<TType>; client: ScopedAnnotationsClient }) => Promise<any>
handler: (params: {
data: t.TypeOf<TType>;
client: ScopedAnnotationsClient;
}) => Promise<any>
): RequestHandler {
return async (...args: Parameters<RequestHandler>) => {
const [context, request, response] = args;
Expand Down Expand Up @@ -72,7 +75,9 @@ export function registerAnnotationAPIs({
return response.custom({
statusCode: err.output?.statusCode ?? 500,
body: {
message: err.output?.payload?.message ?? 'An internal server error occured',
message:
err.output?.payload?.message ??
'An internal server error occured',
},
});
}
Expand All @@ -88,9 +93,12 @@ export function registerAnnotationAPIs({
body: unknowns,
},
},
wrapRouteHandler(t.type({ body: createAnnotationRt }), ({ data, client }) => {
return client.create(data.body);
})
wrapRouteHandler(
t.type({ body: createAnnotationRt }),
({ data, client }) => {
return client.create(data.body);
}
)
);

router.delete(
Expand All @@ -100,9 +108,12 @@ export function registerAnnotationAPIs({
params: unknowns,
},
},
wrapRouteHandler(t.type({ params: deleteAnnotationRt }), ({ data, client }) => {
return client.delete(data.params);
})
wrapRouteHandler(
t.type({ params: deleteAnnotationRt }),
({ data, client }) => {
return client.delete(data.params);
}
)
);

router.get(
Expand All @@ -112,8 +123,11 @@ export function registerAnnotationAPIs({
params: unknowns,
},
},
wrapRouteHandler(t.type({ params: getAnnotationByIdRt }), ({ data, client }) => {
return client.getById(data.params);
})
wrapRouteHandler(
t.type({ params: getAnnotationByIdRt }),
({ data, client }) => {
return client.getById(data.params);
}
)
);
}
5 changes: 4 additions & 1 deletion x-pack/plugins/observability/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export class ObservabilityPlugin implements Plugin<ObservabilityPluginSetup> {
this.initContext = initContext;
}

public async setup(core: CoreSetup, plugins: {}): Promise<ObservabilityPluginSetup> {
public async setup(
core: CoreSetup,
plugins: {}
): Promise<ObservabilityPluginSetup> {
const config$ = this.initContext.config.create<ObservabilityConfig>();

const config = await config$.pipe(take(1)).toPromise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export async function createOrUpdateIndex({
});

if (!result.acknowledged) {
const resultError = result && result.error && JSON.stringify(result.error);
const resultError =
result && result.error && JSON.stringify(result.error);
throw new Error(resultError);
}
},
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/observability/typings/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

export type PromiseReturnType<Func> = Func extends (...args: any[]) => Promise<infer Value>
export type PromiseReturnType<Func> = Func extends (
...args: any[]
) => Promise<infer Value>
? Value
: Func;

0 comments on commit f60716d

Please sign in to comment.