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

The automatic page refresh is not working in Wazuh Dashboard in version 4.9.0 #7016

Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5c71f21
Add APP_STATE_URL_KEY and GLOBAL_STATE_URL_KEY constants
guidomodarelli Sep 30, 2024
2711749
Add OsdUrlStateStorage for managing app state in URL
guidomodarelli Sep 30, 2024
f70fea6
Add state storage to exported services
guidomodarelli Sep 30, 2024
0415371
Remove unused "fixedFilters" variable assignment
guidomodarelli Sep 30, 2024
1636dc2
Update button permissions props interface
guidomodarelli Sep 30, 2024
b8485d4
Add allowJs option to compilerOptions in tsconfig.json
guidomodarelli Sep 30, 2024
2e81ed8
Update import path for 'opensearch_dashboards/public'.
guidomodarelli Sep 30, 2024
da700cb
Update getFileContent method signature and parameters
guidomodarelli Sep 30, 2024
8e0afb6
Add unit tests for clearStateFromSavedQuery function
guidomodarelli Sep 30, 2024
f7476eb
Add constant for saved query
guidomodarelli Sep 30, 2024
f61b299
Add test for populating state from saved query
guidomodarelli Sep 30, 2024
159cf01
Add NavigationService and createHashHistory in useSearchBar.test
guidomodarelli Sep 30, 2024
a654b40
Update OSD_URL_STATE_STORAGE_ID to APP_STATE_URL_KEY
guidomodarelli Sep 30, 2024
ee63aaf
Add useSavedQuery hook for handling saved queries
guidomodarelli Sep 30, 2024
0c3e8cd
Add useSavedQuery hook in search-bar configuration
guidomodarelli Sep 30, 2024
2de0c18
Update useSearchBar to set refresh interval directly
guidomodarelli Sep 30, 2024
b0a2f15
Fix Prettier issues
guidomodarelli Sep 30, 2024
0afc562
Update timefilter configuration in use-search-bar.test.ts
guidomodarelli Sep 30, 2024
ce14b23
Merge branch '4.10.0' into bug/25617-the-automatic-page-refresh-is-no…
guidomodarelli Oct 1, 2024
af2e38e
Merge branch '4.10.0' into bug/25617-the-automatic-page-refresh-is-no…
asteriscos Oct 1, 2024
137f13d
Merge branch '4.10.0' into bug/25617-the-automatic-page-refresh-is-no…
asteriscos Oct 2, 2024
8426a47
Merge branch '4.10.0' into bug/25617-the-automatic-page-refresh-is-no…
yenienserrano Oct 8, 2024
bb471c0
Fix automatic page refresh issue
guidomodarelli Oct 8, 2024
8fe70f9
Fix automatic page refresh in Wazuh Dashboard
guidomodarelli Oct 9, 2024
49e772b
Merge branch '4.10.0' into bug/25617-the-automatic-page-refresh-is-no…
guidomodarelli Oct 10, 2024
c8d0f5e
Merge branch '4.10.0' into bug/25617-the-automatic-page-refresh-is-no…
guidomodarelli Oct 14, 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
3 changes: 3 additions & 0 deletions plugins/main/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,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