Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UnifiedDocViewer] Redesign header and make actions responsive #173780

Merged
merged 32 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
53d96e1
[UnifiedDocViewer] Update design of DocViewer header
jughosta Dec 20, 2023
6ff2ea3
[UnifiedDocViewer] Restore styles
jughosta Dec 20, 2023
4e0c420
[UnifiedDocViewer] Clean up
jughosta Dec 20, 2023
465596f
[UnifiedDocViewer] Responsive actions
jughosta Dec 20, 2023
93d3a07
Merge branch 'main' into 164660-doc-viewer-header
jughosta Dec 20, 2023
0082173
[UnifiedDocViewer] Add context menu for remaining actions
jughosta Dec 21, 2023
8bb08d1
[UnifiedDocViewer] Add tests
jughosta Dec 21, 2023
690c38e
[UnifiedDocViewer] Update example plugin
jughosta Dec 21, 2023
d57f705
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 2, 2024
121b810
Merge branch 'main' into 164660-doc-viewer-header
jughosta Jan 2, 2024
fe78d50
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 2, 2024
0e57f87
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jan 2, 2024
5013ba2
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 3, 2024
5aea973
Merge branch 'main' into 164660-doc-viewer-header
jughosta Jan 3, 2024
150cb32
[Discover] Address PR comments
jughosta Jan 3, 2024
5bc3a75
Merge remote-tracking branch 'origin/164660-doc-viewer-header' into 1…
jughosta Jan 3, 2024
6bca18f
[Discover] Cleanup
jughosta Jan 3, 2024
f210bf2
[Discover] Fix spacing
jughosta Jan 3, 2024
0804964
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 5, 2024
9d9fa29
[Discover] Address PR comments
jughosta Jan 5, 2024
58ba789
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 5, 2024
9c4d60a
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 5, 2024
d85d5f9
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 5, 2024
fd72647
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 5, 2024
7d08583
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 8, 2024
edf8a3d
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 9, 2024
ef10dff
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 10, 2024
499c184
[Discover] Add help text
jughosta Jan 10, 2024
180445a
[Discover] Restore translations
jughosta Jan 10, 2024
05ec043
[Discover] Cleanup translations
jughosta Jan 10, 2024
20264a6
Update src/plugins/discover/public/components/discover_grid_flyout/di…
jughosta Jan 10, 2024
4c15b53
Merge branch 'main' into 163239-doc-viewer-actions
jughosta Jan 10, 2024
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
23 changes: 23 additions & 0 deletions examples/discover_customization_examples/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
EuiFlexItem,
EuiPopover,
EuiWrappingPopover,
IconType,
} from '@elastic/eui';
import {
AppNavLinkStatus,
Expand Down Expand Up @@ -401,6 +402,28 @@ export class DiscoverCustomizationExamplesPlugin implements Plugin {
},
});

customizations.set({
id: 'flyout',
size: '60%',
title: 'Example custom flyout',
actions: {
getActionItems: () =>
Array.from({ length: 5 }, (_, i) => {
Copy link
Contributor Author

@jughosta jughosta Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can update this number of extra items (2 default ones are always present) during testing to check how it works inside Discover Customization example plugin.

const index = i + 1;
return {
id: `action-item-${index}`,
enabled: true,
label: `Action ${index}`,
iconType: ['faceHappy', 'faceNeutral', 'faceSad', 'infinity', 'bell'].at(
i
) as IconType,
dataTestSubj: `customActionItem${index}`,
onClick: () => alert(index),
};
}),
},
});

return () => {
// eslint-disable-next-line no-console
console.log('Cleaning up Logs explorer customizations');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@
min-height: 0;
}

.unifiedDataTable__flyoutHeader {
white-space: nowrap;
}

.unifiedDataTable__flyoutDocumentNavigation {
justify-content: flex-end;
}

// We only truncate if the cell is not a control column.
.euiDataGridHeader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import React from 'react';
import { EuiButtonIcon, EuiContextMenuItem, EuiPopover } from '@elastic/eui';
import { findTestSubject } from '@elastic/eui/lib/test';
import { EuiFlexItem } from '@elastic/eui';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import type { Query, AggregateQuery } from '@kbn/es-query';
import { DiscoverGridFlyout, DiscoverGridFlyoutProps } from './discover_grid_flyout';
Expand Down Expand Up @@ -36,6 +36,22 @@ jest.mock('../../customizations', () => ({
useDiscoverCustomization: jest.fn(),
}));

let mockBreakpointSize: string | null = null;

jest.mock('@elastic/eui', () => {
const original = jest.requireActual('@elastic/eui');
return {
...original,
useIsWithinBreakpoints: jest.fn((breakpoints: string[]) => {
if (mockBreakpointSize && breakpoints.includes(mockBreakpointSize)) {
return true;
}

return original.useIsWithinBreakpoints(breakpoints);
}),
};
});

const waitNextTick = () => new Promise((resolve) => setTimeout(resolve, 0));

const waitNextUpdate = async (component: ReactWrapper) => {
Expand Down Expand Up @@ -227,7 +243,7 @@ describe('Discover flyout', function () {
const singleDocumentView = findTestSubject(component, 'docTableRowAction');
expect(singleDocumentView.length).toBeFalsy();
const flyoutTitle = findTestSubject(component, 'docTableRowDetailsTitle');
expect(flyoutTitle.text()).toBe('Expanded row');
expect(flyoutTitle.text()).toBe('Row');
});

describe('with applied customizations', () => {
Expand All @@ -246,17 +262,32 @@ describe('Discover flyout', function () {

describe('when actions are customized', () => {
it('should display actions added by getActionItems', async () => {
mockBreakpointSize = 'xl';
mockFlyoutCustomization.actions = {
getActionItems: jest.fn(() => [
{
id: 'action-item-1',
enabled: true,
Content: () => <EuiFlexItem data-test-subj="customActionItem1">Action 1</EuiFlexItem>,
label: 'Action 1',
iconType: 'document',
dataTestSubj: 'customActionItem1',
onClick: jest.fn(),
},
{
id: 'action-item-2',
enabled: true,
Content: () => <EuiFlexItem data-test-subj="customActionItem2">Action 2</EuiFlexItem>,
label: 'Action 2',
iconType: 'document',
dataTestSubj: 'customActionItem2',
onClick: jest.fn(),
},
{
id: 'action-item-3',
enabled: false,
label: 'Action 3',
iconType: 'document',
dataTestSubj: 'customActionItem3',
onClick: jest.fn(),
},
]),
};
Expand All @@ -268,6 +299,88 @@ describe('Discover flyout', function () {

expect(action1.text()).toBe('Action 1');
expect(action2.text()).toBe('Action 2');
expect(findTestSubject(component, 'customActionItem3').exists()).toBe(false);
mockBreakpointSize = null;
});

it('should display multiple actions added by getActionItems', async () => {
mockFlyoutCustomization.actions = {
getActionItems: jest.fn(() =>
Array.from({ length: 5 }, (_, i) => ({
id: `action-item-${i}`,
enabled: true,
label: `Action ${i}`,
iconType: 'document',
dataTestSubj: `customActionItem${i}`,
onClick: jest.fn(),
}))
),
};

const { component } = await mountComponent({});
expect(
findTestSubject(component, 'docViewerFlyoutActions')
.find(EuiButtonIcon)
.map((button) => button.prop('data-test-subj'))
).toEqual([
'docTableRowAction',
'customActionItem0',
'customActionItem1',
'docViewerMoreFlyoutActionsButton',
]);

act(() => {
findTestSubject(component, 'docViewerMoreFlyoutActionsButton').simulate('click');
});

component.update();

expect(
component
.find(EuiPopover)
.find(EuiContextMenuItem)
.map((button) => button.prop('data-test-subj'))
).toEqual(['customActionItem2', 'customActionItem3', 'customActionItem4']);
});

it('should display multiple actions added by getActionItems in mobile view', async () => {
mockBreakpointSize = 's';

mockFlyoutCustomization.actions = {
getActionItems: jest.fn(() =>
Array.from({ length: 3 }, (_, i) => ({
id: `action-item-${i}`,
enabled: true,
label: `Action ${i}`,
iconType: 'document',
dataTestSubj: `customActionItem${i}`,
onClick: jest.fn(),
}))
),
};

const { component } = await mountComponent({});
expect(findTestSubject(component, 'docViewerFlyoutActions').length).toBe(0);

act(() => {
findTestSubject(component, 'docViewerMobileActionsButton').simulate('click');
});

component.update();

expect(
component
.find(EuiPopover)
.find(EuiContextMenuItem)
.map((button) => button.prop('data-test-subj'))
).toEqual([
'docTableRowAction',
'customActionItem0',
'customActionItem1',
'customActionItem2',
]);

mockBreakpointSize = null;
});

it('should allow disabling default actions', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React, { useMemo, useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { css } from '@emotion/react';
import type { DataView } from '@kbn/data-views-plugin/public';
import {
EuiFlexGroup,
Expand All @@ -29,6 +30,7 @@ import { useDiscoverServices } from '../../hooks/use_discover_services';
import { isTextBasedQuery } from '../../application/main/utils/is_text_based_query';
import { useFlyoutActions } from './use_flyout_actions';
import { useDiscoverCustomization } from '../../customizations';
import { DiscoverGridFlyoutActions } from './discover_grid_flyout_actions';

export interface DiscoverGridFlyoutProps {
savedSearchId?: string;
Expand Down Expand Up @@ -189,14 +191,13 @@ export function DiscoverGridFlyout({
);

const defaultFlyoutTitle = isPlainRecord
? i18n.translate('discover.grid.tableRow.textBasedDetailHeading', {
defaultMessage: 'Expanded row',
? i18n.translate('discover.grid.tableRow.docViewerTextBasedDetailHeading', {
defaultMessage: 'Row',
})
: i18n.translate('discover.grid.tableRow.detailHeading', {
defaultMessage: 'Expanded document',
: i18n.translate('discover.grid.tableRow.docViewerDetailHeading', {
defaultMessage: 'Document',
});
const flyoutTitle = flyoutCustomization?.title ?? defaultFlyoutTitle;

const flyoutSize = flyoutCustomization?.size ?? 'm';

return (
Expand All @@ -209,17 +210,24 @@ export function DiscoverGridFlyout({
ownFocus={false}
>
<EuiFlyoutHeader hasBorder>
<EuiTitle
size="s"
className="unifiedDataTable__flyoutHeader"
data-test-subj="docTableRowDetailsTitle"
<EuiFlexGroup
direction="row"
alignItems="center"
gutterSize="m"
responsive={false}
wrap={true}
>
<h2>{flyoutTitle}</h2>
</EuiTitle>
<EuiSpacer size="s" />
<EuiFlexGroup responsive={false} gutterSize="s" alignItems="center">
{!isPlainRecord &&
flyoutActions.map((action) => action.enabled && <action.Content key={action.id} />)}
<EuiFlexItem grow={false}>
<EuiTitle
size="s"
data-test-subj="docTableRowDetailsTitle"
css={css`
white-space: nowrap;
`}
>
<h2>{flyoutTitle}</h2>
</EuiTitle>
</EuiFlexItem>
{activePage !== -1 && (
<EuiFlexItem data-test-subj={`dscDocNavigationPage-${activePage}`}>
<EuiPagination
Expand All @@ -229,13 +237,18 @@ export function DiscoverGridFlyout({
pageCount={pageCount}
activePage={activePage}
onPageClick={setPage}
className="unifiedDataTable__flyoutDocumentNavigation"
compressed
data-test-subj="dscDocNavigation"
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
{isPlainRecord || !flyoutActions.length ? null : (
<>
<EuiSpacer size="s" />
<DiscoverGridFlyoutActions flyoutActions={flyoutActions} />
</>
)}
</EuiFlyoutHeader>
<EuiFlyoutBody>{bodyContent}</EuiFlyoutBody>
</EuiFlyout>
Expand Down
Loading