mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
# Backport This will backport the following commits from `main` to `8.16`: - [[Links] Fix link settings not persisting (#211041)](https://github.com/elastic/kibana/pull/211041) <!--- Backport version: 9.6.4 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Hannah Mudge","email":"Heenawter@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-02-13T21:03:31Z","message":"[Links] Fix link settings not persisting (#211041)\n\nCloses https://github.com/elastic/kibana/issues/211022\r\n\r\n## Summary\r\n\r\nThis PR fixes a bug with persisting Link options where, because we\r\nweren't providing the \"initial\" state to the options editor, it was\r\nalways starting with the default state - therefore, editing something\r\n**other** than the options would reset the link options back to the\r\ndefault.\r\n\r\nI tested this in `8.14` and the bug was present there, too - based on\r\n[the file history / git\r\nblame](https://github.com/elastic/kibana/blame/main/src/platform/plugins/private/links/public/components/editor/link_editor.tsx#L60),\r\nthis bug has been around from the very beginning 🙈\r\n\r\n**Before:**\r\n\r\n\r\nd1e93bfa
-566a-4506-99e3-47f92c922d49\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"c6e6a77c546450af30936fdedeef93221f83d291","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","loe:small","impact:low","backport:prev-major","Project:Dashboard Navigation","v9.1.0"],"title":"[Links] Fix link settings not persisting","number":211041,"url":"https://github.com/elastic/kibana/pull/211041","mergeCommit":{"message":"[Links] Fix link settings not persisting (#211041)\n\nCloses https://github.com/elastic/kibana/issues/211022\r\n\r\n## Summary\r\n\r\nThis PR fixes a bug with persisting Link options where, because we\r\nweren't providing the \"initial\" state to the options editor, it was\r\nalways starting with the default state - therefore, editing something\r\n**other** than the options would reset the link options back to the\r\ndefault.\r\n\r\nI tested this in `8.14` and the bug was present there, too - based on\r\n[the file history / git\r\nblame](https://github.com/elastic/kibana/blame/main/src/platform/plugins/private/links/public/components/editor/link_editor.tsx#L60),\r\nthis bug has been around from the very beginning 🙈\r\n\r\n**Before:**\r\n\r\n\r\nd1e93bfa
-566a-4506-99e3-47f92c922d49\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"c6e6a77c546450af30936fdedeef93221f83d291"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/211041","number":211041,"mergeCommit":{"message":"[Links] Fix link settings not persisting (#211041)\n\nCloses https://github.com/elastic/kibana/issues/211022\r\n\r\n## Summary\r\n\r\nThis PR fixes a bug with persisting Link options where, because we\r\nweren't providing the \"initial\" state to the options editor, it was\r\nalways starting with the default state - therefore, editing something\r\n**other** than the options would reset the link options back to the\r\ndefault.\r\n\r\nI tested this in `8.14` and the bug was present there, too - based on\r\n[the file history / git\r\nblame](https://github.com/elastic/kibana/blame/main/src/platform/plugins/private/links/public/components/editor/link_editor.tsx#L60),\r\nthis bug has been around from the very beginning 🙈\r\n\r\n**Before:**\r\n\r\n\r\nd1e93bfa
-566a-4506-99e3-47f92c922d49\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"c6e6a77c546450af30936fdedeef93221f83d291"}},{"url":"https://github.com/elastic/kibana/pull/211103","number":211103,"branch":"8.18","state":"OPEN"},{"url":"https://github.com/elastic/kibana/pull/211104","number":211104,"branch":"8.x","state":"OPEN"}]}] BACKPORT-->
This commit is contained in:
parent
0488ecd532
commit
526a7b78d1
3 changed files with 109 additions and 4 deletions
105
src/plugins/links/public/components/editor/link_editor.test.tsx
Normal file
105
src/plugins/links/public/components/editor/link_editor.test.tsx
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the "Elastic License
|
||||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
|
||||
* Public License v 1"; you may not use this file except in compliance with, at
|
||||
* your election, the "Elastic License 2.0", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import React from 'react';
|
||||
import { LinkEditor } from './link_editor';
|
||||
|
||||
jest.mock('./link_destination', () => {
|
||||
// mock this component to prevent handleDestinationPicked from being called on mount
|
||||
return { LinkDestination: () => <>LinkDestinationMock</> };
|
||||
});
|
||||
|
||||
describe('LinksEditor', () => {
|
||||
const nonDefaultOptions = {
|
||||
openInNewTab: true,
|
||||
useCurrentDateRange: false,
|
||||
useCurrentFilters: false,
|
||||
};
|
||||
|
||||
const defaultProps = {
|
||||
link: {
|
||||
id: 'foo',
|
||||
type: 'dashboardLink' as const,
|
||||
destination: '123',
|
||||
title: 'dashboard 01',
|
||||
},
|
||||
parentDashboardId: 'test',
|
||||
onSave: jest.fn(),
|
||||
onClose: jest.fn(),
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
const getOptionAriaChecked = (option: string): string | null => {
|
||||
return screen
|
||||
.getByTestId(`dashboardDrillDownOptions--${option}--checkbox`)
|
||||
.getAttribute('aria-checked');
|
||||
};
|
||||
|
||||
describe('dashboard link options', () => {
|
||||
test('starts with default when options not provided', async () => {
|
||||
render(<LinkEditor {...defaultProps} />);
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByTestId('dashboardDrillDownOptions')).not.toBeNull(); // wait for lazy load
|
||||
});
|
||||
|
||||
expect(getOptionAriaChecked('useCurrentFilters')).toBe('true');
|
||||
expect(getOptionAriaChecked('useCurrentDateRange')).toBe('true');
|
||||
expect(getOptionAriaChecked('openInNewTab')).toBe('false');
|
||||
});
|
||||
|
||||
test('properly overrides default values when provided', async () => {
|
||||
render(
|
||||
<LinkEditor
|
||||
{...defaultProps}
|
||||
link={{
|
||||
...defaultProps.link,
|
||||
options: nonDefaultOptions,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByTestId('dashboardDrillDownOptions')).not.toBeNull(); // wait for lazy load
|
||||
});
|
||||
|
||||
expect(getOptionAriaChecked('useCurrentFilters')).toBe('false');
|
||||
expect(getOptionAriaChecked('useCurrentDateRange')).toBe('false');
|
||||
expect(getOptionAriaChecked('openInNewTab')).toBe('true');
|
||||
});
|
||||
|
||||
test('options are persisted on edit', async () => {
|
||||
render(
|
||||
<LinkEditor
|
||||
{...defaultProps}
|
||||
link={{
|
||||
...defaultProps.link,
|
||||
options: nonDefaultOptions,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByTestId('dashboardDrillDownOptions')).not.toBeNull(); // wait for lazy load
|
||||
});
|
||||
|
||||
await userEvent.click(screen.getByTestId('links--linkEditor--linkLabel--input'));
|
||||
await userEvent.keyboard('test label');
|
||||
await userEvent.click(screen.getByTestId('links--linkEditor--saveBtn'));
|
||||
|
||||
expect(defaultProps.onSave).toBeCalledWith({
|
||||
...defaultProps.link,
|
||||
label: 'test label',
|
||||
options: nonDefaultOptions,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -54,10 +54,10 @@ export const LinkEditor = ({
|
|||
const [selectedLinkType, setSelectedLinkType] = useState<LinkType>(
|
||||
link?.type ?? DASHBOARD_LINK_TYPE
|
||||
);
|
||||
const [defaultLinkLabel, setDefaultLinkLabel] = useState<string | undefined>();
|
||||
const [defaultLinkLabel, setDefaultLinkLabel] = useState<string | undefined>(link?.title);
|
||||
const [currentLinkLabel, setCurrentLinkLabel] = useState<string>(link?.label ?? '');
|
||||
const [linkDescription, setLinkDescription] = useState<string | undefined>();
|
||||
const [linkOptions, setLinkOptions] = useState<LinkOptions | undefined>();
|
||||
const [linkDescription, setLinkDescription] = useState<string | undefined>(link?.description);
|
||||
const [linkOptions, setLinkOptions] = useState<LinkOptions | undefined>(link?.options);
|
||||
const [linkDestination, setLinkDestination] = useState<string | undefined>(link?.destination);
|
||||
|
||||
const linkTypes: EuiRadioGroupOption[] = useMemo(() => {
|
||||
|
|
|
@ -24,7 +24,7 @@ export const DashboardDrilldownOptionsComponent = ({
|
|||
}: DashboardDrilldownOptionsProps) => {
|
||||
return (
|
||||
<>
|
||||
<EuiFormRow hasChildLabel={false}>
|
||||
<EuiFormRow hasChildLabel={false} data-test-subj="dashboardDrillDownOptions">
|
||||
<EuiSwitch
|
||||
name="useCurrentFilters"
|
||||
label={dashboardDrilldownConfigStrings.component.getUseCurrentFiltersLabel()}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue