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

Add custom saved queries and fix duplicate requests #7090

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9cc1419
Add custom saved queries
asteriscos Oct 9, 2024
0745834
Add changelog
asteriscos Oct 9, 2024
4bc0e50
Add setTimeFilter function to save and update saved queries
guidomodarelli Oct 10, 2024
e5b866a
Remove absolute date and add fingerprint to lastReloadRequestTime
asteriscos Oct 10, 2024
14e0139
Add explanation to fingerprint state
asteriscos Oct 10, 2024
59966f7
Add support for setting and updating refresh interval
guidomodarelli Oct 10, 2024
ee044e2
Update saveSavedQuery function to handle newSavedQuery
guidomodarelli Oct 10, 2024
a0ed10c
Refactor saved query functions for better organization
guidomodarelli Oct 10, 2024
7ca1239
Refactor functions to accept options for first time use
guidomodarelli Oct 10, 2024
bbf48ae
Merge branch '4.9.1' into enhancement/7083-remove-duplicate-requests-…
asteriscos Oct 11, 2024
43ff18b
Add absolute date range for data grids
asteriscos Oct 11, 2024
84edd34
Refactor saved query hooks for setQuery and setFilters
guidomodarelli Oct 14, 2024
0b60aa6
Remove saved query clearing functionality
guidomodarelli Oct 14, 2024
f58f465
Refactor useSavedQuery function for better readability
guidomodarelli Oct 14, 2024
cc39c04
Delete unused test and function for saved queries
guidomodarelli Oct 14, 2024
9313658
Add jest spy for setFilters in useSearchBar hook test
guidomodarelli Oct 14, 2024
16016f4
Fix search-bar autorefresh feature
asteriscos Oct 14, 2024
349734d
Apply autoRefreshFingerprint in dashboards
asteriscos Oct 14, 2024
cbc1d71
Add fingerprint to Vulnerabilities module
asteriscos Oct 14, 2024
d68abfa
Refactor useSearchBar test for readability
guidomodarelli Oct 14, 2024
705c07a
Fix unit test
asteriscos Oct 15, 2024
4f16cbf
Prettier
asteriscos Oct 15, 2024
e7c4d68
Hide save query button in flyout search bar
asteriscos Oct 15, 2024
bf90d4e
Fix absolute date string format
asteriscos Oct 15, 2024
fb25a7d
By default show the save query button in the saved queries popover
asteriscos Oct 15, 2024
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 @@ -25,6 +25,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed style when unnpinned an agent in endpoint summary section [#7015](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7015)
- Fixed overflow style on a long value filter [#7021](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7021)
- Fixed buttons enabled for a readonly user in `Endpoint groups` section [#7056](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7056)
- Fixed the automatic page refresh in dashboards and prevent duplicate requests [#7090](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7090)

asteriscos marked this conversation as resolved.
Show resolved Hide resolved
### Changed

Expand Down
3 changes: 3 additions & 0 deletions plugins/main/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,6 @@ export const SEARCH_BAR_DEBOUNCE_UPDATE_TIME = 400;

// ID used to refer the createOsdUrlStateStorage state
export const OSD_URL_STATE_STORAGE_ID = 'state:storeInSessionStorage';

export const APP_STATE_URL_KEY = '_a';
export const GLOBAL_STATE_URL_KEY = '_g';
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export function useDataSource<
const {
filters: initialFilters = [...defaultFilters],
fetchFilters: initialFetchFilters = [],
fixedFilters: initialFixedFilters = [],
DataSource: DataSourceConstructor,
repository,
factory: injectedFactory,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { clearStateFromSavedQuery } from './clear_saved_query';

import { dataPluginMock } from '../../../../../../../src/plugins/data/public/mocks';
import { DataPublicPluginStart } from '../../../../../../../src/plugins/data/public';

describe('clearStateFromSavedQuery', () => {
let dataMock: jest.Mocked<DataPublicPluginStart>;

beforeEach(() => {
dataMock = dataPluginMock.createStartContract();
});

it('should clear filters and query', async () => {
dataMock.query.filterManager.removeAll = jest.fn();
clearStateFromSavedQuery(dataMock.query);
expect(dataMock.query.queryString.clearQuery).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { QueryStart } from '../../../../../../../src/plugins/data/public';

export const clearStateFromSavedQuery = (queryService: QueryStart) => {
queryService.queryString.clearQuery();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SAVED_QUERY = 'savedQuery';
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { populateStateFromSavedQuery } from './populate_state_from_saved_query';

import { dataPluginMock } from '../../../../../../../src/plugins/data/public/mocks';
import { DataPublicPluginStart } from '../../../../../../../src/plugins/data/public';
import { SavedQuery } from '../../../../../../../src/plugins/data/public/query/saved_query/types';
import { FilterStateStore } from '../../../../../../../src/plugins/data/common/opensearch_query/filters/meta_filter';
import { getFilter } from '../../../../../../../src/plugins/data/public/query/filter_manager/test_helpers/get_stub_filter';

describe('populateStateFromSavedQuery', () => {
let dataMock: jest.Mocked<DataPublicPluginStart>;

const baseSavedQuery: SavedQuery = {
id: 'test',
attributes: {
title: 'test',
description: 'test',
query: {
query: 'test',
language: 'kuery',
},
},
};

beforeEach(() => {
dataMock = dataPluginMock.createStartContract();
dataMock.query.filterManager.setFilters = jest.fn();
dataMock.query.filterManager.getGlobalFilters = jest
.fn()
.mockReturnValue([]);
});

it('should set query', async () => {
const savedQuery: SavedQuery = {
...baseSavedQuery,
};
populateStateFromSavedQuery(dataMock.query, savedQuery);
expect(dataMock.query.queryString.setQuery).toHaveBeenCalled();
});

it('should set filters', async () => {
const savedQuery: SavedQuery = {
...baseSavedQuery,
};
const f1 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
savedQuery.attributes.filters = [f1];
populateStateFromSavedQuery(dataMock.query, savedQuery);
expect(dataMock.query.queryString.setQuery).toHaveBeenCalled();
});

it('should preserve global filters', async () => {
const globalFilter = getFilter(
FilterStateStore.GLOBAL_STATE,
false,
false,
'age',
34,
);
dataMock.query.filterManager.getGlobalFilters = jest
.fn()
.mockReturnValue([globalFilter]);
const savedQuery: SavedQuery = {
...baseSavedQuery,
};
const f1 = getFilter(FilterStateStore.APP_STATE, false, false, 'age', 34);
savedQuery.attributes.filters = [f1];
populateStateFromSavedQuery(dataMock.query, savedQuery);
expect(dataMock.query.queryString.setQuery).toHaveBeenCalled();
});

it('should update timefilter', async () => {
const savedQuery: SavedQuery = {
...baseSavedQuery,
};
savedQuery.attributes.timefilter = {
from: '2018',
to: '2019',
refreshInterval: {
pause: true,
value: 10,
},
};

dataMock.query.timefilter.timefilter.setTime = jest.fn();
dataMock.query.timefilter.timefilter.setRefreshInterval = jest.fn();

populateStateFromSavedQuery(dataMock.query, savedQuery);

expect(dataMock.query.timefilter.timefilter.setTime).toHaveBeenCalledWith({
from: savedQuery.attributes.timefilter.from,
to: savedQuery.attributes.timefilter.to,
});
expect(
dataMock.query.timefilter.timefilter.setRefreshInterval,
).toHaveBeenCalledWith(savedQuery.attributes.timefilter.refreshInterval);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import {
Filter,
QueryStart,
SavedQuery,
} from '../../../../../../../src/plugins/data/public';

export const populateStateFromSavedQuery = (
queryService: QueryStart,
savedQuery: SavedQuery,
) => {
const {
timefilter: { timefilter },
queryString,
} = queryService;
// timefilter
if (savedQuery.attributes.timefilter) {
timefilter.setTime({
from: savedQuery.attributes.timefilter.from,
to: savedQuery.attributes.timefilter.to,
});
if (savedQuery.attributes.timefilter.refreshInterval) {
timefilter.setRefreshInterval(
savedQuery.attributes.timefilter.refreshInterval,
);
}
}

// query string
queryString.setQuery(savedQuery.attributes.query);
};
Loading
Loading