Skip to content

Commit c921f7e

Browse files
Fix remove filter icon visibility when pin and unpin agent (#6685)
* Fix hide remove filter icon * Change disable remove filter behavior in fixed filters * Remove vuln repository warning * Update changelog * Update CHANGELOG --------- Co-authored-by: Federico Rodriguez <federico.rodriguez@wazuh.com>
1 parent 6aba5cc commit c921f7e

File tree

7 files changed

+152
-140
lines changed

7 files changed

+152
-140
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ All notable changes to the Wazuh app project will be documented in this file.
2121

2222
### Changed
2323

24-
- Removed embedded discover [#6120](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6120) [#6235](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6235) [#6254](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6254) [#6285](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6285) [#6288](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6288) [#6290](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6290) [#6289](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6289) [#6286](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6286) [#6275](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6275) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6297](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6297) [#6291](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6459](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6459) [#6434](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6434) [#6504](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6504) [#6649](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6649) [#6506](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6506) [#6537](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6537) [#6528](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6528) [#6675](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6675) [#6674](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6674) [#6558](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6558) [#6691](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6691)
24+
- Removed embedded discover [#6120](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6120) [#6235](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6235) [#6254](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6254) [#6285](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6285) [#6288](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6288) [#6290](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6290) [#6289](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6289) [#6286](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6286) [#6275](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6275) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6297](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6297) [#6291](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6459](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6459) [#6434](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6434) [#6504](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6504) [#6649](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6649) [#6506](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6506) [#6537](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6537) [#6528](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6528) [#6675](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6675) [#6674](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6674) [#6558](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6558) [#6685](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6685) [#6691](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6691)
2525
- Develop logic of a new index for the fim module [#6227](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6227)
2626
- Allow editing groups for an agent from Endpoints Summary [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250)
2727
- Change how the configuration is managed in the backend side [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337) [#6519](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6519) [#6573](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6573)

plugins/main/public/components/common/data-source/hooks/use-data-source.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,25 @@ export function useDataSource<
132132

133133
useEffect(() => {
134134
if (dataSourceFilterManager && dataSource) {
135-
const filteredPinnedAgent = dataSourceFilterManager
136-
.getFilters()
137-
.filter(
138-
(filter: tFilter) =>
139-
filter.meta.controlledBy !==
140-
PinnedAgentManager.FILTER_CONTROLLED_PINNED_AGENT_KEY,
141-
);
142135
if (pinnedAgentManager.isPinnedAgent()) {
143136
const pinnedAgent = PatternDataSourceFilterManager.getPinnedAgentFilter(
144137
dataSource.id,
145138
);
146139

147-
dataSourceFilterManager.setFilters([
148-
...filteredPinnedAgent,
149-
...pinnedAgent,
150-
]);
140+
dataSourceFilterManager.addFilters([...pinnedAgent]);
151141
} else {
152-
dataSourceFilterManager.setFilters([...filteredPinnedAgent]);
142+
const pinnedAgentFilter = dataSourceFilterManager
143+
.getFilters()
144+
.filter(
145+
(filter: tFilter) =>
146+
filter.meta.controlledBy ===
147+
PinnedAgentManager.FILTER_CONTROLLED_PINNED_AGENT_KEY,
148+
);
149+
150+
if(pinnedAgentFilter.length){
151+
dataSourceFilterManager.removeFilter(pinnedAgentFilter[0])
152+
}
153+
153154
}
154155
}
155156
}, [JSON.stringify(pinnedAgent)]);

plugins/main/public/components/common/data-source/pattern/pattern-data-source-filter-manager.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ export class PatternDataSourceFilterManager
198198
);
199199
}
200200

201+
addFilters(filter: tFilter) {
202+
this.filterManager.addFilters(filter);
203+
}
204+
205+
removeAll() {
206+
this.filterManager.setFilters([]);
207+
}
208+
201209
/**
202210
* Concatenate the filters to fetch the data from the data source
203211
* @returns
@@ -217,24 +225,16 @@ export class PatternDataSourceFilterManager
217225
* @returns
218226
*/
219227
createFilter(field: string, value: string): tFilter {
220-
return this.generateFilter(field, value, this.dataSource.id);
228+
return this.generateFilter(field, value, this.dataSource.id) as tFilter;
221229
}
222230

223231
/**
224232
* Search the the field and value received and remove the filter when exists
225233
* @param field
226234
* @param value
227235
*/
228-
removeFilter(field: string, value: string): void {
229-
let filters = this.filterManager.getFilters();
230-
const filterIndex = filters.findIndex(
231-
f => f.meta?.key === field && f.meta?.value === value,
232-
);
233-
// only remove when exists the filter
234-
if (filterIndex > -1) {
235-
filters.splice(filterIndex, 1);
236-
this.setFilters(filters);
237-
}
236+
removeFilter(filter: tFilter): void {
237+
this.filterManager.removeFilter(filter);
238238
}
239239

240240
/**
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
import { PatternDataSourceRepository } from '../pattern-data-source-repository';
2-
import { tDataSource, tParsedIndexPattern } from '../../index'
3-
2+
import { tDataSource, tParsedIndexPattern } from '../../index';
43

54
export class VulnerabilitiesDataSourceRepository extends PatternDataSourceRepository {
6-
constructor() {
7-
super();
8-
}
9-
10-
async get(id: string) {
11-
const dataSource = await super.get(id);
12-
if (this.validate(dataSource)) {
13-
return dataSource;
14-
} else {
15-
throw new Error('Vulnerabilities index pattern not found');
16-
}
17-
}
5+
constructor() {
6+
super();
7+
}
188

19-
async getAll() {
20-
const indexs = await super.getAll();
21-
return indexs.filter(this.validate);
22-
}
23-
24-
validate(dataSource): boolean {
25-
// check if the dataSource has the id or the title have the vulnerabilities word
26-
const fieldsToCheck = ['id', 'attributes.title'];
27-
// must check in the object and the attributes
28-
for (const field of fieldsToCheck) {
29-
if (dataSource[field] && dataSource[field].toLowerCase().includes('vulnerabilities')) {
30-
return true;
31-
}
32-
}
33-
return false;
9+
async get(id: string) {
10+
const dataSource = await super.get(id);
11+
if (this.validate(dataSource)) {
12+
return dataSource;
13+
} else {
14+
throw new Error('Vulnerabilities index pattern not found');
3415
}
16+
}
3517

36-
getDefault(){
37-
console.warn('getDefault not implemented for vulnerabilities data source repository');
38-
return Promise.resolve(null);
39-
}
18+
async getAll() {
19+
const indexs = await super.getAll();
20+
return indexs.filter(this.validate);
21+
}
4022

41-
setDefault(dataSource: tParsedIndexPattern){
42-
console.warn('setDefault not implemented for vulnerabilities data source repository');
43-
return;
23+
validate(dataSource): boolean {
24+
// check if the dataSource has the id or the title have the vulnerabilities word
25+
const fieldsToCheck = ['id', 'attributes.title'];
26+
// must check in the object and the attributes
27+
for (const field of fieldsToCheck) {
28+
if (
29+
dataSource[field] &&
30+
dataSource[field].toLowerCase().includes('vulnerabilities')
31+
) {
32+
return true;
33+
}
4434
}
35+
return false;
36+
}
37+
38+
getDefault() {
39+
return Promise.resolve(null);
40+
}
4541

46-
}
42+
setDefault(dataSource: tParsedIndexPattern) {
43+
return;
44+
}
45+
}
Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,81 @@
1-
import { Filter } from "../../../../../../src/plugins/data/common";
2-
import { FilterManager } from "../../../../../../src/plugins/data/public";
1+
import { Filter } from '../../../../../../src/plugins/data/common';
2+
import { FilterManager } from '../../../../../../src/plugins/data/public';
33

44
export type tSearchParams = {
5-
filters?: Filter[];
6-
query?: any;
7-
pagination?: {
8-
pageIndex?: number;
9-
pageSize?: number;
10-
};
11-
fields?: string[],
12-
sorting?: {
13-
columns: {
14-
id: string;
15-
direction: 'asc' | 'desc';
16-
}[];
17-
};
18-
dateRange?: {
19-
from: string;
20-
to: string;
21-
};
22-
aggs?: any;
23-
}
5+
filters?: Filter[];
6+
query?: any;
7+
pagination?: {
8+
pageIndex?: number;
9+
pageSize?: number;
10+
};
11+
fields?: string[];
12+
sorting?: {
13+
columns: {
14+
id: string;
15+
direction: 'asc' | 'desc';
16+
}[];
17+
};
18+
dateRange?: {
19+
from: string;
20+
to: string;
21+
};
22+
aggs?: any;
23+
};
2424

2525
export type tFilter = Filter;
2626

2727
// create a new type using the FilterManager type but only the getFilters, setFilters, addFilters, getUpdates$
28-
export type tFilterManager = Pick<FilterManager, 'getFilters' | 'setFilters' | 'addFilters' | 'getUpdates$'>;
28+
export type tFilterManager = Pick<
29+
FilterManager,
30+
'getFilters' | 'setFilters' | 'addFilters' | 'getUpdates$' | 'removeFilter'
31+
>;
2932

3033
export type tDataSource = {
31-
id: string;
32-
title: string;
33-
select(): Promise<void>;
34-
getFields(): any[];
35-
getFixedFilters: () => tFilter[];
36-
getFetchFilters: () => tFilter[];
37-
fetch: (params: tSearchParams) => Promise<any>;
38-
toJSON(): object;
39-
}
34+
id: string;
35+
title: string;
36+
select(): Promise<void>;
37+
getFields(): any[];
38+
getFixedFilters: () => tFilter[];
39+
getFetchFilters: () => tFilter[];
40+
fetch: (params: tSearchParams) => Promise<any>;
41+
toJSON(): object;
42+
};
4043

4144
export interface IDataSourceFactoryConstructor<T extends tDataSource> {
42-
new(id: T['id'], title: T['title']): T;
45+
new (id: T['id'], title: T['title']): T;
4346
}
4447

4548
export type tDataSourceFactory<T extends object, K extends tDataSource> = {
46-
create: (DataSourceType: IDataSourceFactoryConstructor<K>, data: T) => Promise<K>;
47-
createAll: (DataSourceType: IDataSourceFactoryConstructor<K>, data: T[]) => Promise<K[]>;
48-
}
49+
create: (
50+
DataSourceType: IDataSourceFactoryConstructor<K>,
51+
data: T,
52+
) => Promise<K>;
53+
createAll: (
54+
DataSourceType: IDataSourceFactoryConstructor<K>,
55+
data: T[],
56+
) => Promise<K[]>;
57+
};
4958

5059
export type tDataSourceFilterManager = {
51-
fetch: () => Promise<any>;
52-
setFilters: (filters: tFilter[]) => void;
53-
getFilters: () => tFilter[];
54-
getFixedFilters: () => tFilter[];
55-
getFetchFilters: () => tFilter[];
56-
}
60+
fetch: () => Promise<any>;
61+
setFilters: (filters: tFilter[]) => void;
62+
getFilters: () => tFilter[];
63+
getFixedFilters: () => tFilter[];
64+
getFetchFilters: () => tFilter[];
65+
};
5766

5867
export type tDataSourceRepository<T extends object> = {
59-
get(id: string): Promise<T>;
60-
getAll(): Promise<T[]>;
61-
setDefault(dataSourceData: T): void;
62-
getDefault(): Promise<T | null>;
63-
}
64-
68+
get(id: string): Promise<T>;
69+
getAll(): Promise<T[]>;
70+
setDefault(dataSourceData: T): void;
71+
getDefault(): Promise<T | null>;
72+
};
6573

6674
export type tDataSourceSelector<T extends tDataSource> = {
67-
existsDataSource: (id: string) => Promise<boolean>;
68-
getFirstValidDataSource: () => Promise<T>;
69-
getAllDataSources: () => Promise<T[]>;
70-
getDataSource: (id: string) => Promise<T>;
71-
getSelectedDataSource: () => Promise<T>;
72-
selectDataSource: (id: string) => Promise<void>;
73-
}
75+
existsDataSource: (id: string) => Promise<boolean>;
76+
getFirstValidDataSource: () => Promise<T>;
77+
getAllDataSources: () => Promise<T[]>;
78+
getDataSource: (id: string) => Promise<T>;
79+
getSelectedDataSource: () => Promise<T>;
80+
selectDataSource: (id: string) => Promise<void>;
81+
};

plugins/main/public/components/common/search-bar/search-bar-service.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ export const search = async (
133133
};
134134

135135
const getValueDisplayedOnFilter = (filter: tFilter) => {
136-
return filter.query?.bool?.minimum_should_match === 1 ?
137-
`is one of ${filter.meta?.value}` :
138-
filter.meta?.params?.query || filter.meta?.value;
139-
}
136+
return filter.query?.bool?.minimum_should_match === 1
137+
? `is one of ${filter.meta?.value}`
138+
: filter.meta?.params?.query || filter.meta?.value;
139+
};
140140

141141
export const hideCloseButtonOnFixedFilters = (
142142
filters: tFilter[],
@@ -152,7 +152,7 @@ export const hideCloseButtonOnFixedFilters = (
152152
index,
153153
filter,
154154
field: filter.meta?.key,
155-
value: getValueDisplayedOnFilter(filter)
155+
value: getValueDisplayedOnFilter(filter),
156156
};
157157
}
158158
})
@@ -173,22 +173,24 @@ export const hideCloseButtonOnFixedFilters = (
173173
filter?.value === filterValue &&
174174
filter?.index === index,
175175
);
176+
const removeButton = element.querySelector('.euiBadge__iconButton');
177+
const badgeButton = element.querySelector(
178+
'.euiBadge__content .euiBadge__childButton',
179+
) as HTMLElement;
176180
if (filter) {
177-
// hide the remove button
178-
const iconButton = element.querySelector(
179-
'.euiBadge__iconButton',
180-
) as HTMLElement;
181-
iconButton?.style?.setProperty('display', 'none');
182-
// change the cursor to not-allowed
183-
const badgeButton = element.querySelector(
184-
'.euiBadge__content .euiBadge__childButton',
185-
) as HTMLElement;
186-
badgeButton?.style?.setProperty('cursor', 'not-allowed');
187-
// remove the popup on click to prevent the filter from being removed
188-
element.addEventListener('click', event => {
189-
event.preventDefault();
190-
event.stopPropagation();
181+
$(removeButton).addClass('hide-close-button');
182+
$(removeButton).on('click', ev => {
183+
ev.stopPropagation();
184+
});
185+
$(badgeButton).on('click', ev => {
186+
ev.stopPropagation();
191187
});
188+
$(badgeButton).css('cursor', 'not-allowed');
189+
} else {
190+
$(removeButton).removeClass('hide-close-button');
191+
$(removeButton).off('click');
192+
$(badgeButton).off('click');
193+
$(badgeButton).css('cursor', 'pointer');
192194
}
193195
});
194196
};

0 commit comments

Comments
 (0)