mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# Backport This will backport the following commits from `main` to `8.8`: - [[SecuritySolution] Update checkIndicesExists logic (#159806)](https://github.com/elastic/kibana/pull/159806) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Angela Chuang","email":"6295984+angorayc@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-06-15T19:06:30Z","message":"[SecuritySolution] Update checkIndicesExists logic (#159806)\n\n## Summary\r\n\r\nissue: https://github.com/elastic/kibana/issues/159107\r\n\r\n\r\n\r\n**Steps to verify:**\r\n\r\n1. Generate some alerts and enable host or user risk score module.\r\n2. Hard refresh the page, select the alerts data view. \r\n\r\n<img width=\"639\" alt=\"Screenshot 2023-06-15 at 14 54 54\"\r\nsrc=\"412a2a9c
-9125-4972-8c95-24dda90ad529\">\r\n\r\n3. Visit overview, host, network and users page. All should `Not`\r\ndisplay the get started page.\r\n\r\n\r\n\r\n4b942604
-f98f-40fe-bbca-9cfd11cdf275\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"24bfa0514efb3eb16b3eb3276679dd53229d01ba","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Threat Hunting","Team: SecuritySolution","Team:Threat Hunting:Explore","v8.9.0","v8.8.2"],"number":159806,"url":"https://github.com/elastic/kibana/pull/159806","mergeCommit":{"message":"[SecuritySolution] Update checkIndicesExists logic (#159806)\n\n## Summary\r\n\r\nissue: https://github.com/elastic/kibana/issues/159107\r\n\r\n\r\n\r\n**Steps to verify:**\r\n\r\n1. Generate some alerts and enable host or user risk score module.\r\n2. Hard refresh the page, select the alerts data view. \r\n\r\n<img width=\"639\" alt=\"Screenshot 2023-06-15 at 14 54 54\"\r\nsrc=\"412a2a9c
-9125-4972-8c95-24dda90ad529\">\r\n\r\n3. Visit overview, host, network and users page. All should `Not`\r\ndisplay the get started page.\r\n\r\n\r\n\r\n4b942604
-f98f-40fe-bbca-9cfd11cdf275\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"24bfa0514efb3eb16b3eb3276679dd53229d01ba"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/159806","number":159806,"mergeCommit":{"message":"[SecuritySolution] Update checkIndicesExists logic (#159806)\n\n## Summary\r\n\r\nissue: https://github.com/elastic/kibana/issues/159107\r\n\r\n\r\n\r\n**Steps to verify:**\r\n\r\n1. Generate some alerts and enable host or user risk score module.\r\n2. Hard refresh the page, select the alerts data view. \r\n\r\n<img width=\"639\" alt=\"Screenshot 2023-06-15 at 14 54 54\"\r\nsrc=\"412a2a9c
-9125-4972-8c95-24dda90ad529\">\r\n\r\n3. Visit overview, host, network and users page. All should `Not`\r\ndisplay the get started page.\r\n\r\n\r\n\r\n4b942604
-f98f-40fe-bbca-9cfd11cdf275\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"24bfa0514efb3eb16b3eb3276679dd53229d01ba"}},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Angela Chuang <6295984+angorayc@users.noreply.github.com>
This commit is contained in:
parent
8899487bbf
commit
1bdfebab70
3 changed files with 112 additions and 3 deletions
|
@ -372,6 +372,7 @@ export const useSourcererDataView = (
|
|||
[]
|
||||
);
|
||||
const {
|
||||
defaultDataView,
|
||||
signalIndexName,
|
||||
selectedDataView,
|
||||
sourcererScope: { missingPatterns, selectedPatterns: scopeSelectedPatterns, loading },
|
||||
|
@ -383,6 +384,7 @@ export const useSourcererDataView = (
|
|||
sourcererScope,
|
||||
};
|
||||
});
|
||||
|
||||
const selectedPatterns = useMemo(
|
||||
() => sortWithExcludesAtEnd(scopeSelectedPatterns),
|
||||
[scopeSelectedPatterns]
|
||||
|
@ -431,8 +433,17 @@ export const useSourcererDataView = (
|
|||
scopeId,
|
||||
signalIndexName,
|
||||
patternList: sourcererDataView.patternList,
|
||||
isDefaultDataViewSelected: sourcererDataView.id === defaultDataView.id,
|
||||
}),
|
||||
[loading, scopeId, signalIndexName, sourcererDataView.loading, sourcererDataView.patternList]
|
||||
[
|
||||
defaultDataView.id,
|
||||
loading,
|
||||
scopeId,
|
||||
signalIndexName,
|
||||
sourcererDataView.id,
|
||||
sourcererDataView.loading,
|
||||
sourcererDataView.patternList,
|
||||
]
|
||||
);
|
||||
|
||||
const browserFields = useCallback(() => {
|
||||
|
|
|
@ -7,7 +7,11 @@
|
|||
|
||||
import { mockGlobalState, mockSourcererState } from '../../mock';
|
||||
import { SourcererScopeName } from './model';
|
||||
import { getScopePatternListSelection, validateSelectedPatterns } from './helpers';
|
||||
import {
|
||||
checkIfIndicesExist,
|
||||
getScopePatternListSelection,
|
||||
validateSelectedPatterns,
|
||||
} from './helpers';
|
||||
import { sortWithExcludesAtEnd } from '../../../../common/utils/sourcerer';
|
||||
|
||||
const signalIndexName = mockGlobalState.sourcerer.signalIndexName;
|
||||
|
@ -278,3 +282,93 @@ describe('sourcerer store helpers', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkIfIndicesExist', () => {
|
||||
it('should return true when scopeId is "detections" and patternList includes signalIndexName', () => {
|
||||
const result = checkIfIndicesExist({
|
||||
patternList: ['index1', 'index2', 'signalIndex'],
|
||||
scopeId: SourcererScopeName.detections,
|
||||
signalIndexName: 'signalIndex',
|
||||
isDefaultDataViewSelected: false,
|
||||
});
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when scopeId is "detections" and patternList does not include signalIndexName', () => {
|
||||
const result = checkIfIndicesExist({
|
||||
patternList: ['index1', 'index2'],
|
||||
scopeId: SourcererScopeName.detections,
|
||||
signalIndexName: 'signalIndex',
|
||||
isDefaultDataViewSelected: false,
|
||||
});
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when scopeId is "default" and isDefaultDataViewSelected is true and patternList has elements other than signalIndexName', () => {
|
||||
const result = checkIfIndicesExist({
|
||||
patternList: ['index1', 'index2', 'index3'],
|
||||
scopeId: SourcererScopeName.default,
|
||||
signalIndexName: 'signalIndex',
|
||||
isDefaultDataViewSelected: true,
|
||||
});
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when scopeId is "default" and isDefaultDataViewSelected is true and patternList only contains signalIndexName', () => {
|
||||
const result = checkIfIndicesExist({
|
||||
patternList: ['signalIndex'],
|
||||
scopeId: SourcererScopeName.default,
|
||||
signalIndexName: 'signalIndex',
|
||||
isDefaultDataViewSelected: true,
|
||||
});
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when scopeId is "default" and isDefaultDataViewSelected is false and patternList has elements', () => {
|
||||
const result = checkIfIndicesExist({
|
||||
patternList: ['index1', 'index2'],
|
||||
scopeId: SourcererScopeName.default,
|
||||
signalIndexName: 'signalIndex',
|
||||
isDefaultDataViewSelected: false,
|
||||
});
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when scopeId is "default" and isDefaultDataViewSelected is false and patternList is empty', () => {
|
||||
const result = checkIfIndicesExist({
|
||||
patternList: [],
|
||||
scopeId: SourcererScopeName.default,
|
||||
signalIndexName: 'signalIndex',
|
||||
isDefaultDataViewSelected: false,
|
||||
});
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when scopeId is not "detections" or "default" and patternList has elements', () => {
|
||||
const result = checkIfIndicesExist({
|
||||
patternList: ['index1', 'index2'],
|
||||
scopeId: 'other' as SourcererScopeName,
|
||||
signalIndexName: 'signalIndex',
|
||||
isDefaultDataViewSelected: false,
|
||||
});
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when scopeId is not "detections" or "default" and patternList is empty', () => {
|
||||
const result = checkIfIndicesExist({
|
||||
patternList: [],
|
||||
scopeId: 'other' as SourcererScopeName,
|
||||
signalIndexName: 'signalIndex',
|
||||
isDefaultDataViewSelected: false,
|
||||
});
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -104,14 +104,18 @@ interface CheckIfIndicesExistParams {
|
|||
patternList: sourcererModel.SourcererDataView['patternList'];
|
||||
scopeId: sourcererModel.SourcererScopeName;
|
||||
signalIndexName: string | null;
|
||||
isDefaultDataViewSelected: boolean;
|
||||
}
|
||||
export const checkIfIndicesExist = ({
|
||||
patternList,
|
||||
scopeId,
|
||||
signalIndexName,
|
||||
isDefaultDataViewSelected,
|
||||
}: CheckIfIndicesExistParams) =>
|
||||
scopeId === SourcererScopeName.detections
|
||||
? patternList.includes(`${signalIndexName}`)
|
||||
: scopeId === SourcererScopeName.default
|
||||
? patternList.filter((i) => i !== signalIndexName).length > 0
|
||||
? isDefaultDataViewSelected
|
||||
? patternList.filter((i) => i !== signalIndexName).length > 0
|
||||
: patternList.length > 0
|
||||
: patternList.length > 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue