Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -123,6 +123,7 @@ describe('RelatedDashboardsClient', () => {
},
},
},
type: 'lens',
},
},
},
Expand All @@ -149,6 +150,7 @@ describe('RelatedDashboardsClient', () => {
},
},
},
type: 'lens',
},
},
},
Expand Down Expand Up @@ -182,6 +184,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field2' }] }] },
},
},
type: 'lens',
},
},
panelIndex: expect.any(String),
Expand Down Expand Up @@ -212,6 +215,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field1' }] }] },
},
},
type: 'lens',
},
},
panelIndex: expect.any(String),
Expand All @@ -233,6 +237,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field1' }] }] },
},
},
type: 'lens',
},
},
panelIndex: expect.any(String),
Expand Down Expand Up @@ -277,6 +282,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field1' }] }] },
},
},
type: 'lens',
},
},
},
Expand Down Expand Up @@ -324,6 +330,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field1' }] }] }, // matches by field which is handled by getDashboardsByField
},
},
type: 'lens',
},
},
},
Expand Down Expand Up @@ -357,6 +364,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field1' }] }] },
},
},
type: 'lens',
},
},
panelIndex: '123',
Expand Down Expand Up @@ -407,6 +415,7 @@ describe('RelatedDashboardsClient', () => {
type: 'lens',
panelConfig: {
attributes: {
type: 'lens',
references: [
{ name: 'indexpattern', id: 'index2' },
{ name: 'irrelevant', id: 'index1' },
Expand All @@ -430,6 +439,50 @@ describe('RelatedDashboardsClient', () => {
index: ['index2'],
});
});

it('should return an empty set when lens attributes are not available', () => {
client.dashboardsById.set('dashboard1', {
id: 'dashboard1',
attributes: {
title: 'Dashboard 1',
panels: [
{
type: 'lens',
panelConfig: {
attributes: null, // Lens attributes are not available
},
},
],
},
} as any);

// @ts-ignore next-line
const result = client.getDashboardsByIndex('index1');
expect(result.dashboards).toEqual([]);
});
});

describe('getPanelsByField', () => {
it('should return an empty set when lens attributes are not available', () => {
client.dashboardsById.set('dashboard1', {
id: 'dashboard1',
attributes: {
title: 'Dashboard 1',
panels: [
{
type: 'lens',
panelConfig: {
attributes: null, // Lens attributes are not available
},
},
],
},
} as any);

// @ts-ignore next-line
const result = client.getDashboardsByField(['field1']);
expect(result.dashboards).toEqual([]);
});
});

describe('dedupePanels', () => {
Expand Down Expand Up @@ -669,6 +722,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field1' }] }] }, // matches by field which is handled by getDashboardsByField
},
},
type: 'lens',
},
},
},
Expand All @@ -691,6 +745,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field2' }] }] },
},
},
type: 'lens',
},
},
},
Expand Down Expand Up @@ -732,6 +787,7 @@ describe('RelatedDashboardsClient', () => {
formBased: { layers: [{ columns: [{ sourceField: 'field1' }] }] },
},
},
type: 'lens',
},
},
panelIndex: '123',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class RelatedDashboardsClient {
return { dashboards: relevantDashboards };
}

getPanelsByIndex(index: string, panels: DashboardAttributes['panels']): DashboardPanel[] {
private getPanelsByIndex(index: string, panels: DashboardAttributes['panels']): DashboardPanel[] {
const panelsByIndex = panels.filter((p) => {
if (isDashboardSection(p)) return false; // filter out sections
const panelIndices = this.getPanelIndices(p);
Expand All @@ -233,7 +233,7 @@ export class RelatedDashboardsClient {
return panelsByIndex;
}

getPanelsByField(
private getPanelsByField(
fields: string[],
panels: DashboardAttributes['panels']
): Array<{ matchingFields: Set<string>; panel: DashboardPanel }> {
Expand All @@ -249,31 +249,46 @@ export class RelatedDashboardsClient {
return panelsByField;
}

getPanelIndices(panel: DashboardPanel): Set<string> {
const indices = new Set<string>();
private getPanelIndices(panel: DashboardPanel): Set<string> {
const emptyIndicesSet = new Set<string>();
switch (panel.type) {
case 'lens':
const lensAttr = panel.panelConfig.attributes as unknown as LensAttributes;
if (!lensAttr) {
return indices;
const maybeLensAttr = panel.panelConfig.attributes;
if (this.isLensVizAttributes(maybeLensAttr)) {
const lensIndices = this.getLensVizIndices(maybeLensAttr);
return lensIndices;
}
const lensIndices = this.getLensVizIndices(lensAttr);
return lensIndices;
return emptyIndicesSet;
default:
return indices;
return emptyIndicesSet;
}
}

getPanelFields(panel: DashboardPanel): Set<string> {
const fields = new Set<string>();
private getPanelFields(panel: DashboardPanel): Set<string> {
const emptyFieldsSet = new Set<string>();
switch (panel.type) {
case 'lens':
const lensAttr = panel.panelConfig.attributes as unknown as LensAttributes;
const lensFields = this.getLensVizFields(lensAttr);
return lensFields;
const maybeLensAttr = panel.panelConfig.attributes;
if (this.isLensVizAttributes(maybeLensAttr)) {
const lensFields = this.getLensVizFields(maybeLensAttr);
return lensFields;
}
return emptyFieldsSet;
default:
return fields;
return emptyFieldsSet;
}
}

private isLensVizAttributes(attributes: unknown): attributes is LensAttributes {
if (!attributes) {
return false;
}
return (
Boolean(attributes) &&
typeof attributes === 'object' &&
'type' in attributes &&
attributes.type === 'lens'
);
}

private getRuleQueryIndex(): string | null {
Expand Down