Skip to content

Commit

Permalink
Drilldowns various 2 (#60103)
Browse files Browse the repository at this point in the history
* chore: πŸ€– address review comments

* test: πŸ’ fix embeddable_panel.test.tsx tests

* chore: πŸ€– clean up ActionInternal

* chore: πŸ€– make isConfigValid a simple predicate

* chore: πŸ€– fix TypeScript type errors
  • Loading branch information
streamich authored Mar 13, 2020
1 parent 3c94332 commit 6f59d1a
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ test('HelloWorldContainer in edit mode hides disabledActions', async () => {
const fooContextMenuActionItem1 = findTestSubject(component1, 'embeddablePanelAction-FOO');
const fooContextMenuActionItem2 = findTestSubject(component2, 'embeddablePanelAction-FOO');

expect(fooContextMenuActionItem1.length).toBe(1);
expect(fooContextMenuActionItem1.length).toBe(2);
expect(fooContextMenuActionItem2.length).toBe(0);
});

Expand Down
71 changes: 0 additions & 71 deletions src/plugins/ui_actions/public/actions/action_internal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,75 +30,4 @@ describe('ActionInternal', () => {
const action = new ActionInternal(defaultActionDef);
expect(action.id).toBe('test-action');
});

describe('serialize()', () => {
test('can serialize very simple action', () => {
const action = new ActionInternal(defaultActionDef);

action.config = {};

const serialized = action.serialize();

expect(serialized).toMatchObject({
id: 'test-action',
name: '',
config: expect.any(Object),
});
});

test('can serialize action with modified state', () => {
const action = new ActionInternal({
...defaultActionDef,
type: 'ACTION_TYPE' as any,
order: 11,
});

action.name = 'qux';
action.config = { foo: 'bar' };

const serialized = action.serialize();

expect(serialized).toMatchObject({
id: 'test-action',
factoryId: 'ACTION_TYPE',
name: 'qux',
config: {
foo: 'bar',
},
});
});
});

describe('deserialize', () => {
const serialized = {
id: 'id',
factoryId: 'type',
name: 'name',
config: {
foo: 'foo',
},
};

test('can deserialize action state', () => {
const action = new ActionInternal({
...defaultActionDef,
});

action.deserialize(serialized);

expect(action.name).toBe('name');
expect(action.config).toMatchObject(serialized.config);
});

test('does not overwrite action id and type', () => {
const action = new ActionInternal({
...defaultActionDef,
});

action.deserialize(serialized);

expect(action.id).toBe('test-action');
expect(action.type).toBe('');
});
});
});
23 changes: 0 additions & 23 deletions src/plugins/ui_actions/public/actions/action_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { Action, ActionContext as Context, AnyActionDefinition } from './action'
import { Presentable } from '../util/presentable';
import { uiToReactComponent } from '../../../kibana_react/public';
import { ActionType } from '../types';
import { SerializedAction } from './types';

export class ActionInternal<A extends AnyActionDefinition>
implements Action<Context<A>>, Presentable<Context<A>> {
Expand All @@ -33,9 +32,6 @@ export class ActionInternal<A extends AnyActionDefinition>
public readonly MenuItem? = this.definition.MenuItem;
public readonly ReactMenuItem? = this.MenuItem ? uiToReactComponent(this.MenuItem) : undefined;

public name: string = '';
public config?: object;

public execute(context: Context<A>) {
return this.definition.execute(context);
}
Expand All @@ -59,25 +55,6 @@ export class ActionInternal<A extends AnyActionDefinition>
if (!this.definition.getHref) return undefined;
return this.definition.getHref(context);
}

public serialize() {
if (!this.config) {
throw new Error('Action does not have a config.');
}

const serialized: SerializedAction<unknown> = {
factoryId: this.type,
name: this.name,
config: this.config,
};

return serialized;
}

public deserialize({ name, config }: SerializedAction<unknown>) {
this.name = name;
this.config = config as object;
}
}

export type AnyActionInternal = ActionInternal<any>;
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface State {
readonly fetchCount: number;

/**
* List of all fetched events. If `null`, means now events have been loaded yet.
* List of all fetched events.
*/
readonly events: readonly SerializedEvent[];
}
Expand Down Expand Up @@ -71,7 +71,7 @@ export const transitions: Transitions = {

addEvent: state => (event: SerializedEvent) => ({
...state,
events: [...(state.events || []), event],
events: [...state.events, event],
}),

removeEvent: state => (eventId: string) => ({
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/ui_actions/public/util/configurable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ export interface Configurable<Config extends ConfigurableBaseConfig = Configurab

/**
* Is this config valid. Used to validate user's input before saving.
*
* @todo Rename this to `isConfig`?
*/
readonly isConfigValid: (config: Config) => config is Config;
readonly isConfigValid: (config: Config) => boolean;

/**
* `UiComponent` to be rendered when collecting configuration for this item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function useDrilldownsStateManager(
notifications: NotificationsStart
) {
const [isLoading, setIsLoading] = useState(false);
const [drilldowns, setDrilldowns] = useState<UiActionsSerializedEvent[]>();
const [drilldowns, setDrilldowns] = useState<readonly UiActionsSerializedEvent[]>();
const isMounted = useMountedState();

async function run(op: () => Promise<void>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class MockDynamicActionManager implements PublicMethodsOf<DynamicActionManager>
};
}

async deleteEvent() {
throw new Error('not implemented');
}

async start() {}
async stop() {}
}
Expand Down

0 comments on commit 6f59d1a

Please sign in to comment.