Skip to content

Commit

Permalink
fix bug that broke pagination on shared exception lists page when cha…
Browse files Browse the repository at this point in the history
…nging number of rows displayed after page 1
  • Loading branch information
yctercero committed Feb 16, 2023
1 parent d7d9d78 commit 77eb735
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
EuiSpacer,
EuiPageHeader,
EuiHorizontalRule,
EuiText,
} from '@elastic/eui';

import type { NamespaceType, ExceptionListFilter } from '@kbn/securitysolution-io-ts-list-types';
Expand Down Expand Up @@ -151,7 +152,7 @@ export const SharedLists = React.memo(() => {
);

const handleDelete = useCallback(
({ id, listId, namespaceType }: { id: string; listId: string; namespaceType: NamespaceType }) =>
({ id, namespaceType }: { id: string; namespaceType: NamespaceType }) =>
async () => {
try {
if (exceptionsListsRef[id] != null) {
Expand Down Expand Up @@ -329,44 +330,28 @@ export const SharedLists = React.memo(() => {
iconSide="right"
onClick={onRowSizeButtonClick}
>
{/* TODO move to translations */}
{`Rows per page: ${rowSize}`}
{i18n.allExceptionsRowPerPage(rowSize)}
</EuiButtonEmpty>
);

const getIconType = (size: number) => {
return size === rowSize ? 'check' : 'empty';
};

const onPerPageClick = useCallback((size: number) => {
closeRowSizePopover();
setRowSize(size);
setActivePage(0);
}, []);

const rowSizeItems = [
<EuiContextMenuItem
key="5 rows"
icon={getIconType(5)}
onClick={() => {
closeRowSizePopover();
setRowSize(5);
}}
>
<EuiContextMenuItem key="5 rows" icon={getIconType(5)} onClick={() => onPerPageClick(5)}>
{'5 rows'}
</EuiContextMenuItem>,
<EuiContextMenuItem
key="10 rows"
icon={getIconType(10)}
onClick={() => {
closeRowSizePopover();
setRowSize(10);
}}
>
<EuiContextMenuItem key="10 rows" icon={getIconType(10)} onClick={() => onPerPageClick(10)}>
{'10 rows'}
</EuiContextMenuItem>,
<EuiContextMenuItem
key="25 rows"
icon={getIconType(25)}
onClick={() => {
closeRowSizePopover();
setRowSize(25);
}}
>
<EuiContextMenuItem key="25 rows" icon={getIconType(25)} onClick={() => onPerPageClick(25)}>
{'25 rows'}
</EuiContextMenuItem>,
];
Expand Down Expand Up @@ -397,14 +382,16 @@ export const SharedLists = React.memo(() => {
return (
<>
<MissingPrivilegesCallOut />
<EuiFlexGroup>
<EuiFlexItem>
<EuiPageHeader
pageTitle={i18n.ALL_EXCEPTIONS}
description={
<>
<div>
{"To view rule specific exceptions navigate to that rule's details page."}
<EuiPageHeader
pageTitle={i18n.ALL_EXCEPTIONS}
description={
<EuiFlexGroup gutterSize="xs" direction="column">
<EuiFlexItem>
<EuiFlexGroup gutterSize="none" direction="row">
<EuiFlexItem grow={false}>
<EuiText>{i18n.ALL_EXCEPTIONS_SUBTITLE}</EuiText>
</EuiFlexItem>
<EuiFlexItem>
<EuiButtonIcon
iconType="popout"
aria-label="go-to-rules"
Expand All @@ -413,24 +400,18 @@ export const SharedLists = React.memo(() => {
navigateToApp('security', { openInNewTab: true, path: '/rules' })
}
/>
</div>
{/* TODO: update the above text to incorporate a navigateToApp link to the rule management page */}
<div>
{timelines.getLastUpdated({
showUpdating: loading,
updatedAt: lastUpdated,
})}
</div>
</>
}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton iconType={'importAction'} onClick={() => setDisplayImportListFlyout(true)}>
{i18n.IMPORT_EXCEPTION_LIST_BUTTON}
</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem>
{timelines.getLastUpdated({
showUpdating: loading,
updatedAt: lastUpdated,
})}
</EuiFlexItem>
</EuiFlexGroup>
}
rightSideItems={[
<EuiPopover
data-test-subj="manageExceptionListCreateButton"
button={
Expand Down Expand Up @@ -463,9 +444,12 @@ export const SharedLists = React.memo(() => {
</EuiContextMenuItem>,
]}
/>
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPopover>,
<EuiButton iconType={'importAction'} onClick={() => setDisplayImportListFlyout(true)}>
{i18n.IMPORT_EXCEPTION_LIST_BUTTON}
</EuiButton>,
]}
/>

{displayCreateSharedListFlyout && (
<CreateSharedListFlyout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ export const ALL_EXCEPTIONS = i18n.translate(
}
);

export const ALL_EXCEPTIONS_SUBTITLE = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.allExceptions.tableSubtitle',
{
defaultMessage: "To view rule specific exceptions navigate to that rule's details page.",
}
);

export const allExceptionsRowPerPage = (rowSize: number) =>
i18n.translate('xpack.securitySolution.exceptions.allExceptionsRowPerPage', {
defaultMessage: 'Rows per page: {rowSize}',
values: { rowSize },
});

export const NO_LISTS_BODY = i18n.translate(
'xpack.securitySolution.detectionEngine.rules.allExceptions.filters.noListsBody',
{
Expand Down

0 comments on commit 77eb735

Please sign in to comment.