Skip to content

Commit ddf99b6

Browse files
flash1293mbondyra
andauthored
[Lens] Fix rollup related bugs (#75314)
Co-authored-by: Marta Bondyra <marta.bondyra@elastic.co>
1 parent eecf4aa commit ddf99b6

File tree

26 files changed

+1765
-34
lines changed

26 files changed

+1765
-34
lines changed

x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const initialState: IndexPatternPrivateState = {
8484
id: '1',
8585
title: 'idx1',
8686
timeFieldName: 'timestamp',
87+
hasRestrictions: false,
8788
fields: [
8889
{
8990
name: 'timestamp',
@@ -134,6 +135,7 @@ const initialState: IndexPatternPrivateState = {
134135
id: '2',
135136
title: 'idx2',
136137
timeFieldName: 'timestamp',
138+
hasRestrictions: true,
137139
fields: [
138140
{
139141
name: 'timestamp',
@@ -191,6 +193,7 @@ const initialState: IndexPatternPrivateState = {
191193
id: '3',
192194
title: 'idx3',
193195
timeFieldName: 'timestamp',
196+
hasRestrictions: false,
194197
fields: [
195198
{
196199
name: 'timestamp',
@@ -322,8 +325,20 @@ describe('IndexPattern Data Panel', () => {
322325
isFirstExistenceFetch: false,
323326
currentIndexPatternId: 'a',
324327
indexPatterns: {
325-
a: { id: 'a', title: 'aaa', timeFieldName: 'atime', fields: [] },
326-
b: { id: 'b', title: 'bbb', timeFieldName: 'btime', fields: [] },
328+
a: {
329+
id: 'a',
330+
title: 'aaa',
331+
timeFieldName: 'atime',
332+
fields: [],
333+
hasRestrictions: false,
334+
},
335+
b: {
336+
id: 'b',
337+
title: 'bbb',
338+
timeFieldName: 'btime',
339+
fields: [],
340+
hasRestrictions: false,
341+
},
327342
},
328343
layers: {
329344
1: {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export function IndexPatternDataPanel({
126126
title: indexPatterns[id].title,
127127
timeFieldName: indexPatterns[id].timeFieldName,
128128
fields: indexPatterns[id].fields,
129+
hasRestrictions: indexPatterns[id].hasRestrictions,
129130
}));
130131

131132
const dslQuery = buildSafeEsQuery(
@@ -422,6 +423,8 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
422423
]
423424
);
424425

426+
const fieldInfoUnavailable = existenceFetchFailed || currentIndexPattern.hasRestrictions;
427+
425428
return (
426429
<ChildDragDropProvider {...dragDropContext}>
427430
<EuiFlexGroup
@@ -568,7 +571,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
568571
initialIsOpen={localState.isAvailableAccordionOpen}
569572
id="lnsIndexPatternAvailableFields"
570573
label={
571-
existenceFetchFailed
574+
fieldInfoUnavailable
572575
? i18n.translate('xpack.lens.indexPattern.allFieldsLabel', {
573576
defaultMessage: 'All fields',
574577
})
@@ -577,6 +580,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
577580
})
578581
}
579582
exists={true}
583+
hideDetails={fieldInfoUnavailable}
580584
hasLoaded={!!hasSyncedExistingFields}
581585
fieldsCount={filteredFieldGroups.availableFields.length}
582586
isFiltered={
@@ -609,7 +613,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
609613
}
610614
/>
611615
<EuiSpacer size="m" />
612-
{!existenceFetchFailed && (
616+
{!fieldInfoUnavailable && (
613617
<FieldsAccordion
614618
initialIsOpen={localState.isEmptyAccordionOpen}
615619
isFiltered={

x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const expectedIndexPatterns = {
4242
title: 'my-fake-index-pattern',
4343
timeFieldName: 'timestamp',
4444
hasExistence: true,
45+
hasRestrictions: false,
4546
fields: [
4647
{
4748
name: 'timestamp',
@@ -1256,6 +1257,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
12561257
foo: {
12571258
id: 'foo',
12581259
title: 'Foo pattern',
1260+
hasRestrictions: false,
12591261
fields: [
12601262
{
12611263
aggregatable: true,

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface FieldsAccordionProps {
4747
renderCallout: JSX.Element;
4848
exists: boolean;
4949
showExistenceFetchError?: boolean;
50+
hideDetails?: boolean;
5051
}
5152

5253
export const InnerFieldsAccordion = function InnerFieldsAccordion({
@@ -61,13 +62,20 @@ export const InnerFieldsAccordion = function InnerFieldsAccordion({
6162
fieldProps,
6263
renderCallout,
6364
exists,
65+
hideDetails,
6466
showExistenceFetchError,
6567
}: FieldsAccordionProps) {
6668
const renderField = useCallback(
6769
(field: IndexPatternField) => (
68-
<FieldItem {...fieldProps} key={field.name} field={field} exists={!!exists} />
70+
<FieldItem
71+
{...fieldProps}
72+
key={field.name}
73+
field={field}
74+
exists={exists}
75+
hideDetails={hideDetails}
76+
/>
6977
),
70-
[fieldProps, exists]
78+
[fieldProps, exists, hideDetails]
7179
);
7280

7381
return (

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const expectedIndexPatterns = {
2121
id: '1',
2222
title: 'my-fake-index-pattern',
2323
timeFieldName: 'timestamp',
24+
hasRestrictions: false,
2425
fields: [
2526
{
2627
name: 'timestamp',
@@ -70,6 +71,7 @@ const expectedIndexPatterns = {
7071
id: '2',
7172
title: 'my-fake-restricted-pattern',
7273
timeFieldName: 'timestamp',
74+
hasRestrictions: true,
7375
fields: [
7476
{
7577
name: 'timestamp',

x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const expectedIndexPatterns = {
2020
id: '1',
2121
title: 'my-fake-index-pattern',
2222
timeFieldName: 'timestamp',
23+
hasRestrictions: false,
2324
fields: [
2425
{
2526
name: 'timestamp',
@@ -68,6 +69,7 @@ const expectedIndexPatterns = {
6869
2: {
6970
id: '2',
7071
title: 'my-fake-restricted-pattern',
72+
hasRestrictions: true,
7173
timeFieldName: 'timestamp',
7274
fields: [
7375
{
@@ -322,6 +324,7 @@ describe('IndexPattern Data Source suggestions', () => {
322324
1: {
323325
id: '1',
324326
title: 'no timefield',
327+
hasRestrictions: false,
325328
fields: [
326329
{
327330
name: 'bytes',
@@ -532,6 +535,7 @@ describe('IndexPattern Data Source suggestions', () => {
532535
1: {
533536
id: '1',
534537
title: 'no timefield',
538+
hasRestrictions: false,
535539
fields: [
536540
{
537541
name: 'bytes',
@@ -1350,6 +1354,7 @@ describe('IndexPattern Data Source suggestions', () => {
13501354
1: {
13511355
id: '1',
13521356
title: 'my-fake-index-pattern',
1357+
hasRestrictions: false,
13531358
fields: [
13541359
{
13551360
name: 'field1',
@@ -1493,6 +1498,7 @@ describe('IndexPattern Data Source suggestions', () => {
14931498
1: {
14941499
id: '1',
14951500
title: 'my-fake-index-pattern',
1501+
hasRestrictions: false,
14961502
fields: [
14971503
{
14981504
name: 'field1',
@@ -1555,6 +1561,7 @@ describe('IndexPattern Data Source suggestions', () => {
15551561
1: {
15561562
id: '1',
15571563
title: 'my-fake-index-pattern',
1564+
hasRestrictions: false,
15581565
fields: [
15591566
{
15601567
name: 'field1',

x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const initialState: IndexPatternPrivateState = {
6262
id: '1',
6363
title: 'my-fake-index-pattern',
6464
timeFieldName: 'timestamp',
65+
hasRestrictions: false,
6566
fields: [
6667
{
6768
name: 'timestamp',
@@ -103,6 +104,7 @@ const initialState: IndexPatternPrivateState = {
103104
'2': {
104105
id: '2',
105106
title: 'my-fake-restricted-pattern',
107+
hasRestrictions: true,
106108
timeFieldName: 'timestamp',
107109
fields: [
108110
{
@@ -160,6 +162,7 @@ const initialState: IndexPatternPrivateState = {
160162
id: '3',
161163
title: 'my-compatible-pattern',
162164
timeFieldName: 'timestamp',
165+
hasRestrictions: false,
163166
fields: [
164167
{
165168
name: 'timestamp',

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const indexPattern1 = ({
4040
id: '1',
4141
title: 'my-fake-index-pattern',
4242
timeFieldName: 'timestamp',
43+
hasRestrictions: false,
4344
fields: [
4445
{
4546
name: 'timestamp',
@@ -105,6 +106,7 @@ const indexPattern2 = ({
105106
id: '2',
106107
title: 'my-fake-restricted-pattern',
107108
timeFieldName: 'timestamp',
109+
hasRestrictions: true,
108110
fields: [
109111
{
110112
name: 'timestamp',
@@ -733,9 +735,9 @@ describe('loader', () => {
733735
dateRange: { fromDate: '1900-01-01', toDate: '2000-01-01' },
734736
fetchJson,
735737
indexPatterns: [
736-
{ id: '1', title: '1', fields: [] },
737-
{ id: '2', title: '1', fields: [] },
738-
{ id: '3', title: '1', fields: [] },
738+
{ id: '1', title: '1', fields: [], hasRestrictions: false },
739+
{ id: '2', title: '1', fields: [], hasRestrictions: false },
740+
{ id: '3', title: '1', fields: [], hasRestrictions: false },
739741
],
740742
setState,
741743
dslQuery,
@@ -783,9 +785,9 @@ describe('loader', () => {
783785
dateRange: { fromDate: '1900-01-01', toDate: '2000-01-01' },
784786
fetchJson,
785787
indexPatterns: [
786-
{ id: '1', title: '1', fields: [] },
787-
{ id: '2', title: '1', fields: [] },
788-
{ id: 'c', title: '1', fields: [] },
788+
{ id: '1', title: '1', fields: [], hasRestrictions: false },
789+
{ id: '2', title: '1', fields: [], hasRestrictions: false },
790+
{ id: 'c', title: '1', fields: [], hasRestrictions: false },
789791
],
790792
setState,
791793
dslQuery,
@@ -817,6 +819,7 @@ describe('loader', () => {
817819
{
818820
id: '1',
819821
title: '1',
822+
hasRestrictions: false,
820823
fields: [{ name: 'field1' }, { name: 'field2' }] as IndexPatternField[],
821824
},
822825
],

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export async function loadIndexPatterns({
9191
timeFieldName,
9292
fieldFormatMap,
9393
fields: newFields,
94+
hasRestrictions: !!typeMeta?.aggs,
9495
};
9596

9697
return {
@@ -334,6 +335,7 @@ export async function syncExistingFields({
334335
title: string;
335336
fields: IndexPatternField[];
336337
timeFieldName?: string | null;
338+
hasRestrictions: boolean;
337339
}>;
338340
fetchJson: HttpSetup['post'];
339341
setState: SetState;
@@ -343,6 +345,12 @@ export async function syncExistingFields({
343345
showNoDataPopover: () => void;
344346
}) {
345347
const existenceRequests = indexPatterns.map((pattern) => {
348+
if (pattern.hasRestrictions) {
349+
return {
350+
indexPatternTitle: pattern.title,
351+
existingFieldNames: pattern.fields.map((field) => field.name),
352+
};
353+
}
346354
const body: Record<string, string | object> = {
347355
dslQuery,
348356
fromDate: dateRange.fromDate,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const createMockedIndexPattern = (): IndexPattern => ({
1111
id: '1',
1212
title: 'my-fake-index-pattern',
1313
timeFieldName: 'timestamp',
14+
hasRestrictions: false,
1415
fields: [
1516
{
1617
name: 'timestamp',
@@ -70,6 +71,7 @@ export const createMockedRestrictedIndexPattern = () => ({
7071
id: '2',
7172
title: 'my-fake-restricted-pattern',
7273
timeFieldName: 'timestamp',
74+
hasRestrictions: true,
7375
fields: [
7476
{
7577
name: 'timestamp',

0 commit comments

Comments
 (0)