sprinklers3/app/components/SectionTable.tsx

55 lines
2.0 KiB
TypeScript
Raw Normal View History

import * as classNames from "classnames";
2017-08-29 23:21:36 -06:00
import { observer } from "mobx-react";
import * as React from "react";
2017-10-10 18:00:01 -06:00
import { Icon, Table } from "semantic-ui-react";
import { Section } from "@common/sprinklers";
/* tslint:disable:object-literal-sort-keys */
@observer
2017-08-29 23:21:36 -06:00
export default class SectionTable extends React.Component<{ sections: Section[] }> {
private static renderRow(section: Section, index: number) {
if (!section) {
return null;
}
2017-08-29 23:21:36 -06:00
const { name, state } = section;
const sectionStateClass = classNames({
"section--state": true,
"section--state-true": state,
"section--state-false": !state,
});
const sectionState = state ?
2018-04-12 17:27:42 -06:00
(<span><Icon name={"shower" as any} /> Irrigating</span>)
2017-08-29 23:21:36 -06:00
: "Not irrigating";
return (
<Table.Row key={index}>
<Table.Cell className="section--number">{"" + (index + 1)}</Table.Cell>
<Table.Cell className="section--name">{name}</Table.Cell>
2017-08-29 23:21:36 -06:00
<Table.Cell className={sectionStateClass}>{sectionState}</Table.Cell>
</Table.Row>
);
}
render() {
2017-08-29 23:21:36 -06:00
const rows = this.props.sections.map(SectionTable.renderRow);
return (
2018-06-26 11:53:22 -06:00
<Table celled striped unstackable compact>
<Table.Header>
<Table.Row>
<Table.HeaderCell colSpan="3">Sections</Table.HeaderCell>
</Table.Row>
<Table.Row>
<Table.HeaderCell className="section--number">#</Table.HeaderCell>
<Table.HeaderCell className="section--name">Name</Table.HeaderCell>
<Table.HeaderCell className="section--state">State</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
2017-08-29 23:21:36 -06:00
{rows}
</Table.Body>
</Table>
);
}
}