mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* Fixed minor UI bug on all rules table pagination
This commit is contained in:
parent
e29a53f5ba
commit
76480dadc0
4 changed files with 58 additions and 16 deletions
|
@ -23,7 +23,7 @@ export interface UseRules {
|
|||
pagination: PaginationOptions;
|
||||
filterOptions: FilterOptions;
|
||||
refetchPrePackagedRulesStatus?: () => void;
|
||||
dispatchRulesInReducer?: (rules: Rule[]) => void;
|
||||
dispatchRulesInReducer?: (rules: Rule[], pagination: Partial<PaginationOptions>) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,14 +59,18 @@ export const useRules = ({
|
|||
if (isSubscribed) {
|
||||
setRules(fetchRulesResult);
|
||||
if (dispatchRulesInReducer != null) {
|
||||
dispatchRulesInReducer(fetchRulesResult.data);
|
||||
dispatchRulesInReducer(fetchRulesResult.data, {
|
||||
page: fetchRulesResult.page,
|
||||
perPage: fetchRulesResult.perPage,
|
||||
total: fetchRulesResult.total,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (isSubscribed) {
|
||||
errorToToaster({ title: i18n.RULE_FETCH_FAILURE, error, dispatchToaster });
|
||||
if (dispatchRulesInReducer != null) {
|
||||
dispatchRulesInReducer([]);
|
||||
dispatchRulesInReducer([], {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { bucketRulesResponse } from './helpers';
|
||||
import { bucketRulesResponse, showRulesTable } from './helpers';
|
||||
import { mockRule, mockRuleError } from './__mocks__/mock';
|
||||
import uuid from 'uuid';
|
||||
import { Rule, RuleError } from '../../../../containers/detection_engine/rules';
|
||||
|
@ -44,4 +44,46 @@ describe('AllRulesTable Helpers', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('showRulesTable', () => {
|
||||
test('returns false when rulesCustomInstalled and rulesInstalled are null', () => {
|
||||
const result = showRulesTable({
|
||||
rulesCustomInstalled: null,
|
||||
rulesInstalled: null,
|
||||
});
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
test('returns false when rulesCustomInstalled and rulesInstalled are 0', () => {
|
||||
const result = showRulesTable({
|
||||
rulesCustomInstalled: 0,
|
||||
rulesInstalled: 0,
|
||||
});
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
test('returns false when both rulesCustomInstalled and rulesInstalled checks return false', () => {
|
||||
const result = showRulesTable({
|
||||
rulesCustomInstalled: 0,
|
||||
rulesInstalled: null,
|
||||
});
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
test('returns true if rulesCustomInstalled is not null or 0', () => {
|
||||
const result = showRulesTable({
|
||||
rulesCustomInstalled: 5,
|
||||
rulesInstalled: null,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
test('returns true if rulesInstalled is not null or 0', () => {
|
||||
const result = showRulesTable({
|
||||
rulesCustomInstalled: null,
|
||||
rulesInstalled: 5,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -21,6 +21,7 @@ import {
|
|||
CreatePreBuiltRules,
|
||||
FilterOptions,
|
||||
Rule,
|
||||
PaginationOptions,
|
||||
} from '../../../../containers/detection_engine/rules';
|
||||
import { HeaderSection } from '../../../../components/header_section';
|
||||
import {
|
||||
|
@ -118,10 +119,11 @@ export const AllRules = React.memo<AllRulesProps>(
|
|||
const history = useHistory();
|
||||
const [, dispatchToaster] = useStateToaster();
|
||||
|
||||
const setRules = useCallback((newRules: Rule[]) => {
|
||||
const setRules = useCallback((newRules: Rule[], newPagination: Partial<PaginationOptions>) => {
|
||||
dispatch({
|
||||
type: 'setRules',
|
||||
rules: newRules,
|
||||
pagination: newPagination,
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
|
|
@ -26,9 +26,8 @@ export type Action =
|
|||
| { type: 'exportRuleIds'; ids: string[] }
|
||||
| { type: 'loadingRuleIds'; ids: string[]; actionType: LoadingRuleAction }
|
||||
| { type: 'selectedRuleIds'; ids: string[] }
|
||||
| { type: 'setRules'; rules: Rule[] }
|
||||
| { type: 'setRules'; rules: Rule[]; pagination: Partial<PaginationOptions> }
|
||||
| { type: 'updateRules'; rules: Rule[] }
|
||||
| { type: 'updatePagination'; pagination: Partial<PaginationOptions> }
|
||||
| {
|
||||
type: 'updateFilterOptions';
|
||||
filterOptions: Partial<FilterOptions>;
|
||||
|
@ -76,6 +75,10 @@ export const allRulesReducer = (
|
|||
selectedRuleIds: [],
|
||||
loadingRuleIds: [],
|
||||
loadingRulesAction: null,
|
||||
pagination: {
|
||||
...state.pagination,
|
||||
...action.pagination,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'updateRules': {
|
||||
|
@ -101,15 +104,6 @@ export const allRulesReducer = (
|
|||
}
|
||||
return state;
|
||||
}
|
||||
case 'updatePagination': {
|
||||
return {
|
||||
...state,
|
||||
pagination: {
|
||||
...state.pagination,
|
||||
...action.pagination,
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'updateFilterOptions': {
|
||||
return {
|
||||
...state,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue