import React, { useState } from 'react' import { FormControl } from '../form-control' import { TextField } from '../text-field' import { Select } from './select' export enum Standard { 'WAIT_FOR_ELEMENT', 'CLICK_ELEMENT', 'SET_FIELD', 'CLEAR_FIELD', 'CHECK_FIELD', 'UNCHECK_FIELD', } export enum WAIT_OPTIONS { 'ADDED', 'REMOVED', 'VISIBLE', 'HIDDEN', 'EMIT_LOAD', 'EMIT_LOADED', } export type StandardKeys = keyof typeof Standard const standards = Object.values(Standard).filter( (value) => typeof value === 'string' ) const waitOptions = Object.values(WAIT_OPTIONS).filter( (value) => typeof value === 'string' ) export type WaitOptionKeys = keyof typeof WAIT_OPTIONS export interface InputProps { onStandardChange(event: any): void standard?: StandardKeys path: string } // determine if the element select form should appear const elementSelectForm = (value: string) => { let canSelect = false switch (value) { case Standard[0]: { canSelect = true break } case Standard[1]: { canSelect = true break } case Standard[2]: { canSelect = true break } case Standard[3]: { canSelect = true break } case Standard[4]: { canSelect = true break } case Standard[5]: { canSelect = true break } default: { canSelect = false break } } return canSelect } export const ActionsSelectInput = ({ onStandardChange, path }: InputProps) => { const [action, setAction] = useState( standards[0] as StandardKeys ) const [waitFor, setWaitFor] = useState( waitOptions[0] as WaitOptionKeys ) const [selector, setSelector] = useState('') const [selectorValue, setSelectorValue] = useState('') const constructAction = () => { const actionName = action.replace(/\_/g, ' ').toLowerCase() const val = action === Standard[2] ? ` ${selectorValue}` : '' const waitVal = action === Standard[0] ? ` ${waitFor.replace(/\_/g, ' ').toLowerCase()}` : '' const sel = selector ? ` ${selector}` : '' onStandardChange(`${actionName}${sel}${val}${waitVal}`) } const onActionSelect = (e: React.ChangeEvent) => { setAction(e.target.value) } const onElementChangeEvent = (e: React.ChangeEvent) => { setSelector(e.target.value) constructAction() } const onWaitForChangeEvent = (e: React.ChangeEvent) => { setWaitFor(e.target.value) constructAction() } const onSelectorValueEvent = (e: React.ChangeEvent) => { setSelectorValue(e.target.value) constructAction() } const actionId = `${path}-action-select-outlined-label` const waitForId = `${path}-wait-action-select-outlined-label` return (
<> ACTION ) : null}
) }