From 8a64175c0ab5e3a0b775e94234589b37828c1fd8 Mon Sep 17 00:00:00 2001 From: arpitnath Date: Mon, 8 Apr 2024 18:15:18 +0530 Subject: [PATCH] fixes: renaming entities sets the references component value to default value current state was not updating to latest state removed/deleted render count hook [dev-testing purpose] --- frontend/src/Editor/Components/Button.jsx | 3 --- frontend/src/Editor/Components/Text.jsx | 13 +------------ frontend/src/Editor/Editor.jsx | 7 ++----- frontend/src/_helpers/utils.js | 17 ++--------------- frontend/src/_hooks/useRenderCount.js | 11 ----------- 5 files changed, 5 insertions(+), 46 deletions(-) delete mode 100644 frontend/src/_hooks/useRenderCount.js diff --git a/frontend/src/Editor/Components/Button.jsx b/frontend/src/Editor/Components/Button.jsx index 29bbb7ac49..aa49466759 100644 --- a/frontend/src/Editor/Components/Button.jsx +++ b/frontend/src/Editor/Components/Button.jsx @@ -1,11 +1,8 @@ import React, { useEffect, useState } from 'react'; import cx from 'classnames'; const tinycolor = require('tinycolor2'); -import useRenderCount from '@/_hooks/useRenderCount'; export const Button = function Button(props) { - useRenderCount(`Button Main component ${props.id}`); - const { height, properties, styles, fireEvent, id, dataCy, setExposedVariable, setExposedVariables } = props; const { backgroundColor, textColor, borderRadius, loaderColor, disabledState, borderColor, boxShadow } = styles; diff --git a/frontend/src/Editor/Components/Text.jsx b/frontend/src/Editor/Components/Text.jsx index ef9a91808b..6cbd11e256 100644 --- a/frontend/src/Editor/Components/Text.jsx +++ b/frontend/src/Editor/Components/Text.jsx @@ -3,7 +3,6 @@ import DOMPurify from 'dompurify'; import Markdown from 'react-markdown'; import './text.scss'; import Loader from '@/ToolJetUI/Loader/Loader'; -import useRenderCount from '@/_hooks/useRenderCount'; const VERTICAL_ALIGNMENT_VS_CSS_VALUE = { top: 'flex-start', @@ -11,17 +10,7 @@ const VERTICAL_ALIGNMENT_VS_CSS_VALUE = { bottom: 'flex-end', }; -export const Text = function Text({ - height, - properties, - fireEvent, - styles, - darkMode, - setExposedVariable, - dataCy, - ...props -}) { - useRenderCount(`TextComponent Main component ${props.id}`); +export const Text = function Text({ height, properties, fireEvent, styles, darkMode, setExposedVariable, dataCy }) { let { textSize, textColor, diff --git a/frontend/src/Editor/Editor.jsx b/frontend/src/Editor/Editor.jsx index 1d85b00343..505d284934 100644 --- a/frontend/src/Editor/Editor.jsx +++ b/frontend/src/Editor/Editor.jsx @@ -213,8 +213,6 @@ const EditorComponent = (props) => { const prevAppDefinition = useRef(appDefinition); - const onAppLoadAndPageLoadEventsAreTriggered = useRef(false); - useLayoutEffect(() => { resetAllStores(); }, []); @@ -282,9 +280,9 @@ const EditorComponent = (props) => { } if (mounted && didAppDefinitionChanged && currentPageId) { - // const components = appDefinition?.pages[currentPageId]?.components || {}; + const components = appDefinition?.pages[currentPageId]?.components || {}; - // computeComponentState(components); + computeComponentState(components); if (appDiffOptions?.skipAutoSave === true || appDiffOptions?.entityReferenceUpdated === true) return; @@ -789,7 +787,6 @@ const EditorComponent = (props) => { handleLowPriorityWork(async () => { await runQueries(useDataQueriesStore.getState().dataQueries, editorRef, true); await handleEvent('onPageLoad', currentPageEvents, {}, true); - await handleLowPriorityWork(() => (onAppLoadAndPageLoadEventsAreTriggered.current = true)); }); }); }; diff --git a/frontend/src/_helpers/utils.js b/frontend/src/_helpers/utils.js index 9ef51e0e57..70aa1bdae4 100644 --- a/frontend/src/_helpers/utils.js +++ b/frontend/src/_helpers/utils.js @@ -3,17 +3,15 @@ import moment from 'moment'; import _, { isEmpty } from 'lodash'; import axios from 'axios'; import JSON5 from 'json5'; -import { previewQuery, executeAction } from '@/_helpers/appUtils'; +import { executeAction } from '@/_helpers/appUtils'; import { toast } from 'react-hot-toast'; import { authenticationService } from '@/_services/authentication.service'; import { useDataQueriesStore } from '@/_stores/dataQueriesStore'; -import { getCurrentState, useCurrentState } from '@/_stores/currentStateStore'; +import { getCurrentState } from '@/_stores/currentStateStore'; import { getWorkspaceIdOrSlugFromURL, getSubpath, returnWorkspaceIdIfNeed } from './routes'; import { getCookie, eraseCookie } from '@/_helpers/cookie'; import { staticDataSources } from '@/Editor/QueryManager/constants'; -import { resolveReferences as newResolver } from '@/Editor/CodeEditor/utils'; -import { useResolveStore } from '@/_stores/resolverStore'; export function findProp(obj, prop, defval) { if (typeof defval === 'undefined') defval = null; @@ -329,18 +327,7 @@ export const serializeNestedObjectToQueryParams = function (obj, prefix) { export function resolveWidgetFieldValue(prop, _default = [], customResolveObjects = {}) { const widgetFieldValue = prop; - const isStoreAndEditorReady = useResolveStore.getState().updateStoreState && useCurrentState.getState().isEditorReady; - try { - if (isStoreAndEditorReady) { - const [_, _error, resolveValue] = newResolver(widgetFieldValue?.value); - - if (_error) { - return _default; - } - - return resolveValue; - } const state = getCurrentState(); return resolveReferences(widgetFieldValue, state, _default, customResolveObjects); } catch (err) { diff --git a/frontend/src/_hooks/useRenderCount.js b/frontend/src/_hooks/useRenderCount.js deleted file mode 100644 index c07b5734e3..0000000000 --- a/frontend/src/_hooks/useRenderCount.js +++ /dev/null @@ -1,11 +0,0 @@ -import { useRef, useEffect } from 'react'; - -function useRenderCount(componentName) { - const renderCountRef = useRef(0); - - renderCountRef.current++; - - return renderCountRef.current; -} - -export default useRenderCount;