import React from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCircle } from "@fortawesome/free-solid-svg-icons"; import guidGenerator from "../utilities/randomId"; /** * This function splits the input of a dashboard field into the parts that are inside and outside of ${...} * @param {*} text - the value of the input in the Dashboard Input Field * @returns */ const findReferences = (text) => { var splitText = text.split('${'); let textArray = [splitText[0]]; for (var i = 1; i < splitText.length; i++) { let insideBrackets = "${" + splitText[i].split('}')[0] if (splitText[i].includes('}')) { insideBrackets += "}" } textArray.push(insideBrackets) textArray.push(splitText[i].split('}')[1]) } return textArray; } /** * This component renders the input fields on the dashboard * @param {*} index - the order number of a keyPair * @param {*} onChangeHandler - what happens when the input is modified * @param {*} type - whether the input field is for a Key Name or for a Key Value * @param {*} value - value of the InputField * @param {*} blurred - whether the input field should be blurred (behind the gray dots) or not; this can be turned on/off in the dashboard * @returns */ const DashboardInputField = ({index, onChangeHandler, type, value, blurred}) => { if (type === "varName") { return (
onChangeHandler(e.target.value, index)} type={type} value={value} className="asolute z-10 peer font-mono ph-no-capture bg-bunker-800 rounded-md caret-white text-gray-400 text-md px-2 py-1.5 w-full min-w-16 outline-none focus:ring-4 focus:ring-primary/50 duration-200" spellCheck="false" />
); } else if (type === "value") { return (
onChangeHandler(e.target.value, index)} type={type} value={value} className={`${ blurred ? "text-transparent group-hover:text-transparent focus:text-transparent active:text-transparent" : "" } asolute z-10 peer font-mono ph-no-capture bg-transparent rounded-md caret-white text-transparent text-md px-2 py-1.5 w-full min-w-16 outline-none focus:ring-4 focus:ring-primary/50 duration-200`} spellCheck="false" />
{findReferences(value).map((text, id) => id % 2 == 0 || text.length <= 2 ? {text} : {text.slice(0, 2)} {text.slice(2, text.length - 1)} {text.slice(text.length - 1, text.length) == "}" ? {text.slice(text.length - 1, text.length)} : {text.slice(text.length - 1, text.length)} } )}
{blurred && (

{value .split("") .slice(0,42) .map(() => ( ))}
)}
); } }; export default React.memo(DashboardInputField);