import { observable, runInAction } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; interface IKeyRestrictionProps { contains: boolean; script: (value: string) => void; field: string; value: string; } @observer export default class KeyRestrictionRow extends React.Component { @observable private _key = this.props.field; @observable private _value = this.props.value; @observable private _contains = this.props.contains; render() { if (this._key && this._value) { let parsedValue: string | number = `"${this._value}"`; const parsed = parseInt(this._value); let type = 'string'; if (!isNaN(parsed)) { parsedValue = parsed; type = 'number'; } const scriptText = `${this._contains ? '' : '!'}(((doc.${this._key} && (doc.${this._key} as ${type})${type === 'string' ? '.includes' : '<='}(${parsedValue}))) || ((doc.data_ext && doc.data_ext.${this._key}) && (doc.data_ext.${this._key} as ${type})${type === 'string' ? '.includes' : '<='}(${parsedValue}))))`; // let doc = new Doc(); // ((doc.data_ext && doc.data_ext!.text) && (doc.data_ext!.text as string).includes("hello")); this.props.script(scriptText); } else { this.props.script(''); } return (
runInAction(() => (this._key = e.target.value))} placeholder="KEY" /> runInAction(() => (this._value = e.target.value))} placeholder="VALUE" />
); } }