Empty dashboard message

This commit is contained in:
Jan Zípek 2024-04-01 13:13:35 +02:00
parent 0fc4eb2f8c
commit e1b0d16ce6
Signed by: kamen
GPG Key ID: A17882625B33AC31
2 changed files with 27 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import { GRID_WIDTH, GRID_H_SNAP } from '../../constants'
import { useDashboardContext } from '../../contexts/DashboardContext'
import { normalizeBoxes } from '../../utils/normalizeBoxes'
import { NoDashboard } from '../NoDashboard'
@ -6,9 +7,29 @@ import { GeneralBox } from './components/GeneralBox'
export const DashboardGrid = () => {
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 ? (
<div className="grid-sensors-container">
<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) => (
<GeneralBox
box={b}

View File

@ -1,6 +1,6 @@
import { BoxDialContent } from './BoxDialContent'
import { BoxGraphContent } from './BoxGraphContent'
import { EditableBoxProps } from './EditableBox'
import { EditableBox, EditableBoxProps } from './EditableBox'
export const GeneralBox = (props: EditableBoxProps) => {
switch (props.box.data?.type) {
@ -9,6 +9,10 @@ export const GeneralBox = (props: EditableBoxProps) => {
case 'graph':
return <BoxGraphContent {...props} data={props.box.data} />
default:
return <div>Unknown box type</div>
return (
<EditableBox {...props} onRefresh={() => null}>
<></>
</EditableBox>
)
}
}