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

Feature/pagination drilldown tables #3544

Merged
merged 5 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -46,6 +46,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Created a separate component to check for sample data [#3475](https://github.com/wazuh/wazuh-kibana-app/pull/3475)
- Added a new hook for getting value suggestions [#3506](https://github.com/wazuh/wazuh-kibana-app/pull/3506)
- Added base Module Panel view with Office365 setup [#3518](https://github.com/wazuh/wazuh-kibana-app/pull/3518)
- Adding Pagination and filter to drilldown tables at Office pannel [#3544](https://github.com/wazuh/wazuh-kibana-app/issues/3544).

### Changed

Expand Down
2 changes: 1 addition & 1 deletion public/components/common/hooks/use-es-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const useEsSearch = ({ preAppliedFilters = [], preAppliedAggs = {}, size = 10 })
setIsLoading(false);
}
})();
}, [indexPattern, query, filters, page]);
}, [indexPattern, query, filters, page, preAppliedAggs]);

const search = async (): Promise<SearchResponse> => {
if (indexPattern) {
Expand Down
52 changes: 38 additions & 14 deletions public/components/common/modules/panel/components/agg-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Find more information about this on the LICENSE file.
*/

import { EuiBasicTable, EuiPanel, EuiTitle, EuiBasicTableColumn } from '@elastic/eui';
import { EuiPanel, EuiTitle, EuiBasicTableColumn, EuiInMemoryTable } from '@elastic/eui';
import { useEsSearch } from '../../../hooks';
import React from 'react';
import React, { useState, useMemo } from 'react';

export const AggTable = ({
onRowClick = (field, value) => {},
Expand All @@ -24,27 +24,33 @@ export const AggTable = ({
panelProps,
titleProps,
}) => {
const preAppliedAggs = {
buckets: {
terms: {
field: aggTerm,
size: maxRows,
order: { _count: 'desc' },
const [order, setOrder] = useState({ _count: 'desc' });
const preAppliedAggs = useMemo(() => {
return {
buckets: {
terms: {
field: aggTerm,
size: maxRows,
order,
},
},
},
};
};
}, [order, aggTerm, maxRows]);

const { esResults, isLoading, error } = useEsSearch({ preAppliedAggs });
const buckets = ((esResults.aggregations || {}).buckets || {}).buckets || [];
const columns: EuiBasicTableColumn<any>[] = [
{
field: 'key',
name: aggLabel,
sortable: true,
},
{
field: 'doc_count',
name: 'Count',
isExpander: false,
align: 'right',
sortable: true,
},
];
const getRowProps = (item) => {
Expand All @@ -56,18 +62,36 @@ export const AggTable = ({
},
};
};

const pagination = {
hidePerPageOptions: true,
pageSize: 10,
};
const sorting = {
sort: {
field: 'doc_count',
direction: 'desc',
},
};
const onTableChange = ({ sort = {} }) => {
if (sort.field) {
const field = { key: '_key', doc_count: '_count' }[sort.field];
setOrder({ [field]: sort.direction });
}
};
return (
<EuiPanel data-test-subj={`${aggTerm}-aggTable`} {...panelProps}>
<EuiTitle {...titleProps}>
<h2>{tableTitle}</h2>
</EuiTitle>
<EuiBasicTable
items={buckets}
<EuiInMemoryTable
columns={columns}
rowProps={getRowProps}
items={buckets}
loading={isLoading}
rowProps={getRowProps}
error={error ? error.message : undefined}
pagination={pagination}
onTableChange={onTableChange}
sorting={sorting}
/>
</EuiPanel>
);
Expand Down