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 20 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.

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;
}
};
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
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,34 @@
/*
* 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 { ForwardedDashboardState } from '../../locator';
import { DashboardPanelMap, DashboardState } from '../../types';

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

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

const panelsMap: DashboardPanelMap = {};
panels!.forEach((panel, idx) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very similar to the code in loadDashboardUrlState in src/plugins/dashboard/public/application/lib/load_dashboard_url_state.ts when loading the RawDashboardState from the URL, and the code in savedObjectToDashboardState in src/plugins/dashboard/public/application/lib/convert_dashboard_state.ts.

I wonder if we should have a common method for convertSavedPanelsToPanelMap to reduce repitition.

panelsMap![panel.panelIndex ?? String(idx)] = convertSavedDashboardPanelToPanelState(panel);
});

return {
...restOfState,
...{ panels: panelsMap },
};
};
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
* Side Public License, v 1.
*/

import { Capabilities } from 'src/core/public';
import { EuiCheckboxGroup } from '@elastic/eui';
import React from 'react';
import { ReactElement, useState } from 'react';
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import React, { ReactElement, useState } from 'react';
import type { Capabilities } from 'src/core/public';
import { DashboardSavedObject } from '../..';
import { shareModalStrings } from '../../dashboard_strings';
import { DashboardAppLocatorParams, DASHBOARD_APP_LOCATOR } from '../../locator';
import { TimeRange } from '../../services/data';
import { ViewMode } from '../../services/embeddable';
import { setStateToKbnUrl, unhashUrl } from '../../services/kibana_utils';
import { SharePluginStart } from '../../services/share';
import { dashboardUrlParams } from '../dashboard_router';
import { shareModalStrings } from '../../dashboard_strings';
import { DashboardAppCapabilities, DashboardState } from '../../types';
import { dashboardUrlParams } from '../dashboard_router';
import { stateToRawDashboardState } from '../lib/convert_dashboard_state';

const showFilterBarId = 'showFilterBar';
Expand All @@ -28,6 +32,7 @@ interface ShowShareModalProps {
savedDashboard: DashboardSavedObject;
currentDashboardState: DashboardState;
dashboardCapabilities: DashboardAppCapabilities;
timeRange: TimeRange;
}

export const showPublicUrlSwitch = (anonymousUserCapabilities: Capabilities) => {
Expand All @@ -46,6 +51,7 @@ export function ShowShareModal({
savedDashboard,
dashboardCapabilities,
currentDashboardState,
timeRange,
}: ShowShareModalProps) {
const EmbedUrlParamExtension = ({
setParamValue,
Expand Down Expand Up @@ -104,21 +110,49 @@ export function ShowShareModal({
);
};

const rawDashboardState = stateToRawDashboardState({
state: currentDashboardState,
version: kibanaVersion,
});

const locatorParams: DashboardAppLocatorParams = {
dashboardId: savedDashboard.id,
filters: rawDashboardState.filters,
preserveSavedFilters: true,
query: rawDashboardState.query,
savedQuery: rawDashboardState.savedQuery,
useHash: false,
panels: rawDashboardState.panels,
timeRange,
viewMode: ViewMode.VIEW, // For share locators we always load the dashboard in view mode
refreshInterval: undefined, // We don't share refresh interval externally
};

share.toggleShareContextMenu({
isDirty,
anchorElement,
allowEmbed: true,
allowShortUrl: dashboardCapabilities.createShortUrl,
shareableUrl: setStateToKbnUrl(
'_a',
stateToRawDashboardState({ state: currentDashboardState, version: kibanaVersion }),
rawDashboardState,
{ useHash: false, storeInHashQuery: true },
unhashUrl(window.location.href)
),
objectId: savedDashboard.id,
objectType: 'dashboard',
sharingData: {
title: savedDashboard.title,
title:
savedDashboard.title ||
i18n.translate('dashboard.share.defaultDashboardTitle', {
defaultMessage: 'Dashboard [{date}]',
values: { date: moment().toISOString(true) },
Copy link
Member

Choose a reason for hiding this comment

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

Does this date string need to be converted to the user's timezone and formatted per the time format in Advanced Settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whether we issue a request for v1 or v2 reports depends on the jobProviderOptions that are passed in. If they contain locatorParams then we know it's a v2 report type. To answer your question: yes v1 can be accessed from this UI and depends on the values passed in from the consumer.

I decided to keep it this way because I was not sure whether other parts of Kibana (like Canvas and visualize) still depend on v1 report types based on the params they pass in. Once they've all been updated we should remove this funcitonality - and probably send out a message that Reports now requires locators. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Does this date string need to be converted to the user's timezone and formatted per the time format in Advanced Settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great point @tsullivan ! Do you mind if I address this in a follow up PR as I did this same thing in discover

}),
locatorParams: {
id: DASHBOARD_APP_LOCATOR,
version: kibanaVersion,
params: locatorParams,
},
},
embedUrlParamExtensions: [
{
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/dashboard/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export {
createDashboardUrlGenerator,
DashboardUrlGeneratorState,
} from './url_generator';
export { DashboardAppLocator, DashboardAppLocatorParams } from './locator';
export {
DashboardAppLocator,
DashboardAppLocatorParams,
SerializableDashboardAppLocatorParams,
} from './locator';

export { DashboardSavedObject } from './saved_dashboards';
export { SavedDashboardPanel, DashboardContainerInput } from './types';
Expand Down
Loading