-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Split apart config panel component to more manageable chunks (#…
…63910) * [Lens] Split apart config panel component to more manageable chunks * Moving around and renaming SASS appropriately * Remove layer limit Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: cchaos <caroline.horn@elastic.co>
- Loading branch information
1 parent
f7ea9b9
commit dd094f2
Showing
20 changed files
with
832 additions
and
723 deletions.
There are no files selected for viewing
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/_config_panel.scss
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,7 @@ | ||
.lnsConfigPanel__addLayerBtn { | ||
color: transparentize($euiColorMediumShade, .3); | ||
// Remove EuiButton's default shadow to make button more subtle | ||
// sass-lint:disable-block no-important | ||
box-shadow: none !important; | ||
border: 1px dashed currentColor; | ||
} |
9 changes: 9 additions & 0 deletions
9
...lugins/lens/public/editor_frame_service/editor_frame/config_panel/_dimension_popover.scss
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,9 @@ | ||
.lnsDimensionPopover { | ||
line-height: 0; | ||
flex-grow: 1; | ||
} | ||
|
||
.lnsDimensionPopover__trigger { | ||
max-width: 100%; | ||
display: block; | ||
} |
4 changes: 4 additions & 0 deletions
4
x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/_index.scss
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,4 @@ | ||
@import 'chart_switch'; | ||
@import 'config_panel'; | ||
@import 'dimension_popover'; | ||
@import 'layer_panel'; |
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
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
177 changes: 177 additions & 0 deletions
177
x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.tsx
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,177 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useMemo, memo } from 'react'; | ||
import { EuiFlexItem, EuiToolTip, EuiButton, EuiForm } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { Visualization } from '../../../types'; | ||
import { ChartSwitch } from './chart_switch'; | ||
import { LayerPanel } from './layer_panel'; | ||
import { trackUiEvent } from '../../../lens_ui_telemetry'; | ||
import { generateId } from '../../../id_generator'; | ||
import { removeLayer, appendLayer } from './layer_actions'; | ||
import { ConfigPanelWrapperProps } from './types'; | ||
|
||
export const ConfigPanelWrapper = memo(function ConfigPanelWrapper(props: ConfigPanelWrapperProps) { | ||
const activeVisualization = props.visualizationMap[props.activeVisualizationId || '']; | ||
const { visualizationState } = props; | ||
|
||
return ( | ||
<> | ||
<ChartSwitch | ||
data-test-subj="lnsChartSwitcher" | ||
visualizationMap={props.visualizationMap} | ||
visualizationId={props.activeVisualizationId} | ||
visualizationState={props.visualizationState} | ||
datasourceMap={props.datasourceMap} | ||
datasourceStates={props.datasourceStates} | ||
dispatch={props.dispatch} | ||
framePublicAPI={props.framePublicAPI} | ||
/> | ||
{activeVisualization && visualizationState && ( | ||
<LayerPanels {...props} activeVisualization={activeVisualization} /> | ||
)} | ||
</> | ||
); | ||
}); | ||
|
||
function LayerPanels( | ||
props: ConfigPanelWrapperProps & { | ||
activeDatasourceId: string; | ||
activeVisualization: Visualization; | ||
} | ||
) { | ||
const { | ||
framePublicAPI, | ||
activeVisualization, | ||
visualizationState, | ||
dispatch, | ||
activeDatasourceId, | ||
datasourceMap, | ||
} = props; | ||
const setVisualizationState = useMemo( | ||
() => (newState: unknown) => { | ||
props.dispatch({ | ||
type: 'UPDATE_VISUALIZATION_STATE', | ||
visualizationId: activeVisualization.id, | ||
newState, | ||
clearStagedPreview: false, | ||
}); | ||
}, | ||
[props.dispatch, activeVisualization] | ||
); | ||
const updateDatasource = useMemo( | ||
() => (datasourceId: string, newState: unknown) => { | ||
props.dispatch({ | ||
type: 'UPDATE_DATASOURCE_STATE', | ||
updater: () => newState, | ||
datasourceId, | ||
clearStagedPreview: false, | ||
}); | ||
}, | ||
[props.dispatch] | ||
); | ||
const updateAll = useMemo( | ||
() => (datasourceId: string, newDatasourceState: unknown, newVisualizationState: unknown) => { | ||
props.dispatch({ | ||
type: 'UPDATE_STATE', | ||
subType: 'UPDATE_ALL_STATES', | ||
updater: prevState => { | ||
return { | ||
...prevState, | ||
datasourceStates: { | ||
...prevState.datasourceStates, | ||
[datasourceId]: { | ||
state: newDatasourceState, | ||
isLoading: false, | ||
}, | ||
}, | ||
visualization: { | ||
...prevState.visualization, | ||
state: newVisualizationState, | ||
}, | ||
stagedPreview: undefined, | ||
}; | ||
}, | ||
}); | ||
}, | ||
[props.dispatch] | ||
); | ||
const layerIds = activeVisualization.getLayerIds(visualizationState); | ||
|
||
return ( | ||
<EuiForm className="lnsConfigPanel"> | ||
{layerIds.map(layerId => ( | ||
<LayerPanel | ||
{...props} | ||
key={layerId} | ||
layerId={layerId} | ||
activeVisualization={activeVisualization} | ||
visualizationState={visualizationState} | ||
updateVisualization={setVisualizationState} | ||
updateDatasource={updateDatasource} | ||
updateAll={updateAll} | ||
frame={framePublicAPI} | ||
isOnlyLayer={layerIds.length === 1} | ||
onRemoveLayer={() => { | ||
dispatch({ | ||
type: 'UPDATE_STATE', | ||
subType: 'REMOVE_OR_CLEAR_LAYER', | ||
updater: state => | ||
removeLayer({ | ||
activeVisualization, | ||
layerId, | ||
trackUiEvent, | ||
datasourceMap, | ||
state, | ||
}), | ||
}); | ||
}} | ||
/> | ||
))} | ||
{activeVisualization.appendLayer && visualizationState && ( | ||
<EuiFlexItem grow={true}> | ||
<EuiToolTip | ||
className="eui-fullWidth" | ||
content={i18n.translate('xpack.lens.xyChart.addLayerTooltip', { | ||
defaultMessage: | ||
'Use multiple layers to combine chart types or visualize different index patterns.', | ||
})} | ||
position="bottom" | ||
> | ||
<EuiButton | ||
className="lnsConfigPanel__addLayerBtn" | ||
fullWidth | ||
size="s" | ||
data-test-subj="lnsXY_layer_add" | ||
aria-label={i18n.translate('xpack.lens.xyChart.addLayerButton', { | ||
defaultMessage: 'Add layer', | ||
})} | ||
title={i18n.translate('xpack.lens.xyChart.addLayerButton', { | ||
defaultMessage: 'Add layer', | ||
})} | ||
onClick={() => { | ||
dispatch({ | ||
type: 'UPDATE_STATE', | ||
subType: 'ADD_LAYER', | ||
updater: state => | ||
appendLayer({ | ||
activeVisualization, | ||
generateId, | ||
trackUiEvent, | ||
activeDatasource: datasourceMap[activeDatasourceId], | ||
state, | ||
}), | ||
}); | ||
}} | ||
iconType="plusInCircleFilled" | ||
/> | ||
</EuiToolTip> | ||
</EuiFlexItem> | ||
)} | ||
</EuiForm> | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
.../plugins/lens/public/editor_frame_service/editor_frame/config_panel/dimension_popover.tsx
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,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiPopover } from '@elastic/eui'; | ||
import { VisualizationDimensionGroupConfig } from '../../../types'; | ||
import { DimensionPopoverState } from './types'; | ||
|
||
export function DimensionPopover({ | ||
popoverState, | ||
setPopoverState, | ||
groups, | ||
accessor, | ||
groupId, | ||
trigger, | ||
panel, | ||
}: { | ||
popoverState: DimensionPopoverState; | ||
setPopoverState: (newState: DimensionPopoverState) => void; | ||
groups: VisualizationDimensionGroupConfig[]; | ||
accessor: string; | ||
groupId: string; | ||
trigger: React.ReactElement; | ||
panel: React.ReactElement; | ||
}) { | ||
const noMatch = popoverState.isOpen ? !groups.some(d => d.accessors.includes(accessor)) : false; | ||
return ( | ||
<EuiPopover | ||
className="lnsDimensionPopover" | ||
anchorClassName="lnsDimensionPopover__trigger" | ||
isOpen={ | ||
popoverState.isOpen && | ||
(popoverState.openId === accessor || (noMatch && popoverState.addingToGroupId === groupId)) | ||
} | ||
closePopover={() => { | ||
setPopoverState({ isOpen: false, openId: null, addingToGroupId: null }); | ||
}} | ||
button={trigger} | ||
anchorPosition="leftUp" | ||
withTitle | ||
panelPaddingSize="s" | ||
> | ||
{panel} | ||
</EuiPopover> | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/index.ts
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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { ConfigPanelWrapper } from './config_panel'; |
File renamed without changes.
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.