mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
## Summary Closes #97064. This scrolls to a newly added panel on a dashboard instead of remaining at the top. The user can see the new panel without having to manually scroll to the bottom. ~This also scrolls to the maximized panel when you minimize instead of just throwing you back to the top of the dashboard.~ Note: Scrolling on minimize will be addressed in a future PR. This scrolling behavior also seems to work with portable dashboards embedded in another apps, but it may require additional work on the consumer to call `scrollToPanel` in the appropriate callbacks when adding panels. #### Scrolls to newly added panel and shows a success border animation  #### Scrolls to panel on return from editor  #### Scrolls to panel clone  #### Scrolling in portable dashboards example  ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### Risk Matrix Delete this section if it is not applicable to this PR. Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Hannah Mudge <Heenawter@users.noreply.github.com>
202 lines
5.9 KiB
TypeScript
202 lines
5.9 KiB
TypeScript
/*
|
|
* 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 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 or the Server
|
|
* Side Public License, v 1.
|
|
*/
|
|
|
|
import { pickBy } from 'lodash';
|
|
import React, { useState } from 'react';
|
|
import {
|
|
EuiButton,
|
|
EuiButtonEmpty,
|
|
EuiButtonGroup,
|
|
EuiFlexGroup,
|
|
EuiFlexItem,
|
|
EuiLoadingContent,
|
|
EuiPanel,
|
|
EuiSpacer,
|
|
EuiText,
|
|
EuiTitle,
|
|
} from '@elastic/eui';
|
|
import { ViewMode } from '@kbn/embeddable-plugin/public';
|
|
import { OPTIONS_LIST_CONTROL, RANGE_SLIDER_CONTROL } from '@kbn/controls-plugin/common';
|
|
import {
|
|
type ControlGroupInput,
|
|
ControlGroupRenderer,
|
|
AwaitingControlGroupAPI,
|
|
ACTION_EDIT_CONTROL,
|
|
ACTION_DELETE_CONTROL,
|
|
} from '@kbn/controls-plugin/public';
|
|
import { ControlInputTransform } from '@kbn/controls-plugin/common/types';
|
|
|
|
const INPUT_KEY = 'kbnControls:saveExample:input';
|
|
|
|
const WITH_CUSTOM_PLACEHOLDER = 'Custom Placeholder';
|
|
|
|
export const EditExample = () => {
|
|
const [isSaving, setIsSaving] = useState(false);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [controlGroupAPI, setControlGroupAPI] = useState<AwaitingControlGroupAPI>(null);
|
|
const [toggleIconIdToSelectedMapIcon, setToggleIconIdToSelectedMapIcon] = useState<{
|
|
[id: string]: boolean;
|
|
}>({});
|
|
|
|
function onChangeIconsMultiIcons(optionId: string) {
|
|
const newToggleIconIdToSelectedMapIcon = {
|
|
...toggleIconIdToSelectedMapIcon,
|
|
...{
|
|
[optionId]: !toggleIconIdToSelectedMapIcon[optionId],
|
|
},
|
|
};
|
|
|
|
if (controlGroupAPI) {
|
|
const disabledActions: string[] = Object.keys(
|
|
pickBy(newToggleIconIdToSelectedMapIcon, (value) => value)
|
|
);
|
|
controlGroupAPI.updateInput({ disabledActions });
|
|
}
|
|
|
|
setToggleIconIdToSelectedMapIcon(newToggleIconIdToSelectedMapIcon);
|
|
}
|
|
|
|
async function onSave() {
|
|
if (!controlGroupAPI) return;
|
|
|
|
setIsSaving(true);
|
|
localStorage.setItem(INPUT_KEY, JSON.stringify(controlGroupAPI.getInput()));
|
|
|
|
// simulated async save await
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
|
setIsSaving(false);
|
|
}
|
|
|
|
async function onLoad() {
|
|
setIsLoading(true);
|
|
|
|
// simulated async load await
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
|
let input: Partial<ControlGroupInput> = {};
|
|
const inputAsString = localStorage.getItem(INPUT_KEY);
|
|
if (inputAsString) {
|
|
try {
|
|
input = JSON.parse(inputAsString);
|
|
const disabledActions = input.disabledActions ?? [];
|
|
setToggleIconIdToSelectedMapIcon({
|
|
[ACTION_EDIT_CONTROL]: disabledActions.includes(ACTION_EDIT_CONTROL),
|
|
[ACTION_DELETE_CONTROL]: disabledActions.includes(ACTION_DELETE_CONTROL),
|
|
[WITH_CUSTOM_PLACEHOLDER]: false,
|
|
});
|
|
} catch (e) {
|
|
// ignore parse errors
|
|
}
|
|
}
|
|
setIsLoading(false);
|
|
return input;
|
|
}
|
|
|
|
const controlInputTransform: ControlInputTransform = (newState, type) => {
|
|
if (type === OPTIONS_LIST_CONTROL && toggleIconIdToSelectedMapIcon[WITH_CUSTOM_PLACEHOLDER]) {
|
|
return {
|
|
...newState,
|
|
placeholder: 'Custom Placeholder',
|
|
};
|
|
}
|
|
|
|
if (type === RANGE_SLIDER_CONTROL) {
|
|
return {
|
|
...newState,
|
|
value: ['0', '4'],
|
|
};
|
|
}
|
|
|
|
return newState;
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<EuiTitle>
|
|
<h2>Edit and save example</h2>
|
|
</EuiTitle>
|
|
<EuiText>
|
|
<p>Customize controls and persist state to local storage.</p>
|
|
</EuiText>
|
|
<EuiSpacer size="m" />
|
|
<EuiPanel hasBorder={true}>
|
|
<EuiFlexGroup gutterSize="m" alignItems="center">
|
|
<EuiFlexItem grow={false}>
|
|
<EuiButtonEmpty
|
|
color="primary"
|
|
iconType="plusInCircle"
|
|
isDisabled={controlGroupAPI === undefined}
|
|
onClick={() => {
|
|
controlGroupAPI!.openAddDataControlFlyout({ controlInputTransform });
|
|
}}
|
|
>
|
|
Add control
|
|
</EuiButtonEmpty>
|
|
</EuiFlexItem>
|
|
<EuiFlexItem grow={true}>
|
|
<EuiButtonGroup
|
|
legend="Text style"
|
|
buttonSize="m"
|
|
options={[
|
|
{
|
|
id: ACTION_EDIT_CONTROL,
|
|
label: 'Disable edit action',
|
|
value: ACTION_EDIT_CONTROL,
|
|
},
|
|
{
|
|
id: ACTION_DELETE_CONTROL,
|
|
label: 'Disable delete action',
|
|
value: ACTION_DELETE_CONTROL,
|
|
},
|
|
{
|
|
id: WITH_CUSTOM_PLACEHOLDER,
|
|
label: WITH_CUSTOM_PLACEHOLDER,
|
|
value: WITH_CUSTOM_PLACEHOLDER,
|
|
},
|
|
]}
|
|
idToSelectedMap={toggleIconIdToSelectedMapIcon}
|
|
type="multi"
|
|
onChange={(id: string) => onChangeIconsMultiIcons(id)}
|
|
/>
|
|
</EuiFlexItem>
|
|
<EuiFlexItem grow={false}>
|
|
<EuiButton
|
|
fill
|
|
color="primary"
|
|
isDisabled={controlGroupAPI === undefined || isSaving}
|
|
onClick={onSave}
|
|
isLoading={isSaving}
|
|
>
|
|
Save
|
|
</EuiButton>
|
|
</EuiFlexItem>
|
|
</EuiFlexGroup>
|
|
{isLoading ? (
|
|
<>
|
|
<EuiSpacer />
|
|
<EuiLoadingContent lines={1} />
|
|
</>
|
|
) : null}
|
|
<ControlGroupRenderer
|
|
ref={setControlGroupAPI}
|
|
getCreationOptions={async (initialInput, builder) => {
|
|
const persistedInput = await onLoad();
|
|
return {
|
|
initialInput: {
|
|
...initialInput,
|
|
...persistedInput,
|
|
viewMode: ViewMode.EDIT,
|
|
},
|
|
};
|
|
}}
|
|
/>
|
|
</EuiPanel>
|
|
</>
|
|
);
|
|
};
|