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.
[Streams 🌊] Extract schema editor component (elastic#209514)
## 📓 Summary Closes elastic/streams-program#130 This work decouples the `SchemaEditor` component from the business logic used for the stream management schema detail to make this part re-usable with a consistent UX on the enrichment processing part. The core changes of this work are: - Move the new `SchemaEditor` component into its own folder and provide it to the existing stream details section. - Expose event handlers and custom hooks to facilitate interacting with a definition streams. - Refactor internal state to push down those states the consumer doesn't need to know about (editing form, loadings) It is now responsibility of a consumer to adapt into the supported properties, which can of course be extended for upcoming changes. ```tsx <SchemaEditor fields={fields} isLoading={isLoadingDefinition || isLoadingUnmappedFields} stream={definition.stream} onFieldUnmap={unmapField} onFieldUpdate={updateField} onRefreshData={refreshFields} withControls withFieldSimulation withTableActions={!isRootStreamDefinition(definition.stream)} /> ```
- Loading branch information
1 parent
6635fe5
commit ddf3bdc
Showing
40 changed files
with
1,370 additions
and
1,498 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
15 changes: 15 additions & 0 deletions
15
...kbn-react-field/src/field_name_with_icon/__snapshots__/field_name_with_icon.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...rm/packages/shared/kbn-react-field/src/field_name_with_icon/field_name_with_icon.test.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,22 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { FieldNameWithIcon } from './field_name_with_icon'; | ||
|
||
test('FieldNameWithIcon renders an icon when type is passed', () => { | ||
const component = shallow(<FieldNameWithIcon name="agent.name" type="keyword" />); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('FieldNameWithIcon renders only the name when the type is not passed', () => { | ||
const component = shallow(<FieldNameWithIcon name="agent.name" />); | ||
expect(component).toMatchSnapshot(); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...latform/packages/shared/kbn-react-field/src/field_name_with_icon/field_name_with_icon.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,28 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiFlexGroup } from '@elastic/eui'; | ||
import { FieldIcon, FieldIconProps } from '../field_icon'; | ||
|
||
export interface FieldNameWithIconProps { | ||
name: string; | ||
type?: FieldIconProps['type']; | ||
} | ||
|
||
export const FieldNameWithIcon = ({ name, type }: FieldNameWithIconProps) => { | ||
return type ? ( | ||
<EuiFlexGroup alignItems="center" gutterSize="s"> | ||
<FieldIcon type={type} /> | ||
{name} | ||
</EuiFlexGroup> | ||
) : ( | ||
name | ||
); | ||
}; |
11 changes: 11 additions & 0 deletions
11
src/platform/packages/shared/kbn-react-field/src/field_name_with_icon/index.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,11 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export { FieldNameWithIcon } from './field_name_with_icon'; | ||
export type { FieldNameWithIconProps } from './field_name_with_icon'; |
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
149 changes: 149 additions & 0 deletions
149
...tions/observability/plugins/streams_app/public/components/schema_editor/field_actions.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,149 @@ | ||
/* | ||
* 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, { useMemo } from 'react'; | ||
import { EuiButtonIcon, EuiContextMenu, EuiPopover, useGeneratedHtmlId } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useBoolean } from '@kbn/react-hooks'; | ||
import { toMountPoint } from '@kbn/react-kibana-mount'; | ||
import { StreamsAppContextProvider } from '../streams_app_context_provider'; | ||
import { SchemaEditorFlyout } from './flyout'; | ||
import { useSchemaEditorContext } from './schema_editor_context'; | ||
import { SchemaField } from './types'; | ||
import { UnpromoteFieldModal } from './unpromote_field_modal'; | ||
import { useKibana } from '../../hooks/use_kibana'; | ||
|
||
export const FieldActionsCell = ({ field }: { field: SchemaField }) => { | ||
const context = useKibana(); | ||
const schemaEditorContext = useSchemaEditorContext(); | ||
|
||
const { core } = context; | ||
|
||
const contextMenuPopoverId = useGeneratedHtmlId({ | ||
prefix: 'fieldsTableContextMenuPopover', | ||
}); | ||
|
||
const [popoverIsOpen, { off: closePopover, toggle }] = useBoolean(false); | ||
|
||
const panels = useMemo(() => { | ||
const { onFieldUnmap, onFieldUpdate, stream, withFieldSimulation } = schemaEditorContext; | ||
|
||
let actions = []; | ||
|
||
const openFlyout = (props: { isEditingByDefault: boolean } = { isEditingByDefault: false }) => { | ||
const overlay = core.overlays.openFlyout( | ||
toMountPoint( | ||
<StreamsAppContextProvider context={context}> | ||
<SchemaEditorFlyout | ||
field={field} | ||
onClose={() => overlay.close()} | ||
onSave={onFieldUpdate} | ||
stream={stream} | ||
withFieldSimulation={withFieldSimulation} | ||
{...props} | ||
/> | ||
</StreamsAppContextProvider>, | ||
core | ||
), | ||
{ maxWidth: 500 } | ||
); | ||
}; | ||
|
||
const openUnpromoteModal = () => { | ||
const overlay = core.overlays.openModal( | ||
toMountPoint( | ||
<UnpromoteFieldModal | ||
field={field} | ||
onClose={() => overlay.close()} | ||
onFieldUnmap={onFieldUnmap} | ||
/>, | ||
core | ||
), | ||
{ maxWidth: 500 } | ||
); | ||
}; | ||
|
||
const viewFieldAction = { | ||
name: i18n.translate('xpack.streams.actions.viewFieldLabel', { | ||
defaultMessage: 'View field', | ||
}), | ||
onClick: () => openFlyout(), | ||
}; | ||
|
||
switch (field.status) { | ||
case 'mapped': | ||
actions = [ | ||
viewFieldAction, | ||
{ | ||
name: i18n.translate('xpack.streams.actions.editFieldLabel', { | ||
defaultMessage: 'Edit field', | ||
}), | ||
onClick: () => openFlyout({ isEditingByDefault: true }), | ||
}, | ||
{ | ||
name: i18n.translate('xpack.streams.actions.unpromoteFieldLabel', { | ||
defaultMessage: 'Unmap field', | ||
}), | ||
onClick: openUnpromoteModal, | ||
}, | ||
]; | ||
break; | ||
case 'unmapped': | ||
actions = [ | ||
viewFieldAction, | ||
{ | ||
name: i18n.translate('xpack.streams.actions.mapFieldLabel', { | ||
defaultMessage: 'Map field', | ||
}), | ||
onClick: () => openFlyout({ isEditingByDefault: true }), | ||
}, | ||
]; | ||
break; | ||
case 'inherited': | ||
actions = [viewFieldAction]; | ||
break; | ||
} | ||
|
||
return [ | ||
{ | ||
id: 0, | ||
title: i18n.translate('xpack.streams.streamDetailSchemaEditorFieldsTableActionsTitle', { | ||
defaultMessage: 'Field actions', | ||
}), | ||
items: actions.map((action) => ({ | ||
name: action.name, | ||
onClick: () => { | ||
action.onClick(); | ||
closePopover(); | ||
}, | ||
})), | ||
}, | ||
]; | ||
}, [closePopover, context, core, field, schemaEditorContext]); | ||
|
||
return ( | ||
<EuiPopover | ||
id={contextMenuPopoverId} | ||
button={ | ||
<EuiButtonIcon | ||
aria-label={i18n.translate( | ||
'xpack.streams.streamDetailSchemaEditorFieldsTableActionsTriggerButton', | ||
{ defaultMessage: 'Open actions menu' } | ||
)} | ||
data-test-subj="streamsAppActionsButton" | ||
iconType="boxesVertical" | ||
onClick={toggle} | ||
/> | ||
} | ||
isOpen={popoverIsOpen} | ||
closePopover={closePopover} | ||
panelPaddingSize="none" | ||
> | ||
<EuiContextMenu initialPanelId={0} panels={panels} /> | ||
</EuiPopover> | ||
); | ||
}; |
File renamed without changes.
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
Oops, something went wrong.