Empty dashboard message
This commit is contained in:
parent
0fc4eb2f8c
commit
e1b0d16ce6
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { GRID_WIDTH, GRID_H_SNAP } from '../../constants'
|
||||||
import { useDashboardContext } from '../../contexts/DashboardContext'
|
import { useDashboardContext } from '../../contexts/DashboardContext'
|
||||||
import { normalizeBoxes } from '../../utils/normalizeBoxes'
|
import { normalizeBoxes } from '../../utils/normalizeBoxes'
|
||||||
import { NoDashboard } from '../NoDashboard'
|
import { NoDashboard } from '../NoDashboard'
|
||||||
|
|
@ -6,9 +7,29 @@ import { GeneralBox } from './components/GeneralBox'
|
||||||
export const DashboardGrid = () => {
|
export const DashboardGrid = () => {
|
||||||
const { isDashboardSelected, boxes, setBoxes } = useDashboardContext()
|
const { isDashboardSelected, boxes, setBoxes } = useDashboardContext()
|
||||||
|
|
||||||
|
const addNewBox = () => {
|
||||||
|
const box = {
|
||||||
|
id: new Date().getTime().toString(),
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
w: GRID_WIDTH / 2,
|
||||||
|
h: GRID_H_SNAP * 20,
|
||||||
|
}
|
||||||
|
|
||||||
|
setBoxes((previous) => [box, ...previous])
|
||||||
|
}
|
||||||
|
|
||||||
return isDashboardSelected ? (
|
return isDashboardSelected ? (
|
||||||
<div className="grid-sensors-container">
|
<div className="grid-sensors-container">
|
||||||
<div className="grid-sensors">
|
<div className="grid-sensors">
|
||||||
|
{boxes.length === 0 && (
|
||||||
|
<div className="empty">
|
||||||
|
<div>Empty dashboard</div>
|
||||||
|
<div>
|
||||||
|
<button onClick={() => addNewBox()}>Add box</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{boxes.map((b) => (
|
{boxes.map((b) => (
|
||||||
<GeneralBox
|
<GeneralBox
|
||||||
box={b}
|
box={b}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { BoxDialContent } from './BoxDialContent'
|
import { BoxDialContent } from './BoxDialContent'
|
||||||
import { BoxGraphContent } from './BoxGraphContent'
|
import { BoxGraphContent } from './BoxGraphContent'
|
||||||
import { EditableBoxProps } from './EditableBox'
|
import { EditableBox, EditableBoxProps } from './EditableBox'
|
||||||
|
|
||||||
export const GeneralBox = (props: EditableBoxProps) => {
|
export const GeneralBox = (props: EditableBoxProps) => {
|
||||||
switch (props.box.data?.type) {
|
switch (props.box.data?.type) {
|
||||||
|
|
@ -9,6 +9,10 @@ export const GeneralBox = (props: EditableBoxProps) => {
|
||||||
case 'graph':
|
case 'graph':
|
||||||
return <BoxGraphContent {...props} data={props.box.data} />
|
return <BoxGraphContent {...props} data={props.box.data} />
|
||||||
default:
|
default:
|
||||||
return <div>Unknown box type</div>
|
return (
|
||||||
|
<EditableBox {...props} onRefresh={() => null}>
|
||||||
|
<></>
|
||||||
|
</EditableBox>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue