Skip to content
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

[Lens] show the "Requires field" validation message for empty visualization for inline editing #178393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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