Skip to content

Commit c19334a

Browse files
Merge branch 'master' of github.com:elastic/kibana into feat/init-osquery
2 parents 3ded958 + 7bb8d3a commit c19334a

9 files changed

Lines changed: 84 additions & 16 deletions

File tree

x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export const WorkplaceSearchConfigured: React.FC<InitialAppData> = (props) => {
7878
<Route exact path="/">
7979
{errorConnecting ? <ErrorState /> : <Overview />}
8080
</Route>
81+
<Route path={PERSONAL_SOURCES_PATH}>
82+
{/* TODO: replace Layout with PrivateSourcesLayout (needs to be created) */}
83+
<Layout navigation={<></>} restrictWidth readOnlyMode={readOnlyMode}>
84+
<SourcesRouter />
85+
</Layout>
86+
</Route>
8187
<Route path={SOURCES_PATH}>
8288
<Layout
8389
navigation={<WorkplaceSearchNav sourcesSubNav={showSourcesSubnav && <SourceSubNav />} />}

x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { EuiCallOut, EuiEmptyPrompt, EuiSpacer, EuiPanel } from '@elastic/eui';
1212

1313
import { LicensingLogic } from '../../../../applications/shared/licensing';
1414

15-
import { ADD_SOURCE_PATH } from '../../routes';
15+
import { ADD_SOURCE_PATH, getSourcesPath } from '../../routes';
1616

1717
import noSharedSourcesIcon from '../../assets/share_circle.svg';
1818

@@ -74,12 +74,17 @@ export const PrivateSources: React.FC = () => {
7474
sidebarLinks.push({
7575
title: PRIVATE_LINK_TITLE,
7676
iconType: 'plusInCircle',
77-
path: ADD_SOURCE_PATH,
77+
path: getSourcesPath(ADD_SOURCE_PATH, false),
7878
});
7979
}
8080

8181
const headerAction = (
82-
<EuiButtonTo to={ADD_SOURCE_PATH} fill color="primary" data-test-subj="AddSourceButton">
82+
<EuiButtonTo
83+
to={getSourcesPath(ADD_SOURCE_PATH, false)}
84+
fill
85+
color="primary"
86+
data-test-subj="AddSourceButton"
87+
>
8388
{PRIVATE_LINK_TITLE}
8489
</EuiButtonTo>
8590
);

x-pack/plugins/lens/public/editor_frame_service/editor_frame/editor_frame.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,12 @@ describe('editor_frame', () => {
188188
/>
189189
);
190190
});
191-
expect(mockDatasource.initialize).toHaveBeenCalledWith(datasource1State, [], undefined);
192-
expect(mockDatasource2.initialize).toHaveBeenCalledWith(datasource2State, [], undefined);
191+
expect(mockDatasource.initialize).toHaveBeenCalledWith(datasource1State, [], undefined, {
192+
isFullEditor: true,
193+
});
194+
expect(mockDatasource2.initialize).toHaveBeenCalledWith(datasource2State, [], undefined, {
195+
isFullEditor: true,
196+
});
193197
expect(mockDatasource3.initialize).not.toHaveBeenCalled();
194198
});
195199

x-pack/plugins/lens/public/editor_frame_service/editor_frame/editor_frame.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export function EditorFrame(props: EditorFrameProps) {
8181
props.datasourceMap,
8282
state.datasourceStates,
8383
props.doc?.references,
84-
visualizeTriggerFieldContext
84+
visualizeTriggerFieldContext,
85+
{ isFullEditor: true }
8586
)
8687
.then((result) => {
8788
if (!isUnmounted) {

x-pack/plugins/lens/public/editor_frame_service/editor_frame/state_helpers.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Datasource,
1111
DatasourcePublicAPI,
1212
FramePublicAPI,
13+
InitializationOptions,
1314
Visualization,
1415
VisualizationDimensionGroupConfig,
1516
} from '../../types';
@@ -21,14 +22,20 @@ export async function initializeDatasources(
2122
datasourceMap: Record<string, Datasource>,
2223
datasourceStates: Record<string, { state: unknown; isLoading: boolean }>,
2324
references?: SavedObjectReference[],
24-
initialContext?: VisualizeFieldContext
25+
initialContext?: VisualizeFieldContext,
26+
options?: InitializationOptions
2527
) {
2628
const states: Record<string, { isLoading: boolean; state: unknown }> = {};
2729
await Promise.all(
2830
Object.entries(datasourceMap).map(([datasourceId, datasource]) => {
2931
if (datasourceStates[datasourceId]) {
3032
return datasource
31-
.initialize(datasourceStates[datasourceId].state || undefined, references, initialContext)
33+
.initialize(
34+
datasourceStates[datasourceId].state || undefined,
35+
references,
36+
initialContext,
37+
options
38+
)
3239
.then((datasourceState) => {
3340
states[datasourceId] = { isLoading: false, state: datasourceState };
3441
});
@@ -82,7 +89,9 @@ export async function persistedStateToExpression(
8289
{ isLoading: false, state },
8390
])
8491
),
85-
references
92+
references,
93+
undefined,
94+
{ isFullEditor: false }
8695
);
8796

8897
const datasourceLayers = createDatasourceLayers(datasources, datasourceStates);

x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
Operation,
1919
DatasourceLayerPanelProps,
2020
PublicAPIProps,
21+
InitializationOptions,
2122
} from '../types';
2223
import {
2324
loadInitialState,
@@ -104,7 +105,8 @@ export function getIndexPatternDatasource({
104105
async initialize(
105106
persistedState?: IndexPatternPersistedState,
106107
references?: SavedObjectReference[],
107-
initialContext?: VisualizeFieldContext
108+
initialContext?: VisualizeFieldContext,
109+
options?: InitializationOptions
108110
) {
109111
return loadInitialState({
110112
persistedState,
@@ -114,6 +116,7 @@ export function getIndexPatternDatasource({
114116
storage,
115117
indexPatternsService,
116118
initialContext,
119+
options,
117120
});
118121
},
119122

x-pack/plugins/lens/public/indexpattern_datasource/loader.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ describe('loader', () => {
346346
savedObjectsClient: mockClient(),
347347
indexPatternsService: mockIndexPatternsService(),
348348
storage,
349+
options: { isFullEditor: true },
349350
});
350351

351352
expect(state).toMatchObject({
@@ -364,12 +365,35 @@ describe('loader', () => {
364365
});
365366
});
366367

368+
it('should load a default state without loading the indexPatterns when embedded', async () => {
369+
const storage = createMockStorage();
370+
const savedObjectsClient = mockClient();
371+
const state = await loadInitialState({
372+
savedObjectsClient,
373+
indexPatternsService: mockIndexPatternsService(),
374+
storage,
375+
options: { isFullEditor: false },
376+
});
377+
378+
expect(state).toMatchObject({
379+
currentIndexPatternId: undefined,
380+
indexPatternRefs: [],
381+
indexPatterns: {},
382+
layers: {},
383+
});
384+
385+
expect(storage.set).not.toHaveBeenCalled();
386+
387+
expect(savedObjectsClient.find).not.toHaveBeenCalled();
388+
});
389+
367390
it('should load a default state when lastUsedIndexPatternId is not found in indexPatternRefs', async () => {
368391
const storage = createMockStorage({ indexPatternId: 'c' });
369392
const state = await loadInitialState({
370393
savedObjectsClient: mockClient(),
371394
indexPatternsService: mockIndexPatternsService(),
372395
storage,
396+
options: { isFullEditor: true },
373397
});
374398

375399
expect(state).toMatchObject({
@@ -393,6 +417,7 @@ describe('loader', () => {
393417
savedObjectsClient: mockClient(),
394418
indexPatternsService: mockIndexPatternsService(),
395419
storage: createMockStorage({ indexPatternId: '2' }),
420+
options: { isFullEditor: true },
396421
});
397422

398423
expect(state).toMatchObject({
@@ -415,6 +440,7 @@ describe('loader', () => {
415440
savedObjectsClient: mockClient(),
416441
indexPatternsService: mockIndexPatternsService(),
417442
storage,
443+
options: { isFullEditor: true },
418444
});
419445

420446
expect(state).toMatchObject({
@@ -443,6 +469,7 @@ describe('loader', () => {
443469
indexPatternId: '1',
444470
fieldName: '',
445471
},
472+
options: { isFullEditor: true },
446473
});
447474

448475
expect(state).toMatchObject({
@@ -499,6 +526,7 @@ describe('loader', () => {
499526
savedObjectsClient: mockClient(),
500527
indexPatternsService: mockIndexPatternsService(),
501528
storage,
529+
options: { isFullEditor: true },
502530
});
503531

504532
expect(state).toMatchObject({

x-pack/plugins/lens/public/indexpattern_datasource/loader.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import _ from 'lodash';
88
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
99
import { SavedObjectsClientContract, HttpSetup, SavedObjectReference } from 'kibana/public';
10-
import { StateSetter } from '../types';
10+
import { InitializationOptions, StateSetter } from '../types';
1111
import {
1212
IndexPattern,
1313
IndexPatternRef,
@@ -190,6 +190,7 @@ export async function loadInitialState({
190190
storage,
191191
indexPatternsService,
192192
initialContext,
193+
options,
193194
}: {
194195
persistedState?: IndexPatternPersistedState;
195196
references?: SavedObjectReference[];
@@ -198,8 +199,10 @@ export async function loadInitialState({
198199
storage: IStorageWrapper;
199200
indexPatternsService: IndexPatternsService;
200201
initialContext?: VisualizeFieldContext;
202+
options?: InitializationOptions;
201203
}): Promise<IndexPatternPrivateState> {
202-
const indexPatternRefs = await loadIndexPatternRefs(savedObjectsClient);
204+
const { isFullEditor } = options ?? {};
205+
const indexPatternRefs = await (isFullEditor ? loadIndexPatternRefs(savedObjectsClient) : []);
203206
const lastUsedIndexPatternId = getLastUsedIndexPatternId(storage, indexPatternRefs);
204207

205208
const state =
@@ -210,11 +213,15 @@ export async function loadInitialState({
210213
? Object.values(state.layers)
211214
.map((l) => l.indexPatternId)
212215
.concat(state.currentIndexPatternId)
213-
: [lastUsedIndexPatternId || defaultIndexPatternId || indexPatternRefs[0].id]
214-
);
216+
: [lastUsedIndexPatternId || defaultIndexPatternId || indexPatternRefs[0]?.id]
217+
)
218+
// take out the undefined from the list
219+
.filter(Boolean);
215220

216221
const currentIndexPatternId = initialContext?.indexPatternId ?? requiredPatterns[0];
217-
setLastUsedIndexPatternId(storage, currentIndexPatternId);
222+
if (currentIndexPatternId) {
223+
setLastUsedIndexPatternId(storage, currentIndexPatternId);
224+
}
218225

219226
const indexPatterns = await loadIndexPatterns({
220227
indexPatternsService,

x-pack/plugins/lens/public/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export interface DatasourceSuggestion<T = unknown> {
139139

140140
export type StateSetter<T> = (newState: T | ((prevState: T) => T)) => void;
141141

142+
export interface InitializationOptions {
143+
isFullEditor?: boolean;
144+
}
145+
142146
/**
143147
* Interface for the datasource registry
144148
*/
@@ -151,7 +155,8 @@ export interface Datasource<T = unknown, P = unknown> {
151155
initialize: (
152156
state?: P,
153157
savedObjectReferences?: SavedObjectReference[],
154-
initialContext?: VisualizeFieldContext
158+
initialContext?: VisualizeFieldContext,
159+
options?: InitializationOptions
155160
) => Promise<T>;
156161

157162
// Given the current state, which parts should be saved?

0 commit comments

Comments
 (0)