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

Lens adhoc dataviews #138482

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
57d814d
Move lens dataViews state into main state
dej611 Jul 27, 2022
751c2a2
:fire: Remove some old cruft from the code
dej611 Jul 27, 2022
c7a9ce8
:bug: Fix dataViews layer change
dej611 Jul 27, 2022
79566af
:bug: Fix datasourceLayers refs
dej611 Jul 27, 2022
4822b36
:fire: Remove more old cruft
dej611 Jul 27, 2022
220aa39
:bug: Fix bug when loading SO
dej611 Jul 28, 2022
759f19a
:bug: Fix initial existence flag
dej611 Jul 28, 2022
7f590da
:label: Fix type issues
dej611 Jul 28, 2022
12b91fc
:label: Fix types and tests
dej611 Jul 28, 2022
2ee6f6d
:label: Fix types issues
dej611 Jul 29, 2022
ce7bddd
:white_check_mark: Fix more tests
dej611 Jul 29, 2022
80647be
:white_check_mark: Fix with new dataViews structure
dej611 Aug 3, 2022
63bf020
:white_check_mark: Fix more test mocks
dej611 Aug 3, 2022
3a7f9fb
:white_check_mark: More tests fixed
dej611 Aug 3, 2022
2fc1f0f
:fire: Removed unused prop
dej611 Aug 4, 2022
e9abe5a
:white_check_mark: Down to single broken test suite
dej611 Aug 4, 2022
ca51c4f
Merge remote-tracking branch 'upstream/main' into feature/dataview-state
dej611 Aug 4, 2022
13a669e
:label: Fix type issue
dej611 Aug 4, 2022
120e52a
Merge branch 'main' into feature/dataview-state
flash1293 Aug 8, 2022
af27366
Merge with main and resolve conflicts
stratoula Aug 10, 2022
f340ff5
Persistable state change
stratoula Aug 10, 2022
70000f0
Fix types
stratoula Aug 10, 2022
7c77bf1
Adds support for adhoc dataviews
stratoula Aug 11, 2022
b43a72a
Fix types and unit test
stratoula Aug 12, 2022
5ca1470
Fixes field statistics
stratoula Aug 12, 2022
b5ee47e
Fix
stratoula Aug 12, 2022
e8657ee
Populate adhoc dataview to dashboard
stratoula Aug 12, 2022
fb223fd
Enhace the dataview picker lists with the adhoc dataviews
stratoula Aug 12, 2022
0916a3c
Fix test
stratoula Aug 12, 2022
2a38fdf
Merge with main and resolve conflicts
stratoula Aug 12, 2022
eaa2093
Cleanup from merge coflicts
stratoula Aug 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('filter manager persistable state tests', () => {
const updatedFilters = inject(filters, [
{ type: DATA_VIEW_SAVED_OBJECT_TYPE, name: 'test123', id: '123' },
]);
expect(updatedFilters[0]).toHaveProperty('meta.index', undefined);
expect(updatedFilters[0]).toHaveProperty('meta.index', 'test');
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/common/query/filters/persistable_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const inject = (filters: Filter[], references: SavedObjectReference[]) =>
...filter,
meta: {
...filter.meta,
index: reference && reference.id,
// if no reference has been found, keep the current "index" property (used for adhoc data views)
index: reference ? reference.id : filter.meta.index,
},
};
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/query/persistable_state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('query service persistable state tests', () => {
const updatedQueryState = inject(queryState, [
{ type: DATA_VIEW_SAVED_OBJECT_TYPE, name: 'test123', id: '123' },
]);
expect(updatedQueryState.filters[0]).toHaveProperty('meta.index', undefined);
expect(updatedQueryState.filters[0]).toHaveProperty('meta.index', 'test');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function ChangeDataView({
onSaveTextLanguageQuery,
onTextLangQuerySubmit,
textBasedLanguage,
adHocDataViews,
}: DataViewPickerPropsExtended) {
const { euiTheme } = useEuiTheme();
const [isPopoverOpen, setPopoverIsOpen] = useState(false);
Expand All @@ -93,10 +94,21 @@ export function ChangeDataView({
useEffect(() => {
const fetchDataViews = async () => {
const dataViewsRefs = await data.dataViews.getIdsWithTitle();
if (adHocDataViews?.length) {
adHocDataViews.forEach((adHocDataView) => {
if (adHocDataView.id) {
dataViewsRefs.push({
title: adHocDataView.title,
name: adHocDataView.name,
id: adHocDataView.id,
});
}
});
}
setDataViewsList(dataViewsRefs);
};
fetchDataViews();
}, [data, currentDataViewId]);
}, [data, currentDataViewId, adHocDataViews]);

useEffect(() => {
if (trigger.label) {
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/unified_search/public/dataview_picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React from 'react';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { EuiButtonProps, EuiSelectableProps } from '@elastic/eui';
import type { AggregateQuery, Query } from '@kbn/es-query';
import { ChangeDataView } from './change_dataview';
Expand Down Expand Up @@ -44,6 +45,10 @@ export interface DataViewPickerProps {
* The id of the selected dataview.
*/
currentDataViewId?: string;
/**
* The adHocDataview selected.
*/
adHocDataViews?: DataView[];
/**
* EuiSelectable properties.
*/
Expand Down Expand Up @@ -84,6 +89,7 @@ export interface DataViewPickerPropsExtended extends DataViewPickerProps {
export const DataViewPicker = ({
isMissingCurrent,
currentDataViewId,
adHocDataViews,
onChangeDataView,
onAddField,
onDataViewCreated,
Expand All @@ -98,6 +104,7 @@ export const DataViewPicker = ({
<ChangeDataView
isMissingCurrent={isMissingCurrent}
currentDataViewId={currentDataViewId}
adHocDataViews={adHocDataViews}
onChangeDataView={onChangeDataView}
onAddField={onAddField}
onDataViewCreated={onDataViewCreated}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ describe('Lens App', () => {
expect(services.navigation.ui.TopNavMenu).toHaveBeenCalledWith(
expect.objectContaining({
query: 'fake query',
indexPatterns: [{ id: 'mockip', isTimeBased: expect.any(Function) }],
indexPatterns: [{ id: 'mockip', isTimeBased: expect.any(Function), fields: [] }],
}),
{}
);
Expand Down
29 changes: 28 additions & 1 deletion x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import {
LensAppState,
DispatchSetState,
selectSavedObjectFormat,
updateIndexPatterns,
} from '../state_management';
import { SaveModalContainer, runSaveLensVisualization } from './save_modal_container';
import { LensInspector } from '../lens_inspector_service';
import { getEditPath } from '../../common';
import { isLensEqual } from './lens_document_equality';
import { IndexPatternServiceAPI, createIndexPatternService } from '../indexpattern_service/service';

export type SaveProps = Omit<OnSaveProps, 'onTitleDuplicate' | 'newDescription'> & {
returnToOrigin: boolean;
Expand Down Expand Up @@ -66,6 +68,7 @@ export function App({
getOriginatingAppName,
spaces,
http,
notifications,
executionContext,
// Temporarily required until the 'by value' paradigm is default.
dashboardFeatureFlag,
Expand Down Expand Up @@ -360,6 +363,22 @@ export function App({
);
}, [initialContext]);

const indexPatternService = useMemo(
() =>
createIndexPatternService({
dataViews: lensAppServices.dataViews,
uiSettings: lensAppServices.uiSettings,
core: { http, notifications },
updateIndexPatterns: (newIndexPatternsState, options) => {
dispatch(updateIndexPatterns(newIndexPatternsState));
if (options?.applyImmediately) {
dispatch(applyChanges());
}
},
}),
[dispatch, http, notifications, lensAppServices]
);

return (
<>
<div className="lnsApp" data-test-subj="lnsApp">
Expand All @@ -381,13 +400,15 @@ export function App({
topNavMenuEntryGenerators={topNavMenuEntryGenerators}
initialContext={initialContext}
theme$={theme$}
indexPatternService={indexPatternService}
/>
{getLegacyUrlConflictCallout()}
{(!isLoading || persistedDoc) && (
<MemoizedEditorFrameWrapper
editorFrame={editorFrame}
showNoDataPopover={showNoDataPopover}
lensInspector={lensInspector}
indexPatternService={indexPatternService}
/>
)}
</div>
Expand Down Expand Up @@ -449,13 +470,19 @@ const MemoizedEditorFrameWrapper = React.memo(function EditorFrameWrapper({
editorFrame,
showNoDataPopover,
lensInspector,
indexPatternService,
}: {
editorFrame: EditorFrameInstance;
lensInspector: LensInspector;
showNoDataPopover: () => void;
indexPatternService: IndexPatternServiceAPI;
}) {
const { EditorFrameContainer } = editorFrame;
return (
<EditorFrameContainer showNoDataPopover={showNoDataPopover} lensInspector={lensInspector} />
<EditorFrameContainer
showNoDataPopover={showNoDataPopover}
lensInspector={lensInspector}
indexPatternService={indexPatternService}
/>
);
});
Loading