forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dashboard] [Collapsable Panels] Add panel management API (elastic#19…
…5513) Closes elastic#190445 ## Summary This PR adds the first steps of a panel management API to the `GridLayout` component: - A method to delete a panel - A method to replace a panel - A method to add a panel with a given size and placement technique (`'placeAtTop' | 'findTopLeftMostOpenSpace'`) - Currently, we only support adding a panel to the first row, since this is all that is necessary for parity with the current Dashboard layout engine - we can revisit this decision as part of the [row API](elastic#195807). - A method to get panel count - This might not be necessary for the dashboard (we'll see), but I needed it for the example plugin to be able to generate suggested panel IDs. It's possible this will get removed 🤷 - The ability to serialize the grid layout state I only included the bare minimum here that I know will be necessary for a dashboard integration, but it's possible I missed some things and so this API will most likely expand in the future. https://github.com/user-attachments/assets/28df844c-5c12-40fd-b4f4-8fbd1a8abc20 ### Serialization With respect to serialization, there are still some open questions about how we want to handle it from the Dashboard side - therefore, in this PR, I opted to keep the serialization as simple as possible (i.e. both the input and serialized output take identical forms for the `GridLayout` component). Our goal is to keep `kbn-grid-layout` as **generic** as possible so, while I considered making the serialize method return the form that the Dashboard expects, I ultimately decided against that; instead, I think Dashboard should be responsible for taking the grid layout's serialized form and turning it into a dashboard-specific serialization of a grid layout and vice-versa for deserializing and sending the initial layout to the `GridLayout` component. The dashboard grid layout serialization will be tackled as part of elastic#190446, where it's possible my opinion might change :) This is just a first draft of the `kbn-grid-layout` API, after all. ### Example Grid Layout In the grid layout example plugin, I integrated the API by adding some pretty bare-bones buttons to each panel in order to ensure the API works as expected - that being said, I didn't worry too much about the design of these things and so it looks pretty ugly 😆 My next step is elastic#190379, where I will have to integrate the grid layout API with the embeddable actions, at which point the design will be improved - so this is a very temporary state :bow: ### Checklist - [x] 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) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### 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 <[email protected]>
- Loading branch information
Showing
17 changed files
with
775 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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 React, { useState } from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiCallOut, | ||
EuiFieldText, | ||
EuiModal, | ||
EuiModalBody, | ||
EuiModalFooter, | ||
EuiModalHeader, | ||
EuiModalHeaderTitle, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
import { CoreStart } from '@kbn/core-lifecycle-browser'; | ||
import { toMountPoint } from '@kbn/react-kibana-mount'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const PanelIdModal = ({ | ||
suggestion, | ||
onClose, | ||
onSubmit, | ||
}: { | ||
suggestion: string; | ||
onClose: () => void; | ||
onSubmit: (id: string) => void; | ||
}) => { | ||
const [panelId, setPanelId] = useState<string>(suggestion); | ||
|
||
return ( | ||
<EuiModal onClose={onClose}> | ||
<EuiModalHeader> | ||
<EuiModalHeaderTitle> | ||
{i18n.translate('examples.gridExample.getPanelIdModalTitle', { | ||
defaultMessage: 'Panel ID', | ||
})} | ||
</EuiModalHeaderTitle> | ||
</EuiModalHeader> | ||
<EuiModalBody> | ||
<EuiCallOut | ||
color="warning" | ||
title={i18n.translate('examples.gridExample.getPanelIdWarning', { | ||
defaultMessage: 'Ensure the panel ID is unique, or you may get unexpected behaviour.', | ||
})} | ||
/> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<EuiFieldText | ||
placeholder={suggestion} | ||
value={panelId} | ||
onChange={(e) => { | ||
setPanelId(e.target.value ?? ''); | ||
}} | ||
/> | ||
</EuiModalBody> | ||
<EuiModalFooter> | ||
<EuiButton | ||
onClick={() => { | ||
onSubmit(panelId); | ||
}} | ||
> | ||
{i18n.translate('examples.gridExample.getPanelIdSubmitButton', { | ||
defaultMessage: 'Submit', | ||
})} | ||
</EuiButton> | ||
</EuiModalFooter> | ||
</EuiModal> | ||
); | ||
}; | ||
|
||
export const getPanelId = async ({ | ||
coreStart, | ||
suggestion, | ||
}: { | ||
coreStart: CoreStart; | ||
suggestion: string; | ||
}): Promise<string | undefined> => { | ||
return new Promise<string | undefined>((resolve) => { | ||
const session = coreStart.overlays.openModal( | ||
toMountPoint( | ||
<PanelIdModal | ||
suggestion={suggestion} | ||
onClose={() => { | ||
resolve(undefined); | ||
session.close(); | ||
}} | ||
onSubmit={(newPanelId) => { | ||
resolve(newPanelId); | ||
session.close(); | ||
}} | ||
/>, | ||
{ | ||
theme: coreStart.theme, | ||
i18n: coreStart.i18n, | ||
} | ||
) | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.