-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specify filters for Office365 search bar (#3533)
* feat(filter-office365): Added specified filters to searchbar on Office365 * feat(configuration-view): Separated responsibilities of use-value-suggestion. Added new helper. * feat(configuration-view): PR comments * feat(configuration-view): Improvements TS on helper * feat(filter-office365): Replaced switch by dictionary, added another example of custom field * doc(changelog): Update * feat(filter-office365): Added options and filterByKey property for custom filters. * feat: add multi-select filter * remove DEVELOPER GUIDE * fix: no filters found incorrectly displayed * feat(filter-office365): Fixed onChange from searchBar and added onRemove handler. * feat(filter-office365): Fixed onSearch on multi-select component. added support to use query on se-value-suggestion for predefined options. * feat(filter-office365): Implement multiSelect for all filters. * feat(filter-office365): PR comments * delete combobox component and fix is one of filters Co-authored-by: Franco Charriol <francocharriol@gmail.com> Co-authored-by: Ezequiel Airaudo <36004787+eze9252@users.noreply.github.com>
- Loading branch information
1 parent
2b7a899
commit 17b7105
Showing
10 changed files
with
276 additions
and
62 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,3 +346,4 @@ export const UI_TOAST_COLOR = { | |
WARNING: 'warning', | ||
DANGER: 'danger', | ||
}; | ||
|
26 changes: 0 additions & 26 deletions
26
public/components/common/custom-search-bar/components/combobox.tsx
This file was deleted.
Oops, something went wrong.
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
160 changes: 160 additions & 0 deletions
160
public/components/common/custom-search-bar/components/multi-select.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,160 @@ | ||
/* | ||
* Wazuh app - React component Multi-select | ||
* Copyright (C) 2015-2021 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
EuiFieldSearch, | ||
EuiFilterButton, | ||
EuiFilterGroup, | ||
EuiFilterSelectItem, | ||
EuiIcon, | ||
EuiLoadingChart, | ||
EuiPopover, | ||
EuiPopoverTitle, | ||
EuiSpacer, | ||
FilterChecked, | ||
} from '@elastic/eui'; | ||
import { IValueSuggestion, useValueSuggestion } from '../../hooks'; | ||
|
||
const ON = 'on'; | ||
const OFF = 'off'; | ||
|
||
export const MultiSelect = ({ item, onChange, selectedOptions, onRemove }) => { | ||
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false); | ||
const { suggestedValues, isLoading, setQuery }: IValueSuggestion = useValueSuggestion( | ||
item.key, | ||
item?.options | ||
); | ||
const [items, setItems] = useState< | ||
{ key: any; label: any; value: any; checked: FilterChecked }[] | ||
>([]); | ||
const [activeFilters, setActiveFilters] = useState<number>(0); | ||
|
||
useEffect(() => { | ||
if (!isLoading) { | ||
setItems( | ||
suggestedValues | ||
.map((value, key) => ({ | ||
key: key, | ||
label: value, | ||
value: item.key, | ||
filterByKey: item.filterByKey, | ||
checked: OFF as FilterChecked, | ||
})) | ||
.sort((a, b) => a.label - b.label) | ||
); | ||
} | ||
}, [suggestedValues, isLoading]); | ||
|
||
useEffect(() => { | ||
setItems( | ||
items.map((item) => ({ | ||
...item, | ||
checked: selectedOptions.find((element) => element.label === filterBy(item)) ? ON : OFF, | ||
})) | ||
); | ||
setActiveFilters(selectedOptions.length); | ||
}, [selectedOptions]); | ||
|
||
const filterBy = (item) => { | ||
return item.filterByKey ? item.key.toString() : item.label; | ||
}; | ||
|
||
const toggleFilter = (item) => { | ||
item.checked = item.checked === ON ? OFF : ON; | ||
updateFilters(item.value); | ||
}; | ||
|
||
const updateFilters = (id) => { | ||
const selectedItems = items.filter((item) => item.checked === ON); | ||
setActiveFilters(selectedItems.length); | ||
if (selectedItems.length) { | ||
onChange(selectedItems,id); | ||
} else { | ||
onRemove(item.key); | ||
} | ||
}; | ||
|
||
const onSearch = (selectedOptions) => { | ||
setQuery(selectedOptions.target.value); | ||
}; | ||
|
||
const onButtonClick = () => { | ||
setIsPopoverOpen(!isPopoverOpen); | ||
}; | ||
|
||
const closePopover = () => { | ||
setIsPopoverOpen(false); | ||
setQuery(''); | ||
}; | ||
|
||
const button = ( | ||
<EuiFilterButton | ||
iconType="arrowDown" | ||
onClick={onButtonClick} | ||
isSelected={isPopoverOpen} | ||
numFilters={selectedOptions.length} | ||
hasActiveFilters={activeFilters > 0} | ||
numActiveFilters={activeFilters} | ||
> | ||
{item.placeholder} | ||
</EuiFilterButton> | ||
); | ||
|
||
return ( | ||
<EuiFilterGroup data-test-subj={`multiSelect-${item.key}`}> | ||
<EuiPopover | ||
id={`popoverMultiSelect-${item.key}`} | ||
ownFocus | ||
button={button} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
panelPaddingSize="none" | ||
withTitle | ||
> | ||
<EuiPopoverTitle> | ||
<EuiFieldSearch onChange={onSearch} /> | ||
</EuiPopoverTitle> | ||
<div className="euiFilterSelect__items"> | ||
{items.map((item) => ( | ||
<EuiFilterSelectItem | ||
checked={item.checked} | ||
key={item.key} | ||
onClick={() => toggleFilter(item)} | ||
showIcons={item.checked === ON} | ||
> | ||
{item.label} | ||
</EuiFilterSelectItem> | ||
))} | ||
{isLoading && ( | ||
<div className="euiFilterSelect__note"> | ||
<div className="euiFilterSelect__noteContent"> | ||
<EuiLoadingChart size="m" /> | ||
<EuiSpacer size="xs" /> | ||
<p>Loading filters</p> | ||
</div> | ||
</div> | ||
)} | ||
{suggestedValues.length === 0 && ( | ||
<div className="euiFilterSelect__note"> | ||
<div className="euiFilterSelect__noteContent"> | ||
<EuiIcon type="minusInCircle" /> | ||
<EuiSpacer size="xs" /> | ||
<p>No filters found</p> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</EuiPopover> | ||
</EuiFilterGroup> | ||
); | ||
}; |
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
Oops, something went wrong.