Skip to content

Commit

Permalink
Merge pull request #898 from akto-api-security/fix/add_selectAll_in_d…
Browse files Browse the repository at this point in the history
…ropdown_list

added select all feature in dropdown
  • Loading branch information
notshivansh authored Feb 21, 2024
2 parents 19c3613 + 63192ce commit 8f74188
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Autocomplete, Avatar, Icon, TextContainer } from '@shopify/polaris';
import { Autocomplete, Avatar, Checkbox, Icon, TextContainer } from '@shopify/polaris';
import { SearchMinor, ChevronDownMinor } from '@shopify/polaris-icons';
import React, { useState, useCallback, useEffect } from 'react';
import func from "@/util/func";
Expand All @@ -13,6 +13,7 @@ function DropdownSearch(props) {
const [inputValue, setInputValue] = useState(value ? value : undefined);
const [options, setOptions] = useState(deselectedOptions);
const [loading, setLoading] = useState(false);
const [checked,setChecked] = useState(false)


useEffect(() => {
Expand Down Expand Up @@ -102,6 +103,18 @@ function DropdownSearch(props) {
[options],
);

const selectAllFunc = () => {
if(!checked){
const valueArr = deselectedOptions.map((obj) => obj.value)
updateSelection(valueArr)
setChecked(true)
}else{
setChecked(false)
updateSelection([])
}

}

const textField = (
<Autocomplete.TextField
id={id}
Expand All @@ -122,6 +135,9 @@ function DropdownSearch(props) {
/>
);

const showSelectAll = (allowMultiple && optionsList.length > 5)
const checkboxLabel = checked ? "Deselect all" : "Select all"

const emptyState = (
<React.Fragment>
<Icon source={SearchMinor} />
Expand All @@ -141,6 +157,10 @@ function DropdownSearch(props) {
loading={loading}
textField={textField}
preferredPosition='below'
{...(showSelectAll ? {actionBefore:{
content:(<Checkbox label={checkboxLabel} checked={checked} onChange={() => selectAllFunc()}/>),
onAction: () => selectAllFunc(),
}} : {})}
/>
);
}
Expand Down

0 comments on commit 8f74188

Please sign in to comment.