Diagnose and resolve errors instantly to keep your apps running smoothly
> ); } const PreviewContainer = ({ children, isFocused, enablePreview, setCursorInsidePreview, isPortalOpen, previewRef, showPreview, onAiSuggestionAccept, ...restProps }) => { const { validationSchema, isWorkspaceVariable, errorStateActive, previewPlacement, validationFn, componentId, paramName, fieldMeta, setIsFocused, currentValue, } = restProps; const aiFeaturesEnabled = useStore((state) => state.ai?.aiFeaturesEnabled ?? false); const fetchErrorFixUsingAi = useStore((state) => state.fetchErrorFixUsingAi); const clearChatHistory = useStore((state) => state.clearChatHistory); const componentDefinition = useStore((state) => state.getComponentDefinition(componentId), shallow); // TODO: check if moduleId needs to be passed here const componentName = componentDefinition?.component?.name; const componentKey = `${componentName} - ${fieldMeta?.displayName}`; const chatList = useStore((state) => state.fixWithAiSlice?.[componentId]?.[componentKey]?.chatHistory ?? []); const [errorMessage, setErrorMessage] = useState(null); const [popoverToShow, setPopoverToShow] = useState('preview'); // preview | fixWithAI const errMsg = errorMessage?.message ?? null; const typeofError = getCurrentNodeType(errMsg); const errorMsg = typeofError === 'Array' ? errMsg[0] : errMsg; const darkMode = localStorage.getItem('darkMode') === 'true'; useEffect(() => { !showPreview && setPopoverToShow('preview'); }, [showPreview]); useEffect(() => { setPopoverToShow('preview'); if (chatList?.length) { clearChatHistory(componentId, componentKey); } }, [currentValue]); const fetchFixUsingAi = () => { const defaultValue = validationSchema?.defaultValue ? validationSchema?.defaultValue : validationSchema ? findDefault(validationSchema?.schema ?? {}, errorMessage?.value) : undefined; const errorData = { key: componentKey, componentId: componentId, message: errorMessage?.completeErrorMessage, error: { resolvedProperty: { [paramName]: errorMessage?.value }, effectiveProperty: { [paramName]: defaultValue }, componentId, }, }; fetchErrorFixUsingAi(errorData, { componentDisplayName: componentDefinition?.component?.displayName ?? componentDefinition?.component?.component ?? componentName, errorPropertyDisplayName: fieldMeta?.displayName, customErrMessage: errorMessage?.message, }); }; const handleFixErrorWithAI = () => { setPopoverToShow('fixWithAI'); if (!componentId || chatList?.length) { return; } fetchFixUsingAi(); }; const fixWithAIPopover = (
{prettyPrintedJson?.startsWith('{{') && prettyPrintedJson?.endsWith('{{')
? prettyPrintedJson?.replace(/{{/g, '').replace(/}}/g, '')
: prettyPrintedJson}