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

Refactor ruleset management #4174

Merged
merged 88 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
2f87445
Refactored implementation of wazuh table
asteriscos May 26, 2022
1d07dec
Refactored action buttons
asteriscos May 27, 2022
8aa84f2
Partial commit ruleset views segregation
asteriscos May 30, 2022
ccc99e0
Added searchbar input custom filter buttons
asteriscos May 31, 2022
49da44c
Added Custom Field Filter to table & removed redux from action buttons
asteriscos May 31, 2022
1e45afd
Segregated file tables
asteriscos Jun 1, 2022
7a5f031
set showingFiles locally
asteriscos Jun 1, 2022
3f2d38b
Fixed details flyout
asteriscos Jun 15, 2022
25d0ec9
Segregate views
asteriscos Jun 16, 2022
16e6f8e
Removed redux from ruleset editor
asteriscos Jun 22, 2022
bc0ec81
refactored Decoders section
asteriscos Jun 23, 2022
4a50e2d
delete obsolete decoder-info
asteriscos Jun 23, 2022
779308c
Fixed decoder flyout
asteriscos Jun 27, 2022
ca705f8
Added decoder info.tsx
asteriscos Jun 27, 2022
491ec09
Remove unused files
asteriscos Jun 27, 2022
64822e4
Set CDBList views
asteriscos Jun 27, 2022
c6df6b9
Dynamically build table custom action buttons
asteriscos Jun 27, 2022
b8b5579
Deleted hardcoded export csv filename
asteriscos Jun 27, 2022
097b45d
Fix CDB List row click handler
asteriscos Jun 27, 2022
0ce3da1
Fixed suggestions and custom actions responsive styles
asteriscos Jun 28, 2022
c1856de
columns configuration fix
asteriscos Jun 28, 2022
e5e7d11
wzApiTable optimization + obsolete redux cleaning
asteriscos Jun 28, 2022
82aa3af
Implemented Wazuh flyouts
asteriscos Jun 29, 2022
ca83b38
Convert to typescript
asteriscos Jun 29, 2022
aad34b7
Extracted tables components
asteriscos Jun 29, 2022
e75376e
Fix mapStateToProps to null
asteriscos Jun 29, 2022
b0ef504
Removed ruleset redux files
asteriscos Jun 29, 2022
b1add41
Removed Add CDB List button in ruleset and decoders views
asteriscos Jun 29, 2022
00badf6
Fix missing updateListContent
asteriscos Jun 30, 2022
29a8e15
Added external reload to the tables
asteriscos Jul 1, 2022
42ce820
Fixed redirectRule url cleaning
asteriscos Jul 1, 2022
f3c158c
Fix onClose modal preventDefault
asteriscos Jul 1, 2022
ef90888
Fix reload props
asteriscos Jul 1, 2022
5699d6a
Fix onClick modal preventDefault
asteriscos Jul 1, 2022
8b9f4f3
Clean code comments
asteriscos Jul 1, 2022
9ac06e1
Merge branch '4.4-7.10' into refactor/management-rules-4105
asteriscos Jul 1, 2022
7822cc5
Added error handling to tables columns
asteriscos Jul 12, 2022
93e718e
removed deprecated code
asteriscos Jul 12, 2022
3d3f6b6
Fixed file description and objects destructuring
asteriscos Jul 12, 2022
f1cb4dd
Refactored class components to functional
asteriscos Jul 12, 2022
e0e0f6a
Changed file view state handling
asteriscos Jul 14, 2022
992a969
Refactored implementation of wazuh table
asteriscos May 26, 2022
a54478c
Refactored action buttons
asteriscos May 27, 2022
d00c49d
Partial commit ruleset views segregation
asteriscos May 30, 2022
57573d9
Added searchbar input custom filter buttons
asteriscos May 31, 2022
1991ddf
Added Custom Field Filter to table & removed redux from action buttons
asteriscos May 31, 2022
5ae5b93
Segregated file tables
asteriscos Jun 1, 2022
af6a4dd
set showingFiles locally
asteriscos Jun 1, 2022
2227403
Fixed details flyout
asteriscos Jun 15, 2022
c96276b
Segregate views
asteriscos Jun 16, 2022
16c2ab1
Removed redux from ruleset editor
asteriscos Jun 22, 2022
85d4b19
refactored Decoders section
asteriscos Jun 23, 2022
af8ff24
delete obsolete decoder-info
asteriscos Jun 23, 2022
e0daf5c
Fixed decoder flyout
asteriscos Jun 27, 2022
c797fde
Added decoder info.tsx
asteriscos Jun 27, 2022
3b7565f
Remove unused files
asteriscos Jun 27, 2022
860948c
Set CDBList views
asteriscos Jun 27, 2022
e8903c8
Dynamically build table custom action buttons
asteriscos Jun 27, 2022
25b6f0e
Deleted hardcoded export csv filename
asteriscos Jun 27, 2022
2f3b46c
Fix CDB List row click handler
asteriscos Jun 27, 2022
2c4fe24
Fixed suggestions and custom actions responsive styles
asteriscos Jun 28, 2022
b8d73cd
columns configuration fix
asteriscos Jun 28, 2022
4688796
wzApiTable optimization + obsolete redux cleaning
asteriscos Jun 28, 2022
79e20af
Implemented Wazuh flyouts
asteriscos Jun 29, 2022
2813738
Convert to typescript
asteriscos Jun 29, 2022
1ce01a8
Extracted tables components
asteriscos Jun 29, 2022
f140be3
Fix mapStateToProps to null
asteriscos Jun 29, 2022
fc229db
Removed ruleset redux files
asteriscos Jun 29, 2022
4cf8b61
Removed Add CDB List button in ruleset and decoders views
asteriscos Jun 29, 2022
676dc03
Fix missing updateListContent
asteriscos Jun 30, 2022
5e3dc25
Added external reload to the tables
asteriscos Jul 1, 2022
4510579
Fixed redirectRule url cleaning
asteriscos Jul 1, 2022
0a2310e
Fix onClose modal preventDefault
asteriscos Jul 1, 2022
647772b
Fix reload props
asteriscos Jul 1, 2022
77bd1c9
Fix onClick modal preventDefault
asteriscos Jul 1, 2022
1f2318a
Clean code comments
asteriscos Jul 1, 2022
dc03938
Added error handling to tables columns
asteriscos Jul 12, 2022
33b977b
removed deprecated code
asteriscos Jul 12, 2022
2df0d43
Fixed file description and objects destructuring
asteriscos Jul 12, 2022
0f1cca3
Refactored class components to functional
asteriscos Jul 12, 2022
ebb4581
Changed file view state handling
asteriscos Jul 14, 2022
4d2621e
Merge branch 'refactor/management-rules-4105' of https://github.com/w…
AlexRuiz7 Sep 5, 2022
472e6e6
Remove unused imports
AlexRuiz7 Sep 5, 2022
842cfb3
Fixed ResourcesHandler
asteriscos Sep 5, 2022
61d1527
Added interfaces and fixed comments
asteriscos Sep 7, 2022
8af9d99
Add section contants
asteriscos Sep 7, 2022
fec6c9e
Code styling
asteriscos Sep 8, 2022
99b6152
Replaced string for constants
asteriscos Sep 8, 2022
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
8 changes: 4 additions & 4 deletions public/components/common/buttons/modal-confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ interface WzButtonModalConfirmProps{
};

const renderModal = ({onConfirm, onCancel, modalTitle, modalConfirmText, modalCancelText, modalProps }) => ({close}) => {
const onModalConfirm = () => {
close();
const onModalConfirm = (ev) => {
close(ev);
onConfirm && onConfirm();
};
const onModalCancel = () => {
close();
const onModalCancel = (ev) => {
close(ev);
onCancel && onCancel();
};
return (
Expand Down
12 changes: 9 additions & 3 deletions public/components/common/hocs/withButtonOpenOnClick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
import React, { useState } from 'react';


export const withButtonOpenOnClick = WrappedComponent => ({render, ...rest} : {render?:any, [x:string]: any}) => {
export const withButtonOpenOnClick = WrappedComponent => ({render, onClick, onClose, ...rest} : {render?:any, [x:string]: any}) => {
const [isOpen, setIsOpen] = useState(false);

const open = ev => setIsOpen(true);
const close = ev => setIsOpen(false);
const open = ev => {
typeof onClick === 'function' && onClick(ev);
setIsOpen(true);
};
const close = ev => {
typeof onClose === 'function' && onClose(ev);
setIsOpen(false)
};

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrat
import { UI_LOGGER_LEVELS } from '../../../../../common/constants';
import { getErrorOrchestrator } from '../../../../react-services/common-services';

export function ExportTableCsv({endpoint,totalItems,filters,title}){
export function ExportTableCsv({ endpoint, totalItems, filters, title }) {

const showToast = (color, title, time) => {
getToasts().add({
Expand All @@ -42,7 +42,7 @@ export function ExportTableCsv({endpoint,totalItems,filters,title}){
[
...formatedFilters
],
`vuls-${(title).toLowerCase()}`
`${(title).toLowerCase()}`
);
} catch (error) {
const options = {
Expand Down
21 changes: 18 additions & 3 deletions public/components/common/tables/table-default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Find more information about this on the LICENSE file.
*/

import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { EuiBasicTable } from '@elastic/eui';
import { UI_ERROR_SEVERITIES } from '../../../react-services/error-orchestrator/types';
import { UI_LOGGER_LEVELS } from '../../../../common/constants';
Expand Down Expand Up @@ -43,6 +43,8 @@ export function TableDefault({
}
});

const isMounted = useRef(false);

function tableOnChange({ page = {}, sort = {} }){
const { index: pageIndex, size: pageSize } = page;
const { field, direction } = sort;
Expand All @@ -59,9 +61,14 @@ export function TableDefault({
};

useEffect(() => {
// Reset the page index when the endpoint changes.
// This will cause that onSearch function is triggered because to changes in pagination in the another effect.
// This effect is triggered when the component is mounted because of how to the useEffect hook works.
// We don't want to set the pagination state because there is another effect that has this dependency
// and will cause the effect is triggered (redoing the onSearch function).
if (isMounted.current) {
// Reset the page index when the endpoint changes.
// This will cause that onSearch function is triggered because to changes in pagination in the another effect.
setPagination({pageIndex: 0, pageSize: pagination.pageSize});
}
}, [endpoint]);

useEffect(() => {
Expand Down Expand Up @@ -90,6 +97,14 @@ export function TableDefault({
})()
}, [endpoint, pagination, sorting, reload]);


// It is required that this effect runs after other effects that use isMounted
// to avoid that these effects run when the component is mounted, only running
// when one of its dependencies changes.
useEffect(() => {
isMounted.current = true;
}, []);

const tablePagination = {
...pagination,
totalItemCount: totalItems,
Expand Down
64 changes: 43 additions & 21 deletions public/components/common/tables/table-with-search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* Find more information about this on the LICENSE file.
*/

import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { EuiBasicTable, EuiSpacer } from '@elastic/eui';
import _ from 'lodash';
import { WzSearchBar } from '../../wz-search-bar/';
import { UI_ERROR_SEVERITIES } from '../../../react-services/error-orchestrator/types';
import { UI_LOGGER_LEVELS } from '../../../../common/constants';
Expand Down Expand Up @@ -48,29 +49,38 @@ export function TableWithSearchBar({
},
});

const isMounted = useRef(false);

function tableOnChange({ page = {}, sort = {} }) {
const { index: pageIndex, size: pageSize } = page;
const { field, direction } = sort;
setPagination({
pageIndex,
pageSize,
});
setSorting({
sort: {
field,
direction,
},
});
if (isMounted.current) {
const { index: pageIndex, size: pageSize } = page;
const { field, direction } = sort;
setPagination({
pageIndex,
pageSize,
});
setSorting({
sort: {
field,
direction,
},
});
}
}

useEffect(() => {
// Reset the page index when the endpoint changes.
// This will cause that onSearch function is triggered because to changes in pagination in the another effect.
setPagination({pageIndex: 0, pageSize: pagination.pageSize});
}, [endpoint]);
// This effect is triggered when the component is mounted because of how to the useEffect hook works.
// We don't want to set the pagination state because there is another effect that has this dependency
// and will cause the effect is triggered (redoing the onSearch function).
if (isMounted.current) {
// Reset the page index when the endpoint changes.
// This will cause that onSearch function is triggered because to changes in pagination in the another effect.
setPagination({ pageIndex: 0, pageSize: pagination.pageSize });
}
}, [endpoint, reload]);

useEffect(() => {
(async function () {
useEffect(function () {
(async () => {
try {
setLoading(true);
const { items, totalItems } = await onSearch(endpoint, filters, pagination, sorting);
Expand All @@ -93,12 +103,24 @@ export function TableWithSearchBar({
}
setLoading(false);
})();
}, [filters, pagination, sorting, reload]);
}, [filters, pagination, sorting]);

useEffect(() => {
setFilters(rest.filters || []);
// This effect is triggered when the component is mounted because of how to the useEffect hook works.
// We don't want to set the filters state because there is another effect that has this dependency
// and will cause the effect is triggered (redoing the onSearch function).
if (isMounted.current && !_.isEqual(rest.filters, filters)) {
setFilters(rest.filters || []);
}
}, [rest.filters]);

// It is required that this effect runs after other effects that use isMounted
// to avoid that these effects run when the component is mounted, only running
// when one of its dependencies changes.
useEffect(() => {
isMounted.current = true;
}, []);

const tablePagination = {
...pagination,
totalItemCount: totalItems,
Expand Down
119 changes: 96 additions & 23 deletions public/components/common/tables/table-wz-api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,59 @@
* Find more information about this on the LICENSE file.
*/

import React, { useCallback, useState } from 'react';
import React, { ReactNode, useCallback, useEffect, useState } from 'react';
import {
EuiTitle,
EuiLoadingSpinner,
EuiFlexGroup,
EuiFlexItem,
EuiText,
EuiButtonEmpty
} from '@elastic/eui';
import { filtersToObject } from '../../wz-search-bar';
import { TableWithSearchBar } from './table-with-search-bar';
import { TableDefault } from './table-default'
import { WzRequest } from '../../../react-services/wz-request';
import { ExportTableCsv } from './components/export-table-csv';
import { ExportTableCsv } from './components/export-table-csv';
import { UI_ERROR_SEVERITIES } from '../../../react-services/error-orchestrator/types';
import { UI_LOGGER_LEVELS } from '../../../../common/constants';
import { getErrorOrchestrator } from '../../../react-services/common-services';

export function TableWzAPI({...rest}){
/**
* Search input custom filter button
*/
interface CustomFilterButton {
label: string
field: string
value: string
}

export function TableWzAPI({ actionButtons, ...rest }: {
actionButtons?: ReactNode | ReactNode[]
title?: string
description?: string
downloadCsv?: boolean
searchTable?: boolean
endpoint: string
buttonOptions?: CustomFilterButton[]
onFiltersChange?: Function,
showReload?: boolean
searchBarProps?: any
reload?: any
}) {

const [totalItems, setTotalItems] = useState(0);
const [filters, setFilters] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const onFiltersChange = filters => typeof rest.onFiltersChange === 'function' ? rest.onFiltersChange(filters) : null;

const onSearch = useCallback(async function(endpoint, filters, pagination, sorting){
/**
* Changing the reloadFootprint timestamp will trigger reloading the table
*/
const [reloadFootprint, setReloadFootprint] = useState(rest.reload || 0);


const onSearch = useCallback(async function (endpoint, filters, pagination, sorting) {
try {
const { pageIndex, pageSize } = pagination;
const { field, direction } = sorting.sort;
Expand Down Expand Up @@ -68,36 +97,80 @@ export function TableWzAPI({...rest}){
};
getErrorOrchestrator().handleError(options);
};
},[]);
}, []);

const renderActionButtons = (<>
{Array.isArray(actionButtons) ?
actionButtons.map((button, key) => <EuiFlexItem key={key} grow={false}>{button}</EuiFlexItem>) :
(typeof actionButtons === 'object') && <EuiFlexItem grow={false}>{actionButtons}</EuiFlexItem>}
</>)

/**
* Generate a new reload footprint
*/
const triggerReload = () => {
setReloadFootprint(Date.now());
}

useEffect(() => {
if (rest.reload)
triggerReload();
}, [rest.reload])

const ReloadButton = () => (
<EuiFlexItem grow={false}>
<EuiButtonEmpty isDisabled={(totalItems == 0)} iconType="refresh" onClick={() => triggerReload()}>
Refresh
</EuiButtonEmpty>
</EuiFlexItem>
)
asteriscos marked this conversation as resolved.
Show resolved Hide resolved

const header = (
<EuiFlexGroup>
<EuiFlexItem>
<EuiFlexGroup wrap>
<EuiFlexItem className="wz-flex-basis-auto" grow={false}>
{rest.title && (
<EuiTitle size="s">
<h1>{rest.title} {isLoading ? <EuiLoadingSpinner size="s" /> : <span>({ totalItems })</span>}</h1>
<h1>{rest.title} {isLoading ? <EuiLoadingSpinner size="s" /> : <span>({totalItems})</span>}</h1>
</EuiTitle>
)}
{rest.description && (
<EuiText color="subdued">
{rest.description}
</EuiText>
)}
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup
wrap
justifyContent={'flexEnd'}
alignItems={'center'}
>
{/* Render optional custom action button */}
{renderActionButtons}
{/* Render optional reload button */}
{rest.showReload && <ReloadButton />}
{/* Render optional export to CSV button */}
{rest.downloadCsv && <ExportTableCsv endpoint={rest.endpoint} totalItems={totalItems} filters={filters} title={rest.title} />}
</EuiFlexGroup>
</EuiFlexItem>
{rest.downloadCsv && <ExportTableCsv endpoint={rest.endpoint} totalItems={totalItems} filters={filters} title={rest.title}/>}
</EuiFlexGroup>
)

const table = rest.searchTable ?
<TableWithSearchBar
onSearch={onSearch}
{...rest}
/> :
<TableDefault
onSearch={onSearch}
{...rest}
/>
const table = rest.searchTable ?
<TableWithSearchBar
onSearch={onSearch}
{...{...rest, reload: reloadFootprint}}
/> :
<TableDefault
onSearch={onSearch}
{...{...rest, reload: reloadFootprint}}
/>

return (
<>
{header}
{table}
</>)
<>
{header}
{table}
</>)
}

// Set default props
Expand Down
1 change: 0 additions & 1 deletion public/components/common/welcome/components/menu-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ class WzMenuAgent extends Component {

const mapStateToProps = (state) => {
return {
state: state.rulesetReducers,
currentAgentData: state.appStateReducers.currentAgentData,
currentTab: state.appStateReducers.currentTab,
};
Expand Down
1 change: 0 additions & 1 deletion public/components/wz-menu/wz-menu-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ class WzMenuAgent extends Component {

const mapStateToProps = state => {
return {
state: state.rulesetReducers,
currentAgentData: state.appStateReducers.currentAgentData,
currentTab: state.appStateReducers.currentTab
};
Expand Down
2 changes: 1 addition & 1 deletion public/components/wz-menu/wz-menu-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class WzMenuManagement extends Component {

const mapStateToProps = state => {
return {
state: state.rulesetReducers,
state: state.managementReducers,
};
};

Expand Down
1 change: 0 additions & 1 deletion public/components/wz-menu/wz-menu-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ class WzMenuOverview extends Component {

const mapStateToProps = state => {
return {
state: state.rulesetReducers,
currentAgentData: state.appStateReducers.currentAgentData,
currentTab: state.appStateReducers.currentTab
};
Expand Down
Loading