Skip to content

Commit da23fd1

Browse files
committed
[Dashboard][ES|QL] Unable to load page error on edit/add ES|QL panel (#188664)
## Summary Fixes #184544 (cherry picked from commit b7b3260)
1 parent 4f091a7 commit da23fd1

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

x-pack/plugins/lens/public/visualizations/metric/dimension_editor.test.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ describe('dimension editor', () => {
245245
userEvent.type(customPrefixTextbox, prefix);
246246
};
247247
return {
248-
settingNone: screen.getByTitle(/none/i),
249-
settingAuto: screen.getByTitle(/auto/i),
250-
settingCustom: screen.getByTitle(/custom/i),
248+
settingNone: () => screen.getByTitle(/none/i),
249+
settingAuto: () => screen.getByTitle(/auto/i),
250+
settingCustom: () => screen.getByTitle(/custom/i),
251251
customPrefixTextbox,
252252
typePrefix,
253253
...rtlRender,
@@ -262,6 +262,11 @@ describe('dimension editor', () => {
262262
expect(screen.queryByTestId(SELECTORS.BREAKDOWN_EDITOR)).not.toBeInTheDocument();
263263
});
264264

265+
it(`doesn't break when layer data is missing`, () => {
266+
renderSecondaryMetricEditor({ frame: { activeData: { first: undefined } } });
267+
expect(screen.getByTestId(SELECTORS.SECONDARY_METRIC_EDITOR)).toBeInTheDocument();
268+
});
269+
265270
describe('metric prefix', () => {
266271
const NONE_PREFIX = '';
267272
const AUTO_PREFIX = undefined;
@@ -276,19 +281,19 @@ describe('dimension editor', () => {
276281
state: localState,
277282
});
278283

279-
expect(settingAuto).toHaveAttribute('aria-pressed', 'true');
280-
expect(settingNone).toHaveAttribute('aria-pressed', 'false');
281-
expect(settingCustom).toHaveAttribute('aria-pressed', 'false');
284+
expect(settingAuto()).toHaveAttribute('aria-pressed', 'true');
285+
expect(settingNone()).toHaveAttribute('aria-pressed', 'false');
286+
expect(settingCustom()).toHaveAttribute('aria-pressed', 'false');
282287
expect(customPrefixTextbox).not.toBeInTheDocument();
283288
});
284289

285290
it('correctly renders chosen none prefix', () => {
286291
const { settingAuto, settingCustom, settingNone, customPrefixTextbox } =
287292
renderSecondaryMetricEditor({ state: { ...localState, secondaryPrefix: NONE_PREFIX } });
288293

289-
expect(settingNone).toHaveAttribute('aria-pressed', 'true');
290-
expect(settingAuto).toHaveAttribute('aria-pressed', 'false');
291-
expect(settingCustom).toHaveAttribute('aria-pressed', 'false');
294+
expect(settingNone()).toHaveAttribute('aria-pressed', 'true');
295+
expect(settingAuto()).toHaveAttribute('aria-pressed', 'false');
296+
expect(settingCustom()).toHaveAttribute('aria-pressed', 'false');
292297
expect(customPrefixTextbox).not.toBeInTheDocument();
293298
});
294299

@@ -297,9 +302,9 @@ describe('dimension editor', () => {
297302
const { settingAuto, settingCustom, settingNone, customPrefixTextbox } =
298303
renderSecondaryMetricEditor({ state: customPrefixState });
299304

300-
expect(settingAuto).toHaveAttribute('aria-pressed', 'false');
301-
expect(settingNone).toHaveAttribute('aria-pressed', 'false');
302-
expect(settingCustom).toHaveAttribute('aria-pressed', 'true');
305+
expect(settingAuto()).toHaveAttribute('aria-pressed', 'false');
306+
expect(settingNone()).toHaveAttribute('aria-pressed', 'false');
307+
expect(settingCustom()).toHaveAttribute('aria-pressed', 'true');
303308
expect(customPrefixTextbox).toHaveValue(customPrefixState.secondaryPrefix);
304309
});
305310

@@ -312,12 +317,12 @@ describe('dimension editor', () => {
312317
state: { ...localState, secondaryPrefix: customPrefix },
313318
});
314319

315-
userEvent.click(settingNone);
320+
userEvent.click(settingNone());
316321
expect(setState).toHaveBeenCalledWith(
317322
expect.objectContaining({ secondaryPrefix: NONE_PREFIX })
318323
);
319324

320-
userEvent.click(settingAuto);
325+
userEvent.click(settingAuto());
321326
expect(setState).toHaveBeenCalledWith(
322327
expect.objectContaining({ secondaryPrefix: AUTO_PREFIX })
323328
);

x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function MaximumEditor({ setState, state, idPrefix }: SubProps) {
134134
}
135135

136136
function SecondaryMetricEditor({ accessor, idPrefix, frame, layerId, setState, state }: SubProps) {
137-
const columnName = getColumnByAccessor(accessor, frame.activeData?.[layerId].columns)?.name;
137+
const columnName = getColumnByAccessor(accessor, frame.activeData?.[layerId]?.columns)?.name;
138138
const defaultPrefix = columnName || '';
139139

140140
return (

0 commit comments

Comments
 (0)