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

[Reporting/Dashboard] Update integration to use v2 reports #108553

Merged
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
40ab51f
very wip, updating dashboard integration to use v2 reports. at the mo…
jloleysens Aug 13, 2021
56985bd
Merge branch 'master' into dashboard/update-report-to-use-v2
kibanamachine Aug 16, 2021
47ec77a
added missing dependency to hook
jloleysens Aug 16, 2021
1cb0766
added tests and refined ForwadedAppState interface
jloleysens Aug 16, 2021
adee42b
remove unused import
jloleysens Aug 16, 2021
3a93a16
updated test because generating a report from an unsaved report is po…
jloleysens Aug 17, 2021
9eacc30
migrated locator to forward state on history only, reordered methods …
jloleysens Aug 17, 2021
06ef623
remove unused import
jloleysens Aug 17, 2021
6cd42ba
update locator test and use panel index number if panelIndex does not…
jloleysens Aug 17, 2021
99b7479
ensure locator params are serializable
jloleysens Aug 17, 2021
db13ecd
- moved getSerializableRecord to locator.ts to ensure that the
jloleysens Aug 18, 2021
7c4260c
Merge branch 'master' into dashboard/update-report-to-use-v2
kibanamachine Aug 18, 2021
27d86a7
update generated api docs
jloleysens Aug 18, 2021
c9d09e7
remove unused variable
jloleysens Aug 18, 2021
8261f76
Merge branch 'master' into dashboard/update-report-to-use-v2
kibanamachine Aug 19, 2021
a002d5c
- removed SerializedRecord extension from dashboard locator params
jloleysens Aug 19, 2021
6116fc3
updated locator jest tests and SerializableRecord types
jloleysens Aug 19, 2021
f69d78f
explicitly map values to dashboardlocatorparams and export serializab…
jloleysens Aug 19, 2021
e3e7f7e
use serializable params type in embeddable
jloleysens Aug 19, 2021
9d97c06
Merge branch 'master' into dashboard/update-report-to-use-v2
kibanamachine Aug 20, 2021
566851e
Merge branch 'master' into dashboard/update-report-to-use-v2
kibanamachine Aug 23, 2021
d302131
factored out logic for converting panels to dashboard panels map
jloleysens Aug 23, 2021
84cbc7b
use "type =" instead of "interface"
jloleysens Aug 23, 2021
c3a8f4f
big update to locator params: type fixes and added options key
jloleysens Aug 23, 2021
4f2b82d
Merge branch 'master' into dashboard/update-report-to-use-v2
kibanamachine Aug 24, 2021
2ad676a
Merge branch 'master' into dashboard/update-report-to-use-v2
kibanamachine Aug 25, 2021
cb39ce9
added comment about why we are using "type" alias instead of "interfa…
jloleysens Aug 25, 2021
30978d9
simplify is v2 job param check
jloleysens Aug 25, 2021
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 @@ -80,7 +80,6 @@
| [QuerySuggestionField](./kibana-plugin-plugins-data-public.querysuggestionfield.md) | \* |
| [QuerySuggestionGetFnArgs](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md) | \* |
| [Reason](./kibana-plugin-plugins-data-public.reason.md) | |
| [RefreshInterval](./kibana-plugin-plugins-data-public.refreshinterval.md) | |
| [SavedQuery](./kibana-plugin-plugins-data-public.savedquery.md) | |
| [SavedQueryService](./kibana-plugin-plugins-data-public.savedqueryservice.md) | |
| [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) | Provide info about current search session to be stored in the Search Session saved object |
Expand Down Expand Up @@ -176,6 +175,7 @@
| [RangeFilter](./kibana-plugin-plugins-data-public.rangefilter.md) | |
| [RangeFilterMeta](./kibana-plugin-plugins-data-public.rangefiltermeta.md) | |
| [RangeFilterParams](./kibana-plugin-plugins-data-public.rangefilterparams.md) | |
| [RefreshInterval](./kibana-plugin-plugins-data-public.refreshinterval.md) | |
| [SavedQueryTimeFilter](./kibana-plugin-plugins-data-public.savedquerytimefilter.md) | |
| [SearchBarProps](./kibana-plugin-plugins-data-public.searchbarprops.md) | |
| [StatefulSearchBarProps](./kibana-plugin-plugins-data-public.statefulsearchbarprops.md) | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [RefreshInterval](./kibana-plugin-plugins-data-public.refreshinterval.md)

## RefreshInterval interface
## RefreshInterval type

<b>Signature:</b>

```typescript
export interface RefreshInterval
export declare type RefreshInterval = {
pause: boolean;
value: number;
};
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [pause](./kibana-plugin-plugins-data-public.refreshinterval.pause.md) | <code>boolean</code> | |
| [value](./kibana-plugin-plugins-data-public.refreshinterval.value.md) | <code>number</code> | |

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion src/plugins/dashboard/common/bwc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { SavedObjectReference } from 'kibana/public';
import type { Serializable } from '@kbn/utility-types';

import { GridData } from '../';

Expand Down Expand Up @@ -110,7 +111,7 @@ export type RawSavedDashboardPanel630 = RawSavedDashboardPanel620;
// In 6.2 we added an inplace migration, moving uiState into each panel's new embeddableConfig property.
// Source: https://github.com/elastic/kibana/pull/14949
export type RawSavedDashboardPanel620 = RawSavedDashboardPanel610 & {
embeddableConfig: { [key: string]: unknown };
embeddableConfig: { [key: string]: Serializable };
version: string;
};

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/dashboard/common/embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
* Side Public License, v 1.
*/

export interface GridData {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type GridData = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done to address issues with emebedding this type inside of a SerializableRecord type. There are issues with index types not being present in interface definitions, these are not an issue with type definitions as they are more permissive (it seems). Otherwise we run into what I think is: microsoft/TypeScript#1889

w: number;
h: number;
x: number;
y: number;
i: string;
}
};
7 changes: 4 additions & 3 deletions src/plugins/dashboard/common/migrate_to_730_panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { i18n } from '@kbn/i18n';
import type { SerializableRecord } from '@kbn/utility-types';
import semverSatisfies from 'semver/functions/satisfies';
import uuid from 'uuid';
import {
Expand Down Expand Up @@ -80,7 +81,7 @@ function migratePre61PanelToLatest(
panel: RawSavedDashboardPanelTo60,
version: string,
useMargins: boolean,
uiState?: { [key: string]: { [key: string]: unknown } }
uiState?: { [key: string]: SerializableRecord }
): RawSavedDashboardPanel730ToLatest {
if (panel.col === undefined || panel.row === undefined) {
throw new Error(
Expand Down Expand Up @@ -138,7 +139,7 @@ function migrate610PanelToLatest(
panel: RawSavedDashboardPanel610,
version: string,
useMargins: boolean,
uiState?: { [key: string]: { [key: string]: unknown } }
uiState?: { [key: string]: SerializableRecord }
): RawSavedDashboardPanel730ToLatest {
(['w', 'x', 'h', 'y'] as Array<keyof GridData>).forEach((key) => {
if (panel.gridData[key] === undefined) {
Expand Down Expand Up @@ -273,7 +274,7 @@ export function migratePanelsTo730(
>,
version: string,
useMargins: boolean,
uiState?: { [key: string]: { [key: string]: unknown } }
uiState?: { [key: string]: SerializableRecord }
): RawSavedDashboardPanel730ToLatest[] {
return panels.map((panel) => {
if (isPre61Panel(panel)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import {
DashboardRedirect,
DashboardState,
} from '../../types';
import { DashboardAppLocatorParams } from '../../locator';
import {
loadDashboardHistoryLocationState,
tryDestroyDashboardContainer,
syncDashboardContainerInput,
savedObjectToDashboardState,
Expand Down Expand Up @@ -88,6 +90,7 @@ export const useDashboardAppState = ({
savedObjectsTagging,
dashboardCapabilities,
dashboardSessionStorage,
scopedHistory,
} = services;
const { docTitle } = chrome;
const { notifications } = core;
Expand Down Expand Up @@ -149,10 +152,15 @@ export const useDashboardAppState = ({
*/
const dashboardSessionStorageState = dashboardSessionStorage.getState(savedDashboardId) || {};
const dashboardURLState = loadDashboardUrlState(dashboardBuildContext);
const forwardedAppState = loadDashboardHistoryLocationState(
scopedHistory()?.location?.state as undefined | DashboardAppLocatorParams
);

const initialDashboardState = {
...savedDashboardState,
...dashboardSessionStorageState,
...dashboardURLState,
...forwardedAppState,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we add the state from scopedHistory.location.state to the dashboard state.


// if there is an incoming embeddable, dashboard always needs to be in edit mode to receive it.
...(incomingEmbeddable ? { viewMode: ViewMode.EDIT } : {}),
Expand Down Expand Up @@ -312,6 +320,7 @@ export const useDashboardAppState = ({
getStateTransfer,
savedDashboards,
usageCollection,
scopedHistory,
notifications,
indexPatterns,
kibanaVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ import type { KibanaExecutionContext } from 'src/core/public';
import { DashboardSavedObject } from '../../saved_dashboards';
import { getTagsFromSavedDashboard, migrateAppState } from '.';
import { EmbeddablePackageState, ViewMode } from '../../services/embeddable';
import {
convertPanelStateToSavedDashboardPanel,
convertSavedDashboardPanelToPanelState,
} from '../../../common/embeddable/embeddable_saved_object_converters';
import { convertPanelStateToSavedDashboardPanel } from '../../../common/embeddable/embeddable_saved_object_converters';
import {
DashboardState,
RawDashboardState,
DashboardPanelMap,
SavedDashboardPanel,
DashboardAppServices,
DashboardContainerInput,
DashboardBuildContext,
} from '../../types';
import { convertSavedPanelsToPanelMap } from './convert_saved_panels_to_panel_map';

interface SavedObjectToDashboardStateProps {
version: string;
Expand Down Expand Up @@ -77,11 +73,7 @@ export const savedObjectToDashboardState = ({
usageCollection
);

const panels: DashboardPanelMap = {};
rawState.panels?.forEach((panel: SavedDashboardPanel) => {
panels[panel.panelIndex] = convertSavedDashboardPanelToPanelState(panel);
});
return { ...rawState, panels };
return { ...rawState, panels: convertSavedPanelsToPanelMap(rawState.panels) };
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { convertSavedDashboardPanelToPanelState } from '../../../common/embeddable/embeddable_saved_object_converters';
import type { SavedDashboardPanel, DashboardPanelMap } from '../../types';

export const convertSavedPanelsToPanelMap = (panels?: SavedDashboardPanel[]): DashboardPanelMap => {
const panelsMap: DashboardPanelMap = {};
panels?.forEach((panel, idx) => {
panelsMap![panel.panelIndex ?? String(idx)] = convertSavedDashboardPanelToPanelState(panel);
});
return panelsMap;
};
1 change: 1 addition & 0 deletions src/plugins/dashboard/public/application/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export { syncDashboardFilterState } from './sync_dashboard_filter_state';
export { syncDashboardIndexPatterns } from './sync_dashboard_index_patterns';
export { syncDashboardContainerInput } from './sync_dashboard_container_input';
export { diffDashboardContainerInput, diffDashboardState } from './diff_dashboard_state';
export { loadDashboardHistoryLocationState } from './load_dashboard_history_location_state';
export { buildDashboardContainer, tryDestroyDashboardContainer } from './build_dashboard_container';
export {
stateToDashboardContainerInput,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { ForwardedDashboardState } from '../../locator';
import { DashboardState } from '../../types';
import { convertSavedPanelsToPanelMap } from './convert_saved_panels_to_panel_map';

export const loadDashboardHistoryLocationState = (
state?: ForwardedDashboardState
): Partial<DashboardState> => {
if (!state) {
return {};
}

const { panels, ...restOfState } = state;
if (!panels?.length) {
return restOfState;
}

return {
...restOfState,
...{ panels: convertSavedPanelsToPanelMap(panels) },
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import _ from 'lodash';
import { migrateAppState } from '.';
import { replaceUrlHashQuery } from '../../../../kibana_utils/public';
import { DASHBOARD_STATE_STORAGE_KEY } from '../../dashboard_constants';
import { convertSavedDashboardPanelToPanelState } from '../../../common/embeddable/embeddable_saved_object_converters';
import {
import type {
DashboardBuildContext,
DashboardPanelMap,
DashboardState,
RawDashboardState,
SavedDashboardPanel,
} from '../../types';
import { migrateLegacyQuery } from './migrate_legacy_query';
import { convertSavedPanelsToPanelMap } from './convert_saved_panels_to_panel_map';

/**
* Loads any dashboard state from the URL, and removes the state from the URL.
Expand All @@ -32,12 +31,10 @@ export const loadDashboardUrlState = ({
const rawAppStateInUrl = kbnUrlStateStorage.get<RawDashboardState>(DASHBOARD_STATE_STORAGE_KEY);
if (!rawAppStateInUrl) return {};

const panelsMap: DashboardPanelMap = {};
let panelsMap: DashboardPanelMap = {};
if (rawAppStateInUrl.panels && rawAppStateInUrl.panels.length > 0) {
const rawState = migrateAppState(rawAppStateInUrl, kibanaVersion, usageCollection);
rawState.panels?.forEach((panel: SavedDashboardPanel) => {
panelsMap[panel.panelIndex] = convertSavedDashboardPanelToPanelState(panel);
});
panelsMap = convertSavedPanelsToPanelMap(rawState.panels);
}

const migratedQuery = rawAppStateInUrl.query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import semverSatisfies from 'semver/functions/satisfies';
import type { SerializableRecord } from '@kbn/utility-types';
import { i18n } from '@kbn/i18n';
import { METRIC_TYPE } from '@kbn/analytics';

Expand Down Expand Up @@ -75,7 +76,7 @@ export function migrateAppState(
>,
kibanaVersion,
appState.useMargins as boolean,
appState.uiState as Record<string, Record<string, unknown>>
appState.uiState as { [key: string]: SerializableRecord }
) as SavedDashboardPanel[];
delete appState.uiState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ export function DashboardTopNav({
(anchorElement: HTMLElement) => {
if (!share) return;
const currentState = dashboardAppState.getLatestDashboardState();
const timeRange = timefilter.getTime();
ShowShareModal({
share,
kibanaVersion,
Expand All @@ -412,9 +413,10 @@ export function DashboardTopNav({
currentDashboardState: currentState,
savedDashboard: dashboardAppState.savedDashboard,
isDirty: Boolean(dashboardAppState.hasUnsavedChanges),
timeRange,
});
},
[dashboardAppState, dashboardCapabilities, share, kibanaVersion]
[dashboardAppState, dashboardCapabilities, share, kibanaVersion, timefilter]
);

const dashboardTopNavActions = useMemo(() => {
Expand Down
Loading