Skip to content

Commit b7b3260

Browse files
authored
[Dashboard][ES|QL] Unable to load page error on edit/add ES|QL panel (#188664)
## Summary Fixes #184544
1 parent 76c6f55 commit b7b3260

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
@@ -249,9 +249,9 @@ describe('dimension editor', () => {
249249
userEvent.type(customPrefixTextbox, prefix);
250250
};
251251
return {
252-
settingNone: screen.getByTitle(/none/i),
253-
settingAuto: screen.getByTitle(/auto/i),
254-
settingCustom: screen.getByTitle(/custom/i),
252+
settingNone: () => screen.getByTitle(/none/i),
253+
settingAuto: () => screen.getByTitle(/auto/i),
254+
settingCustom: () => screen.getByTitle(/custom/i),
255255
customPrefixTextbox,
256256
typePrefix,
257257
...rtlRender,
@@ -266,6 +266,11 @@ describe('dimension editor', () => {
266266
expect(screen.queryByTestId(SELECTORS.BREAKDOWN_EDITOR)).not.toBeInTheDocument();
267267
});
268268

269+
it(`doesn't break when layer data is missing`, () => {
270+
renderSecondaryMetricEditor({ frame: { activeData: { first: undefined } } });
271+
expect(screen.getByTestId(SELECTORS.SECONDARY_METRIC_EDITOR)).toBeInTheDocument();
272+
});
273+
269274
describe('metric prefix', () => {
270275
const NONE_PREFIX = '';
271276
const AUTO_PREFIX = undefined;
@@ -280,19 +285,19 @@ describe('dimension editor', () => {
280285
state: localState,
281286
});
282287

283-
expect(settingAuto).toHaveAttribute('aria-pressed', 'true');
284-
expect(settingNone).toHaveAttribute('aria-pressed', 'false');
285-
expect(settingCustom).toHaveAttribute('aria-pressed', 'false');
288+
expect(settingAuto()).toHaveAttribute('aria-pressed', 'true');
289+
expect(settingNone()).toHaveAttribute('aria-pressed', 'false');
290+
expect(settingCustom()).toHaveAttribute('aria-pressed', 'false');
286291
expect(customPrefixTextbox).not.toBeInTheDocument();
287292
});
288293

289294
it('correctly renders chosen none prefix', () => {
290295
const { settingAuto, settingCustom, settingNone, customPrefixTextbox } =
291296
renderSecondaryMetricEditor({ state: { ...localState, secondaryPrefix: NONE_PREFIX } });
292297

293-
expect(settingNone).toHaveAttribute('aria-pressed', 'true');
294-
expect(settingAuto).toHaveAttribute('aria-pressed', 'false');
295-
expect(settingCustom).toHaveAttribute('aria-pressed', 'false');
298+
expect(settingNone()).toHaveAttribute('aria-pressed', 'true');
299+
expect(settingAuto()).toHaveAttribute('aria-pressed', 'false');
300+
expect(settingCustom()).toHaveAttribute('aria-pressed', 'false');
296301
expect(customPrefixTextbox).not.toBeInTheDocument();
297302
});
298303

@@ -301,9 +306,9 @@ describe('dimension editor', () => {
301306
const { settingAuto, settingCustom, settingNone, customPrefixTextbox } =
302307
renderSecondaryMetricEditor({ state: customPrefixState });
303308

304-
expect(settingAuto).toHaveAttribute('aria-pressed', 'false');
305-
expect(settingNone).toHaveAttribute('aria-pressed', 'false');
306-
expect(settingCustom).toHaveAttribute('aria-pressed', 'true');
309+
expect(settingAuto()).toHaveAttribute('aria-pressed', 'false');
310+
expect(settingNone()).toHaveAttribute('aria-pressed', 'false');
311+
expect(settingCustom()).toHaveAttribute('aria-pressed', 'true');
307312
expect(customPrefixTextbox).toHaveValue(customPrefixState.secondaryPrefix);
308313
});
309314

@@ -316,12 +321,12 @@ describe('dimension editor', () => {
316321
state: { ...localState, secondaryPrefix: customPrefix },
317322
});
318323

319-
userEvent.click(settingNone);
324+
userEvent.click(settingNone());
320325
expect(setState).toHaveBeenCalledWith(
321326
expect.objectContaining({ secondaryPrefix: NONE_PREFIX })
322327
);
323328

324-
userEvent.click(settingAuto);
329+
userEvent.click(settingAuto());
325330
expect(setState).toHaveBeenCalledWith(
326331
expect.objectContaining({ secondaryPrefix: AUTO_PREFIX })
327332
);

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

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

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

137137
return (

0 commit comments

Comments
 (0)