Skip to content

Commit

Permalink
[Lens] show the standard Lens "Requires field" validation message for…
Browse files Browse the repository at this point in the history
… empty visualization for inline editing
  • Loading branch information
mbondyra committed Mar 11, 2024
1 parent 9500c3b commit eeecfe0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,38 @@ describe('LayerPanel', () => {
expect(screen.getByText('Requires field')).toBeInTheDocument();
});

it('should not render the required warning when the chart is empty', async () => {
mockVisualization.getConfiguration.mockReturnValue({
groups: [
{
...defaultGroup,
groupLabel: 'B',
groupId: 'b',
requiredMinDimensionCount: 1,
},
],
});

renderLayerPanel();
expect(screen.queryByText('Requires field')).not.toBeInTheDocument();
});

it('should render the required warning when the chart is empty but isInlineEditing', async () => {
mockVisualization.getConfiguration.mockReturnValue({
groups: [
{
...defaultGroup,
groupLabel: 'B',
groupId: 'b',
requiredMinDimensionCount: 1,
},
],
});

renderLayerPanel({ setIsInlineFlyoutVisible: jest.fn() });
expect(screen.queryByText('Requires field')).toBeInTheDocument();
});

it('should tell the user to remove the correct number of dimensions', async () => {
mockVisualization.getConfiguration.mockReturnValue({
groups: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export function LayerPanel(props: LayerPanelProps) {
shouldDisplayChartSwitch,
} = props;

const isInlineEditing = Boolean(props?.setIsInlineFlyoutVisible);

const isSaveable = useLensSelector((state) => state.lens.isSaveable);

const datasourceStates = useLensSelector(selectDatasourceStates);
Expand Down Expand Up @@ -434,7 +436,7 @@ export function LayerPanel(props: LayerPanelProps) {
.map((group, groupIndex) => {
let errorText: string = '';

if (!isEmptyLayer) {
if (!isEmptyLayer || isInlineEditing) {
if (
group.requiredMinDimensionCount &&
group.requiredMinDimensionCount > group.accessors.length
Expand Down Expand Up @@ -659,7 +661,7 @@ export function LayerPanel(props: LayerPanelProps) {
handleClose={() => {
setPanelSettingsOpen(false);
}}
isInlineEditing={Boolean(props?.setIsInlineFlyoutVisible)}
isInlineEditing={isInlineEditing}
>
<div id={layerId}>
<div className="lnsIndexPatternDimensionEditor--padded">
Expand Down Expand Up @@ -726,7 +728,7 @@ export function LayerPanel(props: LayerPanelProps) {
isOpen={isDimensionPanelOpen}
isFullscreen={isFullscreen}
label={openColumnGroup?.dimensionEditorGroupLabel ?? (openColumnGroup?.groupLabel || '')}
isInlineEditing={Boolean(props?.setIsInlineFlyoutVisible)}
isInlineEditing={isInlineEditing}
handleClose={closeDimensionEditor}
panel={
<>
Expand Down Expand Up @@ -786,7 +788,7 @@ export function LayerPanel(props: LayerPanelProps) {
addLayer: props.addLayer,
removeLayer: props.onRemoveLayer,
panelRef,
isInlineEditing: Boolean(props?.setIsInlineFlyoutVisible),
isInlineEditing,
}}
/>
</div>
Expand Down

0 comments on commit eeecfe0

Please sign in to comment.