Skip to content

Commit

Permalink
[7.x] [SIEM] [Detection Engine] remove all unknowns from all r… (#62527)
Browse files Browse the repository at this point in the history
* remove all unknowns from all rules table props

* update sorting property type remove optional, also remove unnecessary properties we are not using in sorting, rename paginationMemo prop to pagination, remove null from rulesStatuses type as we are defaulting to empty array now

* fixes type mismatch for sorting and rulesStatuses

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
dhurley14 and elasticmachine authored Apr 4, 2020
1 parent 91ffafa commit a64de84
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Func = (ruleId: string) => void;
export type ReturnRuleStatus = [boolean, RuleStatus | null, Func | null];
export interface ReturnRulesStatuses {
loading: boolean;
rulesStatuses: RuleStatusRowItemType[] | null;
rulesStatuses: RuleStatusRowItemType[];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export type RuleStatusRowItemType = RuleStatus & {
name: string;
id: string;
};
type RulesColumns = EuiBasicTableColumn<Rule> | EuiTableActionsColumnType<Rule>;
type RulesStatusesColumns = EuiBasicTableColumn<RuleStatusRowItemType>;
export type RulesColumns = EuiBasicTableColumn<Rule> | EuiTableActionsColumnType<Rule>;
export type RulesStatusesColumns = EuiBasicTableColumn<RuleStatusRowItemType>;

interface GetColumns {
dispatch: React.Dispatch<Action>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { Loader } from '../../../../components/loader';
import { Panel } from '../../../../components/panel';
import { PrePackagedRulesPrompt } from '../components/pre_packaged_rules/load_empty_prompt';
import { GenericDownloader } from '../../../../components/generic_downloader';
import { AllRulesTables } from '../components/all_rules_tables';
import { AllRulesTables, SortingType } from '../components/all_rules_tables';
import { getPrePackagedRuleStatus } from '../helpers';
import * as i18n from '../translations';
import { EuiBasicTableOnChange } from '../types';
Expand Down Expand Up @@ -128,7 +128,7 @@ export const AllRules = React.memo<AllRulesProps>(
});

const sorting = useMemo(
() => ({ sort: { field: 'enabled', direction: filterOptions.sortOrder } }),
(): SortingType => ({ sort: { field: 'enabled', direction: filterOptions.sortOrder } }),
[filterOptions.sortOrder]
);

Expand Down Expand Up @@ -330,7 +330,7 @@ export const AllRules = React.memo<AllRulesProps>(
euiBasicTableSelectionProps={euiBasicTableSelectionProps}
hasNoPermissions={hasNoPermissions}
monitoringColumns={monitoringColumns}
paginationMemo={paginationMemo}
pagination={paginationMemo}
rules={rules}
rulesColumns={rulesColumns}
rulesStatuses={rulesStatuses}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,59 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiBasicTable, EuiTab, EuiTabs, EuiEmptyPrompt } from '@elastic/eui';
import {
EuiBasicTable,
EuiBasicTableColumn,
EuiTab,
EuiTabs,
EuiEmptyPrompt,
Direction,
EuiTableSelectionType,
} from '@elastic/eui';
import React, { useMemo, memo, useState } from 'react';
import styled from 'styled-components';

import { EuiBasicTableOnChange } from '../../types';
import * as i18n from '../../translations';
import { RuleStatusRowItemType } from '../../../../../pages/detection_engine/rules/all/columns';
import { Rules } from '../../../../../containers/detection_engine/rules';
import {
RulesColumns,
RuleStatusRowItemType,
} from '../../../../../pages/detection_engine/rules/all/columns';
import { Rule, Rules } from '../../../../../containers/detection_engine/rules';

// EuiBasicTable give me a hardtime with adding the ref attributes so I went the easy way
// after few hours of fight with typescript !!!! I lost :(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const MyEuiBasicTable = styled(EuiBasicTable as any)`` as any;

export interface SortingType {
sort: {
field: 'enabled';
direction: Direction;
};
}

interface AllRulesTablesProps {
euiBasicTableSelectionProps: unknown;
euiBasicTableSelectionProps: EuiTableSelectionType<Rule>;
hasNoPermissions: boolean;
monitoringColumns: unknown;
paginationMemo: unknown;
monitoringColumns: Array<EuiBasicTableColumn<RuleStatusRowItemType>>;
pagination: {
pageIndex: number;
pageSize: number;
totalItemCount: number;
pageSizeOptions: number[];
};
rules: Rules;
rulesColumns: unknown;
rulesStatuses: RuleStatusRowItemType[] | null;
sorting: unknown;
tableOnChangeCallback: unknown;
tableRef?: unknown;
rulesColumns: RulesColumns[];
rulesStatuses: RuleStatusRowItemType[];
sorting: {
sort: {
field: 'enabled';
direction: Direction;
};
};
tableOnChangeCallback: ({ page, sort }: EuiBasicTableOnChange) => void;
tableRef?: React.MutableRefObject<EuiBasicTable | undefined>;
}

enum AllRulesTabs {
Expand All @@ -52,7 +81,7 @@ const AllRulesTablesComponent: React.FC<AllRulesTablesProps> = ({
euiBasicTableSelectionProps,
hasNoPermissions,
monitoringColumns,
paginationMemo,
pagination,
rules,
rulesColumns,
rulesStatuses,
Expand Down Expand Up @@ -95,7 +124,7 @@ const AllRulesTablesComponent: React.FC<AllRulesTablesProps> = ({
items={rules ?? []}
noItemsMessage={emptyPrompt}
onChange={tableOnChangeCallback}
pagination={paginationMemo}
pagination={pagination}
ref={tableRef}
sorting={sorting}
selection={hasNoPermissions ? undefined : euiBasicTableSelectionProps}
Expand All @@ -110,7 +139,7 @@ const AllRulesTablesComponent: React.FC<AllRulesTablesProps> = ({
items={rulesStatuses}
noItemsMessage={emptyPrompt}
onChange={tableOnChangeCallback}
pagination={paginationMemo}
pagination={pagination}
sorting={sorting}
/>
)}
Expand Down

0 comments on commit a64de84

Please sign in to comment.