-
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.
[Onboarding] Connection details + Quick Stats (#192636)
## Summary Adding in the connection details and quickstats for the search_details page. ![Screenshot 2024-09-11 at 20 36 31](https://github.com/user-attachments/assets/5f030c06-4a98-4d9d-a465-c6719998ca56) ![Screenshot 2024-09-11 at 20 36 27](https://github.com/user-attachments/assets/d96be2f1-bcaa-42e5-9d32-1612e090b916) ![Screenshot 2024-09-11 at 20 36 09](https://github.com/user-attachments/assets/1f7995ae-5a0d-4810-acfb-3fafe33be451) ### Checklist Delete any items that are not applicable to this PR. --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Liam Thompson <[email protected]> (cherry picked from commit 4d48881)
- Loading branch information
1 parent
259bfca
commit abb63db
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.