-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nested context menu to link to dashboards
* introduces a separate TableRowActionsNested component * moves TableRowActions back into agent config components
- Loading branch information
Showing
6 changed files
with
120 additions
and
28 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...ingest_manager/public/applications/ingest_manager/components/table_row_actions_nested.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,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> | ||
); | ||
} | ||
); |
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
77 changes: 77 additions & 0 deletions
77
...ions/ingest_manager/sections/data_stream/list_page/components/data_stream_row_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,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} />; | ||
}); |
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