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

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 @@ -56,7 +56,7 @@ const renderComponent = ({
);
};

const getSelectAllCheckbox = () => screen.getByRole('checkbox', { name: /Select all/i });
const getSelectAllCheckbox = () => screen.queryByRole('checkbox', { name: /Select all/i });

const getSearchInput = () => screen.getByRole('searchbox', { name: /Filter suggestions/i });

Expand Down Expand Up @@ -93,6 +93,16 @@ describe('Options list popover', () => {
expect(getSelectAllCheckbox()).not.toBeChecked();
});

test('hides "Select all" checkbox if the control only allows single selections', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see a test addition here!

const contextMock = getOptionsListContextMock();
contextMock.componentApi.setTotalCardinality(80);
contextMock.componentApi.setAvailableOptions(take(allOptions, 10));
contextMock.componentApi.setSingleSelect(true);
renderComponent(contextMock);

expect(getSelectAllCheckbox()).not.toBeInTheDocument();
});

test('Select all is checked when all available options are selected ', async () => {
const contextMock = getOptionsListContextMock();
contextMock.componentApi.setTotalCardinality(80);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const OptionsListPopoverActionBar = ({
allowExpensiveQueries,
availableOptions = [],
dataLoading,
singleSelect,
] = useBatchedPublishingSubjects(
componentApi.searchTechnique$,
componentApi.searchStringValid$,
Expand All @@ -97,7 +98,8 @@ export const OptionsListPopoverActionBar = ({
componentApi.fieldName$,
componentApi.parentApi.allowExpensiveQueries$,
componentApi.availableOptions$,
componentApi.dataLoading$
componentApi.dataLoading$,
componentApi.singleSelect$
);

const compatibleSearchTechniques = useMemo(() => {
Expand Down Expand Up @@ -188,38 +190,40 @@ export const OptionsListPopoverActionBar = ({
</EuiFlexItem>
</>
)}
<EuiFlexItem grow={false}>
<EuiToolTip
content={
hasTooManyOptions
? OptionsListStrings.popover.getMaximumBulkSelectionTooltip()
: undefined
}
>
<EuiCheckbox
checked={areAllSelected}
id={`optionsList-control-selectAll-checkbox-${componentApi.uuid}`}
// indeterminate={selectedOptions.length > 0 && !areAllSelected}
disabled={isBulkSelectDisabled}
data-test-subj="optionsList-control-selectAll"
onChange={() => {
if (areAllSelected) {
handleBulkAction(componentApi.deselectAll);
setAllSelected(false);
} else {
handleBulkAction(componentApi.selectAll);
setAllSelected(true);
}
}}
css={styles.selectAllCheckbox}
label={
<EuiText size="xs">
{OptionsListStrings.popover.getSelectAllButtonLabel()}
</EuiText>
{!singleSelect && (
<EuiFlexItem grow={false}>
<EuiToolTip
content={
hasTooManyOptions
? OptionsListStrings.popover.getMaximumBulkSelectionTooltip()
: undefined
}
/>
</EuiToolTip>
</EuiFlexItem>
>
<EuiCheckbox
checked={areAllSelected}
id={`optionsList-control-selectAll-checkbox-${componentApi.uuid}`}
// indeterminate={selectedOptions.length > 0 && !areAllSelected}
disabled={isBulkSelectDisabled}
data-test-subj="optionsList-control-selectAll"
onChange={() => {
if (areAllSelected) {
handleBulkAction(componentApi.deselectAll);
setAllSelected(false);
} else {
handleBulkAction(componentApi.selectAll);
setAllSelected(true);
}
}}
css={styles.selectAllCheckbox}
label={
<EuiText size="xs">
{OptionsListStrings.popover.getSelectAllButtonLabel()}
</EuiText>
}
/>
</EuiToolTip>
</EuiFlexItem>
)}
<EuiFlexItem grow={true}>
<EuiFlexGroup
gutterSize="xs"
Expand Down