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

[Discover] Allow to store the configured ES|QL visualization v3 #175227

Merged
merged 165 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
38d4298
[Discover] Initial implementation for allowing to store ES|QL customi…
jughosta Jan 5, 2024
d3aaeeb
[Discover] Some refactoring
jughosta Jan 8, 2024
6f6f78b
[Discover] More refactoring
jughosta Jan 9, 2024
cc0ca64
Merge branch 'main' into 167887-esql-saved-search
jughosta Jan 9, 2024
631b174
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Jan 9, 2024
599653c
[Discover] Fix comparison for customVisualizationJSON
jughosta Jan 10, 2024
d982b33
[Discover] Support customization for histogram too. Reset when vis in…
jughosta Jan 11, 2024
97656ac
[Discover] Fix reverting saved search changes
jughosta Jan 11, 2024
ddb6b15
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Jan 12, 2024
6347d35
[Discover] Some fixes to make customVisualization work
jughosta Jan 12, 2024
aa9946d
[Discover] Refactor what is being saved. Persist all Lens attributes …
jughosta Jan 12, 2024
d0b3d85
[Discover] Update suggestion selector
jughosta Jan 12, 2024
96dc0b8
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 12, 2024
1caa803
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Jan 15, 2024
538e422
Merge remote-tracking branch 'origin/167887-esql-saved-search-v2' int…
jughosta Jan 15, 2024
6796374
[Discover] Fix suggestion change
jughosta Jan 15, 2024
f323642
[Discover] Fix suggestion type selector
jughosta Jan 15, 2024
266f99c
[Discover] Improve the resetting of suggestion
jughosta Jan 15, 2024
772a701
[Discover] Reduce the state size
jughosta Jan 15, 2024
482121d
Merge branch 'main' into 167887-esql-saved-search-v2
jughosta Jan 17, 2024
cb8e18e
[Discover] Update tests
jughosta Jan 17, 2024
e49a423
[Discover] Clean up
jughosta Jan 17, 2024
08f30be
[Discover] Update tests
jughosta Jan 17, 2024
a1643b4
[Discover] Update tests
jughosta Jan 17, 2024
2033a6d
[Discover] Fix typescript errors
jughosta Jan 17, 2024
c9dbaba
[Discover] Remove some logging
jughosta Jan 17, 2024
c6ee408
[Discover] Some fixes
jughosta Jan 17, 2024
55e3641
[Discover] Don't reset the vis on save
jughosta Jan 17, 2024
98b3c9d
[Discover] Fix histogram case
jughosta Jan 17, 2024
70455f0
[Discover] Fix other case
jughosta Jan 17, 2024
cf130cf
[Discover] Refactor to a service
jughosta Jan 18, 2024
34d01f4
[Discover] Add fixes
jughosta Jan 18, 2024
494fde5
[Discover] Refactor to props
jughosta Jan 22, 2024
c4eb455
[Discover] Clean up
jughosta Jan 22, 2024
b882203
[Discover] Fix tests
jughosta Jan 22, 2024
14c224d
[Discover] Fix tests
jughosta Jan 22, 2024
f835ad3
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 22, 2024
a5b59aa
[Discover] Clean up
jughosta Jan 23, 2024
56ca482
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Jan 23, 2024
9996c5d
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Jan 23, 2024
1dc7474
[Discover] Simplify state management
jughosta Jan 23, 2024
5de6c05
[Discover] Update tests
jughosta Jan 24, 2024
73d5819
[Discover] Don't sync with URL
jughosta Jan 24, 2024
1871a4e
[Discover] Improve resetting of lens attributes
jughosta Jan 24, 2024
f28d4bd
[Discover] Add logging
jughosta Jan 24, 2024
ac9d3fe
[Discover] Remove suggestion from histogram main state
jughosta Jan 24, 2024
9ece3ce
[Discover] Return suggestion to histogram main state as it triggers r…
jughosta Jan 25, 2024
fc2ec95
[Discover] Disable logging
jughosta Jan 25, 2024
38c69af
[Discover] Fix breakdown field
jughosta Jan 26, 2024
4181550
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Jan 31, 2024
0328095
[Discover] Delay calculation of table until search is complete
jughosta Jan 31, 2024
6d23632
Migrate Lens Vis State to InternalStateContainer
kertal Jan 30, 2024
1b2fb11
[Discover] Skip syncing to internalStateContainer
jughosta Jan 31, 2024
db9a48d
[Discover] Change props format
jughosta Jan 31, 2024
c0eda01
[Discover] Back to the problem
jughosta Jan 31, 2024
ee25770
[Discover] Improve reverting logic
jughosta Jan 31, 2024
525e7c3
[Discover] Comment logs out
jughosta Feb 1, 2024
bad165d
[Discover] Comment logs out
jughosta Feb 1, 2024
7e53323
[Discover] Fix checks
jughosta Feb 1, 2024
c6b124c
[Discover] Fix sample size schema
jughosta Feb 1, 2024
ae17bcf
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 1, 2024
3a211b2
[Discover] Check tests
jughosta Feb 2, 2024
5b382b9
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Feb 2, 2024
031343e
[Discover] Merge
jughosta Feb 2, 2024
895a08e
[Discover] Fix checks
jughosta Feb 2, 2024
c8f837c
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 2, 2024
30f9df0
[Discover] Fix for ft
jughosta Feb 2, 2024
60e217d
[Discover] Clean up
jughosta Feb 2, 2024
1e5c502
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 5, 2024
7e9dd06
[Discover] Fix based on tests
jughosta Feb 5, 2024
825aa71
[Discover] Update mocks
jughosta Feb 5, 2024
04a3430
[Discover] Restore tests for lens attributes
jughosta Feb 5, 2024
09960ce
[Discover] Fix tests
jughosta Feb 5, 2024
189a182
[Discover] Simplify tests
jughosta Feb 5, 2024
98923df
[Discover] Restore tests for vis suggestions
jughosta Feb 5, 2024
d7be568
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 5, 2024
1fce17f
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 6, 2024
9940078
[Discover] Add new functional tests
jughosta Feb 6, 2024
a5c1281
[Discover] Update tests
jughosta Feb 6, 2024
ab9593b
[Discover] Switch to local utils
jughosta Feb 6, 2024
9bd096c
[Discover] Add more tests
jughosta Feb 7, 2024
7ff9e21
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 7, 2024
6c11f14
[Discover] Remove redundant chart title
jughosta Feb 7, 2024
f2fc2ce
[Discover] Use the shared util for lens attributes
jughosta Feb 7, 2024
b555cd5
[Discover] Update on revert
jughosta Feb 7, 2024
7f8cb6b
[Discover] Add a test
jughosta Feb 7, 2024
cf5666c
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 7, 2024
c2c15b2
[Discover] Clean up i18n
jughosta Feb 7, 2024
9e49be3
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Feb 7, 2024
f25029a
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Feb 7, 2024
9898d6c
[Discover] Avoid circular deps
jughosta Feb 8, 2024
f1d3994
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 8, 2024
96c3f13
[Discover] Revert type changes
jughosta Feb 8, 2024
7f85d86
[Discover] Update types
jughosta Feb 8, 2024
fbc0181
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Feb 8, 2024
9602ee2
Merge branch 'main' into 167887-esql-saved-search-v3
stratoula Feb 9, 2024
2035802
[Discover] Return previous logic
jughosta Feb 9, 2024
e24d977
Merge branch 'main' into 167887-esql-saved-search-v3
stratoula Feb 12, 2024
d41009a
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Mar 4, 2024
de8347a
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Mar 4, 2024
b2de107
[Discover] Fix after the merge
jughosta Mar 4, 2024
e0b14a8
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Mar 4, 2024
ad4aabd
[Discover] Split saved search plugin into 2 plugins and a new package…
jughosta Jan 16, 2024
d66451b
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Mar 4, 2024
1f9e86b
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Mar 4, 2024
48ebc37
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Mar 4, 2024
db28b3d
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Mar 4, 2024
998ba35
[Discover] Make lens migrations optional
jughosta Feb 9, 2024
2707333
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Mar 5, 2024
133afb3
Revert "[Discover] Make lens migrations optional"
jughosta Mar 18, 2024
bc5b78c
Revert [Discover] Split saved search plugin into 2 plugins and a new …
jughosta Mar 18, 2024
35d193a
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Mar 18, 2024
1c2fd84
[Discover] Convert visContextJSON string into visContext object insid…
jughosta Mar 18, 2024
14e4f6f
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Mar 18, 2024
2ac30f8
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Mar 18, 2024
6c03da3
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine Mar 18, 2024
3931132
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Mar 18, 2024
b604434
[DataView] Update code style
jughosta Mar 20, 2024
5f68c09
[Discover] Fix types
jughosta Mar 20, 2024
01be3f9
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Mar 20, 2024
d4b53ee
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Mar 20, 2024
9b64a66
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Mar 22, 2024
8e0ee34
[Discover] Rename suggestion types
jughosta Mar 22, 2024
a599413
[Discover] Rename lensAttributesContext into visContext
jughosta Mar 22, 2024
03eb966
[Discover] Remove console logs
jughosta Mar 22, 2024
a0bc190
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Mar 22, 2024
a9229a1
[Discover] Fix types
jughosta Mar 22, 2024
d1ebe77
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Mar 22, 2024
ef97fd7
[Discover] Fix lens title
jughosta Mar 22, 2024
3150a5e
[Discover] Revert redundant changes
jughosta Mar 22, 2024
f356277
[Discover] Add tests
jughosta Mar 22, 2024
ac87b1a
[Discover] Fix tests
jughosta Mar 22, 2024
1a74c67
Merge remote-tracking branch 'upstream/main' into 167887-esql-saved-s…
jughosta Mar 25, 2024
b6b5ac5
[Discover] Change how visContext updates are managed in Discover
jughosta Mar 25, 2024
bd3adb3
[Discover] Update tests
jughosta Mar 25, 2024
d0daf77
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Mar 25, 2024
990c623
[Discover] Some fixes for this version
jughosta Mar 26, 2024
8fb8e8e
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Mar 26, 2024
d97c3f6
[Discover] Update implementation
jughosta Mar 26, 2024
a8f6e5b
[Discover] Simplify the implementation
jughosta Mar 26, 2024
d064930
[Discover] Simplify the implementation even more
jughosta Mar 26, 2024
47b28db
[Discover] New updates
jughosta Mar 26, 2024
55b5cf7
[Discover] Better clearing implementation
jughosta Mar 26, 2024
64a0056
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Mar 26, 2024
d5c1b5d
[Discover] Update tests after the merge
jughosta Mar 27, 2024
a4755a6
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Mar 27, 2024
e658447
[Discover] Fix when suggestion type is changed via flyout
jughosta Mar 27, 2024
f3d92d2
[Discover] Fix when suggestion type is changed to an unfamiliar one v…
jughosta Mar 27, 2024
a9e0d9a
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Mar 27, 2024
3400b7e
[Discover] Add more checks
jughosta Mar 27, 2024
6151f7d
[Discover] Update invalidation logic
jughosta Mar 28, 2024
46330ea
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Mar 28, 2024
53139df
[Discover] Fix invalidation logic
jughosta Mar 28, 2024
12b4b1c
Merge remote-tracking branch 'origin/167887-esql-saved-search-v3' int…
jughosta Mar 28, 2024
90448a0
Merge branch 'main' into 167887-esql-saved-search-v3
stratoula Apr 2, 2024
051bd82
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Apr 3, 2024
4406b0e
[Discover] Mark other lnsXY charts as Customized too
jughosta Apr 3, 2024
531c7a7
Merge branch 'main' into 167887-esql-saved-search-v3
stratoula Apr 4, 2024
b6637ba
[Discover] Address PR comments
jughosta Apr 5, 2024
e52a57b
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Apr 5, 2024
7088f98
[Discover] Fix flyout Cancel action and improve the icon
jughosta Apr 5, 2024
280323d
[Discover] Update tests
jughosta Apr 5, 2024
d49f1e3
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Apr 5, 2024
3f1330e
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Apr 8, 2024
0d9235f
Merge branch 'main' into 167887-esql-saved-search-v3
jughosta Apr 8, 2024
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 @@ -134,7 +134,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"risk-engine-configuration": "b105d4a3c6adce40708d729d12e5ef3c8fbd9508",
"rules-settings": "892a2918ebaeba809a612b8d97cec0b07c800b5f",
"sample-data-telemetry": "37441b12f5b0159c2d6d5138a494c9f440e950b5",
"search": "2c1ab8a17e6972be2fa8d3880ba2305dfd9a5a6e",
"search": "04a2141f9fa9e59cf824ad23ae3982fb1556dea2",
"search-session": "b2fcd840e12a45039ada50b1355faeafa39876d1",
"search-telemetry": "b568601618744720b5662946d3103e3fb75fe8ee",
"security-rule": "07abb4d7e707d91675ec0495c73816394c7b521f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const DiscoverHistogramLayout = ({
const { dataState } = stateContainer;
const searchSessionId = useObservable(stateContainer.searchSessionManager.searchSessionId$);
const hideChart = useAppStateSelector((state) => state.hideChart);

const unifiedHistogramProps = useDiscoverHistogram({
stateContainer,
inspectorAdapters: dataState.inspectorAdapters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { useQuerySubscriber } from '@kbn/unified-field-list/src/hooks/use_query_subscriber';
import {
ExternalVisContext,
UnifiedHistogramApi,
UnifiedHistogramFetchStatus,
UnifiedHistogramState,
Expand Down Expand Up @@ -88,13 +89,17 @@ export const useDiscoverHistogram = ({
const subscription = createUnifiedHistogramStateObservable(unifiedHistogram?.state$)?.subscribe(
(changes) => {
const { lensRequestAdapter, ...stateChanges } = changes;

const appState = stateContainer.appState.getState();
const oldState = {
hideChart: appState.hideChart,
interval: appState.interval,
breakdownField: appState.breakdownField,
};
const newState = { ...oldState, ...stateChanges };
const newState = {
...oldState,
...stateChanges,
};

if ('lensRequestAdapter' in changes) {
inspectorAdapters.lensRequests = lensRequestAdapter;
Expand Down Expand Up @@ -217,10 +222,12 @@ export const useDiscoverHistogram = ({
const {
dataView: textBasedDataView,
query: textBasedQuery,
externalVisContext: textBasedExternalVisContext,
columns,
} = useObservable(textBasedFetchComplete$, {
dataView: stateContainer.internalState.getState().dataView!,
query: stateContainer.appState.getState().query,
query: stateContainer.appState.getState().query!,
externalVisContext: stateContainer.appState.getState().visContext,
columns: savedSearchData$.documents$.getValue().textBasedQueryColumns ?? [],
});

Expand All @@ -229,12 +236,14 @@ export const useDiscoverHistogram = ({
return;
}

const fetchStart = stateContainer.dataState.fetch$.subscribe(() => {
const fetchStart = stateContainer.dataState.fetch$.subscribe((value) => {
// console.log('fetchStart', value);
if (!skipRefetch.current) {
setIsSuggestionLoading(true);
}
});
const fetchComplete = textBasedFetchComplete$.subscribe(() => {
const fetchComplete = textBasedFetchComplete$.subscribe((value) => {
// console.log('fetchComplete', value);
setIsSuggestionLoading(false);
});

Expand Down Expand Up @@ -321,6 +330,14 @@ export const useDiscoverHistogram = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
const timeRangeMemoized = useMemo(() => timeRange, [timeRange?.from, timeRange?.to]);

const onVisContextChanged = useCallback(
(newVisContext: ExternalVisContext | undefined) => {
// console.log('got new vis context from histogram', newVisContext);
stateContainer.appState.update({ visContext: newVisContext });
},
[stateContainer]
);

return {
ref,
getCreationOptions,
Expand All @@ -336,6 +353,8 @@ export const useDiscoverHistogram = ({
withDefaultActions: histogramCustomization?.withDefaultActions,
disabledActions: histogramCustomization?.disabledActions,
isChartLoading: isSuggestionLoading,
externalVisContext: isPlainRecord ? textBasedExternalVisContext : undefined, // visContext should be in sync with current query
onVisContextChanged: isPlainRecord ? onVisContextChanged : undefined,
};
};

Expand All @@ -349,7 +368,9 @@ const createUnifiedHistogramStateObservable = (state$?: Observable<UnifiedHistog
startWith(undefined),
pairwise(),
map(([prev, curr]) => {
const changes: Partial<DiscoverAppState> & { lensRequestAdapter?: RequestAdapter } = {};
const changes: Partial<DiscoverAppState> & {
lensRequestAdapter?: RequestAdapter;
} = {};

if (!curr) {
return changes;
Expand Down Expand Up @@ -413,6 +434,7 @@ const createFetchCompleteObservable = (stateContainer: DiscoverStateContainer) =
map(({ textBasedQueryColumns }) => ({
dataView: stateContainer.internalState.getState().dataView!,
query: stateContainer.appState.getState().query!,
externalVisContext: stateContainer.appState.getState().visContext,
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 delay updates to query and externalVisContext.

columns: textBasedQueryColumns ?? [],
}))
);
Expand All @@ -427,7 +449,7 @@ const createTotalHitsObservable = (state$?: Observable<UnifiedHistogramState>) =

const createCurrentSuggestionObservable = (state$: Observable<UnifiedHistogramState>) => {
return state$.pipe(
map((state) => state.currentSuggestion),
map((state) => state.currentSuggestionContext),
distinctUntilChanged(isEqual)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { omit } from 'lodash';
import { i18n } from '@kbn/i18n';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { TopNavMenuData } from '@kbn/navigation-plugin/public';
Expand Down Expand Up @@ -138,7 +139,7 @@ export const getTopNavLinks = ({

// Share -> Get links -> Snapshot
const params: DiscoverAppLocatorParams = {
...appState,
...omit(appState, 'visContext'), // TODO: Should we make the lens vis sharable? Looks like it's not serializable.
...(savedSearch.id ? { savedSearchId: savedSearch.id } : {}),
...(dataView?.isPersisted()
? { dataViewId: dataView?.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
FilterStateStore,
Query,
} from '@kbn/es-query';
import type { ExternalVisContext } from '@kbn/unified-histogram-plugin/public';
import { SavedSearch, VIEW_MODE } from '@kbn/saved-search-plugin/public';
import { IKbnUrlStateStorage, ISyncStateRef, syncState } from '@kbn/kibana-utils-plugin/public';
import { isEqual } from 'lodash';
Expand Down Expand Up @@ -143,6 +144,10 @@ export interface DiscoverAppState {
* Breakdown field of chart
*/
breakdownField?: string;
/**
* Customization for Lens vis in Histogram area
*/
visContext?: ExternalVisContext;
jughosta marked this conversation as resolved.
Show resolved Hide resolved
}

export const { Provider: DiscoverAppStateProvider, useSelector: useAppStateSelector } =
Expand Down Expand Up @@ -177,6 +182,15 @@ export const getDiscoverAppStateContainer = ({
},
};

const enhancedAppContainerFiltered = {
...enhancedAppContainer,
// get: () => {
// const state = { ...appStateContainer.getState() };
// delete state.visContext; // don't sync visContext to URL as it can be very long
// return state;
// },
};

const hasChanged = () => {
return !isEqualState(initialState, appStateContainer.getState());
};
Expand All @@ -202,14 +216,15 @@ export const getDiscoverAppStateContainer = ({
const replaceUrlState = async (newPartial: DiscoverAppState = {}, merge = true) => {
addLog('[appState] replaceUrlState', { newPartial, merge });
const state = merge ? { ...appStateContainer.getState(), ...newPartial } : newPartial;
// delete state.visContext; // don't sync visContext to URL as it can be very long
await stateStorage.set(APP_STATE_URL_KEY, state, { replace: true });
};

const startAppStateUrlSync = () => {
addLog('[appState] start syncing state with URL');
return syncState({
storageKey: APP_STATE_URL_KEY,
stateContainer: enhancedAppContainer,
stateContainer: enhancedAppContainerFiltered,
stateStorage,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ export function isEqualSavedSearch(savedSearchPrev: SavedSearch, savedSearchNext
return false; // ignore when value was changed from `undefined` to `false` as it happens per app logic, not by a user action
}

const isSame = isEqual(prevSavedSearch[key], nextSavedSearchWithoutSearchSource[key]);
const prevValue = getSavedSearchValueForComparison(prevSavedSearch, key);
const nextValue = getSavedSearchValueForComparison(nextSavedSearchWithoutSearchSource, key);
const isSame = isEqual(prevValue, nextValue);

if (!isSame) {
addLog('[savedSearch] difference between initial and changed version', {
Expand Down Expand Up @@ -330,3 +332,15 @@ function getSearchSourceFieldValueForComparison(

return searchSource.getField(searchSourceFieldName);
}

function getSavedSearchValueForComparison(
savedSearch: Omit<SavedSearch, 'searchSource'>,
key: keyof Omit<SavedSearch, 'searchSource'>
) {
if (key === 'visContextJSON' && savedSearch.visContextJSON) {
// the stringified JSON might have keys in a different order, so we parse it back into an object to compare
return JSON.parse(savedSearch.visContextJSON);
}

return savedSearch[key];
}
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ describe('Test discover state actions', () => {
"sort": Array [],
"timeRange": undefined,
"usesAdHocDataView": false,
"visContextJSON": undefined,
}
`);
expect(searchSource.getField('index')?.id).toEqual('the-data-view-id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import { cloneDeep, isEqual } from 'lodash';
import { IUiSettingsClient } from '@kbn/core/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import { getChartHidden } from '@kbn/unified-histogram-plugin/public';
import {
getChartHidden,
fromExternalVisContextJSONString,
} from '@kbn/unified-histogram-plugin/public';
import {
DEFAULT_COLUMNS_SETTING,
DOC_HIDE_TIME_COLUMN_SETTING,
Expand Down Expand Up @@ -101,6 +104,9 @@ export function getStateDefaults({
if (savedSearch.breakdownField) {
defaultState.breakdownField = savedSearch.breakdownField;
}
if (savedSearch.visContextJSON) {
defaultState.visContext = fromExternalVisContextJSONString(savedSearch.visContextJSON);
}

return defaultState;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import type { SavedSearch, SortOrder } from '@kbn/saved-search-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/common';
import { toExternalVisContextJSONString } from '@kbn/unified-histogram-plugin/public';
import { cloneDeep } from 'lodash';
import { isTextBasedQuery } from './is_text_based_query';
import type { DiscoverAppState } from '../services/discover_app_state_container';
Expand Down Expand Up @@ -64,6 +65,7 @@ export function updateSavedSearch({
savedSearch.rowHeight = state.rowHeight;
savedSearch.rowsPerPage = state.rowsPerPage;
savedSearch.sampleSize = state.sampleSize;
savedSearch.visContextJSON = toExternalVisContextJSONString(state.visContext);

if (state.viewMode) {
savedSearch.viewMode = state.viewMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const savedSearchAttributesSchema = schema.object(
})
),
breakdownField: schema.maybe(schema.string()),
visContextJSON: schema.maybe(schema.string()), // TODO: should we create a new version?
version: schema.maybe(schema.number()),
},
{ unknowns: 'forbid' }
Expand Down
1 change: 1 addition & 0 deletions src/plugins/saved_search/common/saved_searches_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export const fromSavedSearchAttributes = (
rowsPerPage: attributes.rowsPerPage,
sampleSize: attributes.sampleSize,
breakdownField: attributes.breakdownField,
visContextJSON: attributes.visContextJSON,
});
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe('getSavedSearch', () => {
"title": "test1",
"usesAdHocDataView": undefined,
"viewMode": undefined,
"visContextJSON": undefined,
}
`);
});
Expand Down Expand Up @@ -252,6 +253,7 @@ describe('getSavedSearch', () => {
"title": "test2",
"usesAdHocDataView": undefined,
"viewMode": undefined,
"visContextJSON": undefined,
}
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('saved_searches_utils', () => {
"title": "saved search",
"usesAdHocDataView": false,
"viewMode": undefined,
"visContextJSON": undefined,
}
`);
});
Expand Down Expand Up @@ -138,6 +139,7 @@ describe('saved_searches_utils', () => {
"title": "title",
"usesAdHocDataView": false,
"viewMode": undefined,
"visContextJSON": undefined,
}
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ export const toSavedSearchAttributes = (
rowsPerPage: savedSearch.rowsPerPage,
sampleSize: savedSearch.sampleSize,
breakdownField: savedSearch.breakdownField,
visContextJSON: savedSearch.visContextJSON,
});
3 changes: 3 additions & 0 deletions src/plugins/saved_search/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface SavedSearchAttributes {
rowsPerPage?: number;
sampleSize?: number;
breakdownField?: string;
visContextJSON?: string;
}

/** @internal **/
Expand Down Expand Up @@ -74,6 +75,8 @@ export interface SavedSearch {
rowsPerPage?: number;
sampleSize?: number;
breakdownField?: string;
visContextJSON?: string;

references?: SavedObjectReference[];
sharingSavedObjectProps?: {
outcome?: SavedObjectsResolveResponse['outcome'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ describe('getSavedSearchAttributeService', () => {
"title": "saved-search-title",
"usesAdHocDataView": undefined,
"viewMode": undefined,
"visContextJSON": undefined,
}
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class SavedSearchStorage extends SOContentStorage<SavedSearchCrudTypes> {
'refreshInterval',
'rowsPerPage',
'breakdownField',
'visContextJSON',
'sampleSize',
],
logger,
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/saved_search/server/saved_objects/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ export const SCHEMA_SEARCH_V8_12_0 = schema.object({
})
),
});
export const SCHEMA_SEARCH_V8_13_0 = schema.object({
...SCHEMA_SEARCH_BASE,
visContextJSON: schema.maybe(schema.string()),
});
5 changes: 3 additions & 2 deletions src/plugins/saved_search/server/saved_objects/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ANALYTICS_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
import { SavedObjectsType } from '@kbn/core/server';
import { MigrateFunctionsObject } from '@kbn/kibana-utils-plugin/common';
import { getAllMigrations } from './search_migrations';
import { SCHEMA_SEARCH_V8_8_0, SCHEMA_SEARCH_V8_12_0 } from './schema';
import { SCHEMA_SEARCH_V8_8_0, SCHEMA_SEARCH_V8_12_0, SCHEMA_SEARCH_V8_13_0 } from './schema';

export function getSavedSearchObjectType(
getSearchSourceMigrations: () => MigrateFunctionsObject
Expand Down Expand Up @@ -45,7 +45,8 @@ export function getSavedSearchObjectType(
schemas: {
'8.8.0': SCHEMA_SEARCH_V8_8_0,
'8.12.0': SCHEMA_SEARCH_V8_12_0,
'8.13.0': SCHEMA_SEARCH_V8_13_0,
},
migrations: () => getAllMigrations(getSearchSourceMigrations()),
migrations: () => getAllMigrations(getSearchSourceMigrations()), // TODO: add lens embeddable migrations for `visContextJSON`
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const buildDataViewMock = ({
return dataViewFields.find((field) => field.name === timeFieldName);
},
toSpec: () => ({}),
toMinimalSpec: () => ({}),
} as unknown as DataView;

dataView.isTimeBased = () => !!timeFieldName;
Expand Down
Loading