-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Controls Anywhere] Convert time slider to embeddable #238998
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
base: controlsAnywhere
Are you sure you want to change the base?
Changes from 7 commits
e11e24e
2a12163
6996a94
dc2255f
ccb3fca
9fa97ca
c6b82a9
8ff6037
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import { apiCanAddNewPanel, apiCanPinPanel } from '@kbn/presentation-containers'; | ||
import { type EmbeddableApiContext } from '@kbn/presentation-publishing'; | ||
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public'; | ||
import type { ActionDefinition } from '@kbn/ui-actions-plugin/public/actions'; | ||
import { TIME_SLIDER_CONTROL } from '@kbn/controls-constants'; | ||
import { apiPublishesLayout } from '@kbn/dashboard-plugin/public'; | ||
import { map } from 'rxjs'; | ||
import { ACTION_CREATE_TIME_SLIDER } from './constants'; | ||
|
||
const compatibilityCheck = (api: unknown | null) => | ||
apiCanAddNewPanel(api) && | ||
apiCanPinPanel(api) && | ||
apiPublishesLayout(api) && | ||
!Object.values(api.layout$.getValue().controls).find( | ||
(control) => control.type === TIME_SLIDER_CONTROL | ||
); | ||
|
||
export const createTimeSliderAction = (): ActionDefinition<EmbeddableApiContext> => ({ | ||
id: ACTION_CREATE_TIME_SLIDER, | ||
order: 0, | ||
getIconType: () => 'controlsHorizontal', | ||
couldBecomeCompatible: ({ embeddable }) => | ||
apiCanAddNewPanel(embeddable) && apiCanPinPanel(embeddable), | ||
getCompatibilityChangesSubject: ({ embeddable }) => | ||
apiPublishesLayout(embeddable) ? embeddable.layout$.pipe(map(() => undefined)) : undefined, | ||
isCompatible: async ({ embeddable }) => compatibilityCheck(embeddable), | ||
execute: async ({ embeddable }) => { | ||
if (!apiCanAddNewPanel(embeddable) || !apiCanPinPanel(embeddable)) | ||
throw new IncompatibleActionError(); | ||
const newPanel = await embeddable.addNewPanel<{}, { uuid: string }>({ | ||
panelType: TIME_SLIDER_CONTROL, | ||
serializedState: { | ||
rawState: {}, | ||
}, | ||
}); | ||
if (!newPanel) throw new Error('Failed tp create time slider panel'); | ||
embeddable.pinPanel(newPanel.uuid); | ||
}, | ||
getDisplayName: () => | ||
i18n.translate('controls.timeSlider.displayNameAriaLabel', { | ||
defaultMessage: 'Time slider', | ||
}), | ||
|
||
getDisplayNameTooltip: ({ embeddable }) => | ||
compatibilityCheck(embeddable) | ||
? i18n.translate('controls.timeSlider.tooltip', { | ||
defaultMessage: 'Add a time slider control to your dashboard.', | ||
}) | ||
: i18n.translate('controls.timeSlider.disabledTooltip', { | ||
defaultMessage: 'Only one time slider control can be added per dashboard.', | ||
}), | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ import { areLayoutsEqual } from './are_layouts_equal'; | |
import { deserializeLayout } from './deserialize_layout'; | ||
import { serializeLayout } from './serialize_layout'; | ||
import type { DashboardChildren, DashboardLayout, DashboardLayoutPanel } from './types'; | ||
import { TIME_SLIDER_CONTROL } from '@kbn/controls-constants'; | ||
|
||
export function initializeLayoutManager( | ||
incomingEmbeddable: EmbeddablePackageState | undefined, | ||
|
@@ -495,6 +496,9 @@ export function initializeLayoutManager( | |
newControls[uuid] = { | ||
type: controlToPin.type as StickyControlLayoutState['type'], | ||
order: Object.keys(newControls).length, | ||
// TODO Remove this when grow and width settings for pinned controls are implemented | ||
// https://github.com/elastic/kibana/issues/234681 | ||
...(controlToPin.type === TIME_SLIDER_CONTROL ? { width: 'large', grow: true } : {}), | ||
Comment on lines
+499
to
+501
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is not a |
||
}; | ||
const newPanels = { ...layout$.getValue().panels }; | ||
delete newPanels[uuid]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should combine this into a single action - i.e. don't create then pin, just add a new function
addPinnedPanel
to the Dashboard API. What do you think @Zacqary?