[Security Solution][Detection Rules] Fixes rules table tag display bug (#85229)

This commit is contained in:
Davis Plumlee 2020-12-08 17:45:00 -05:00 committed by GitHub
parent 943bce1512
commit 8c8e96ff88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 1 deletions

View file

@ -503,6 +503,7 @@ export const AllRules = React.memo<AllRulesProps>(
onFilterChanged={onFilterChangedCallback}
rulesCustomInstalled={rulesCustomInstalled}
rulesInstalled={rulesInstalled}
currentFilterTags={filterOptions.tags ?? []}
/>
</HeaderSection>

View file

@ -18,6 +18,7 @@ describe('RulesTableFilters', () => {
onFilterChanged={jest.fn()}
rulesCustomInstalled={null}
rulesInstalled={null}
currentFilterTags={[]}
/>
);
@ -37,6 +38,7 @@ describe('RulesTableFilters', () => {
onFilterChanged={jest.fn()}
rulesCustomInstalled={10}
rulesInstalled={9}
currentFilterTags={[]}
/>
);

View file

@ -25,6 +25,7 @@ interface RulesTableFiltersProps {
onFilterChanged: (filterOptions: Partial<FilterOptions>) => void;
rulesCustomInstalled: number | null;
rulesInstalled: number | null;
currentFilterTags: string[];
}
/**
@ -37,6 +38,7 @@ const RulesTableFiltersComponent = ({
onFilterChanged,
rulesCustomInstalled,
rulesInstalled,
currentFilterTags,
}: RulesTableFiltersProps) => {
const [filter, setFilter] = useState<string>('');
const [selectedTags, setSelectedTags] = useState<string[]>([]);
@ -94,6 +96,7 @@ const RulesTableFiltersComponent = ({
onSelectedTagsChanged={handleSelectedTags}
selectedTags={selectedTags}
tags={tags}
currentFilterTags={currentFilterTags}
data-test-subj="allRulesTagPopover"
/>
</EuiFilterGroup>

View file

@ -16,6 +16,7 @@ describe('TagsFilterPopover', () => {
tags={[]}
selectedTags={[]}
onSelectedTagsChanged={jest.fn()}
currentFilterTags={[]}
isLoading={false}
/>
);

View file

@ -33,6 +33,7 @@ interface TagsFilterPopoverProps {
selectedTags: string[];
tags: string[];
onSelectedTagsChanged: Dispatch<SetStateAction<string[]>>;
currentFilterTags: string[];
// eslint-disable-next-line react/no-unused-prop-types
isLoading: boolean; // TO DO reimplement?
}
@ -62,8 +63,12 @@ const TagsFilterPopoverComponent = ({
tags,
selectedTags,
onSelectedTagsChanged,
currentFilterTags,
}: TagsFilterPopoverProps) => {
const sortedTags = useMemo(() => caseInsensitiveSort(tags), [tags]);
const sortedTags = useMemo(
() => caseInsensitiveSort(Array.from(new Set([...tags, ...currentFilterTags]))),
[tags, currentFilterTags]
);
const [isTagPopoverOpen, setIsTagPopoverOpen] = useState(false);
const [searchInput, setSearchInput] = useState('');
const [filterTags, setFilterTags] = useState(sortedTags);