Skip to content

Commit

Permalink
fix tests, imports. also remove http concern from Resolver for now
Browse files Browse the repository at this point in the history
  • Loading branch information
oatkiller committed Jan 2, 2020
1 parent 302134f commit f046418
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 39 deletions.
23 changes: 2 additions & 21 deletions x-pack/plugins/endpoint/public/embeddables/resolver/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,18 @@ import ReactDOM from 'react-dom';
import React from 'react';
import { AppRoot } from './view';
import { storeFactory } from './store';
import {
EmbeddableInput,
IContainer,
Embeddable,
} from '../../../../../../src/plugins/embeddable/public';
import { HttpSetup } from '../../../../../../src/core/public';
import { Embeddable } from '../../../../../../src/plugins/embeddable/public';

export class ResolverEmbeddable extends Embeddable {
public readonly type = 'resolver';
private httpService: HttpSetup;
private lastRenderTarget?: Element;
constructor(initialInput: EmbeddableInput, httpService: HttpSetup, parent?: IContainer) {
super(
// Input state is irrelevant to this embeddable, just pass it along.
initialInput,
// Initial output state - this embeddable does not do anything with output, so just
// pass along an empty object.
{},
// Optional parent component, this embeddable can optionally be rendered inside a container.
parent
);
this.httpService = httpService;
}

public render(node: HTMLElement) {
if (this.lastRenderTarget !== undefined) {
ReactDOM.unmountComponentAtNode(this.lastRenderTarget);
}
this.lastRenderTarget = node;
// TODO, figure out how to destroy middleware
const { store } = storeFactory({ httpService: this.httpService });
const { store } = storeFactory();
ReactDOM.render(<AppRoot store={store} />, node);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { i18n } from '@kbn/i18n';
import { HttpSetup } from 'kibana/public';
import {
EmbeddableFactory,
IContainer,
Expand All @@ -15,19 +14,13 @@ import { ResolverEmbeddable } from './embeddable';

export class ResolverEmbeddableFactory extends EmbeddableFactory {
public readonly type = 'resolver';
private httpService: HttpSetup;

constructor(httpService: HttpSetup) {
super();
this.httpService = httpService;
}

public isEditable() {
return true;
}

public async create(initialInput: EmbeddableInput, parent?: IContainer) {
return new ResolverEmbeddable(initialInput, this.httpService, parent);
return new ResolverEmbeddable(initialInput, {}, parent);
}

public getDisplayName() {
Expand Down
26 changes: 20 additions & 6 deletions x-pack/plugins/endpoint/public/embeddables/resolver/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,29 @@

import { createStore, StoreEnhancer } from 'redux';
import { ResolverAction } from '../types';
import { HttpSetup } from '../../../../../../../src/core/public';
import { resolverReducer } from './reducer';

export const storeFactory = (_dependencies: { httpService: HttpSetup }) => {
export const storeFactory = () => {
/**
* Redux Devtools extension exposes itself via a property on the global object.
* This interface can be used to cast `window` to a type that may expose Redux Devtools.
*/
interface SomethingThatMightHaveReduxDevTools {
__REDUX_DEVTOOLS_EXTENSION__?: (options?: {
name?: string;
actionsBlacklist: readonly string[];
}) => StoreEnhancer;
__REDUX_DEVTOOLS_EXTENSION__?: (options?: PartialReduxDevToolsOptions) => StoreEnhancer;
}

/**
* Some of the options that can be passed when configuring Redux Devtools.
*/
interface PartialReduxDevToolsOptions {
/**
* A name for this store
*/
name?: string;
/**
* A list of action types to ignore. This is used to ignore high frequency events created by a mousemove handler
*/
actionsBlacklist?: readonly string[];
}
const windowWhichMightHaveReduxDevTools = window as SomethingThatMightHaveReduxDevTools;
// Make sure blacklisted action types are valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React from 'react';
import styled from 'styled-components';
import { useSelector } from 'react-redux';
import { Vector2 } from '../types';
import { applyMatrix3 } from '../lib/vector2';
import * as selectors from '../store/selectors';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import React, { useCallback, useState, useEffect, useMemo } from 'react';
import { Store } from 'redux';
import { Provider, useSelector, useDispatch } from 'react-redux';
import styled from 'styled-components';
import { applyMatrix3 } from '../lib/vector2';
import { ResolverState, ResolverAction, Vector2 } from '../types';
import { ResolverState, ResolverAction } from '../types';
import * as selectors from '../store/selectors';
import { useAutoUpdatingClientRect } from './use_autoupdating_client_rect';
import { useNonPassiveWheelHandler } from './use_nonpassive_wheel_handler';
Expand Down Expand Up @@ -148,7 +147,12 @@ const Diagnostic = styled(
useNonPassiveWheelHandler(handleWheel, ref);

return (
<div className={className} ref={refCallback} onMouseDown={handleMouseDown}>
<div
data-test-subj="resolverEmbeddable"
className={className}
ref={refCallback}
onMouseDown={handleMouseDown}
>
{dotPositions.map((worldPosition, index) => (
<DiagnosticDot key={index} worldPosition={worldPosition} />
))}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/endpoint/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class EndpointPlugin
},
});

const resolverEmbeddableFactory = new ResolverEmbeddableFactory(core.http);
const resolverEmbeddableFactory = new ResolverEmbeddableFactory();

plugins.embeddable.registerEmbeddableFactory(
resolverEmbeddableFactory.type,
Expand Down

0 comments on commit f046418

Please sign in to comment.