forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Inventory][ECO] Entities page search bar (elastic#193546)
closes elastic#192329 https://github.com/user-attachments/assets/eb4e7aa6-14dd-48fb-a076-98ceec9cb335 --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Carlos Crespo <[email protected]> (cherry picked from commit 6a0fa96)
- Loading branch information
1 parent
e3723fe
commit c82c41a
Showing
24 changed files
with
626 additions
and
62 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
99 changes: 99 additions & 0 deletions
99
x-pack/plugins/observability_solution/inventory/common/entitites.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,99 @@ | ||
/* | ||
* 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 { isLeft, isRight } from 'fp-ts/lib/Either'; | ||
import { type EntityType, entityTypesRt } from './entities'; | ||
|
||
const validate = (input: unknown) => entityTypesRt.decode(input); | ||
|
||
describe('entityTypesRt codec', () => { | ||
it('should validate a valid string of entity types', () => { | ||
const input = 'service,host,container'; | ||
const result = validate(input); | ||
expect(isRight(result)).toBe(true); | ||
if (isRight(result)) { | ||
expect(result.right).toEqual(['service', 'host', 'container']); | ||
} | ||
}); | ||
|
||
it('should validate a valid array of entity types', () => { | ||
const input = ['service', 'host', 'container']; | ||
const result = validate(input); | ||
expect(isRight(result)).toBe(true); | ||
if (isRight(result)) { | ||
expect(result.right).toEqual(['service', 'host', 'container']); | ||
} | ||
}); | ||
|
||
it('should fail validation when the string contains invalid entity types', () => { | ||
const input = 'service,invalidType,host'; | ||
const result = validate(input); | ||
expect(isLeft(result)).toBe(true); | ||
}); | ||
|
||
it('should fail validation when the array contains invalid entity types', () => { | ||
const input = ['service', 'invalidType', 'host']; | ||
const result = validate(input); | ||
expect(isLeft(result)).toBe(true); | ||
}); | ||
|
||
it('should fail validation when input is not a string or array', () => { | ||
const input = 123; | ||
const result = validate(input); | ||
expect(isLeft(result)).toBe(true); | ||
}); | ||
|
||
it('should fail validation when the array contains non-string elements', () => { | ||
const input = ['service', 123, 'host']; | ||
const result = validate(input); | ||
expect(isLeft(result)).toBe(true); | ||
}); | ||
|
||
it('should fail validation an empty string', () => { | ||
const input = ''; | ||
const result = validate(input); | ||
expect(isLeft(result)).toBe(true); | ||
}); | ||
|
||
it('should validate an empty array as valid', () => { | ||
const input: unknown[] = []; | ||
const result = validate(input); | ||
expect(isRight(result)).toBe(true); | ||
if (isRight(result)) { | ||
expect(result.right).toEqual([]); | ||
} | ||
}); | ||
|
||
it('should fail validation when the string contains only commas', () => { | ||
const input = ',,,'; | ||
const result = validate(input); | ||
expect(isLeft(result)).toBe(true); | ||
}); | ||
|
||
it('should fail validation for partial valid entities in a string', () => { | ||
const input = 'service,invalidType'; | ||
const result = validate(input); | ||
expect(isLeft(result)).toBe(true); | ||
}); | ||
|
||
it('should fail validation for partial valid entities in an array', () => { | ||
const input = ['service', 'invalidType']; | ||
const result = validate(input); | ||
expect(isLeft(result)).toBe(true); | ||
}); | ||
|
||
it('should serialize a valid array back to a string', () => { | ||
const input: EntityType[] = ['service', 'host']; | ||
const serialized = entityTypesRt.encode(input); | ||
expect(serialized).toBe('service,host'); | ||
}); | ||
|
||
it('should serialize an empty array back to an empty string', () => { | ||
const input: EntityType[] = []; | ||
const serialized = entityTypesRt.encode(input); | ||
expect(serialized).toBe(''); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
"entityManager", | ||
"inference", | ||
"dataViews", | ||
"unifiedSearch", | ||
"data", | ||
"share" | ||
], | ||
"requiredBundles": [ | ||
|
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
67 changes: 67 additions & 0 deletions
67
...s/observability_solution/inventory/public/components/search_bar/entity_types_controls.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,67 @@ | ||
/* | ||
* 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 { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui'; | ||
import { css } from '@emotion/react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { EntityType } from '../../../common/entities'; | ||
import { useInventoryAbortableAsync } from '../../hooks/use_inventory_abortable_async'; | ||
import { useInventoryParams } from '../../hooks/use_inventory_params'; | ||
import { useKibana } from '../../hooks/use_kibana'; | ||
import { getEntityTypeLabel } from '../../utils/get_entity_type_label'; | ||
|
||
interface Props { | ||
onChange: (entityTypes: EntityType[]) => void; | ||
} | ||
|
||
const toComboBoxOption = (entityType: EntityType): EuiComboBoxOptionOption<EntityType> => ({ | ||
key: entityType, | ||
label: getEntityTypeLabel(entityType), | ||
}); | ||
|
||
export function EntityTypesControls({ onChange }: Props) { | ||
const { | ||
query: { entityTypes = [] }, | ||
} = useInventoryParams('/*'); | ||
|
||
const { | ||
services: { inventoryAPIClient }, | ||
} = useKibana(); | ||
|
||
const { value, loading } = useInventoryAbortableAsync( | ||
({ signal }) => { | ||
return inventoryAPIClient.fetch('GET /internal/inventory/entities/types', { signal }); | ||
}, | ||
[inventoryAPIClient] | ||
); | ||
|
||
const options = value?.entityTypes.map(toComboBoxOption); | ||
const selectedOptions = entityTypes.map(toComboBoxOption); | ||
|
||
return ( | ||
<EuiComboBox<EntityType> | ||
isLoading={loading} | ||
css={css` | ||
max-width: 325px; | ||
`} | ||
aria-label={i18n.translate( | ||
'xpack.inventory.entityTypesControls.euiComboBox.accessibleScreenReaderLabel', | ||
{ defaultMessage: 'Entity types filter' } | ||
)} | ||
placeholder={i18n.translate( | ||
'xpack.inventory.entityTypesControls.euiComboBox.placeHolderLabel', | ||
{ defaultMessage: 'Types' } | ||
)} | ||
options={options} | ||
selectedOptions={selectedOptions} | ||
onChange={(newOptions) => { | ||
onChange(newOptions.map((option) => option.key as EntityType)); | ||
}} | ||
isClearable | ||
/> | ||
); | ||
} |
Oops, something went wrong.