-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
# Backport This will backport the following commits from `main` to `8.x`: - [[Onboarding] Connection details + Quick Stats (#192636)](#192636) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Joe McElroy","email":"joseph.mcelroy@elastic.co"},"sourceCommit":{"committedDate":"2024-09-16T16:03:01Z","message":"[Onboarding] Connection details + Quick Stats (#192636)\n\n## Summary\r\n\r\nAdding in the connection details and quickstats for the search_details\r\npage.\r\n\r\n\r\n\r\n\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>","sha":"4d488818dc5503c40617d01512cd89c05e1e0345","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:EnterpriseSearch","v8.16.0"],"number":192636,"url":"https://github.com/elastic/kibana/pull/192636","mergeCommit":{"message":"[Onboarding] Connection details + Quick Stats (#192636)\n\n## Summary\r\n\r\nAdding in the connection details and quickstats for the search_details\r\npage.\r\n\r\n\r\n\r\n\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>","sha":"4d488818dc5503c40617d01512cd89c05e1e0345"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192636","number":192636,"mergeCommit":{"message":"[Onboarding] Connection details + Quick Stats (#192636)\n\n## Summary\r\n\r\nAdding in the connection details and quickstats for the search_details\r\npage.\r\n\r\n\r\n\r\n\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com>","sha":"4d488818dc5503c40617d01512cd89c05e1e0345"}},{"branch":"8.x","label":"v8.16.0","labelRegex":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
fac293c
commit 137ed13
Showing
15 changed files
with
603 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
x-pack/plugins/search_indices/public/components/connection_details/connection_details.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { | ||
EuiButtonIcon, | ||
EuiCopy, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiTitle, | ||
useEuiTheme, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { useElasticsearchUrl } from '../../hooks/use_elasticsearch_url'; | ||
|
||
export const ConnectionDetails: React.FC = () => { | ||
const { euiTheme } = useEuiTheme(); | ||
const elasticsearchUrl = useElasticsearchUrl(); | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="s" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiTitle size="xxxs"> | ||
<h1> | ||
<FormattedMessage | ||
id="xpack.searchIndices.connectionDetails.endpointTitle" | ||
defaultMessage="Elasticsearch URL" | ||
/> | ||
</h1> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem css={{ whiteSpace: 'nowrap', overflow: 'hidden' }}> | ||
<p | ||
data-test-subj="connectionDetailsEndpoint" | ||
css={{ | ||
color: euiTheme.colors.successText, | ||
padding: `${euiTheme.size.s} ${euiTheme.size.m}`, | ||
backgroundColor: euiTheme.colors.lightestShade, | ||
textOverflow: 'ellipsis', | ||
overflow: 'hidden', | ||
}} | ||
> | ||
{elasticsearchUrl} | ||
</p> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiCopy | ||
textToCopy={elasticsearchUrl} | ||
afterMessage={i18n.translate('xpack.searchIndices.connectionDetails.copyMessage', { | ||
defaultMessage: 'Copied', | ||
})} | ||
> | ||
{(copy) => ( | ||
<EuiButtonIcon | ||
onClick={copy} | ||
iconType="copy" | ||
aria-label={i18n.translate('xpack.searchIndices.connectionDetails.copyMessage', { | ||
defaultMessage: 'Copy Elasticsearch URL to clipboard', | ||
})} | ||
/> | ||
)} | ||
</EuiCopy> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
x-pack/plugins/search_indices/public/components/quick_stats/mappings_convertor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { Mappings } from '../../types'; | ||
import { countVectorBasedTypesFromMappings } from './mappings_convertor'; | ||
|
||
describe('mappings convertor', () => { | ||
it('should count vector based types from mappings', () => { | ||
const mappings = { | ||
mappings: { | ||
properties: { | ||
field1: { | ||
type: 'dense_vector', | ||
}, | ||
field2: { | ||
type: 'dense_vector', | ||
}, | ||
field3: { | ||
type: 'sparse_vector', | ||
}, | ||
field4: { | ||
type: 'dense_vector', | ||
}, | ||
field5: { | ||
type: 'semantic_text', | ||
}, | ||
}, | ||
}, | ||
}; | ||
const result = countVectorBasedTypesFromMappings(mappings as unknown as Mappings); | ||
expect(result).toEqual({ | ||
dense_vector: 3, | ||
sparse_vector: 1, | ||
semantic_text: 1, | ||
}); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
x-pack/plugins/search_indices/public/components/quick_stats/mappings_convertor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import type { | ||
MappingProperty, | ||
MappingPropertyBase, | ||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import type { Mappings } from '../../types'; | ||
|
||
interface VectorFieldTypes { | ||
semantic_text: number; | ||
dense_vector: number; | ||
sparse_vector: number; | ||
} | ||
|
||
export function countVectorBasedTypesFromMappings(mappings: Mappings): VectorFieldTypes { | ||
const typeCounts: VectorFieldTypes = { | ||
semantic_text: 0, | ||
dense_vector: 0, | ||
sparse_vector: 0, | ||
}; | ||
|
||
const typeCountKeys = Object.keys(typeCounts); | ||
|
||
function recursiveCount(fields: MappingProperty | Mappings | MappingPropertyBase['fields']) { | ||
if (!fields) { | ||
return; | ||
} | ||
if ('mappings' in fields) { | ||
recursiveCount(fields.mappings); | ||
} | ||
if ('properties' in fields && fields.properties) { | ||
Object.keys(fields.properties).forEach((key) => { | ||
const value = (fields.properties as Record<string, MappingProperty>)?.[key]; | ||
|
||
if (value && value.type) { | ||
if (typeCountKeys.includes(value.type)) { | ||
const type = value.type as keyof VectorFieldTypes; | ||
typeCounts[type] = typeCounts[type] + 1; | ||
} | ||
|
||
if ('fields' in value) { | ||
recursiveCount(value.fields); | ||
} | ||
|
||
if ('properties' in value) { | ||
recursiveCount(value.properties); | ||
} | ||
} else if (value.properties || value.fields) { | ||
recursiveCount(value); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
recursiveCount(mappings); | ||
return typeCounts; | ||
} |
116 changes: 116 additions & 0 deletions
116
x-pack/plugins/search_indices/public/components/quick_stats/quick_stat.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { | ||
EuiAccordion, | ||
EuiDescriptionList, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiIcon, | ||
EuiPanel, | ||
EuiText, | ||
useEuiTheme, | ||
useGeneratedHtmlId, | ||
} from '@elastic/eui'; | ||
|
||
interface BaseQuickStatProps { | ||
icon: string; | ||
iconColor: string; | ||
title: string; | ||
secondaryTitle: React.ReactNode; | ||
open: boolean; | ||
content?: React.ReactNode; | ||
stats: Array<{ | ||
title: string; | ||
description: NonNullable<React.ReactNode>; | ||
}>; | ||
setOpen: (open: boolean) => void; | ||
first?: boolean; | ||
} | ||
|
||
export const QuickStat: React.FC<BaseQuickStatProps> = ({ | ||
icon, | ||
title, | ||
stats, | ||
open, | ||
setOpen, | ||
first, | ||
secondaryTitle, | ||
iconColor, | ||
content, | ||
...rest | ||
}) => { | ||
const { euiTheme } = useEuiTheme(); | ||
|
||
const id = useGeneratedHtmlId({ | ||
prefix: 'formAccordion', | ||
suffix: title, | ||
}); | ||
|
||
return ( | ||
<EuiAccordion | ||
forceState={open ? 'open' : 'closed'} | ||
onToggle={() => setOpen(!open)} | ||
paddingSize="none" | ||
id={id} | ||
buttonElement="div" | ||
arrowDisplay="right" | ||
{...rest} | ||
css={{ | ||
borderLeft: euiTheme.border.thin, | ||
...(first ? { borderLeftWidth: 0 } : {}), | ||
'.euiAccordion__arrow': { | ||
marginRight: euiTheme.size.s, | ||
}, | ||
'.euiAccordion__triggerWrapper': { | ||
background: euiTheme.colors.ghost, | ||
}, | ||
'.euiAccordion__children': { | ||
borderTop: euiTheme.border.thin, | ||
padding: euiTheme.size.m, | ||
}, | ||
}} | ||
buttonContent={ | ||
<EuiPanel hasShadow={false} hasBorder={false} paddingSize="s"> | ||
<EuiFlexGroup alignItems="center" gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiIcon type={icon} color={iconColor} /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText> | ||
<h4>{title}</h4> | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText color="subdued">{secondaryTitle}</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
} | ||
> | ||
{content ? ( | ||
content | ||
) : ( | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={false}> | ||
<EuiDescriptionList | ||
type="column" | ||
listItems={stats} | ||
columnWidths={[3, 1]} | ||
compressed | ||
descriptionProps={{ | ||
color: 'subdued', | ||
}} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
)} | ||
</EuiAccordion> | ||
); | ||
}; |
Oops, something went wrong.