Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/cs-fixes' into cs-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsonpl committed Aug 19, 2024
2 parents c54f680 + f15977d commit c381853
Show file tree
Hide file tree
Showing 111 changed files with 2,636 additions and 810 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_security_serverless_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enabled:
- x-pack/test_serverless/functional/test_suites/security/config.cloud_security_posture.basic.ts
- x-pack/test_serverless/functional/test_suites/security/config.cloud_security_posture.essentials.ts
- x-pack/test_serverless/functional/test_suites/security/config.cloud_security_posture.agentless.ts
- x-pack/test_serverless/functional/test_suites/security/config.cloud_security_posture.agentless_api.ts
- x-pack/test_serverless/functional/test_suites/security/config.saved_objects_management.ts
- x-pack/test_serverless/functional/test_suites/security/config.context_awareness.ts
- x-pack/test_serverless/functional/test_suites/security/common_configs/config.group1.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function buildRootCrumb({
color="text"
iconType="gear"
data-test-subj="manageDeploymentBtn"
size="s"
>
{i18n.translate('core.ui.primaryNav.cloud.breadCrumbDropdown.manageDeploymentLabel', {
defaultMessage: 'Manage this deployment',
Expand All @@ -157,16 +158,17 @@ function buildRootCrumb({
color="text"
iconType="spaces"
data-test-subj="viewDeploymentsBtn"
size="s"
>
{cloudLinks.deployments.title}
</EuiButtonEmpty>
)}
</>
),
popoverProps: {
panelPaddingSize: 'm',
panelPaddingSize: 's',
zIndex: 6000,
panelStyle: { width: 260 },
panelStyle: { maxWidth: 240 },
panelProps: {
'data-test-subj': 'deploymentLinksPanel',
},
Expand Down
6 changes: 5 additions & 1 deletion packages/kbn-alerts-grouping/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
*/

export { AlertsGrouping } from './src/components/alerts_grouping';
export { type AlertsGroupingProps } from './src/types';
export {
type AlertsGroupingProps,
type BaseAlertsGroupAggregations,
type AlertsGroupAggregationBucket,
} from './src/types';
export { useAlertsGroupingState } from './src/contexts/alerts_grouping_context';
43 changes: 32 additions & 11 deletions packages/kbn-alerts-grouping/src/components/alerts_grouping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { i18n } from '@kbn/i18n';
import { useAlertsDataView } from '@kbn/alerts-ui-shared/src/common/hooks/use_alerts_data_view';
import useLocalStorage from 'react-use/lib/useLocalStorage';
import { AlertsGroupingLevel, AlertsGroupingLevelProps } from './alerts_grouping_level';
import { AlertsGroupingProps } from '../types';
import type { AlertsGroupingProps, BaseAlertsGroupAggregations } from '../types';
import {
AlertsGroupingContextProvider,
useAlertsGroupingState,
Expand All @@ -40,7 +40,10 @@ const NextLevel = ({
parentGroupingFilter,
groupingFilters,
getLevel,
}: Pick<AlertsGroupingLevelProps, 'children' | 'parentGroupingFilter'> & {
}: Pick<
AlertsGroupingLevelProps<BaseAlertsGroupAggregations>,
'children' | 'parentGroupingFilter'
> & {
level: number;
selectedGroups: string[];
groupingFilters: Filter[];
Expand All @@ -56,7 +59,9 @@ const NextLevel = ({
return children(nextGroupingFilters)!;
};

const AlertsGroupingInternal = (props: AlertsGroupingProps) => {
const AlertsGroupingInternal = <T extends BaseAlertsGroupAggregations>(
props: AlertsGroupingProps<T>
) => {
const {
groupingId,
services,
Expand Down Expand Up @@ -230,6 +235,8 @@ const AlertsGroupingInternal = (props: AlertsGroupingProps) => {
return getLevel(0, selectedGroups[0]);
};

const typedMemo: <T>(c: T) => T = memo;

/**
* A coordinator component to show multiple alert tables grouped by one or more fields
*
Expand All @@ -243,7 +250,7 @@ const AlertsGroupingInternal = (props: AlertsGroupingProps) => {
*
*
* return (
* <AlertsGrouping
* <AlertsGrouping<YourAggregationsType>
* featureIds={[...]}
* globalQuery={{ query: ..., language: 'kql' }}
* globalFilters={...}
Expand Down Expand Up @@ -274,11 +281,25 @@ const AlertsGroupingInternal = (props: AlertsGroupingProps) => {
* </AlertsGrouping>
* );
* ```
*
* To define your aggregations result type, extend the `BaseAlertsGroupAggregations` type:
*
* ```ts
* import { BaseAlertsGroupAggregations } from '@kbn/alerts-grouping';
*
* interface YourAggregationsType extends BaseAlertsGroupAggregations {
* // Your custom aggregations here
* }
* ```
*
* Check {@link useGetAlertsGroupAggregationsQuery} for more info on alerts aggregations.
*/
export const AlertsGrouping = memo((props: AlertsGroupingProps) => {
return (
<AlertsGroupingContextProvider>
<AlertsGroupingInternal {...props} />
</AlertsGroupingContextProvider>
);
});
export const AlertsGrouping = typedMemo(
<T extends BaseAlertsGroupAggregations>(props: AlertsGroupingProps<T>) => {
return (
<AlertsGroupingContextProvider>
<AlertsGroupingInternal {...props} />
</AlertsGroupingContextProvider>
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import {
useGetAlertsGroupAggregationsQuery,
UseGetAlertsGroupAggregationsQueryProps,
} from '@kbn/alerts-ui-shared';
import { AlertsGroupingProps } from '../types';
import { AlertsGroupingProps, BaseAlertsGroupAggregations } from '../types';

export interface AlertsGroupingLevelProps<T extends Record<string, unknown> = {}>
extends AlertsGroupingProps<T> {
export interface AlertsGroupingLevelProps<
T extends BaseAlertsGroupAggregations = BaseAlertsGroupAggregations
> extends AlertsGroupingProps<T> {
getGrouping: (
props: Omit<DynamicGroupingProps<T>, 'groupSelector' | 'pagination'>
) => ReactElement;
Expand All @@ -40,8 +41,9 @@ const DEFAULT_FILTERS: Filter[] = [];
/**
* Renders an alerts grouping level
*/
export const AlertsGroupingLevel = memo(
<T extends Record<string, unknown> = {}>({
const typedMemo: <T>(c: T) => T = memo;
export const AlertsGroupingLevel = typedMemo(
<T extends BaseAlertsGroupAggregations>({
featureIds,
defaultFilters = DEFAULT_FILTERS,
from,
Expand Down
27 changes: 26 additions & 1 deletion packages/kbn-alerts-grouping/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export interface AlertsGroupingState {
[groupingId: string]: GroupModel;
}

export interface AlertsGroupingProps<T extends Record<string, unknown> = {}> {
export interface AlertsGroupingProps<
T extends BaseAlertsGroupAggregations = BaseAlertsGroupAggregations
> {
/**
* The leaf component that will be rendered in the grouping panels
*/
Expand Down Expand Up @@ -96,3 +98,26 @@ export interface AlertsGroupingProps<T extends Record<string, unknown> = {}> {
http: HttpSetup;
};
}

export interface AlertsGroupAggregationBucket {
key: string;
doc_count: number;
isNullGroup?: boolean;
unitsCount?: {
value: number;
};
}

export interface BaseAlertsGroupAggregations {
groupByFields: {
doc_count_error_upper_bound: number;
sum_other_doc_count: number;
buckets: AlertsGroupAggregationBucket[];
};
groupsCount: {
value: number;
};
unitsCount: {
value: number;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface UseGetAlertsGroupAggregationsQueryProps {
*
* The provided `aggregations` are applied within `groupByFields`. Here the `groupByField` runtime
* field can be used to perform grouping-based aggregations.
* `groupByField` buckets computed over a field with a null/absent value are marked with the
* `isNullGroup` flag set to true and their key is set to the `--` string.
*
* Applies alerting RBAC through featureIds.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@

import React from 'react';
import './field_name.scss';
import {
EuiBadge,
EuiFlexGroup,
EuiFlexItem,
EuiToolTip,
EuiHighlight,
EuiIcon,
} from '@elastic/eui';
import { EuiBadge, EuiFlexGroup, EuiFlexItem, EuiToolTip, EuiHighlight } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { FieldIcon, FieldIconProps } from '@kbn/react-field';
Expand All @@ -30,7 +23,6 @@ interface Props {
fieldIconProps?: Omit<FieldIconProps, 'type'>;
scripted?: boolean;
highlight?: string;
isPinned?: boolean;
}

export function FieldName({
Expand All @@ -40,7 +32,6 @@ export function FieldName({
fieldIconProps,
scripted = false,
highlight = '',
isPinned = false,
}: Props) {
const typeName = getFieldTypeName(fieldType);
const displayName =
Expand All @@ -63,17 +54,6 @@ export function FieldName({
<EuiFlexItem grow={false}>
<FieldIcon type={fieldType!} label={typeName} scripted={scripted} {...fieldIconProps} />
</EuiFlexItem>
{isPinned && (
<EuiFlexItem grow={false}>
<EuiIcon
type="pinFilled"
size="s"
aria-label={i18n.translate('unifiedDocViewer.pinnedFieldTooltipContent', {
defaultMessage: 'Pinned field',
})}
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ describe('migration v2', () => {
errors.push(err.message);
})
);
if (i < instances.length - 1) {
if (i < instances.length - 2) {
// We wait between instances, but not after the last one
await delay(delayInSec * 1000);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ export function AlertsPopover({
button={anchorElement}
closePopover={onClose}
isOpen={!alertFlyoutVisible}
panelPaddingSize="s"
>
<EuiContextMenu initialPanelId="mainPanel" panels={panels} />
<EuiContextMenu initialPanelId="mainPanel" size="s" panels={panels} />
</EuiWrappingPopover>
</>
);
Expand Down
Loading

0 comments on commit c381853

Please sign in to comment.