import { observer } from "mobx-react"; import { RouterStore } from "mobx-react-router"; import * as React from "react"; import { Link } from "react-router-dom"; import { Button, ButtonProps, Table } from "semantic-ui-react"; import { ProgramSequenceView, ScheduleView } from "@app/components"; import * as rp from "@app/routePaths"; import { Program, Section, SprinklersDevice } from "@common/sprinklersRpc"; @observer class ProgramRows extends React.Component<{ program: Program, device: SprinklersDevice, routerStore: RouterStore, expanded: boolean, toggleExpanded: (program: Program) => void, }> { render() { const { program, device, expanded, routerStore } = this.props; const { sections } = device; const { name, running, enabled, schedule, sequence } = program; const buttonStyle: ButtonProps = { size: "small", compact: true }; const detailUrl = rp.program(device.id, program.id); const mainRow = ( {"" + program.id} {name} {enabled ? "Enabled" : "Not enabled"} {running ? "Running" : "Not running"} ); const detailRow = expanded && (

Sequence:

Schedule:

); return ( {mainRow} {detailRow} ); } private cancelOrRun = () => { const { program } = this.props; program.running ? program.cancel() : program.run(); } private toggleExpanded = () => { this.props.toggleExpanded(this.props.program); } } @observer export default class ProgramTable extends React.Component<{ device: SprinklersDevice, routerStore: RouterStore, }, { expandedPrograms: Program[], }> { constructor(p: any) { super(p); this.state = { expandedPrograms: [] }; } render() { const { programs, sections } = this.props.device; const programRows = programs.map(this.renderRows); return ( Programs # Name Enabled? Running? Actions {programRows}
); } private renderRows = (program: Program, i: number): JSX.Element | null => { if (!program) { return null; } const expanded = this.state.expandedPrograms.indexOf(program) !== -1; return ( ); } private toggleExpanded = (program: Program) => { const { expandedPrograms } = this.state; const idx = expandedPrograms.indexOf(program); if (idx !== -1) { expandedPrograms.splice(idx, 1); } else { expandedPrograms.push(program); } this.setState({ expandedPrograms, }); } }