Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski committed Jan 26, 2021
1 parent 3303ecc commit 395abff
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 82 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib
# Security Intelligence And Analytics
/x-pack/plugins/security_solution/server/lib/detection_engine/rules/prepackaged_rules @elastic/security-intelligence-analytics

# Security Asset Management
/x-pack/plugins/osquery @elastic/security-asset-management

# Design (at the bottom for specificity of SASS files)
**/*.scss @elastic/kibana-design
#CC# /packages/kbn-ui-framework/ @elastic/kibana-design
Expand Down
9 changes: 0 additions & 9 deletions x-pack/plugins/osquery/.i18nrc.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SearchResponse } from 'elasticsearch';
import { IEsSearchResponse } from '../../../../../../../src/plugins/data/common';

import { CursorType, Inspect, Maybe, PageInfoPaginated } from '../../common';
import { Inspect, Maybe, PageInfoPaginated } from '../../common';
import { RequestOptions, RequestOptionsPaginated } from '../..';

export interface ActionEdge {
node: any[];
cursor: CursorType;
}

export interface ActionResultEdge {
node: any[];
cursor: CursorType;
}
export type ActionEdge = SearchResponse<object>['hits']['hits'];

export type ActionResultEdge = SearchResponse<object>['hits']['hits'];
export interface ActionsStrategyResponse extends IEsSearchResponse {
edges: ActionEdge[];
edges: ActionEdge;
totalCount: number;
pageInfo: PageInfoPaginated;
inspect?: Maybe<Inspect>;
Expand All @@ -38,7 +32,7 @@ export interface ActionDetailsRequestOptions extends RequestOptions {
}

export interface ActionResultsStrategyResponse extends IEsSearchResponse {
edges: ActionResultEdge[];
edges: ActionResultEdge;
totalCount: number;
pageInfo: PageInfoPaginated;
inspect?: Maybe<Inspect>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@

import { IEsSearchResponse } from '../../../../../../../src/plugins/data/common';

import { CursorType, Inspect, Maybe, PageInfoPaginated } from '../../common';
import { Inspect, Maybe, PageInfoPaginated } from '../../common';
import { RequestOptionsPaginated } from '../..';

export interface AgentEdge {
node: any[];
cursor: CursorType;
}
import { Agent } from '../../../shared_imports';

export interface AgentsStrategyResponse extends IEsSearchResponse {
edges: AgentEdge[];
edges: Agent[];
totalCount: number;
pageInfo: PageInfoPaginated;
inspect?: Maybe<Inspect>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SearchResponse } from 'elasticsearch';
import { IEsSearchResponse } from '../../../../../../../src/plugins/data/common';

import { CursorType, Inspect, Maybe, PageInfoPaginated } from '../../common';
import { Inspect, Maybe, PageInfoPaginated } from '../../common';
import { RequestOptionsPaginated } from '../..';

export interface ResultEdge {
node: any[];
cursor: CursorType;
}
export type ResultEdge = SearchResponse<unknown>['hits']['hits'];

export interface ResultsStrategyResponse extends IEsSearchResponse {
edges: ResultEdge[];
edges: ResultEdge;
totalCount: number;
pageInfo: PageInfoPaginated;
inspect?: Maybe<Inspect>;
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/osquery/common/shared_imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { Agent } from '../../fleet/common';
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const ActionResultsTableComponent: React.FC<ActionResultsTableProps> = ({ action
() => ({ rowIndex, columnId, setCellProps }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const data = useContext(DataContext);

// @ts-expect-error
const value = data[rowIndex].fields[columnId];

return !isEmpty(value) ? value : '-';
Expand All @@ -82,6 +82,7 @@ const ActionResultsTableComponent: React.FC<ActionResultsTableProps> = ({ action
);

useEffect(() => {
// @ts-expect-error
const newColumns = keys(results[0]?.fields)
.sort()
.map((fieldName) => ({
Expand Down
15 changes: 8 additions & 7 deletions x-pack/plugins/osquery/public/actions/actions_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { isEmpty, isEqual, keys, map } from 'lodash/fp';
import { EuiDataGrid, EuiDataGridProps, EuiDataGridColumn } from '@elastic/eui';
import { EuiDataGrid, EuiDataGridProps, EuiDataGridColumn, EuiDataGridSorting } from '@elastic/eui';
import React, { createContext, useEffect, useState, useCallback, useContext, useMemo } from 'react';

import { useAllActions } from './use_all_actions';
Expand All @@ -14,7 +14,6 @@ import { ActionEdge, Direction } from '../../common/search_strategy';
const DataContext = createContext<ActionEdge[]>([]);

const ActionsTableComponent = () => {
// ** Pagination config
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 50 });
const onChangeItemsPerPage = useCallback(
(pageSize) =>
Expand All @@ -33,7 +32,7 @@ const ActionsTableComponent = () => {
const [columns, setColumns] = useState<EuiDataGridColumn[]>([]);

// ** Sorting config
const [sortingColumns, setSortingColumns] = useState<string[]>([]);
const [sortingColumns, setSortingColumns] = useState<EuiDataGridSorting['columns']>([]);

const [, { actions, totalCount }] = useAllActions({
activePage: pagination.pageIndex,
Expand All @@ -55,16 +54,17 @@ const ActionsTableComponent = () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const data = useContext(DataContext);

// @ts-expect-error
const value = data[rowIndex].fields[columnId];

return !isEmpty(value) ? value : '-';
};
}, []);

const tableSorting = useMemo(() => ({ columns: sortingColumns, onSort: setSortingColumns }), [
setSortingColumns,
sortingColumns,
]);
const tableSorting: EuiDataGridSorting = useMemo(
() => ({ columns: sortingColumns, onSort: setSortingColumns }),
[setSortingColumns, sortingColumns]
);

const tablePagination = useMemo(
() => ({
Expand All @@ -77,6 +77,7 @@ const ActionsTableComponent = () => {
);

useEffect(() => {
// @ts-expect-error
const newColumns = keys(actions[0]?.fields)
.sort()
.map((fieldName) => ({
Expand Down
30 changes: 19 additions & 11 deletions x-pack/plugins/osquery/public/agents/agents_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@

import { find } from 'lodash/fp';
import React, { useCallback, useEffect, useMemo, useState, useRef } from 'react';
import { EuiBasicTable, EuiBasicTableProps, EuiTableSelectionType, EuiHealth } from '@elastic/eui';
import {
EuiBasicTable,
EuiBasicTableColumn,
EuiBasicTableProps,
EuiTableSelectionType,
EuiHealth,
} from '@elastic/eui';

import { useAllAgents } from './use_all_agents';
import { AgentEdge, Direction } from '../../common/search_strategy';
import { Direction } from '../../common/search_strategy';
import { Agent } from '../shared_imports';

interface AgentsTableProps {
selectedAgents: string[];
Expand All @@ -19,12 +26,12 @@ interface AgentsTableProps {
const AgentsTableComponent: React.FC<AgentsTableProps> = ({ selectedAgents, onChange }) => {
const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(5);
const [sortField, setSortField] = useState('firstName');
const [sortField, setSortField] = useState<keyof Agent>('id');
const [sortDirection, setSortDirection] = useState<Direction>(Direction.asc);
const [selectedItems, setSelectedItems] = useState([]);
const tableRef = useRef<EuiBasicTable<AgentEdge>>(null);
const tableRef = useRef<EuiBasicTable<Agent>>(null);

const onTableChange: EuiBasicTableProps<{}>['onChange'] = useCallback(
const onTableChange: EuiBasicTableProps<Agent>['onChange'] = useCallback(
({ page = {}, sort = {} }) => {
const { index: newPageIndex, size: newPageSize } = page;

Expand All @@ -41,6 +48,7 @@ const AgentsTableComponent: React.FC<AgentsTableProps> = ({ selectedAgents, onCh
const onSelectionChange: EuiTableSelectionType<{}>['onSelectionChange'] = useCallback(
(newSelectedItems) => {
setSelectedItems(newSelectedItems);
// @ts-expect-error
onChange(newSelectedItems.map((item) => item._id));
},
[onChange]
Expand All @@ -59,7 +67,7 @@ const AgentsTableComponent: React.FC<AgentsTableProps> = ({ selectedAgents, onCh
sortField,
});

const columns = useMemo(
const columns: Array<EuiBasicTableColumn<{}>> = useMemo(
() => [
{
field: 'local_metadata.elastic.agent.id',
Expand Down Expand Up @@ -103,11 +111,10 @@ const AgentsTableComponent: React.FC<AgentsTableProps> = ({ selectedAgents, onCh
[sortDirection, sortField]
);

const selection = useMemo(
const selection: EuiBasicTableProps<Agent>['selection'] = useMemo(
() => ({
selectable: (agent: AgentEdge) => agent.active,
selectableMessage: (selectable: boolean) =>
!selectable ? 'User is currently offline' : undefined,
selectable: (agent: Agent) => agent.active,
selectableMessage: (selectable: boolean) => (!selectable ? 'User is currently offline' : ''),
onSelectionChange,
initialSelected: selectedItems,
}),
Expand All @@ -117,13 +124,14 @@ const AgentsTableComponent: React.FC<AgentsTableProps> = ({ selectedAgents, onCh
useEffect(() => {
if (selectedAgents?.length && agents.length && selectedItems.length !== selectedAgents.length) {
tableRef?.current?.setSelection(
// @ts-expect-error
selectedAgents.map((agentId) => find({ _id: agentId }, agents))
);
}
}, [selectedAgents, agents, selectedItems.length]);

return (
<EuiBasicTable<AgentEdge>
<EuiBasicTable<Agent>
ref={tableRef}
items={agents}
itemId="_id"
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/osquery/public/agents/use_all_agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { createFilter } from '../common/helpers';
import { useKibana } from '../common/lib/kibana';
import {
AgentEdge,
PageInfoPaginated,
DocValueFields,
OsqueryQueries,
Expand All @@ -19,6 +18,7 @@ import {
Direction,
} from '../../common/search_strategy';
import { ESTermQuery } from '../../common/typed_json';
import { Agent } from '../shared_imports';

import * as i18n from './translations';
import { isCompleteResponse, isErrorResponse } from '../../../../../src/plugins/data/common';
Expand All @@ -28,7 +28,7 @@ import { generateTablePaginationOptions, getInspectResponse, InspectResponse } f
const ID = 'agentsAllQuery';

export interface AgentsArgs {
agents: AgentEdge[];
agents: Agent[];
id: string;
inspect: InspectResponse;
isInspected: boolean;
Expand Down Expand Up @@ -97,6 +97,7 @@ export const useAllAgents = ({
next: (response) => {
if (isCompleteResponse(response)) {
if (!didCancel) {
console.error('agents', response.edges);
setLoading(false);
setAgentsResponse((prevResponse) => ({
...prevResponse,
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/osquery/public/live_query/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { isEmpty } from 'lodash/fp';
import { EuiSpacer } from '@elastic/eui';
import React from 'react';
import React, { useCallback } from 'react';
import { useParams } from 'react-router-dom';

import { useActionDetails } from '../../actions/use_action_details';
Expand All @@ -17,13 +17,17 @@ const EditLiveQueryPageComponent = () => {
const { actionId } = useParams<{ actionId: string }>();
const [loading, { actionDetails }] = useActionDetails({ actionId });

const handleSubmit = useCallback(() => Promise.resolve(), []);

if (loading) {
return <>{'Loading...'}</>;
}

return (
<>
{!isEmpty(actionDetails) && <LiveQueryForm type="edit" actionDetails={actionDetails} />}
{!isEmpty(actionDetails) && (
<LiveQueryForm actionDetails={actionDetails} onSubmit={handleSubmit} />
)}
<EuiSpacer />
<ResultTabs />
</>
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/public/results/results_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const ResultsTableComponent: React.FC<ResultsTableComponentProps> = ({ actionId
);

useEffect(() => {
// @ts-expect-error
const newColumns: EuiDataGridColumn[] = keys(results[0]?.fields)
.sort()
.map((fieldName) => ({
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/osquery/public/results/use_all_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { createFilter } from '../common/helpers';
import { useKibana } from '../common/lib/kibana';
import {
ResultEdges,
ResultEdge,
PageInfoPaginated,
DocValueFields,
OsqueryQueries,
Expand All @@ -28,7 +28,7 @@ import { generateTablePaginationOptions, getInspectResponse, InspectResponse } f
const ID = 'resultsAllQuery';

export interface ResultsArgs {
results: ResultEdges[];
results: ResultEdge[];
id: string;
inspect: InspectResponse;
isInspected: boolean;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/osquery/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { TypeOf, schema } from '@kbn/config-schema';

export const ConfigSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
enabled: schema.boolean({ defaultValue: false }),
});

export type ConfigType = TypeOf<typeof ConfigSchema>;
7 changes: 6 additions & 1 deletion x-pack/plugins/osquery/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { PluginInitializerContext } from '../../../../src/core/server';
import { OsqueryPlugin } from './plugin';
import { ConfigSchema } from './config';

export const config = { schema: ConfigSchema };
export const config = {
schema: ConfigSchema,
exposeToBrowser: {
enabled: true,
},
};
export function plugin(initializerContext: PluginInitializerContext) {
return new OsqueryPlugin(initializerContext);
}
Expand Down
Loading

0 comments on commit 395abff

Please sign in to comment.