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

[SIEM] [Detection Engine] remove all unknowns from all rules table props #62327

Merged
merged 5 commits into from
Apr 3, 2020
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
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 @@ -81,8 +81,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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw in cases they used type EuiTableSortingType but then again I know we're limiting it to only sort the enabled field. Maybe something like EuiTableSortingType<Pick<Rule, 'enabled'>> (that might be off).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since EuiTableSortingType has sorting as optional, @XavierM mentioned that it might be better to explicitly type this field out, rather than using the eui type.

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