diff --git a/web/client/actions/widgets.js b/web/client/actions/widgets.js index efcf27eee5..054eb3a8be 100644 --- a/web/client/actions/widgets.js +++ b/web/client/actions/widgets.js @@ -46,6 +46,7 @@ export const TOGGLE_TRAY = "WIDGET:TOGGLE_TRAY"; export const REPLACE_LAYOUT_VIEW = "WIDGET:REPLACE_LAYOUT_VIEW"; export const SET_SELECTED_LAYOUT_VIEW_ID = "WIDGET:SET_SELECTED_LAYOUT_VIEW_ID"; +export const SET_LINKED_DASHBOARD_DATA = "WIDGET:SET_LINKED_DASHBOARD_DATA"; /** * Intent to create a new Widgets @@ -348,3 +349,15 @@ export const setSelectedLayoutViewId = (viewId, target = DEFAULT_TARGET) => ({ target, viewId }); + +/** + * Set the layouts, widgets of the linked dashboard + * @param {object} data The layouts and widgets + * @param {string} [target=floating] the target container of the layouts + * @return {object} action with type `WIDGETS:SET_LINKED_DASHBOARD_DATA`, the data and the target + */ +export const setLinkedDashboardData = (data, target = DEFAULT_TARGET) => ({ + type: SET_LINKED_DASHBOARD_DATA, + data, + target +}); diff --git a/web/client/components/dashboard/ConfigureView.jsx b/web/client/components/dashboard/ConfigureView.jsx index a14719fc26..d7e9d61e9f 100644 --- a/web/client/components/dashboard/ConfigureView.jsx +++ b/web/client/components/dashboard/ConfigureView.jsx @@ -1,15 +1,40 @@ import React, { useEffect, useState } from 'react'; import Dialog from '../misc/Dialog'; -import { Button, ControlLabel, FormControl, FormGroup, Glyphicon } from 'react-bootstrap'; +import { Button, ControlLabel, FormControl, FormGroup, Glyphicon, InputGroup } from 'react-bootstrap'; import Message from '../I18N/Message'; import ColorSelector from '../style/ColorSelector'; +import Select from 'react-select'; import Portal from '../misc/Portal'; +import { getCatalogResources } from '../../api/persistence'; +import withTooltip from '../misc/enhancers/tooltip'; +import FlexBox from '../layout/FlexBox'; -const ConfigureView = ({ active, onToggle, name, color, onSave }) => { +const GlyphiconIndicator = withTooltip(Glyphicon); + +const ConfigureView = ({ active, onToggle, data, onSave, user, monitoredState }) => { const [setting, setSetting] = useState({ name: null, color: null }); + const [dashboardOptions, setDashboardOptions] = useState([]); + + useEffect(() => { + setSetting(data); + }, [data]); + useEffect(() => { - setSetting({ name, color }); - }, [name, color]); + if (!active || !user || !monitoredState) return; + const args = [{ params: { pageSize: 9999999 }, monitoredState }, { user }, ["DASHBOARD"]]; + const catalogResources = getCatalogResources(...args).toPromise(); + catalogResources.then(res => { + const options = res.resources.map(d => ({ + value: d.id || d.pk, + label: d.name + })); + setDashboardOptions(options); + }); + }, [active, user, monitoredState]); + + const canAddLayout = !data.dashboard + ? (data.layoutsData?.md?.length === 0 && data.layoutsData?.xxs?.length === 0) + : true; return active && ( @@ -36,9 +61,9 @@ const ConfigureView = ({ active, onToggle, name, color, onSave }) => { }} /> - + -
+ { ...prev, color: colorVal }))} + placement="right" + /> + + + + Link existing dashboard + + { + const { checked } = event.target || {}; + setSetting(prev => ({ ...prev, linkExistingDashboard: checked })); + }} /> -
+ {!canAddLayout && ( + + )} +
+ {setting.linkExistingDashboard && ( + + Select dashboard +