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

[Portable Dashboards] Remove Saved Object Class #138774

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bbfc992
Replaced dashboard loading, removed savedDashboard from app state
ThomThomson Aug 10, 2022
94dedf1
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Aug 10, 2022
989e377
Added dashboard save util
ThomThomson Aug 12, 2022
b9b2f98
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 12, 2022
f2576c1
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Aug 29, 2022
08e72f3
Removed dashboard saved object class
ThomThomson Sep 9, 2022
7963ffb
Merge branch 'portableDashboard/removeSavedObjectClass' of https://gi…
ThomThomson Sep 9, 2022
f90e5ce
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 9, 2022
3abdb38
fix types, jest tests, and skip loading panels when any panel has a v…
ThomThomson Sep 9, 2022
b9da296
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 9, 2022
1ccc78a
jest test import fixes
ThomThomson Sep 9, 2022
42e3991
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 9, 2022
a06e8b8
More type fixes and jest test fixes
ThomThomson Sep 13, 2022
f8c9390
some functional test fixes
ThomThomson Sep 13, 2022
2b52d04
Merge branch 'portableDashboard/removeSavedObjectClass' of https://gi…
ThomThomson Sep 13, 2022
1453d75
more type fixes - fixed clone modal not applying title
ThomThomson Sep 13, 2022
b56ecdf
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 13, 2022
e8bb483
dashboard import change for ML
ThomThomson Sep 13, 2022
9801890
Fix locator getFilterFields to async import
ThomThomson Sep 13, 2022
0063716
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 14, 2022
5989797
Create and implement dashboard saved objects service
ThomThomson Sep 19, 2022
7caa447
remove unused lib functions, rules of hooks
ThomThomson Sep 19, 2022
0db6bae
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 19, 2022
7f12bbc
type fixes
ThomThomson Sep 19, 2022
eef0a73
Merge branch 'portableDashboard/removeSavedObjectClass' of https://gi…
ThomThomson Sep 19, 2022
48a6b25
remove duplicate import from merge
ThomThomson Sep 19, 2022
43eb8e2
shrink bundle size, fix jest tests
ThomThomson Sep 19, 2022
0cd0bf1
restore export
ThomThomson Sep 19, 2022
52fd415
remove dashboard constants from functional tests. Fix action imports
ThomThomson Sep 20, 2022
829a7ec
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 20, 2022
401c318
finish merge
ThomThomson Sep 20, 2022
3d11c44
fix types, dashboard security test
ThomThomson Sep 20, 2022
5a6cac1
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 20, 2022
7abfc42
Fix security tests, remove top level export and unify dashboard const…
ThomThomson Sep 20, 2022
f0613bf
add error handling to load case
ThomThomson Sep 21, 2022
d1f5f97
import viewMode from embeddable common
ThomThomson Sep 21, 2022
28e99e3
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 22, 2022
a625b3d
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 22, 2022
8c136f2
resolve merge issue
ThomThomson Sep 22, 2022
4448541
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 23, 2022
26103a4
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 23, 2022
488024a
Merge branch 'main' of https://github.com/elastic/kibana into portabl…
ThomThomson Sep 26, 2022
ad7e29c
Address review comments
ThomThomson Sep 27, 2022
05fb7ee
Merge branch 'main' into portableDashboard/removeSavedObjectClass
kibanamachine Sep 27, 2022
1d93a4d
Undo change which backed up time range into session storage
ThomThomson Sep 27, 2022
1fc1f55
remove extra conditional from duplicate title check
ThomThomson Sep 28, 2022
474b6ed
Merge branch 'main' into portableDashboard/removeSavedObjectClass
kibanamachine Sep 28, 2022
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
11 changes: 5 additions & 6 deletions src/plugins/controls/public/services/plugin_services.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ import { themeServiceFactory } from './theme/theme.story';
import { registry as stubRegistry } from './plugin_services.story';

export const providers: PluginServiceProviders<ControlsServices> = {
http: new PluginServiceProvider(httpServiceFactory),
controls: new PluginServiceProvider(controlsServiceFactory),
data: new PluginServiceProvider(dataServiceFactory),
overlays: new PluginServiceProvider(overlaysServiceFactory),
dataViews: new PluginServiceProvider(dataViewsServiceFactory),
http: new PluginServiceProvider(httpServiceFactory),
optionsList: new PluginServiceProvider(optionsListServiceFactory),
overlays: new PluginServiceProvider(overlaysServiceFactory),
settings: new PluginServiceProvider(settingsServiceFactory),
unifiedSearch: new PluginServiceProvider(unifiedSearchServiceFactory),
theme: new PluginServiceProvider(themeServiceFactory),

controls: new PluginServiceProvider(controlsServiceFactory),
optionsList: new PluginServiceProvider(optionsListServiceFactory),
unifiedSearch: new PluginServiceProvider(unifiedSearchServiceFactory),
};

export const pluginServices = new PluginServices<ControlsServices>();
Expand Down
11 changes: 5 additions & 6 deletions src/plugins/controls/public/services/plugin_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ export const providers: PluginServiceProviders<
ControlsServices,
KibanaPluginServiceParams<ControlsPluginStartDeps>
> = {
http: new PluginServiceProvider(httpServiceFactory),
controls: new PluginServiceProvider(controlsServiceFactory),
data: new PluginServiceProvider(dataServiceFactory),
unifiedSearch: new PluginServiceProvider(unifiedSearchServiceFactory),
overlays: new PluginServiceProvider(overlaysServiceFactory),
dataViews: new PluginServiceProvider(dataViewsServiceFactory),
http: new PluginServiceProvider(httpServiceFactory),
optionsList: new PluginServiceProvider(optionsListServiceFactory, ['data', 'http']),
overlays: new PluginServiceProvider(overlaysServiceFactory),
settings: new PluginServiceProvider(settingsServiceFactory),
theme: new PluginServiceProvider(themeServiceFactory),

optionsList: new PluginServiceProvider(optionsListServiceFactory, ['data', 'http']),
controls: new PluginServiceProvider(controlsServiceFactory),
unifiedSearch: new PluginServiceProvider(unifiedSearchServiceFactory),
};

export const pluginServices = new PluginServices<ControlsServices>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import type { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';

import {
diffDashboardState,
areTimeRangesEqual,
syncDashboardUrlState,
syncDashboardDataViews,
buildDashboardContainer,
syncDashboardFilterState,
areRefreshIntervalsEqual,
syncDashboardContainerInput,
tryDestroyDashboardContainer,
loadDashboardHistoryLocationState,
Expand Down Expand Up @@ -244,7 +242,7 @@ export const useDashboardAppState = ({
* Any time the redux state, or the last saved state changes, compare them, set the unsaved
* changes state, and and push the unsaved changes to session storage.
*/
const { timefilter } = query.timefilter;

const lastSavedSubscription = combineLatest([
$onLastSavedStateChange,
dashboardAppState.$onDashboardStateChange,
Expand All @@ -261,22 +259,12 @@ export const useDashboardAppState = ({
newState: current,
}).then((unsavedChanges) => {
if (observer.closed) return;
const savedTimeChanged =
lastSaved.timeRestore &&
lastSaved.timeRange &&
(!areTimeRangesEqual(lastSaved.timeRange, timefilter.getTime()) ||
!areRefreshIntervalsEqual(
lastSaved?.refreshInterval,
timefilter.getRefreshInterval()
));

/**
* changes to the dashboard should only be considered 'unsaved changes' when
* editing the dashboard
*/
const hasUnsavedChanges =
current.viewMode === ViewMode.EDIT &&
(Object.keys(unsavedChanges).length > 0 || savedTimeChanged);
current.viewMode === ViewMode.EDIT && Object.keys(unsavedChanges).length > 0;
setDashboardAppState((s) => ({ ...s, hasUnsavedChanges }));

unsavedChanges.viewMode = current.viewMode; // always push view mode into session store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
*/

import fastIsEqual from 'fast-deep-equal';
import { xor, omit, isEmpty } from 'lodash';

import { xor, omit, isEmpty, pick } from 'lodash';

import {
compareFilters,
COMPARE_ALL_OPTIONS,
type Filter,
isFilterPinned,
TimeRange,
} from '@kbn/es-query';
import { RefreshInterval } from '@kbn/data-plugin/common';
import { IEmbeddable } from '@kbn/embeddable-plugin/public';
import { compareFilters, COMPARE_ALL_OPTIONS, type Filter, isFilterPinned } from '@kbn/es-query';
import { persistableControlGroupInputIsEqual } from '@kbn/controls-plugin/common';

import { DashboardContainerInput } from '../..';
import { areTimesEqual } from './filter_utils';
import { DashboardPanelMap } from '../embeddable';
import { DashboardOptions, DashboardState } from '../../types';
import { pluginServices } from '../../services/plugin_services';

const stateKeystoIgnore = [
'expandedPanelId',
Expand Down Expand Up @@ -98,15 +107,67 @@ export const diffDashboardState = async ({
newState.controlGroupInput
);

const timeStatediff = getTimeSettingsAreEqual({
currentTimeRestore: newState.timeRestore,
lastSaved: { ...pick(originalState, ['timeRange', 'timeRestore', 'refreshInterval']) },
})
? {}
: pick(newState, ['timeRange', 'timeRestore', 'refreshInterval']);

Heenawter marked this conversation as resolved.
Show resolved Hide resolved
return {
...commonStateDiff,
...(panelsAreEqual ? {} : { panels: newState.panels }),
...(filtersAreEqual ? {} : { filters: newState.filters }),
...(optionsAreEqual ? {} : { options: newState.options }),
...(controlGroupIsEqual ? {} : { controlGroupInput: newState.controlGroupInput }),
...timeStatediff,
};
};

interface TimeStateDiffArg {
timeRange?: TimeRange;
timeRestore?: boolean;
refreshInterval?: RefreshInterval;
}

export const getTimeSettingsAreEqual = ({
lastSaved,
currentTimeRestore,
}: {
lastSaved?: TimeStateDiffArg;
currentTimeRestore?: boolean;
}) => {
const {
data: {
query: {
timefilter: { timefilter },
},
},
} = pluginServices.getServices();

if (currentTimeRestore !== lastSaved?.timeRestore) return false;
if (!currentTimeRestore) return true;

const currentRange = timefilter.getTime();
const lastRange = lastSaved?.timeRange ?? timefilter.getTimeDefaults();
if (
!areTimesEqual(currentRange.from, lastRange.from) ||
!areTimesEqual(currentRange.to, lastRange.to)
) {
return false;
}

const currentInterval = timefilter.getRefreshInterval();
const lastInterval = lastSaved?.refreshInterval ?? timefilter.getRefreshIntervalDefaults();
if (
currentInterval.pause !== lastInterval.pause ||
currentInterval.value !== lastInterval.value
) {
return false;
}
return true;
};

const getFiltersAreEqual = (
filtersA: Filter[],
filtersB: Filter[],
Expand Down
23 changes: 1 addition & 22 deletions src/plugins/dashboard/public/application/lib/filter_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@

import _ from 'lodash';
import moment, { Moment } from 'moment';
import type { Optional } from '@kbn/utility-types';
import type { RefreshInterval } from '@kbn/data-plugin/public';
import type { Filter, TimeRange } from '@kbn/es-query';

type TimeRangeCompare = Optional<TimeRange>;
type RefreshIntervalCompare = Optional<RefreshInterval>;
import type { Filter } from '@kbn/es-query';

/**
* Converts the time to a utc formatted string. If the time is not valid (e.g. it might be in a relative format like
Expand All @@ -32,22 +27,6 @@ export const convertTimeToUTCString = (time?: string | Moment): undefined | stri
}
};

export const areTimeRangesEqual = (rangeA: TimeRangeCompare, rangeB: TimeRangeCompare): boolean =>
areTimesEqual(rangeA.from, rangeB.from) && areTimesEqual(rangeA.to, rangeB.to);

export const areRefreshIntervalsEqual = (
refreshA?: RefreshIntervalCompare,
refreshB?: RefreshIntervalCompare
): boolean => refreshA?.pause === refreshB?.pause && refreshA?.value === refreshB?.value;

/**
* Compares the two times, making sure they are in both compared in string format. Absolute times
* are sometimes stored as moment objects, but converted to strings when reloaded. Relative times are
* strings that are not convertible to moment objects.
* @param timeA {string|Moment}
* @param timeB {string|Moment}
* @returns {boolean}
*/
export const areTimesEqual = (timeA?: string | Moment, timeB?: string | Moment) => {
return convertTimeToUTCString(timeA) === convertTimeToUTCString(timeB);
};
Expand Down
21 changes: 13 additions & 8 deletions src/plugins/dashboard/public/application/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
* Side Public License, v 1.
*/

export * from './filter_utils';
export {
areTimesEqual,
convertTimeToUTCString,
cleanFiltersForSerialize,
cleanFiltersForComparison,
} from './filter_utils';
export {
createSessionRestorationDataProvider,
enableDashboardSearchSessions,
getSearchSessionIdFromURL,
getSessionURLObservable,
} from './dashboard_session_restoration';
export { addHelpMenuToAppChrome } from './help_menu_util';
export { diffDashboardState } from './diff_dashboard_state';
export { syncDashboardUrlState } from './sync_dashboard_url_state';
export { syncDashboardDataViews } from './sync_dashboard_data_views';
export { syncDashboardFilterState } from './sync_dashboard_filter_state';
export { stateToDashboardContainerInput } from './convert_dashboard_state';
export { syncDashboardContainerInput } from './sync_dashboard_container_input';
export { loadDashboardHistoryLocationState } from './load_dashboard_history_location_state';
export { buildDashboardContainer, tryDestroyDashboardContainer } from './build_dashboard_container';
export { stateToDashboardContainerInput } from './convert_dashboard_state';
export {
createSessionRestorationDataProvider,
enableDashboardSearchSessions,
getSearchSessionIdFromURL,
getSessionURLObservable,
} from './dashboard_session_restoration';
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
*/

import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { PersistableControlGroupInput } from '@kbn/controls-plugin/common';

import { ViewMode } from '@kbn/embeddable-plugin/public';
import { RefreshInterval } from '@kbn/data-plugin/common';
import type { Filter, Query, TimeRange } from '@kbn/es-query';
import { PersistableControlGroupInput } from '@kbn/controls-plugin/common';

import { DashboardPanelMap } from '../../../common';
import type { DashboardOptions, DashboardState } from '../../types';
Expand All @@ -34,11 +36,15 @@ export const dashboardStateSlice = createSlice({
description: string;
tags?: string[];
timeRestore: boolean;
timeRange?: TimeRange;
refreshInterval?: RefreshInterval;
}>
) => {
state.title = action.payload.title;
state.description = action.payload.description;
state.timeRestore = action.payload.timeRestore;
state.timeRange = action.payload.timeRange;
state.refreshInterval = action.payload.refreshInterval;
if (action.payload.tags) {
state.tags = action.payload.tags;
}
Expand Down
Loading