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

Simple filters change between panel and drilldown panel #3568

Merged
merged 7 commits into from
Sep 6, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added base Module Panel view with Office365 setup [#3518](https://github.com/wazuh/wazuh-kibana-app/pull/3518)
- Added specifics and custom filters for Office365 search bar [#3533](https://github.com/wazuh/wazuh-kibana-app/pull/3533)
- Adding Pagination and filter to drilldown tables at Office pannel [#3544](https://github.com/wazuh/wazuh-kibana-app/issues/3544).
- Simple filters change between panel and drilldown panel [#3568](https://github.com/wazuh/wazuh-kibana-app/issues/3568).

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import { IValueSuggestion, useValueSuggestion } from '../../hooks';
const ON = 'on';
const OFF = 'off';

export const MultiSelect = ({ item, onChange, selectedOptions, onRemove, isDisabled }) => {
export const MultiSelect = ({ item, onChange, selectedOptions, onRemove, isDisabled, filterDrillDownValue }) => {
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);
const { suggestedValues, isLoading, setQuery }: IValueSuggestion = useValueSuggestion(
item.key,
item?.options
filterDrillDownValue,
item?.options,
);
const [items, setItems] = useState<
{ key: any; label: any; value: any; checked: FilterChecked }[]
Expand All @@ -48,9 +49,8 @@ export const MultiSelect = ({ item, onChange, selectedOptions, onRemove, isDisab
label: value,
value: item.key,
filterByKey: item.filterByKey,
checked: OFF as FilterChecked,
}))
.sort((a, b) => a.label - b.label)
checked: selectedOptions.find((element) => element.label === value) ? ON as FilterChecked: OFF as FilterChecked,
})).sort((a, b) => (a.label < b.label ? 1 : -1)).sort((a, b) => (a.checked < b.checked ? 1 : -1))
);
}
}, [suggestedValues, isLoading]);
Expand All @@ -59,8 +59,8 @@ export const MultiSelect = ({ item, onChange, selectedOptions, onRemove, isDisab
setItems(
items.map((item) => ({
...item,
checked: selectedOptions.find((element) => element.label === item.label) ? ON : OFF,
}))
checked: selectedOptions.find((element) => element.label === item.label) ? ON as FilterChecked: OFF as FilterChecked,
})).sort((a, b) => (a.label < b.label ? 1 : -1)).sort((a, b) => (a.checked < b.checked ? 1 : -1))
);
setActiveFilters(selectedOptions.length);
}, [selectedOptions]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const CustomSearchBar = ({ filtersValues, filterDrillDownValue = { field:
onChange={onChange}
onRemove={onRemove}
isDisabled={checkSelectDrillDownValue(item.key)}
filterDrillDownValue={filterDrillDownValue}
/>
),
};
Expand Down
23 changes: 21 additions & 2 deletions public/components/common/hooks/use-value-suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ export interface IValueSuggestion {
setQuery: React.Dispatch<React.SetStateAction<string>>;
}

interface BoolFilter {
field: string;
value: string;
}

export const useValueSuggestion = (
filterField: string,
boolFilterValue: BoolFilter = {
field: '',
value: '',
},
options?: string[],
type: 'string' | 'boolean' = 'string'
): IValueSuggestion => {
Expand All @@ -39,19 +48,29 @@ export const useValueSuggestion = (
const [isLoading, setIsLoading] = useState(true);
const data = getDataPlugin();
const indexPattern = useIndexPattern();
//const { filters } = useFilterManager();

const getOptions = (): string[] => {
return options?.filter((element) => element.toLowerCase().includes(query.toLowerCase())) || [];
};

const getValueSuggestions = async (field) => {
const boolFilter =
boolFilterValue.value !== ''
? [
{
term: {
[boolFilterValue.field]: `${boolFilterValue.value}`,
},
},
]
: [];
mpRegalado marked this conversation as resolved.
Show resolved Hide resolved
return options
? getOptions()
: await data.autocomplete.getValueSuggestions({
query,
indexPattern: indexPattern as IIndexPattern,
field,
boolFilter: boolFilter,
});
};

Expand Down Expand Up @@ -83,7 +102,7 @@ export const useValueSuggestion = (
}
})();
}
}, [indexPattern, query, filterField, type]);
}, [indexPattern, query, filterField, type, boolFilterValue]);

return { suggestedValues, isLoading, setQuery };
};
9 changes: 7 additions & 2 deletions public/components/overview/github-panel/github-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@
* Find more information about this on the LICENSE file.
*/

import React from 'react';
import React, {useState} from 'react';
import { MainPanel } from '../../common/modules/panel';
import { withErrorBoundary } from '../../common/hocs';
import { CustomSearchBar } from '../../common/custom-search-bar';
import { ModuleConfiguration } from './views';
import { ModuleConfig, filtersValues } from './config';

export const GitHubPanel = withErrorBoundary(() => {
const [drillDownValue, setDrillDownValue] = useState({ field: '', value: '' });
const filterDrillDownValue = (value) => {
setDrillDownValue(value)
}
mpRegalado marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
<CustomSearchBar filtersValues={filtersValues} />
<CustomSearchBar filtersValues={filtersValues} filterDrillDownValue={drillDownValue}/>
<MainPanel moduleConfig={ModuleConfig} tab={'github'}
filterDrillDownValue={filterDrillDownValue}
sidePanelChildren={<ModuleConfiguration />} />
</>
)
Expand Down