Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import { ActionFactoryDefinition } from '../dynamic_actions';
* `Config` is a serializable object containing the configuration that the
* drilldown is able to collect using UI.
*
* `PlaceContext` is an object that the app that opens drilldown management
* flyout provides to the React component, specifying the contextual information
* about that app. For example, on Dashboard app this context contains
* information about the current embeddable and dashboard.
*
* `ExecutionContext` is an object created in response to user's interaction
* and provided to the `execute` function of the drilldown. This object contains
* information about the action user performed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export interface SerializedAction<Config> {
export interface SerializedAction<Config = unknown> {
readonly factoryId: string;
readonly name: string;
readonly config: Config;
Expand All @@ -16,5 +16,5 @@ export interface SerializedAction<Config> {
export interface SerializedEvent {
eventId: string;
triggers: string[];
action: SerializedAction<unknown>;
action: SerializedAction;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class FlyoutCreateDrilldownAction implements ActionByType<typeof OPEN_FLY
toMountPoint(
<plugins.drilldowns.FlyoutManageDrilldowns
onClose={() => handle.close()}
placeContext={context}
viewMode={'create'}
dynamicActionManager={embeddable.enhancements.dynamicActions}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class FlyoutEditDrilldownAction implements ActionByType<typeof OPEN_FLYOU
toMountPoint(
<plugins.drilldowns.FlyoutManageDrilldowns
onClose={() => handle.close()}
placeContext={context}
viewMode={'manage'}
dynamicActionManager={embeddable.enhancements.dynamicActions}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ const FlyoutManageDrilldowns = createFlyoutManageDrilldowns({

storiesOf('components/FlyoutManageDrilldowns', module).add('default', () => (
<EuiFlyout onClose={() => {}}>
<FlyoutManageDrilldowns placeContext={{}} dynamicActionManager={mockDynamicActionManager} />
<FlyoutManageDrilldowns dynamicActionManager={mockDynamicActionManager} />
</EuiFlyout>
));
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ beforeEach(() => {
});

test('Allows to manage drilldowns', async () => {
const screen = render(
<FlyoutManageDrilldowns placeContext={{}} dynamicActionManager={mockDynamicActionManager} />
);
const screen = render(<FlyoutManageDrilldowns dynamicActionManager={mockDynamicActionManager} />);

// wait for initial render. It is async because resolving compatible action factories is async
await wait(() => expect(screen.getByText(/Manage Drilldowns/i)).toBeVisible());
Expand Down Expand Up @@ -112,9 +110,7 @@ test('Allows to manage drilldowns', async () => {
});

test('Can delete multiple drilldowns', async () => {
const screen = render(
<FlyoutManageDrilldowns placeContext={{}} dynamicActionManager={mockDynamicActionManager} />
);
const screen = render(<FlyoutManageDrilldowns dynamicActionManager={mockDynamicActionManager} />);
// wait for initial render. It is async because resolving compatible action factories is async
await wait(() => expect(screen.getByText(/Manage Drilldowns/i)).toBeVisible());

Expand Down Expand Up @@ -151,7 +147,6 @@ test('Create only mode', async () => {
const onClose = jest.fn();
const screen = render(
<FlyoutManageDrilldowns
placeContext={{}}
dynamicActionManager={mockDynamicActionManager}
viewMode={'create'}
onClose={onClose}
Expand All @@ -175,11 +170,7 @@ test('Create only mode', async () => {

test('After switching between action factories state is restored', async () => {
const screen = render(
<FlyoutManageDrilldowns
placeContext={{}}
dynamicActionManager={mockDynamicActionManager}
viewMode={'create'}
/>
<FlyoutManageDrilldowns dynamicActionManager={mockDynamicActionManager} viewMode={'create'} />
);
// wait for initial render. It is async because resolving compatible action factories is async
await wait(() => expect(screen.getAllByText(/Create/i).length).toBeGreaterThan(0));
Expand Down Expand Up @@ -216,9 +207,7 @@ test("Error when can't save drilldown changes", async () => {
jest.spyOn(mockDynamicActionManager, 'createEvent').mockImplementationOnce(async () => {
throw error;
});
const screen = render(
<FlyoutManageDrilldowns placeContext={{}} dynamicActionManager={mockDynamicActionManager} />
);
const screen = render(<FlyoutManageDrilldowns dynamicActionManager={mockDynamicActionManager} />);
// wait for initial render. It is async because resolving compatible action factories is async
await wait(() => expect(screen.getByText(/Manage Drilldowns/i)).toBeVisible());
fireEvent.click(screen.getByText(/Create new/i));
Expand All @@ -236,9 +225,7 @@ test("Error when can't save drilldown changes", async () => {
});

test('Should show drilldown welcome message. Should be able to dismiss it', async () => {
let screen = render(
<FlyoutManageDrilldowns placeContext={{}} dynamicActionManager={mockDynamicActionManager} />
);
let screen = render(<FlyoutManageDrilldowns dynamicActionManager={mockDynamicActionManager} />);

// wait for initial render. It is async because resolving compatible action factories is async
await wait(() => expect(screen.getByText(/Manage Drilldowns/i)).toBeVisible());
Expand All @@ -248,9 +235,7 @@ test('Should show drilldown welcome message. Should be able to dismiss it', asyn
expect(screen.queryByTestId(WELCOME_MESSAGE_TEST_SUBJ)).toBeNull();
cleanup();

screen = render(
<FlyoutManageDrilldowns placeContext={{}} dynamicActionManager={mockDynamicActionManager} />
);
screen = render(<FlyoutManageDrilldowns dynamicActionManager={mockDynamicActionManager} />);
// wait for initial render. It is async because resolving compatible action factories is async
await wait(() => expect(screen.getByText(/Manage Drilldowns/i)).toBeVisible());
expect(screen.queryByTestId(WELCOME_MESSAGE_TEST_SUBJ)).toBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import {
toastDrilldownsDeleted,
} from './i18n';

interface ConnectedFlyoutManageDrilldownsProps<Context extends object = object> {
placeContext: Context;
interface ConnectedFlyoutManageDrilldownsProps {
dynamicActionManager: DynamicActionManager;
viewMode?: 'create' | 'manage';
onClose?: () => void;
Expand Down Expand Up @@ -75,10 +74,9 @@ export function createFlyoutManageDrilldowns({

const factoryContext: object = React.useMemo(
() => ({
placeContext: props.placeContext,
triggers: selectedTriggers,
}),
[props.placeContext, selectedTriggers]
[selectedTriggers]
);

const actionFactories = useCompatibleActionFactoriesForCurrentContext(
Expand Down Expand Up @@ -222,12 +220,10 @@ export function createFlyoutManageDrilldowns({
}

function useCompatibleActionFactoriesForCurrentContext<Context extends object = object>(
actionFactories: Array<ActionFactory<any>>,
actionFactories: ActionFactory[],
context: Context
) {
const [compatibleActionFactories, setCompatibleActionFactories] = useState<
Array<ActionFactory<any>>
>();
const [compatibleActionFactories, setCompatibleActionFactories] = useState<ActionFactory[]>();
useEffect(() => {
let canceled = false;
async function updateCompatibleFactoriesForContext() {
Expand Down Expand Up @@ -283,7 +279,7 @@ function useDrilldownsStateManager(
}

async function createDrilldown(
action: UiActionsEnhancedSerializedAction<any>,
action: UiActionsEnhancedSerializedAction,
selectedTriggers: Array<keyof TriggerContextMapping>
) {
await run(async () => {
Expand All @@ -297,7 +293,7 @@ function useDrilldownsStateManager(

async function editDrilldown(
drilldownId: string,
action: UiActionsEnhancedSerializedAction<any>,
action: UiActionsEnhancedSerializedAction,
selectedTriggers: Array<keyof TriggerContextMapping>
) {
await run(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ import {
urlFactory,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../advanced_ui_actions/public/components/action_wizard/test_data';
import { AdvancedUiActionsActionFactory as ActionFactory } from '../../../../advanced_ui_actions/public/';

storiesOf('components/FlyoutDrilldownWizard', module)
.add('default', () => {
return <FlyoutDrilldownWizard drilldownActionFactories={[urlFactory, dashboardFactory]} />;
return (
<FlyoutDrilldownWizard
drilldownActionFactories={[urlFactory as ActionFactory, dashboardFactory as ActionFactory]}
/>
);
})
.add('open in flyout - create', () => {
return (
<EuiFlyout onClose={() => {}}>
<FlyoutDrilldownWizard
onClose={() => {}}
drilldownActionFactories={[urlFactory, dashboardFactory]}
drilldownActionFactories={[
urlFactory as ActionFactory,
dashboardFactory as ActionFactory,
]}
/>
</EuiFlyout>
);
Expand All @@ -35,7 +43,10 @@ storiesOf('components/FlyoutDrilldownWizard', module)
<EuiFlyout onClose={() => {}}>
<FlyoutDrilldownWizard
onClose={() => {}}
drilldownActionFactories={[urlFactory, dashboardFactory]}
drilldownActionFactories={[
urlFactory as ActionFactory,
dashboardFactory as ActionFactory,
]}
initialDrilldownWizardConfig={{
name: 'My fancy drilldown',
actionFactory: urlFactory as any,
Expand All @@ -54,7 +65,7 @@ storiesOf('components/FlyoutDrilldownWizard', module)
<EuiFlyout onClose={() => {}}>
<FlyoutDrilldownWizard
onClose={() => {}}
drilldownActionFactories={[dashboardFactory]}
drilldownActionFactories={[dashboardFactory as ActionFactory]}
initialDrilldownWizardConfig={{
name: 'My fancy drilldown',
actionFactory: urlFactory as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface DrilldownWizardConfig<ActionConfig extends object = object> {
}

export interface FlyoutDrilldownWizardProps<CurrentActionConfig extends object = object> {
drilldownActionFactories: Array<ActionFactory<any>>;
drilldownActionFactories: ActionFactory[];

onSubmit?: (drilldownWizardConfig: Required<DrilldownWizardConfig>) => void;
onDelete?: () => void;
Expand Down