Skip to content

Commit

Permalink
[Dashboard][ES|QL] Unable to load page error on edit/add ES|QL panel (#…
Browse files Browse the repository at this point in the history
…188664)

## Summary

Fixes #184544
  • Loading branch information
mbondyra committed Jul 22, 2024
1 parent 76c6f55 commit b7b3260
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ describe('dimension editor', () => {
userEvent.type(customPrefixTextbox, prefix);
};
return {
settingNone: screen.getByTitle(/none/i),
settingAuto: screen.getByTitle(/auto/i),
settingCustom: screen.getByTitle(/custom/i),
settingNone: () => screen.getByTitle(/none/i),
settingAuto: () => screen.getByTitle(/auto/i),
settingCustom: () => screen.getByTitle(/custom/i),
customPrefixTextbox,
typePrefix,
...rtlRender,
Expand All @@ -266,6 +266,11 @@ describe('dimension editor', () => {
expect(screen.queryByTestId(SELECTORS.BREAKDOWN_EDITOR)).not.toBeInTheDocument();
});

it(`doesn't break when layer data is missing`, () => {
renderSecondaryMetricEditor({ frame: { activeData: { first: undefined } } });
expect(screen.getByTestId(SELECTORS.SECONDARY_METRIC_EDITOR)).toBeInTheDocument();
});

describe('metric prefix', () => {
const NONE_PREFIX = '';
const AUTO_PREFIX = undefined;
Expand All @@ -280,19 +285,19 @@ describe('dimension editor', () => {
state: localState,
});

expect(settingAuto).toHaveAttribute('aria-pressed', 'true');
expect(settingNone).toHaveAttribute('aria-pressed', 'false');
expect(settingCustom).toHaveAttribute('aria-pressed', 'false');
expect(settingAuto()).toHaveAttribute('aria-pressed', 'true');
expect(settingNone()).toHaveAttribute('aria-pressed', 'false');
expect(settingCustom()).toHaveAttribute('aria-pressed', 'false');
expect(customPrefixTextbox).not.toBeInTheDocument();
});

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

expect(settingNone).toHaveAttribute('aria-pressed', 'true');
expect(settingAuto).toHaveAttribute('aria-pressed', 'false');
expect(settingCustom).toHaveAttribute('aria-pressed', 'false');
expect(settingNone()).toHaveAttribute('aria-pressed', 'true');
expect(settingAuto()).toHaveAttribute('aria-pressed', 'false');
expect(settingCustom()).toHaveAttribute('aria-pressed', 'false');
expect(customPrefixTextbox).not.toBeInTheDocument();
});

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

expect(settingAuto).toHaveAttribute('aria-pressed', 'false');
expect(settingNone).toHaveAttribute('aria-pressed', 'false');
expect(settingCustom).toHaveAttribute('aria-pressed', 'true');
expect(settingAuto()).toHaveAttribute('aria-pressed', 'false');
expect(settingNone()).toHaveAttribute('aria-pressed', 'false');
expect(settingCustom()).toHaveAttribute('aria-pressed', 'true');
expect(customPrefixTextbox).toHaveValue(customPrefixState.secondaryPrefix);
});

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

userEvent.click(settingNone);
userEvent.click(settingNone());
expect(setState).toHaveBeenCalledWith(
expect.objectContaining({ secondaryPrefix: NONE_PREFIX })
);

userEvent.click(settingAuto);
userEvent.click(settingAuto());
expect(setState).toHaveBeenCalledWith(
expect.objectContaining({ secondaryPrefix: AUTO_PREFIX })
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function MaximumEditor({ setState, state, idPrefix }: SubProps) {
}

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

return (
Expand Down

0 comments on commit b7b3260

Please sign in to comment.