Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dashboard][ES|QL] Unable to load page error on edit/add ES|QL panel #188664

Merged
merged 3 commits into from
Jul 22, 2024
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 @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This is why we enabled noUncheckedIndexedAccess in @elastic/charts elastic/elastic-charts#2006.

That way any array access is treated as a union with undefined unless the type is an explicit tuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! It'd be good to add it in Kibana, we had some bugs in the past caused by it.

const defaultPrefix = columnName || '';

return (
Expand Down