Skip to content

Commit

Permalink
Merge branch 'main' into obs-optional-spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes authored Feb 27, 2023
2 parents 187d4ec + 1a69a86 commit f4c2841
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import numeral from '@elastic/numeral';
import { Link, generatePath } from 'react-router-dom';
import { generatePath, Link } from 'react-router-dom';
import { i18n } from '@kbn/i18n';
import { ColumnNameWithTooltip } from '../../../components/column_name_with_tooltip';
import { ComplianceScoreBar } from '../../../components/compliance_score_bar';
Expand Down Expand Up @@ -126,7 +126,9 @@ const baseColumns: Array<EuiTableFieldDataColumnType<FindingsByResourcePage>> =
width: '15%',
render: (resourceId: FindingsByResourcePage['resource_id']) => (
<Link
to={generatePath(findingsNavigation.resource_findings.path, { resourceId })}
to={generatePath(findingsNavigation.resource_findings.path, {
resourceId: encodeURIComponent(resourceId),
})}
className="eui-textTruncate"
title={resourceId}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const getResourceFindingSharedValues = (sharedValues: {
resourceSubType: string;
resourceName: string;
clusterId: string;
cloudAccountName: string;
}): EuiDescriptionListProps['listItems'] => [
{
title: i18n.translate('xpack.csp.findings.resourceFindingsSharedValues.resourceTypeTitle', {
Expand All @@ -88,10 +89,18 @@ const getResourceFindingSharedValues = (sharedValues: {
}),
description: sharedValues.clusterId,
},
{
title: i18n.translate('xpack.csp.findings.resourceFindingsSharedValues.cloudAccountName', {
defaultMessage: 'Cloud Account Name',
}),
description: sharedValues.cloudAccountName,
},
];

export const ResourceFindings = ({ dataView }: FindingsBaseProps) => {
const params = useParams<{ resourceId: string }>();
const decodedResourceId = decodeURIComponent(params.resourceId);

const getPersistedDefaultQuery = usePersistedQuery(getDefaultQuery);
const { urlQuery, setUrlQuery } = useUrlQuery(getPersistedDefaultQuery);
const { pageSize, setPageSize } = usePageSize(LOCAL_STORAGE_PAGE_SIZE_FINDINGS_KEY);
Expand All @@ -111,7 +120,7 @@ export const ResourceFindings = ({ dataView }: FindingsBaseProps) => {
const resourceFindings = useResourceFindings({
sort: urlQuery.sort,
query: baseEsQuery.query,
resourceId: params.resourceId,
resourceId: decodedResourceId,
enabled: !baseEsQuery.error,
});

Expand Down Expand Up @@ -213,10 +222,11 @@ export const ResourceFindings = ({ dataView }: FindingsBaseProps) => {
resourceFindings.data && (
<CspInlineDescriptionList
listItems={getResourceFindingSharedValues({
resourceId: params.resourceId,
resourceId: decodedResourceId,
resourceName: resourceFindings.data?.resourceName || '',
resourceSubType: resourceFindings.data?.resourceSubType || '',
clusterId: resourceFindings.data?.clusterId || '',
cloudAccountName: resourceFindings.data?.cloudAccountName || '',
})}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ResourceFindingsResponse = IKibanaSearchResponse<
>;

export type ResourceFindingsResponseAggs = Record<
'count' | 'clusterId' | 'resourceSubType' | 'resourceName',
'count' | 'clusterId' | 'resourceSubType' | 'resourceName' | 'cloudAccountName',
estypes.AggregationsMultiBucketAggregateBase<
estypes.AggregationsStringRareTermsBucketKeys | undefined
>
Expand All @@ -59,6 +59,9 @@ const getResourceFindingsQuery = ({
sort: [{ [sort.field]: sort.direction }],
aggs: {
...getFindingsCountAggQuery(),
cloudAccountName: {
terms: { field: 'cloud.account.name' },
},
clusterId: {
terms: { field: 'cluster_id' },
},
Expand Down Expand Up @@ -98,6 +101,7 @@ export const useResourceFindings = (options: UseResourceFindingsOptions) => {
assertNonBucketsArray(aggregations.clusterId?.buckets);
assertNonBucketsArray(aggregations.resourceSubType?.buckets);
assertNonBucketsArray(aggregations.resourceName?.buckets);
assertNonBucketsArray(aggregations.cloudAccountName?.buckets);

return {
page: hits.hits.map((hit) => hit._source!),
Expand All @@ -106,6 +110,7 @@ export const useResourceFindings = (options: UseResourceFindingsOptions) => {
clusterId: getFirstBucketKey(aggregations.clusterId?.buckets),
resourceSubType: getFirstBucketKey(aggregations.resourceSubType?.buckets),
resourceName: getFirstBucketKey(aggregations.resourceName?.buckets),
cloudAccountName: getFirstBucketKey(aggregations.cloudAccountName?.buckets),
};
},
onError: (err: Error) => showErrorToast(toasts, err),
Expand Down

0 comments on commit f4c2841

Please sign in to comment.