Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@
*/

import React from 'react';
import { EuiPopover, EuiPopoverProps, EuiPopoverTitle } from '@elastic/eui';
import {
EuiFlexGroup,
EuiFlexItem,
EuiPopover,
EuiPopoverProps,
EuiPopoverTitle,
} from '@elastic/eui';
import './field_popover.scss';
import { euiThemeVars } from '@kbn/ui-theme';

export interface FieldPopoverProps extends EuiPopoverProps {
renderHeader?: () => React.ReactNode;
renderContent?: () => React.ReactNode;
renderFooter?: () => React.ReactNode;
}

export const FieldPopover: React.FC<FieldPopoverProps> = ({
isOpen,
closePopover,
renderHeader,
renderContent,
renderFooter,
...otherPopoverProps
}) => {
let header = null;
let content = null;
let header: React.ReactNode | null = null;
let content: React.ReactNode | null = null;
let footer: React.ReactNode | null = null;

if (isOpen) {
try {
Expand All @@ -40,6 +50,13 @@ export const FieldPopover: React.FC<FieldPopoverProps> = ({
// eslint-disable-next-line no-console
console.error(error);
}

try {
footer = renderFooter?.() || null;
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}
}

return (
Expand All @@ -54,10 +71,27 @@ export const FieldPopover: React.FC<FieldPopoverProps> = ({
{...otherPopoverProps}
>
{isOpen && (
<>
{content && header ? <EuiPopoverTitle>{header}</EuiPopoverTitle> : header}
{content}
</>
<EuiFlexGroup gutterSize="none" direction="column" css={{ maxHeight: '90vh' }}>
{Boolean(header) && (
<EuiFlexItem grow={false}>
{content ? <EuiPopoverTitle>{header}</EuiPopoverTitle> : header}
</EuiFlexItem>
)}
{content ? (
<EuiFlexItem
className="eui-yScrollWithShadows"
css={{
padding: euiThemeVars.euiSize,
margin: `-${euiThemeVars.euiSize}`,
}}
>
{content}
</EuiFlexItem>
) : (
content
)}
{Boolean(footer) && <EuiFlexItem grow={false}>{footer}</EuiFlexItem>}
</EuiFlexGroup>
)}
</EuiPopover>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,22 +309,39 @@ function UnifiedFieldListItemComponent({
/>
</>
)}

{searchMode === 'documents' && !!services.uiActions && (
<FieldPopoverFooter
field={field}
dataView={dataView}
multiFields={rawMultiFields}
trackUiMetric={trackUiMetric}
contextualFields={workspaceSelectedFieldNames}
originatingApp={stateService.creationOptions.originatingApp}
uiActions={services.uiActions}
/>
)}
</>
);
};

const renderFooter = useMemo(() => {
const uiActions = services.uiActions;

if (searchMode !== 'documents' || !uiActions) {
return;
}

return () => (
<FieldPopoverFooter
field={field}
dataView={dataView}
multiFields={rawMultiFields}
trackUiMetric={trackUiMetric}
contextualFields={workspaceSelectedFieldNames}
originatingApp={stateService.creationOptions.originatingApp}
uiActions={uiActions}
/>
);
}, [
dataView,
field,
rawMultiFields,
searchMode,
services.uiActions,
stateService.creationOptions.originatingApp,
trackUiMetric,
workspaceSelectedFieldNames,
]);

const value = useMemo(
() => ({
id: field.name,
Expand Down Expand Up @@ -393,6 +410,7 @@ function UnifiedFieldListItemComponent({
? renderPopover
: undefined
}
renderFooter={renderFooter}
/>
);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-unified-field-list/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"@kbn/visualization-utils",
"@kbn/esql-utils",
"@kbn/search-types",
"@kbn/fields-metadata-plugin"
"@kbn/fields-metadata-plugin",
"@kbn/ui-theme"
],
"exclude": ["target/**/*"]
}
Loading