Skip to content

Commit

Permalink
[Osquery] Fix small issues (#146101)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsonpl authored Nov 28, 2022
1 parent b300aa5 commit bc2eeda
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 29 deletions.
17 changes: 15 additions & 2 deletions x-pack/plugins/osquery/cypress/e2e/all/packs.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,14 @@ describe('ALL - Packs', () => {
findFormFieldByRowsLabelAndType('Name', shardPack);

cy.contains('Partial deployment (shards)').click();
cy.getBySel('shards-field-policy').type('Default{downArrow}{enter}');
cy.get('#shardsPercentage0').type('{backspace}{backspace}5');
cy.getBySel('packShardsForm-0').within(() => {
cy.getBySel('shards-field-policy').type('Default{downArrow}{enter}');
cy.get('#shardsPercentage0').type('{backspace}{backspace}5');
});
cy.getBySel('packShardsForm-1').within(() => {
cy.getBySel('shards-field-policy').type('{downArrow}{enter}');
cy.get('#shardsPercentage1').type('{backspace}{backspace}{backspace}');
});
findAndClickButton('Save pack');

cy.contains(`Successfully created "${shardPack}" pack`);
Expand All @@ -477,6 +483,13 @@ describe('ALL - Packs', () => {
cy.contains(shardPack).click();
cy.contains('Edit').click();
cy.get('#shardsPercentage0').should('have.value', '15');
cy.getBySel('packShardsForm-1').within(() => {
cy.getBySel('shards-field-policy').contains('testGlobal');
cy.get('#shardsPercentage1').should('have.value', '0');
});
cy.getBySel('policyIdsComboBox').within(() => {
cy.contains('testGlobal').should('not.exist');
});
});
});
});
9 changes: 9 additions & 0 deletions x-pack/plugins/osquery/cypress/e2e/all/saved_queries.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ describe('ALL - Saved queries', () => {
cy.contains('Snapshot');
});
});
it('checks result type on prebuilt saved query', () => {
cy.contains('Saved queries').click();
cy.react('CustomItemAction', {
props: { index: 1, item: { attributes: { id: 'users_elastic' } } },
}).click();
cy.getBySel('resultsTypeField').within(() => {
cy.contains('Snapshot');
});
});
});
10 changes: 7 additions & 3 deletions x-pack/plugins/osquery/public/packs/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { NameField } from './name_field';
import { DescriptionField } from './description_field';
import type { PackQueryFormData } from '../queries/use_pack_query_form';
import { PackTypeSelectable } from './shards/pack_type_selectable';
import { overflowCss } from '../utils';

type PackFormData = Omit<PackItem, 'id' | 'queries'> & { queries: PackQueryFormData[] };

Expand Down Expand Up @@ -80,7 +81,10 @@ const PackFormComponent: React.FC<PackFormProps> = ({
});

const deserializer = (payload: PackItem) => {
const defaultPolicyIds = filter(payload.policy_ids, (policyId) => !payload.shards?.[policyId]);
const defaultPolicyIds = filter(
payload.policy_ids,
(policyId) => payload.shards?.[policyId] == null
);

return {
...payload,
Expand Down Expand Up @@ -259,14 +263,14 @@ const PackFormComponent: React.FC<PackFormProps> = ({
{packType === 'policy' && (
<>
<EuiFlexGroup>
<EuiFlexItem>
<EuiFlexItem css={overflowCss}>
<PolicyIdComboBoxField options={availableOptions} />
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />

<EuiFlexGroup>
<EuiFlexItem>
<EuiFlexItem css={overflowCss}>
<StyledEuiAccordion
id="shardsToggle"
forceState={shardsToggleState}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const PolicyIdComboBoxFieldComponent: React.FC<PolicyIdComboBoxFieldProps> = ({
isInvalid={hasError}
selectedOptions={selectedOptions}
fullWidth
data-test-subj="input"
data-test-subj="policyIdsComboBox"
isClearable
options={options}
renderOption={renderOption}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { useEffect, useMemo } from 'react';
import type { InternalFieldErrors } from 'react-hook-form';
import { useFieldArray, useForm, useFormContext } from 'react-hook-form';
import type { EuiComboBoxOptionOption } from '@elastic/eui';
import { EuiFlexItem } from '@elastic/eui';
import { EuiSpacer } from '@elastic/eui';
import deepEqual from 'fast-deep-equal';
import { isEmpty, last, reject } from 'lodash';
Expand Down Expand Up @@ -111,7 +112,7 @@ const PackShardsFieldComponent = ({ options }: PackShardsFieldProps) => {
<EuiSpacer size="s" />

{fields.map((item, index, array) => (
<div key={item.id}>
<EuiFlexItem key={item.id}>
<ShardsForm
index={index}
onDelete={remove}
Expand All @@ -120,7 +121,7 @@ const PackShardsFieldComponent = ({ options }: PackShardsFieldProps) => {
options={options}
/>
<EuiSpacer size="xs" />
</div>
</EuiFlexItem>
))}
</>
);
Expand Down
25 changes: 13 additions & 12 deletions x-pack/plugins/osquery/public/packs/form/shards/shards_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { UseFieldArrayRemove, UseFormReturn } from 'react-hook-form';
import type { ShardsArray } from '../../../../common/schemas/common/utils';
import { ShardsPolicyField } from './shards_policy_field';
import { ShardsPercentageField } from './shards_percentage_field';
import { overflowCss } from '../../utils';

const StyledButtonWrapper = styled.div`
margin-top: ${(props: { index: number }) => props.index === 0 && '16px'};
Expand Down Expand Up @@ -44,18 +45,18 @@ const ShardsFormComponent = ({

return (
<>
<EuiFlexGroup data-test-subj="packShardsForm" alignItems="flexStart" gutterSize="s">
<EuiFlexItem>
<EuiFlexGroup alignItems="flexStart" gutterSize="s" wrap>
<EuiFlexItem>
<ShardsPolicyField
index={index}
control={control}
hideLabel={index !== 0}
options={options}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiFlexGroup
data-test-subj={`packShardsForm-${index}`}
alignItems="flexStart"
gutterSize="s"
>
<EuiFlexItem css={overflowCss}>
<ShardsPolicyField
index={index}
control={control}
hideLabel={index !== 0}
options={options}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup alignItems="center" gutterSize="s">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import osquerySchema from '../../common/schemas/osquery/v5.5.1.json';
import { FieldIcon } from '../../common/lib/kibana';
import { OsqueryIcon } from '../../components/osquery_icon';
import { removeMultilines } from '../../../common/utils/build_query/remove_multilines';
import { overflowCss } from '../utils';

export type ECSMappingFormReturn = UseFormReturn<{ ecsMappingArray: ECSMappingArray }>;

Expand Down Expand Up @@ -572,8 +573,10 @@ const OsqueryColumnFieldComponent: React.FC<OsqueryColumnFieldProps> = ({
isDisabled={euiFieldProps.isDisabled}
>
<EuiFlexGroup gutterSize="none">
<EuiFlexItem grow={false}>{Prepend}</EuiFlexItem>
<EuiFlexItem>
<EuiFlexItem css={overflowCss} grow={false}>
{Prepend}
</EuiFlexItem>
<EuiFlexItem css={overflowCss}>
<ResultComboBox
error={resultFieldState.error?.message}
// eslint-disable-next-line react/jsx-no-bind, react-perf/jsx-no-new-function-as-prop
Expand Down Expand Up @@ -643,9 +646,9 @@ export const ECSMappingEditorForm: React.FC<ECSMappingEditorFormProps> = ({
return (
<>
<EuiFlexGroup data-test-subj="ECSMappingEditorForm" alignItems="flexStart" gutterSize="s">
<EuiFlexItem>
<EuiFlexItem css={overflowCss}>
<EuiFlexGroup alignItems="flexStart" gutterSize="s" wrap>
<EuiFlexItem>
<EuiFlexItem css={overflowCss}>
<ECSComboboxField
control={control}
watch={watch}
Expand All @@ -663,7 +666,7 @@ export const ECSMappingEditorForm: React.FC<ECSMappingEditorFormProps> = ({
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexItem css={overflowCss}>
<EuiFlexGroup alignItems="flexStart" gutterSize="s" wrap>
<ECSFieldWrapper>
<OsqueryColumnField
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/osquery/public/packs/queries/query_flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { usePackQueryForm } from './use_pack_query_form';
import { SavedQueriesDropdown } from '../../saved_queries/saved_queries_dropdown';
import { ECSMappingEditorField } from './lazy_ecs_mapping_editor_field';
import { useKibana } from '../../common/lib/kibana';
import { overflowCss } from '../utils';

interface QueryFlyoutProps {
uniqueQueryIds: string[];
Expand Down Expand Up @@ -151,7 +152,7 @@ const QueryFlyoutComponent: React.FC<QueryFlyoutProps> = ({
</EuiFlexGroup>
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexItem>
<EuiFlexItem css={overflowCss}>
<ECSMappingEditorField />
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/osquery/public/packs/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const overflowCss = { overflow: 'auto' };
3 changes: 2 additions & 1 deletion x-pack/plugins/osquery/public/saved_queries/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ALL_OSQUERY_VERSIONS_OPTIONS } from '../../packs/queries/constants';
import { ECSMappingEditorField } from '../../packs/queries/lazy_ecs_mapping_editor_field';
import { PlaygroundFlyout } from './playground_flyout';
import { CodeEditorField } from './code_editor_field';
import { overflowCss } from '../../packs/utils';

interface SavedQueryFormProps {
viewMode?: boolean;
Expand Down Expand Up @@ -90,7 +91,7 @@ const SavedQueryFormComponent: React.FC<SavedQueryFormProps> = ({
<CodeEditorField euiFieldProps={euiFieldProps} />
<EuiSpacer size="xl" />
<EuiFlexGroup>
<EuiFlexItem>
<EuiFlexItem css={overflowCss}>
<ECSMappingEditorField euiFieldProps={euiFieldProps} />
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const deserializer = (payload: SavedQuerySOFormData): SavedQueryFormData => ({
description: payload.description,
query: payload.query,
interval: payload.interval ? parseInt(payload.interval, 10) : 3600,
snapshot: payload.snapshot,
removed: payload.removed,
snapshot: payload.snapshot ?? true,
removed: payload.removed ?? false,
platform: payload.platform,
version: payload.version ? [payload.version] : [],
ecs_mapping: !isEmpty(payload.ecs_mapping) ? payload.ecs_mapping : {},
Expand Down

0 comments on commit bc2eeda

Please sign in to comment.