Skip to content

Commit

Permalink
move layer settings action to layer panel
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Nov 14, 2022
1 parent 4152ecc commit 3a326a4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 47 deletions.
17 changes: 0 additions & 17 deletions x-pack/plugins/lens/public/datasources/form_based/form_based.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,23 +618,6 @@ export function getFormBasedDatasource({

getDropProps,
onDrop,
getSupportedActionsForLayer(layerId, state, _, openLayerSettings) {
if (!openLayerSettings) {
return [];
}
return [
{
id: 'openLayerSettings',
displayName: i18n.translate('xpack.lens.indexPattern.layerSettingsAction', {
defaultMessage: 'Layer settings',
}),
execute: openLayerSettings,
icon: 'gear',
isCompatible: Boolean(state.layers[layerId]),
'data-test-subj': 'lnsLayerSettings',
},
];
},

getCustomWorkspaceRenderer: (
state: FormBasedPrivateState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { LayerType } from '../../../..';
import type { LayerAction, Visualization } from '../../../../types';
import { getCloneLayerAction } from './clone_layer_action';
import { getRemoveLayerAction } from './remove_layer_action';
import { getOpenLayerSettingsAction } from './open_layer_settings';

export interface LayerActionsProps {
layerIndex: number;
Expand All @@ -36,6 +37,8 @@ export const getSharedActions = ({
activeVisualization,
isOnlyLayer,
isTextBasedLanguage,
hasLayerSettings,
openLayerSettings,
onCloneLayer,
onRemoveLayer,
}: {
Expand All @@ -48,8 +51,14 @@ export const getSharedActions = ({
visualizationState: unknown;
layerType?: LayerType;
isTextBasedLanguage?: boolean;
hasLayerSettings: boolean;
openLayerSettings: () => void;
core: Pick<CoreStart, 'overlays' | 'theme'>;
}) => [
getOpenLayerSettingsAction({
hasLayerSettings,
openLayerSettings,
}),
getCloneLayerAction({
execute: onCloneLayer,
layerIndex,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import type { LayerAction } from '../../../../types';

export const getOpenLayerSettingsAction = (props: {
openLayerSettings: () => void;
hasLayerSettings: boolean;
}): LayerAction => {
const displayName = i18n.translate('xpack.lens.layerActions.layerSettingsAction', {
defaultMessage: 'Layer settings',
});

return {
id: 'openLayerSettings',
displayName,
execute: props.openLayerSettings,
icon: 'gear',
isCompatible: props.hasLayerSettings,
'data-test-subj': 'lnsLayerSettings',
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ import { onDropForVisualization, shouldRemoveSource } from './buttons/drop_targe
import { getSharedActions } from './layer_actions/layer_actions';
import { FlyoutContainer } from './flyout_container';

// hide the random sampling settings from the UI
const DISPLAY_RANDOM_SAMPLING_SETTINGS = false;

const initialActiveDimensionState = {
isNew: false,
};
Expand Down Expand Up @@ -330,12 +333,6 @@ export function LayerPanel(
);
},
})) || []),
...(layerDatasource?.getSupportedActionsForLayer?.(
layerId,
layerDatasourceState,
(newState) => updateDatasource(datasourceId, newState),
() => setPanelSettingsOpen(true)
) || []),
...getSharedActions({
layerId,
activeVisualization,
Expand All @@ -345,23 +342,25 @@ export function LayerPanel(
layerType: activeVisualization.getLayerType(layerId, visualizationState),
isOnlyLayer,
isTextBasedLanguage,
hasLayerSettings: Boolean(
activeVisualization.renderLayerSettings ||
(layerDatasource?.renderLayerSettings && DISPLAY_RANDOM_SAMPLING_SETTINGS)
),
openLayerSettings: () => setPanelSettingsOpen(true),
onCloneLayer,
onRemoveLayer: () => onRemoveLayer(layerId),
}),
].filter((i) => i.isCompatible),
[
activeVisualization,
core,
datasourceId,
isOnlyLayer,
isTextBasedLanguage,
layerDatasource,
layerDatasourceState,
layerId,
layerIndex,
onCloneLayer,
onRemoveLayer,
updateDatasource,
updateVisualization,
visualizationState,
]
Expand Down Expand Up @@ -688,25 +687,25 @@ export function LayerPanel(
>
<div id={layerId}>
<div className="lnsIndexPatternDimensionEditor--padded lnsIndexPatternDimensionEditor--collapseNext">
{layerDatasource?.renderLayerSettings && (
<NativeRenderer
render={layerDatasource.renderLayerSettings}
nativeProps={layerDatasourceConfigProps}
/>
)}
{activeVisualization?.renderLayerSettings && (
{layerDatasource?.renderLayerSettings && DISPLAY_RANDOM_SAMPLING_SETTINGS && (
<>
<EuiSpacer size="m" />
<NativeRenderer
render={activeVisualization?.renderLayerSettings}
nativeProps={{
...layerVisualizationConfigProps,
setState: props.updateVisualization,
panelRef: settingsPanelRef,
}}
render={layerDatasource.renderLayerSettings}
nativeProps={layerDatasourceConfigProps}
/>
<EuiSpacer size="m" />
</>
)}
{activeVisualization?.renderLayerSettings && (
<NativeRenderer
render={activeVisualization?.renderLayerSettings}
nativeProps={{
...layerVisualizationConfigProps,
setState: props.updateVisualization,
panelRef: settingsPanelRef,
}}
/>
)}
</div>
</div>
</FlyoutContainer>
Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,6 @@ export interface Datasource<T = unknown, P = unknown> {
*/
getUsedDataViews: (state: T) => string[];

getSupportedActionsForLayer?: (
layerId: string,
state: T,
setState: StateSetter<T>,
openLayerSettings?: () => void
) => LayerAction[];

getDatasourceInfo: (
state: T,
references?: SavedObjectReference[],
Expand Down

0 comments on commit 3a326a4

Please sign in to comment.