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

Drilldowns triggers #60339

Merged
merged 3 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/ui_actions/public/actions/action_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ActionFactory<
Config extends object = object,
FactoryContext extends object = object,
ActionContext extends object = object
> implements Presentable<FactoryContext>, Configurable<Config> {
> implements Presentable<FactoryContext>, Configurable<Config, FactoryContext> {
constructor(
protected readonly def: ActionFactoryDefinition<Config, FactoryContext, ActionContext>
) {}
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/ui_actions/public/util/configurable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UiComponent } from 'src/plugins/kibana_utils/common';
/**
* Represents something that can be configured by user using UI.
*/
export interface Configurable<Config extends object = object> {
export interface Configurable<Config extends object = object, Context = object> {
/**
* Create default config for this item, used when item is created for the first time.
*/
Expand All @@ -36,13 +36,13 @@ export interface Configurable<Config extends object = object> {
/**
* `UiComponent` to be rendered when collecting configuration for this item.
*/
readonly CollectConfig: UiComponent<CollectConfigProps<Config>>;
readonly CollectConfig: UiComponent<CollectConfigProps<Config, Context>>;
}

/**
* Props provided to `CollectConfig` component on every re-render.
*/
export interface CollectConfigProps<Config extends object = object> {
export interface CollectConfigProps<Config extends object = object, Context = object> {
/**
* Current (latest) config of the item.
*/
Expand All @@ -52,4 +52,9 @@ export interface CollectConfigProps<Config extends object = object> {
* Callback called when user updates the config in UI.
*/
onConfig: (config: Config) => void;

/**
* Context information about where component is being rendered.
*/
context: Context;
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ const SelectedActionFactory: React.FC<SelectedActionFactoryProps> = ({
</header>
<EuiSpacer size="m" />
<div>
{actionFactory.ReactCollectConfig({
config,
onConfig: onConfigChange,
})}
<actionFactory.ReactCollectConfig
config={config}
onConfig={onConfigChange}
context={context}
/>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class FlyoutCreateDrilldownAction implements ActionByType<typeof OPEN_FLY

private isEmbeddableCompatible(context: EmbeddableContext) {
if (!context.embeddable.dynamicActions) return false;
const supportedTriggers = ['VALUE_CLICK_TRIGGER']; // context.embeddable.supportedTriggers();
const supportedTriggers = context.embeddable.supportedTriggers();
if (!supportedTriggers || !supportedTriggers.length) return false;
return supportedTriggers.indexOf('VALUE_CLICK_TRIGGER') > -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { TEST_SUBJ_DRILLDOWN_ITEM } from '../list_manage_drilldowns';
import { WELCOME_MESSAGE_TEST_SUBJ } from '../drilldown_hello_bar';
import { coreMock } from '../../../../../../src/core/public/mocks';
import { NotificationsStart } from 'kibana/public';
import { toastDrilldownsCRUDError, toastDrilldownsFetchError } from './i18n';
import { toastDrilldownsCRUDError } from './i18n';

const storage = new Storage(new StubBrowserStorage());
const notifications = coreMock.createStart().notifications;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
toastDrilldownsCRUDError,
toastDrilldownsDeleted,
} from './i18n';
import { DrilldownFactoryContext } from '../../types';

interface ConnectedFlyoutManageDrilldownsProps<Context extends object = object> {
context: Context;
Expand Down Expand Up @@ -65,9 +66,15 @@ export function createFlyoutManageDrilldowns({
return (props: ConnectedFlyoutManageDrilldownsProps) => {
const isCreateOnly = props.viewMode === 'create';

const factoryContext: DrilldownFactoryContext<unknown> = {
place: '',
placeContext: props.context,
triggers: [],
};

const actionFactories = useCompatibleActionFactoriesForCurrentContext(
allActionFactories,
props.context
factoryContext
);

const [route, setRoute] = useState<Routes>(
Expand Down Expand Up @@ -121,8 +128,8 @@ export function createFlyoutManageDrilldowns({
return {
id: drilldown.eventId,
drilldownName: drilldown.action.name,
actionName: actionFactory?.getDisplayName(props.context) ?? drilldown.action.factoryId,
icon: actionFactory?.getIconType(props.context),
actionName: actionFactory?.getDisplayName(factoryContext) ?? drilldown.action.factoryId,
icon: actionFactory?.getIconType(factoryContext),
};
}

Expand Down Expand Up @@ -168,7 +175,7 @@ export function createFlyoutManageDrilldowns({
setRoute(Routes.Manage);
setCurrentEditId(null);
}}
actionFactoryContext={props.context}
actionFactoryContext={factoryContext}
initialDrilldownWizardConfig={resolveInitialDrilldownWizardConfig()}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/drilldowns/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export interface Drilldown<
*/
export interface DrilldownFactoryContext<T> {
/**
* List of places as configured in @type {Drilldown} interface.
* Place where factory is being rendered.
*/
places?: string[];
place?: string;

/**
* Context provided to the drilldown factory by the place where the UI is
Expand Down