Settings modal
This commit is contained in:
parent
88fff43b90
commit
4e5cb734b6
|
|
@ -41,7 +41,7 @@ input, select {
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sensors-container {
|
#application {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
@ -188,4 +188,4 @@ form.horizontal .input label {
|
||||||
|
|
||||||
.checkbox-label input[type=checkbox] {
|
.checkbox-label input[type=checkbox] {
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
import { getSensors } from '@/api/sensors'
|
import { getSensors, SensorInfo } from '@/api/sensors'
|
||||||
import { intervalToRange } from '@/utils/intervalToRange'
|
import { intervalToRange } from '@/utils/intervalToRange'
|
||||||
import { useState } from 'preact/hooks'
|
import { useState } from 'preact/hooks'
|
||||||
import { useQuery } from 'react-query'
|
import { useQuery } from 'react-query'
|
||||||
import { Filters, FilterValue } from './components/Filters'
|
import { Filters, FilterValue } from './components/Filters'
|
||||||
import { Sensor } from './components/Sensor'
|
import { Sensor } from './components/Sensor'
|
||||||
|
import { SensorSettings } from './components/SensorSettings'
|
||||||
|
|
||||||
export const DashboardPage = () => {
|
export const DashboardPage = () => {
|
||||||
|
const [editedSensor, setEditedSensor] = useState<SensorInfo>()
|
||||||
|
|
||||||
const [filter, setFilter] = useState<FilterValue>(() => {
|
const [filter, setFilter] = useState<FilterValue>(() => {
|
||||||
const range = intervalToRange('week', new Date(), new Date())
|
const range = intervalToRange('week', new Date(), new Date())
|
||||||
|
|
||||||
|
|
@ -19,9 +22,21 @@ export const DashboardPage = () => {
|
||||||
<Filters preset={filter} onApply={setFilter} />
|
<Filters preset={filter} onApply={setFilter} />
|
||||||
<div className="sensors">
|
<div className="sensors">
|
||||||
{sensors.data?.map((s) => (
|
{sensors.data?.map((s) => (
|
||||||
<Sensor sensor={s} filter={filter} key={s.sensor} />
|
<Sensor
|
||||||
|
sensor={s}
|
||||||
|
filter={filter}
|
||||||
|
key={s.sensor}
|
||||||
|
onEdit={setEditedSensor}
|
||||||
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
{editedSensor && (
|
||||||
|
<SensorSettings
|
||||||
|
sensor={editedSensor}
|
||||||
|
onClose={() => setEditedSensor(undefined)}
|
||||||
|
onUpdate={() => sensors.refetch()}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,10 @@ import { FilterValue } from './Filters'
|
||||||
type Props = {
|
type Props = {
|
||||||
sensor: SensorInfo
|
sensor: SensorInfo
|
||||||
filter: FilterValue
|
filter: FilterValue
|
||||||
|
onEdit: (sensor: SensorInfo) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Sensor = ({ sensor, filter }: Props) => {
|
export const Sensor = ({ sensor, filter, onEdit }: Props) => {
|
||||||
const bodyRef = useRef<HTMLDivElement>(null)
|
const bodyRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const valuesQuery = {
|
const valuesQuery = {
|
||||||
|
|
@ -82,8 +83,12 @@ export const Sensor = ({ sensor, filter }: Props) => {
|
||||||
<div className="header">
|
<div className="header">
|
||||||
<div className="name">{sensor.config?.name ?? sensor.sensor}</div>
|
<div className="name">{sensor.config?.name ?? sensor.sensor}</div>
|
||||||
<div className="actions">
|
<div className="actions">
|
||||||
<button className="config">Config</button>
|
<button className="config" onClick={() => onEdit(sensor)}>
|
||||||
<button className="refresh">Refresh</button>
|
Config
|
||||||
|
</button>
|
||||||
|
<button className="refresh" onClick={() => values.refetch()}>
|
||||||
|
Refresh
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="body">
|
<div className="body">
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ import { useState } from 'preact/hooks'
|
||||||
type Props = {
|
type Props = {
|
||||||
sensor: SensorInfo
|
sensor: SensorInfo
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
|
onUpdate: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SensorSettings = ({ sensor, onClose }: Props) => {
|
export const SensorSettings = ({ sensor, onClose, onUpdate }: Props) => {
|
||||||
const [value, setValue] = useState(() => ({ ...sensor.config }))
|
const [value, setValue] = useState(() => ({ ...sensor.config }))
|
||||||
const [saving, setSaving] = useState(false)
|
const [saving, setSaving] = useState(false)
|
||||||
|
|
||||||
|
|
@ -35,6 +36,7 @@ export const SensorSettings = ({ sensor, onClose }: Props) => {
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
|
|
||||||
onClose()
|
onClose()
|
||||||
|
onUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleChange = (e: Event) => {
|
const handleChange = (e: Event) => {
|
||||||
|
|
@ -51,8 +53,13 @@ export const SensorSettings = ({ sensor, onClose }: Props) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="settings-modal${shown ? ' show' : ''}" onClick={onClose}>
|
<div className="settings-modal show" onMouseDown={onClose}>
|
||||||
<div className="inner" onClick={preventPropagation}>
|
<div
|
||||||
|
className="inner"
|
||||||
|
onMouseDown={preventPropagation}
|
||||||
|
onMouseUp={preventPropagation}
|
||||||
|
onClick={preventPropagation}
|
||||||
|
>
|
||||||
<div className="body">
|
<div className="body">
|
||||||
<form onSubmit={handleSave}>
|
<form onSubmit={handleSave}>
|
||||||
<div className="input">
|
<div className="input">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue