Skip to content

Commit

Permalink
Merge pull request #363 from TheTechCompany/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
balbatross authored Jul 27, 2023
2 parents 78722d8 + 74ba09a commit 5683592
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useMemo } from 'react';
import { Box } from '@mui/material';
import { CommandSurface } from '@hive-command/command-surface';
import { useWatchers } from './utils/watchers';
import { useParams } from 'react-router-dom';
import { useDevice } from './utils/program';
import { useDeviceHistory, useDeviceValues } from './utils/value';
import { useChangeDeviceValue, useChangeMode, usePerformDeviceAction } from '@hive-command/api';
import moment from 'moment';
import { useDeviceReports } from './utils/report';
import { useWebClient } from './utils/client';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import { Box } from '@mui/material';
import { QueryBuilder, Rule, RuleProps, useRule } from 'react-querybuilder';
import React from 'react';
import React, { useState } from 'react';
import 'react-querybuilder/dist/query-builder.css';
import { useCommandEditor } from '../../../context';

export const AlarmConditions = () => {

const { refetch, program: {templates, components, tags, types} } = useCommandEditor()

const [query, setQuery] = useState( {combinator: 'and', rules: []})

console.log(query);

return (
<Box>
<QueryBuilder
fields={[
{name: 'AV101', label: 'AV101', inputType: 'valve'},
{name: 'AV201', label: 'AV201', inputType: 'valve'}
]}

query={query}
onQueryChange={(e) => {
setQuery(e)
}}
fields={tags.map((tag) => ({
name: tag.name,
label: tag.name,
inputType: tag.type
}))}
controlElements={{
rule: AlarmRule
}}
Expand All @@ -23,10 +35,12 @@ export const AlarmConditions = () => {

export const AlarmRule = (props: RuleProps) => {
const r = { ...props, ...useRule(props) };

const { refetch, program: {templates, components, tags, types} } = useCommandEditor()

console.log(props);

if (props.schema.fieldMap[props.rule.field].inputType === 'valve') {
if (types.findIndex((idx) => idx.name == props.schema.fieldMap[props.rule.field].inputType) > -1) {
const {
schema: {
controls: {
Expand Down Expand Up @@ -92,7 +106,10 @@ export const AlarmRule = (props: RuleProps) => {
/>
</div>
<QueryBuilder
fields={[{label: 'open', name: "Open"}]}
fields={types.find((idx) => idx.name == props.schema.fieldMap[props.rule.field].inputType)?.fields?.map((x) => ({
name: x.name,
label: x.name
})) || []}
query={props.value}
onQueryChange={valueChangeHandler}
/>
Expand Down

0 comments on commit 5683592

Please sign in to comment.