mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Drilldowns][chore] Remove some any's from components. Remove PlaceContext
from components (#65854)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
69a61d4ee7
commit
0f5c1ed95a
9 changed files with 31 additions and 46 deletions
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
@ -16,5 +16,5 @@ export interface SerializedAction<Config> {
|
|||
export interface SerializedEvent {
|
||||
eventId: string;
|
||||
triggers: string[];
|
||||
action: SerializedAction<unknown>;
|
||||
action: SerializedAction;
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
/>
|
||||
|
|
|
@ -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}
|
||||
/>
|
||||
|
|
|
@ -38,6 +38,6 @@ const FlyoutManageDrilldowns = createFlyoutManageDrilldowns({
|
|||
|
||||
storiesOf('components/FlyoutManageDrilldowns', module).add('default', () => (
|
||||
<EuiFlyout onClose={() => {}}>
|
||||
<FlyoutManageDrilldowns placeContext={{}} dynamicActionManager={mockDynamicActionManager} />
|
||||
<FlyoutManageDrilldowns dynamicActionManager={mockDynamicActionManager} />
|
||||
</EuiFlyout>
|
||||
));
|
||||
|
|
|
@ -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());
|
||||
|
@ -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());
|
||||
|
||||
|
@ -151,7 +147,6 @@ test('Create only mode', async () => {
|
|||
const onClose = jest.fn();
|
||||
const screen = render(
|
||||
<FlyoutManageDrilldowns
|
||||
placeContext={{}}
|
||||
dynamicActionManager={mockDynamicActionManager}
|
||||
viewMode={'create'}
|
||||
onClose={onClose}
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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());
|
||||
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
@ -75,10 +74,9 @@ export function createFlyoutManageDrilldowns({
|
|||
|
||||
const factoryContext: object = React.useMemo(
|
||||
() => ({
|
||||
placeContext: props.placeContext,
|
||||
triggers: selectedTriggers,
|
||||
}),
|
||||
[props.placeContext, selectedTriggers]
|
||||
[selectedTriggers]
|
||||
);
|
||||
|
||||
const actionFactories = useCompatibleActionFactoriesForCurrentContext(
|
||||
|
@ -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() {
|
||||
|
@ -283,7 +279,7 @@ function useDrilldownsStateManager(
|
|||
}
|
||||
|
||||
async function createDrilldown(
|
||||
action: UiActionsEnhancedSerializedAction<any>,
|
||||
action: UiActionsEnhancedSerializedAction,
|
||||
selectedTriggers: Array<keyof TriggerContextMapping>
|
||||
) {
|
||||
await run(async () => {
|
||||
|
@ -297,7 +293,7 @@ function useDrilldownsStateManager(
|
|||
|
||||
async function editDrilldown(
|
||||
drilldownId: string,
|
||||
action: UiActionsEnhancedSerializedAction<any>,
|
||||
action: UiActionsEnhancedSerializedAction,
|
||||
selectedTriggers: Array<keyof TriggerContextMapping>
|
||||
) {
|
||||
await run(async () => {
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue