import React, { useRef, useState } from 'react'; import CodeHinter from '@/AppBuilder/CodeEditor'; import { resolveReferences } from '@/AppBuilder/CodeEditor/utils'; import SolidIcon from '@/_ui/Icon/SolidIcons'; import { ButtonSolid } from '@/_ui/AppButton/AppButton'; import cx from 'classnames'; import OverlayTrigger from 'react-bootstrap/OverlayTrigger'; import { Popover } from 'react-bootstrap'; import _ from 'lodash'; const transformvalue = (value = '') => { if (typeof value !== 'string') { return JSON.stringify(value); } return value; }; export const CellHinterWrapper = ({ isNotNull, defaultValue, selectedValue, setSelectedValue, saveFunction, isEditCell, columnDetails, close, closePopover, show, previousCellValue, }) => { const initialValueRef = useRef(selectedValue); const defaultValueRef = useRef(defaultValue); const [shouldUpdateToDefaultVal, setShouldUpdateDefaultVal] = useState(false); const [shouldUpdateToNullVal, setShouldUpdateNullVal] = useState(false); const [disabledSaveButton, setDisabledSaveButton] = useState(false); const handleInputError = (bool = false) => { setDisabledSaveButton(bool); }; const handleKeyDown = (e) => { e.stopPropagation(); if (e.key === 'Escape') { const event = new Event('click', { bubbles: true, cancelable: true }); document.body.dispatchEvent(event); } }; const darkMode = localStorage.getItem('darkMode') === 'true'; const tranformedValue = (rawValue) => { if (!rawValue) { return JSON.stringify(rawValue); } const [_, __, resolvedValue] = resolveReferences(`{{${rawValue}}}`); return resolvedValue; }; const SaveChangesSection = () => { const handleNullToggle = (value) => { setShouldUpdateNullVal(false); if (value) { setSelectedValue(null); shouldUpdateToDefaultVal && setShouldUpdateDefaultVal(false); } else { setSelectedValue(tranformedValue(previousCellValue)); } setShouldUpdateNullVal(value); }; const handleDefaultToggle = (value) => { setShouldUpdateDefaultVal(false); if (value) { setSelectedValue(defaultValue); shouldUpdateToNullVal && setShouldUpdateNullVal(false); defaultValueRef.current = defaultValue; } else { const val = tranformedValue(previousCellValue); defaultValueRef.current = val; setSelectedValue(val); } setShouldUpdateDefaultVal(true); }; return (