-
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.
[Log Explorer] Hide hard coded flyout actions using customization ext…
…ension point (#166638) ## 📓 Summary Closes #165217 This work implements a new extension point in the Discover customization framework to allow customizing the flyout content. Although it enables customizing only the actions displayed on top, it could be enhanced for additional flyout customizations in the future. To keep it simple and familiar to other customizations, it relies on a similar API as the `top_nav` customization, allowing one to disable default actions and insert additional ones. ```ts /** * Hide flyout actions to prevent rendering hard-coded actions. */ customizations.set({ id: 'flyout', actions: { defaultActions: { viewSingleDocument: { disabled: true }, viewSurroundingDocument: { disabled: true }, }, }, }); ``` ## 🧪 Testing - Navigate to `/app/observability-log-explorer` and expand the flyout for any grid entry. The actions on top of the flyout should not be displayed, only the title and the pagination control should appear. - Navigate to `/app/discover` and expand the flyout for any grid entry. The actions for viewing a single documents or surrounding documents should be displayed. --------- Co-authored-by: Marco Antonio Ghiani <[email protected]>
- Loading branch information
1 parent
c4a0ba2
commit 0743a11
Showing
8 changed files
with
255 additions
and
79 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
137 changes: 137 additions & 0 deletions
137
src/plugins/discover/public/components/discover_grid_flyout/use_flyout_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,137 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { | ||
EuiButtonEmpty, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiHideFor, | ||
EuiIconTip, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useDiscoverCustomization } from '../../customizations'; | ||
import { UseNavigationProps, useNavigationProps } from '../../hooks/use_navigation_props'; | ||
|
||
interface FlyoutActionProps { | ||
onClick: React.MouseEventHandler<Element>; | ||
href: string; | ||
} | ||
|
||
const staticViewDocumentItem = { | ||
id: 'viewDocument', | ||
enabled: true, | ||
Content: () => <ViewDocument />, | ||
}; | ||
|
||
export const useFlyoutActions = (navigationProps: UseNavigationProps) => { | ||
const { dataView } = navigationProps; | ||
const { singleDocHref, contextViewHref, onOpenSingleDoc, onOpenContextView } = | ||
useNavigationProps(navigationProps); | ||
|
||
const flyoutCustomization = useDiscoverCustomization('flyout'); | ||
|
||
const { | ||
viewSingleDocument = { disabled: false }, | ||
viewSurroundingDocument = { disabled: false }, | ||
} = flyoutCustomization?.actions?.defaultActions ?? {}; | ||
const customActions = [...(flyoutCustomization?.actions?.getActionItems?.() ?? [])]; | ||
|
||
const flyoutActions = [ | ||
{ | ||
id: 'singleDocument', | ||
enabled: !viewSingleDocument.disabled, | ||
Content: () => <SingleDocument href={singleDocHref} onClick={onOpenSingleDoc} />, | ||
}, | ||
{ | ||
id: 'surroundingDocument', | ||
enabled: Boolean(!viewSurroundingDocument.disabled && dataView.isTimeBased() && dataView.id), | ||
Content: () => <SurroundingDocuments onClick={onOpenContextView} href={contextViewHref} />, | ||
}, | ||
...customActions, | ||
]; | ||
|
||
const hasEnabledActions = flyoutActions.some((action) => action.enabled); | ||
|
||
if (hasEnabledActions) { | ||
flyoutActions.unshift(staticViewDocumentItem); | ||
} | ||
|
||
return { flyoutActions, hasEnabledActions }; | ||
}; | ||
|
||
const ViewDocument = () => { | ||
return ( | ||
<EuiHideFor sizes={['xs', 's', 'm']}> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="s"> | ||
<strong> | ||
{i18n.translate('discover.grid.tableRow.viewText', { | ||
defaultMessage: 'View:', | ||
})} | ||
</strong> | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiHideFor> | ||
); | ||
}; | ||
|
||
const SingleDocument = (props: FlyoutActionProps) => { | ||
return ( | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty | ||
size="s" | ||
iconSize="s" | ||
iconType="document" | ||
flush="left" | ||
data-test-subj="docTableRowAction" | ||
{...props} | ||
> | ||
{i18n.translate('discover.grid.tableRow.viewSingleDocumentLinkTextSimple', { | ||
defaultMessage: 'Single document', | ||
})} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
); | ||
}; | ||
|
||
const SurroundingDocuments = (props: FlyoutActionProps) => { | ||
return ( | ||
<EuiFlexGroup alignItems="center" responsive={false} gutterSize="none"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty | ||
size="s" | ||
iconSize="s" | ||
iconType="documents" | ||
flush="left" | ||
data-test-subj="docTableRowAction" | ||
{...props} | ||
> | ||
{i18n.translate('discover.grid.tableRow.viewSurroundingDocumentsLinkTextSimple', { | ||
defaultMessage: 'Surrounding documents', | ||
})} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiIconTip | ||
content={i18n.translate('discover.grid.tableRow.viewSurroundingDocumentsHover', { | ||
defaultMessage: | ||
'Inspect documents that occurred before and after this document. Only pinned filters remain active in the Surrounding documents view.', | ||
})} | ||
type="questionInCircle" | ||
color="subdued" | ||
position="right" | ||
iconProps={{ | ||
className: 'eui-alignTop', | ||
}} | ||
/> | ||
</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
30 changes: 30 additions & 0 deletions
30
src/plugins/discover/public/customizations/customization_types/flyout_customization.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,30 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export interface FlyoutDefaultActionItem { | ||
disabled?: boolean; | ||
} | ||
|
||
export interface FlyoutDefaultActions { | ||
viewSingleDocument?: FlyoutDefaultActionItem; | ||
viewSurroundingDocument?: FlyoutDefaultActionItem; | ||
} | ||
|
||
export interface FlyoutActionItem { | ||
id: string; | ||
Content: React.ElementType; | ||
enabled: boolean; | ||
} | ||
|
||
export interface FlyoutCustomization { | ||
id: 'flyout'; | ||
actions: { | ||
defaultActions?: FlyoutDefaultActions; | ||
getActionItems?: () => FlyoutActionItem[]; | ||
}; | ||
} |
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.