Skip to content

Commit

Permalink
Add nested context menu to link to dashboards
Browse files Browse the repository at this point in the history
* introduces a separate TableRowActionsNested component
* moves TableRowActions back into agent config components
  • Loading branch information
skh committed May 4, 2020
1 parent 2ce2b62 commit d0c6abc
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useCallback, useState } from 'react';
import { EuiButtonIcon, EuiContextMenu, EuiPopover } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { EuiContextMenuProps } from '@elastic/eui/src/components/context_menu/context_menu';

export const TableRowActionsNested = React.memo<{ panels: EuiContextMenuProps['panels'] }>(
({ panels }) => {
const [isOpen, setIsOpen] = useState(false);
const handleCloseMenu = useCallback(() => setIsOpen(false), [setIsOpen]);
const handleToggleMenu = useCallback(() => setIsOpen(!isOpen), [isOpen]);

return (
<EuiPopover
anchorPosition="downRight"
panelPaddingSize="none"
button={
<EuiButtonIcon
iconType="boxesHorizontal"
onClick={handleToggleMenu}
aria-label={i18n.translate('xpack.ingestManager.genericActionsMenuTextB', {
defaultMessage: 'Open',
})}
/>
}
isOpen={isOpen}
closePopover={handleCloseMenu}
>
<EuiContextMenu panels={panels} initialPanelId={0} />
</EuiPopover>
);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const TableRowActions = React.memo<{ items: EuiContextMenuPanelProps['ite
<EuiButtonIcon
iconType="boxesHorizontal"
onClick={handleToggleMenu}
aria-label={i18n.translate('xpack.ingestManager.genericActionsMenuText', {
aria-label={i18n.translate('xpack.ingestManager.agentList.ActionsMenuText', {
defaultMessage: 'Open',
})}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
EuiFlexItem,
} from '@elastic/eui';
import { AgentConfig, Datasource } from '../../../../../types';
import { TableRowActions } from '../../../../../components/table_row_actions';
import { TableRowActions } from '../../../components/table_row_actions';
import { DangerEuiContextMenuItem } from '../../../components/danger_eui_context_menu_item';
import { useCapabilities, useLink } from '../../../../../hooks';
import { useAgentConfigLink } from '../../hooks/use_details_uri';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { CreateAgentConfigFlyout } from './components';
import { SearchBar } from '../../../components/search_bar';
import { LinkedAgentCount } from '../components';
import { useAgentConfigLink } from '../details_page/hooks/use_details_uri';
import { TableRowActions } from '../../../components/table_row_actions';
import { TableRowActions } from '../components/table_row_actions';

const NO_WRAP_TRUNCATE_STYLE: CSSProperties = Object.freeze({
overflow: 'hidden',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { memo } from 'react';

import { FormattedMessage } from '@kbn/i18n/react';
import { useKibanaLink } from '../../../../hooks/use_kibana_link';
import { DataStream } from '../../../../types';
import { TableRowActionsNested } from '../../../../components/table_row_actions_nested';

export const DataStreamRowActions = memo<{ datastream: DataStream }>(({ datastream }) => {
const { dashboards } = datastream;
const panels = [];
const actionNameSingular = (
<FormattedMessage
id="xpack.ingestManager.dataStreamList.viewDashboardActionText"
defaultMessage="View dashboard"
/>
);
const actionNamePlural = (
<FormattedMessage
id="xpack.ingestManager.dataStreamList.viewDashboardsActionText"
defaultMessage="View dashboards"
/>
);

if (!dashboards || dashboards.length === 0) {
panels.push({
id: 0,
items: [
{
icon: 'dashboardApp',
disabled: true,
name: actionNameSingular,
},
],
});
} else if (dashboards.length === 1) {
panels.push({
id: 0,
items: [
{
icon: 'dashboardApp',
href: useKibanaLink(`/dashboard/${dashboards[0].id || ''}`),
name: actionNameSingular,
},
],
});
} else {
panels.push({
id: 0,
items: [
{
icon: 'dashboardApp',
panel: 1,
name: actionNamePlural,
},
],
});
panels.push({
id: 1,
title: 'View dashboards',
items: dashboards.map(dashboard => {
return {
icon: 'dashboardApp',
href: useKibanaLink(`/dashboard/${dashboard.id || ''}`),
name: dashboard.id,
};
}),
});
}

return <TableRowActionsNested panels={panels} />;
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React, { useMemo, memo } from 'react';
import React, { useMemo } from 'react';
import {
EuiBadge,
EuiButton,
Expand All @@ -17,13 +17,11 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage, FormattedDate } from '@kbn/i18n/react';
import { EuiContextMenuItem } from '@elastic/eui';
import { DataStream } from '../../../types';
import { WithHeaderLayout } from '../../../layouts';
import { useGetDataStreams, useStartDeps, usePagination } from '../../../hooks';
import { PackageIcon } from '../../../components/package_icon';
import { TableRowActions } from '../../../components/table_row_actions';
import { useKibanaLink } from '../../../hooks/use_kibana_link';
import { DataStreamRowActions } from './components/data_stream_row_actions';

const DataStreamListPageLayout: React.FunctionComponent = ({ children }) => (
<WithHeaderLayout
Expand Down Expand Up @@ -56,27 +54,6 @@ const DataStreamListPageLayout: React.FunctionComponent = ({ children }) => (
</WithHeaderLayout>
);

const DataStreamRowActions = memo<{ datastream: DataStream }>(({ datastream }) => {
const url = datastream.dashboards.length > 0 ? datastream.dashboards[0].id : '';
return (
<TableRowActions
items={[
<EuiContextMenuItem
icon="dashboardApp"
href={useKibanaLink(`/dashboard/${url}`)}
key="viewDashboard"
disabled={!(datastream.dashboards?.length > 0)}
>
<FormattedMessage
id="xpack.ingestManager.dataStreamList.viewDashboardActionText"
defaultMessage="View dashboard"
/>
</EuiContextMenuItem>,
]}
/>
);
});

export const DataStreamListPage: React.FunctionComponent<{}> = () => {
const {
data: { fieldFormats },
Expand Down

0 comments on commit d0c6abc

Please sign in to comment.