ToolJet/frontend/src/Editor/CodeBuilder/CodeHinter.jsx

431 lines
14 KiB
React
Raw Normal View History

import React, { useEffect, useState, useRef, useContext } from 'react';
import { useSpring, config, animated } from 'react-spring';
import OverlayTrigger from 'react-bootstrap/OverlayTrigger';
import Tooltip from 'react-bootstrap/Tooltip';
import CodeMirror from '@uiw/react-codemirror';
2021-05-03 11:26:31 +00:00
import 'codemirror/mode/handlebars/handlebars';
2021-05-09 04:25:17 +00:00
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/sql/sql';
import 'codemirror/addon/hint/show-hint';
import 'codemirror/addon/display/placeholder';
import 'codemirror/addon/search/match-highlighter';
2021-05-03 14:27:32 +00:00
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/theme/base16-light.css';
import 'codemirror/theme/duotone-light.css';
2021-07-03 17:07:50 +00:00
import 'codemirror/theme/monokai.css';
import { onBeforeChange, handleChange } from './utils';
import { resolveReferences, hasCircularDependency, handleCircularStructureToJSON } from '@/_helpers/utils';
import useHeight from '@/_hooks/use-height-transition';
import usePortal from '@/_hooks/use-portal';
import { Color } from './Elements/Color';
import { Json } from './Elements/Json';
import { Select } from './Elements/Select';
import { Toggle } from './Elements/Toggle';
import { AlignButtons } from './Elements/AlignButtons';
import { TypeMapping } from './TypeMapping';
import { Number } from './Elements/Number';
import { BoxShadow } from './Elements/BoxShadow';
import FxButton from './Elements/FxButton';
import { ToolTip } from '../Inspector/Elements/Components/ToolTip';
import { toast } from 'react-hot-toast';
import { EditorContext } from '@/Editor/Context/EditorContextWrapper';
[Feature]: Added Localisation (#3746) * Added localisation * Closed modal after language selection * updated transaltaion setup * Updated language tooltip * Added fallback language support * Adding english library resource for translation (#3844) * Adding English dictionary for the widget lists in the inspector * added leftSideBar object in en.json and implemented it for leftSidebar icon text * renamed leftSideBar to leftSidebar and added resources for tip in the left side bar * added english translation resources for leftsidebar debugger * added english language resources for the global settings * added english language resources for data sources in left sidebar * added english language resources for the share button and share modal in the editor * added english language resources for release button, manageOrgUsers, appVersionManager * added english language resources for Queries and Please select a widget to inspect in the editor * added english language resources for data source list , data source manager, and query manager(partially) * added english language resources for queryManager, transformation, preview * added english language resources for dark mode toggle in the headers inside homepage * added fallback message for dark mode toggle * added resources for language change in the headers inside homepage * added resources for notification center in the header inside homepage * added resources for organization and manage users components in header inside homepage * added resources in manageGroupPermission * added resources for manageGroupPermissionsResources component * added resources for manageSSO and generalSettings components * added resources for google sso * added resources for github sso * added resources for environment variables in manageSSO * added resources for profile and setting page * added resources for app card and app card menu * added resources for folder section and app list in homepage * added resources for header section in the homepage * added resources for pagination in homepage * added resources for modals in the homepage * added resources for blank page * added resources for login page * added resources for forgot password page * added resources for sign up page * added resources for onBoarding component * added resources for reset password page * deleted duplicate key for readDocumentation * deleted duplicate key for cancel in en.json and added translation for cancel at few places * removing duplicate copy of save key in en.json * added translation for CommentActions.jsx components * deleted duplicate copy of search key in en.json and added resources for create and search queries , select keys * fix typo errors * fixed typo errors * shorten the key for loginAndSignUpAndForgotPassword to loginSignupPage in en.json file and related files * shorten the key noLoginMethodsEnabledForThisWorkspace to noLoginMethodsEnabled * shorten the key pleaseCheckYourEmailForConfirmationLink to emailConfirmLink * shorten the key dontHaveAccountYet to dontHaveAccount * shorten keys from loginSignupPage key in en.json * shorten keys of shareModal nested object in en.json * shorten the key in appVersionManager nested object * shorten the keys for queryManager nested object in the en.json * delete duplicate copy of environmentVar and shorten manageEnvironmentVariables,environmentVariables * shorten keys in the organization nested object * shorten keys in the homePage nested object in en.json file * added inspector and eventManager empty object * added resources to RedirectSSO component * added resources for OAuth2 * added resources for TemplateCard.jsx * added resources for TemplateLibraryModal.jsx * added resources for ConfirmationPage.jsx * added resources for ConfirmationPage component * removed translation in App.jsx file * added resources for Slack.jsx * added resources for GoogleSheets.jsx * added resources for CodeBuilder.jsx * added resources for CommentBody and CommentFooter * added resources for TestConnection component * added resources for AllignButton.jsx * added resources for Openapi and Stripe components * added resources for ErrorBoundary * added resources for Viewer.jsx * Translation for widgets, table Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com> * Commented Language selection * Fixed typos * Updated fr.json file Co-authored-by: Manish Kushare <kushare.manish9@gmail.com>
2022-09-14 08:04:49 +00:00
import { camelCase } from 'lodash';
import { useTranslation } from 'react-i18next';
import cx from 'classnames';
import { useCurrentState } from '@/_stores/currentStateStore';
const AllElements = {
Color,
Json,
Toggle,
Select,
AlignButtons,
Number,
BoxShadow,
};
2021-05-03 14:27:32 +00:00
export function CodeHinter({
initialValue,
onChange,
mode,
theme,
lineNumbers,
placeholder,
ignoreBraces,
enablePreview,
2021-08-21 04:09:04 +00:00
height,
minHeight,
lineWrapping,
componentName = null,
usePortalEditor = true,
className,
width = '',
paramName,
paramLabel,
type,
fieldMeta,
onFxPress,
fxActive,
component,
popOverCallback,
cyLabel = '',
callgpt = () => null,
isCopilotEnabled = false,
Parameters support on RunJS (#7033) * feat: resolve passed arguments in runjs * feat: added popup form for runs params * fix: fixed issue with close function of popupover with codehinter * feat: added input for runjs args * style: for runjs args * fix: added support for params in custom components * fix: fixed default query param for runjs * fix: remove debuggers * refactor: removed commented code * fix: removed unused code * style: arguments input style in event manager * refactor: Moved argument list to separate component * refactor: moved runjs components to single folder * fix: minor refactorings * fix: renamed arguments to parameters for compoennts * refactor: reanamed argument to parameter in runjs * refactor: removed commented code * fix: added hasPramSupported flag against runjs queries * Update frontend/src/Editor/Inspector/ActionConfigurationPanels/RunjsParamters.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * Update frontend/src/Editor/QueryManager/QueryEditors/Runjs/ParameterForm.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * fix: prevent duplication of name * fix: fixed issue that blocked query params from returning * fix: remove extra params from runjs * fix: updated reference to current satte * fix: updated `query.run()` signature * fix: added duplicate check on param add and update * fix: added additonal null check for params runjs * feat: resolve runjs params default value without currentState * fix: hide defaultvalue of runjs in events form * fix: minor UX experience in runjs params * fix: set runjs default values to events on creation * style: updated the runjs param UI * style: runjs param form minor ux improvement * fix: close modal on add button click again --------- Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com>
2023-07-20 11:05:39 +00:00
currentState: _currentState,
}) {
const darkMode = localStorage.getItem('darkMode') === 'true';
2021-05-03 14:27:32 +00:00
const options = {
lineNumbers: lineNumbers ?? false,
lineWrapping: lineWrapping ?? true,
2021-05-03 14:27:32 +00:00
singleLine: true,
mode: mode || 'handlebars',
2021-05-03 14:27:32 +00:00
tabSize: 2,
theme: theme ? theme : darkMode ? 'monokai' : 'default',
2021-05-03 14:27:32 +00:00
readOnly: false,
highlightSelectionMatches: true,
placeholder,
};
const currentState = useCurrentState();
const [realState, setRealState] = useState(currentState);
const [currentValue, setCurrentValue] = useState(initialValue);
const [isFocused, setFocused] = useState(false);
const [heightRef, currentHeight] = useHeight();
const isPreviewFocused = useRef(false);
const wrapperRef = useRef(null);
const slideInStyles = useSpring({
config: { ...config.stiff },
from: { opacity: 0, height: 0 },
to: {
opacity: isFocused ? 1 : 0,
height: isFocused ? currentHeight : 0,
},
});
[Feature]: Added Localisation (#3746) * Added localisation * Closed modal after language selection * updated transaltaion setup * Updated language tooltip * Added fallback language support * Adding english library resource for translation (#3844) * Adding English dictionary for the widget lists in the inspector * added leftSideBar object in en.json and implemented it for leftSidebar icon text * renamed leftSideBar to leftSidebar and added resources for tip in the left side bar * added english translation resources for leftsidebar debugger * added english language resources for the global settings * added english language resources for data sources in left sidebar * added english language resources for the share button and share modal in the editor * added english language resources for release button, manageOrgUsers, appVersionManager * added english language resources for Queries and Please select a widget to inspect in the editor * added english language resources for data source list , data source manager, and query manager(partially) * added english language resources for queryManager, transformation, preview * added english language resources for dark mode toggle in the headers inside homepage * added fallback message for dark mode toggle * added resources for language change in the headers inside homepage * added resources for notification center in the header inside homepage * added resources for organization and manage users components in header inside homepage * added resources in manageGroupPermission * added resources for manageGroupPermissionsResources component * added resources for manageSSO and generalSettings components * added resources for google sso * added resources for github sso * added resources for environment variables in manageSSO * added resources for profile and setting page * added resources for app card and app card menu * added resources for folder section and app list in homepage * added resources for header section in the homepage * added resources for pagination in homepage * added resources for modals in the homepage * added resources for blank page * added resources for login page * added resources for forgot password page * added resources for sign up page * added resources for onBoarding component * added resources for reset password page * deleted duplicate key for readDocumentation * deleted duplicate key for cancel in en.json and added translation for cancel at few places * removing duplicate copy of save key in en.json * added translation for CommentActions.jsx components * deleted duplicate copy of search key in en.json and added resources for create and search queries , select keys * fix typo errors * fixed typo errors * shorten the key for loginAndSignUpAndForgotPassword to loginSignupPage in en.json file and related files * shorten the key noLoginMethodsEnabledForThisWorkspace to noLoginMethodsEnabled * shorten the key pleaseCheckYourEmailForConfirmationLink to emailConfirmLink * shorten the key dontHaveAccountYet to dontHaveAccount * shorten keys from loginSignupPage key in en.json * shorten keys of shareModal nested object in en.json * shorten the key in appVersionManager nested object * shorten the keys for queryManager nested object in the en.json * delete duplicate copy of environmentVar and shorten manageEnvironmentVariables,environmentVariables * shorten keys in the organization nested object * shorten keys in the homePage nested object in en.json file * added inspector and eventManager empty object * added resources to RedirectSSO component * added resources for OAuth2 * added resources for TemplateCard.jsx * added resources for TemplateLibraryModal.jsx * added resources for ConfirmationPage.jsx * added resources for ConfirmationPage component * removed translation in App.jsx file * added resources for Slack.jsx * added resources for GoogleSheets.jsx * added resources for CodeBuilder.jsx * added resources for CommentBody and CommentFooter * added resources for TestConnection component * added resources for AllignButton.jsx * added resources for Openapi and Stripe components * added resources for ErrorBoundary * added resources for Viewer.jsx * Translation for widgets, table Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com> * Commented Language selection * Fixed typos * Updated fr.json file Co-authored-by: Manish Kushare <kushare.manish9@gmail.com>
2022-09-14 08:04:49 +00:00
const { t } = useTranslation();
const { variablesExposedForPreview } = useContext(EditorContext);
const prevCountRef = useRef(false);
useEffect(() => {
Parameters support on RunJS (#7033) * feat: resolve passed arguments in runjs * feat: added popup form for runs params * fix: fixed issue with close function of popupover with codehinter * feat: added input for runjs args * style: for runjs args * fix: added support for params in custom components * fix: fixed default query param for runjs * fix: remove debuggers * refactor: removed commented code * fix: removed unused code * style: arguments input style in event manager * refactor: Moved argument list to separate component * refactor: moved runjs components to single folder * fix: minor refactorings * fix: renamed arguments to parameters for compoennts * refactor: reanamed argument to parameter in runjs * refactor: removed commented code * fix: added hasPramSupported flag against runjs queries * Update frontend/src/Editor/Inspector/ActionConfigurationPanels/RunjsParamters.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * Update frontend/src/Editor/QueryManager/QueryEditors/Runjs/ParameterForm.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * fix: prevent duplication of name * fix: fixed issue that blocked query params from returning * fix: remove extra params from runjs * fix: updated reference to current satte * fix: updated `query.run()` signature * fix: added duplicate check on param add and update * fix: added additonal null check for params runjs * feat: resolve runjs params default value without currentState * fix: hide defaultvalue of runjs in events form * fix: minor UX experience in runjs params * fix: set runjs default values to events on creation * style: updated the runjs param UI * style: runjs param form minor ux improvement * fix: close modal on add button click again --------- Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com>
2023-07-20 11:05:39 +00:00
if (_currentState) {
setRealState(_currentState);
} else {
setRealState(currentState);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Parameters support on RunJS (#7033) * feat: resolve passed arguments in runjs * feat: added popup form for runs params * fix: fixed issue with close function of popupover with codehinter * feat: added input for runjs args * style: for runjs args * fix: added support for params in custom components * fix: fixed default query param for runjs * fix: remove debuggers * refactor: removed commented code * fix: removed unused code * style: arguments input style in event manager * refactor: Moved argument list to separate component * refactor: moved runjs components to single folder * fix: minor refactorings * fix: renamed arguments to parameters for compoennts * refactor: reanamed argument to parameter in runjs * refactor: removed commented code * fix: added hasPramSupported flag against runjs queries * Update frontend/src/Editor/Inspector/ActionConfigurationPanels/RunjsParamters.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * Update frontend/src/Editor/QueryManager/QueryEditors/Runjs/ParameterForm.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * fix: prevent duplication of name * fix: fixed issue that blocked query params from returning * fix: remove extra params from runjs * fix: updated reference to current satte * fix: updated `query.run()` signature * fix: added duplicate check on param add and update * fix: added additonal null check for params runjs * feat: resolve runjs params default value without currentState * fix: hide defaultvalue of runjs in events form * fix: minor UX experience in runjs params * fix: set runjs default values to events on creation * style: updated the runjs param UI * style: runjs param form minor ux improvement * fix: close modal on add button click again --------- Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com>
2023-07-20 11:05:39 +00:00
}, [currentState.components, _currentState]);
useEffect(() => {
const handleClickOutside = (event) => {
if (isOpen) {
return;
}
if (wrapperRef.current && isFocused && !wrapperRef.current.contains(event.target) && prevCountRef.current) {
isPreviewFocused.current = false;
setFocused(false);
prevCountRef.current = false;
} else if (isFocused) {
prevCountRef.current = true;
} else if (!isFocused && prevCountRef.current) prevCountRef.current = false;
};
document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, [wrapperRef, isFocused, isPreviewFocused, currentValue, prevCountRef, isOpen]);
function valueChanged(editor, onChange, ignoreBraces) {
if (editor.getValue()?.trim() !== currentValue) {
handleChange(editor, onChange, ignoreBraces, realState, componentName);
setCurrentValue(editor.getValue()?.trim());
}
}
const getPreviewContent = (content, type) => {
try {
switch (type) {
case 'object':
return JSON.stringify(content);
case 'boolean':
return content.toString();
default:
return content;
}
} catch (e) {
return undefined;
}
};
const focusPreview = () => (isPreviewFocused.current = true);
const unFocusPreview = () => (isPreviewFocused.current = false);
const copyToClipboard = (text) => {
navigator.clipboard.writeText(text);
toast.success('Copied to clipboard');
};
const getCustomResolvables = () => {
if (variablesExposedForPreview.hasOwnProperty(component?.id)) {
if (component?.component?.component === 'Table' && fieldMeta?.name) {
return {
...variablesExposedForPreview[component?.id],
cellValue: variablesExposedForPreview[component?.id]?.rowData?.[fieldMeta?.name],
rowData: { ...variablesExposedForPreview[component?.id]?.rowData },
};
}
return variablesExposedForPreview[component.id];
}
return {};
};
const getPreview = () => {
if (!enablePreview) return;
const customResolvables = getCustomResolvables();
const [preview, error] = resolveReferences(currentValue, realState, null, customResolvables, true, true);
const themeCls = darkMode ? 'bg-dark py-1' : 'bg-light py-1';
if (error) {
const err = String(error);
const errorMessage = err.includes('.run()') ? `${err} in ${componentName.split('::')[0]}'s field` : err;
return (
<animated.div className={isOpen ? themeCls : null} style={{ ...slideInStyles, overflow: 'hidden' }}>
<div ref={heightRef} className="dynamic-variable-preview bg-red-lt px-1 py-1">
<div>
<div className="heading my-1">
<span>Error</span>
</div>
{errorMessage}
</div>
</div>
</animated.div>
);
}
let previewType = typeof preview;
let previewContent = preview;
if (hasCircularDependency(preview)) {
previewContent = JSON.stringify(preview, handleCircularStructureToJSON());
previewType = typeof previewContent;
}
const content = getPreviewContent(previewContent, previewType);
return (
<animated.div
className={isOpen ? themeCls : null}
style={{ ...slideInStyles, overflow: 'hidden' }}
onMouseEnter={() => focusPreview()}
onMouseLeave={() => unFocusPreview()}
>
<div ref={heightRef} className="dynamic-variable-preview bg-green-lt px-1 py-1">
<div>
<div className="d-flex my-1">
<div className="flex-grow-1" style={{ fontWeight: 700, textTransform: 'capitalize' }}>
{previewType}
</div>
{isFocused && (
<div className="preview-icons position-relative">
<CodeHinter.PopupIcon callback={() => copyToClipboard(content)} icon="copy" tip="Copy to clipboard" />
</div>
)}
</div>
{content}
</div>
</div>
</animated.div>
);
};
enablePreview = enablePreview ?? true;
const [isOpen, setIsOpen] = React.useState(false);
const handleToggle = () => {
const changeOpen = (newOpen) => {
setIsOpen(newOpen);
if (typeof popOverCallback === 'function') popOverCallback(newOpen);
};
if (!isOpen) {
changeOpen(true);
}
return new Promise((resolve) => {
const element = document.getElementsByClassName('portal-container');
if (element) {
const checkPortalExits = element[0]?.classList.contains(componentName);
if (checkPortalExits === false) {
const parent = element[0].parentNode;
parent.removeChild(element[0]);
}
changeOpen(false);
resolve();
}
}).then(() => {
changeOpen(true);
forceUpdate();
});
};
const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
const defaultClassName =
className === 'query-hinter' || className === 'custom-component' || undefined ? '' : 'code-hinter';
const ElementToRender = AllElements[TypeMapping[type]];
const [forceCodeBox, setForceCodeBox] = useState(fxActive);
const codeShow = (type ?? 'code') === 'code' || forceCodeBox;
cyLabel = paramLabel ? paramLabel.toLowerCase().trim().replace(/\s+/g, '-') : cyLabel;
return (
<div ref={wrapperRef} className={cx({ 'codeShow-active': codeShow })}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
{paramLabel && (
<div className={`mb-2 field ${options.className}`} data-cy={`${cyLabel}-widget-parameter-label`}>
<ToolTip
[Feature]: Added Localisation (#3746) * Added localisation * Closed modal after language selection * updated transaltaion setup * Updated language tooltip * Added fallback language support * Adding english library resource for translation (#3844) * Adding English dictionary for the widget lists in the inspector * added leftSideBar object in en.json and implemented it for leftSidebar icon text * renamed leftSideBar to leftSidebar and added resources for tip in the left side bar * added english translation resources for leftsidebar debugger * added english language resources for the global settings * added english language resources for data sources in left sidebar * added english language resources for the share button and share modal in the editor * added english language resources for release button, manageOrgUsers, appVersionManager * added english language resources for Queries and Please select a widget to inspect in the editor * added english language resources for data source list , data source manager, and query manager(partially) * added english language resources for queryManager, transformation, preview * added english language resources for dark mode toggle in the headers inside homepage * added fallback message for dark mode toggle * added resources for language change in the headers inside homepage * added resources for notification center in the header inside homepage * added resources for organization and manage users components in header inside homepage * added resources in manageGroupPermission * added resources for manageGroupPermissionsResources component * added resources for manageSSO and generalSettings components * added resources for google sso * added resources for github sso * added resources for environment variables in manageSSO * added resources for profile and setting page * added resources for app card and app card menu * added resources for folder section and app list in homepage * added resources for header section in the homepage * added resources for pagination in homepage * added resources for modals in the homepage * added resources for blank page * added resources for login page * added resources for forgot password page * added resources for sign up page * added resources for onBoarding component * added resources for reset password page * deleted duplicate key for readDocumentation * deleted duplicate key for cancel in en.json and added translation for cancel at few places * removing duplicate copy of save key in en.json * added translation for CommentActions.jsx components * deleted duplicate copy of search key in en.json and added resources for create and search queries , select keys * fix typo errors * fixed typo errors * shorten the key for loginAndSignUpAndForgotPassword to loginSignupPage in en.json file and related files * shorten the key noLoginMethodsEnabledForThisWorkspace to noLoginMethodsEnabled * shorten the key pleaseCheckYourEmailForConfirmationLink to emailConfirmLink * shorten the key dontHaveAccountYet to dontHaveAccount * shorten keys from loginSignupPage key in en.json * shorten keys of shareModal nested object in en.json * shorten the key in appVersionManager nested object * shorten the keys for queryManager nested object in the en.json * delete duplicate copy of environmentVar and shorten manageEnvironmentVariables,environmentVariables * shorten keys in the organization nested object * shorten keys in the homePage nested object in en.json file * added inspector and eventManager empty object * added resources to RedirectSSO component * added resources for OAuth2 * added resources for TemplateCard.jsx * added resources for TemplateLibraryModal.jsx * added resources for ConfirmationPage.jsx * added resources for ConfirmationPage component * removed translation in App.jsx file * added resources for Slack.jsx * added resources for GoogleSheets.jsx * added resources for CodeBuilder.jsx * added resources for CommentBody and CommentFooter * added resources for TestConnection component * added resources for AllignButton.jsx * added resources for Openapi and Stripe components * added resources for ErrorBoundary * added resources for Viewer.jsx * Translation for widgets, table Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com> * Commented Language selection * Fixed typos * Updated fr.json file Co-authored-by: Manish Kushare <kushare.manish9@gmail.com>
2022-09-14 08:04:49 +00:00
label={t(`widget.commonProperties.${camelCase(paramLabel)}`, paramLabel)}
meta={fieldMeta}
labelClass={`form-label ${darkMode && 'color-whitish-darkmode'}`}
/>
</div>
)}
<div className={`col-auto ${(type ?? 'code') === 'code' ? 'd-none' : ''} `}>
<div style={{ width: width, display: codeShow ? 'flex' : 'none', marginTop: '-1px' }}>
<FxButton
active={true}
onPress={() => {
setForceCodeBox(false);
onFxPress(false);
}}
dataCy={cyLabel}
/>
</div>
</div>
</div>
<div
className={`row${height === '150px' || height === '300px' ? ' tablr-gutter-x-0' : ''} custom-row`}
style={{ width: width, display: codeShow ? 'flex' : 'none' }}
>
Query manager revamp (#6680) * global store init * Moved query data to new component * Removed unwanted code * Removed data queries prop drilling * Moved query state out of editor * Added unsafe to componentWillReceiveProps * Selected first query when the version is changed * Fixed bug on renaming query * Fixed issue on dark theme * Fixed running query on page load in viewer * Query manager refactor init * Added global data source in store * Disabled devtools on production * Fixed bug on selecting query after deletion * Reset store when editor is loaded * Moved query manager to functional component * Fixed conflict issues * Fixed infinite loop on tooljetDB * Set the store name and updated devtools logic * Fixed issue on displaying draft query from data sources * Updated comments on the store * Fixed bug on changing data source and creating query from data source * Fixed bug on showing unsaved changes popup * Fixed issue on showing confirmation modal everytime without any changes * feat: autosave data query functionality * feat: show publish button only when the status in draft state * Fixed issues on query renaming * feat: removed discard popup for data query create/edit widget * stye: reduced autosave api call timeout and added draft tag * feat: added minor style changes * feat: fixed issues with restapi plugin, removed unused api calls * fix: fixed issue that breaks restapi creation * fix: reload selected query details after update query * perf: reduced debounce time for data query update apis * feat: removed full reloading of query list on query renaming * feat: duplicate data query feature added * Fixed issue on creating restAPI query * fix: fixed issue in transforming response from update queyr api * fix: refresh selected query details when the selected query is updated * fix: rename query on click enter * fix: full refresh of query list on update * fix: style changes * fix: subscribing to state to autsave * feat: updated the query manager styles to new design * feat: revamped the querypane header buttons * fix: fixed the padding for query panel maximize button * feat: updated search box style * refactor: moved function to render data source icon to its own component * fix: fixed querymanager widget breaking issue * merged with feat/query-manager-autosave * refactor: removed unused consoles * refactor: removed unused consoles * refactor: removed unused consoles * fix: removed commented code * fix: removed unused code * refactor: removed unused comments * fix: show change datasource select only if valid ds available * Update frontend/src/Editor/Inspector/EventManager.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * Update frontend/src/Editor/QueryManager/Components/DataSourceLister.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * Update frontend/src/Editor/QueryManager/Components/DataSourceLister.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * Update frontend/src/Editor/QueryManager/Components/QueryManagerBody.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * feat: modify behaviour of search icon in query panel * fix: fixed theme color mismatch in query manager * refactor: remove dead code * refactor: updated theme for data source listner * fix: theming in filter and sort popup * refactor: remove unused variables * fix: removed draftQuery logic from query manager * refactor: removed unused varibales * Update frontend/src/Editor/QueryManager/QueryEditors/Restapi/TabParams.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * Update frontend/src/Editor/QueryPanel/QueryCard.jsx Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> * feat: diable preview for draft queries * fix: added tooltip for query panel button * fix: fixed issues in saving query manager events * fix: moved query save subscriber to QuerPanel component * feat: converted query run api to save and run * fix: made varibale an optional param in updateDataQuery dto * refactor: cleanup update dataquery status api response * refactor: moved query status to constants file * feat: prompt for queryname when creating new query * fix: store new queryname in state on create query pageload * fix: fixed alignment of Tooljet db component form * fix: correct translation and format file * refactor: removed consoles * merge: merge appbuilder-1.2 * style: updated rename input/button UX * style: revamped dataquery create widget styles * style: revamped data source selector styles * fix: removed code added for debugging * style: updated data query filter design * style: Add prop to control visibility of clear button in search box * style: implement new style for query filter * merge appbuilder-1.2 to feat/query-manager-sort-filter * refactor: remove unintended file change * fix: set default value for method in respapi * style: updated copilot info popup style * style: updated quer panel header icons * style: updated button styles * style: fixed query manager button styles * style: smoothened query preview modal view * fix: correct import for some funs * fix: fixed minor UX bugs * style: fixed styling of REST api GDS * style: fixed styleing of sort and filter popup * style: improved data queries sort filter UI/UX * fix: remove click listner when overlay is closed * fix: moved component declaration out of parent component * fix: set selected datasource for default sources * fix: filter DS based on saerch in create dropdown * fix: restrict draft query running to preview mode * fix: query renamed on input change in create screen * fix: set name to state as soon as user renames query * fix: make query notification message consistent * style: correct s3 bucket plugin layout config * fix: fixed issues with cloning of Static DS queries * fix: made change so that newly created query is reflected immediatly * style: updated spacing for query manager components * fix: hide rename input when no query selected * fix: check bothe selected query and DS before rendering query manager * fix: set isSaving to true only for api calls in querymanager * fix: added success message form in qm * fix: filter out draft queries from viewer on running * fix: fixed inconsistent gutter for runpy and runjs editors * fix: reload dataqueris on LDS deletion * fix: redesigned filter/sort popup * fix: fixed issue that resets filter on search * fix: fixed query manager breaking on plugin select * fix: diable json preview for text output * fix: reset to filter and sort main menu on close filter popup * refactor: rename varibales * stye: redesigned query create panel * feat: revert data query status column from backend * style: redesign query picker section * refactor: removed dead code * style: querypanel expand/collapse btn style * style: add query select and query filter popup style redesign * style: updated filter popup style * feat: removed draft query checks everywhere * style: empty dataqueries style changed * style: updated query selector popup and rest options styles * style: removed 100% height to query option remove btn * feat: added the query runnable status check * style: updated query manager footer style * feat: changed DS filter from kind to DS ID * style: minor ui tweaks in filter popup * style: disable DS filter if no DQs created * style: minor ui change * fix: rerender filter popup post DS api call. fixed rest api copy feature * fix: add local DS to filter popup * refactor: removed dead code/comments * add new row is crashing when no data is fed to table (#7102) * fix: fixed condition that blocked GDS run on load * fix: revert name back to og name if update fails in rename query * feat: added tooltip for show query btn * fix: added click interaction for pill btn as well * fix: minor UI tweaks to make UX better * style: fixed the styling of filter popup * style: minor UI tweaks in query filter popup * fix: fixed minor css issue in ds picker * style: wrap overflowing text in queryname * fix: update updated_at after query update api call success * fix: update remove the caller query from event query dropdown * style: minor ui spacing tweaks * fix: fix issue that cuased app crash when tjdb opened * fix: fixed update row styles * fix: fixed info popup dark theme bg * fix: fixed headers styling according to general QM styles * style: fixed stripe QM UI * fix: added tooltip for quernames * feat: add tooltip for select ds options * added consoles to debug debugger issue * fix: fixed :active style of ds select dropdown in QM * fix: fixed DS kind name in data source selector in QM * fix: fixed border color mismatch for ds select dd * fix: change tooltip msg for maximize/minize QM * Fix automation for query manager revamp. (#7223) * Add data-cy to support modified specs * Fix event handler * Fix RunPy and RunJS specs * Fix event handler label * Fix basic components spec * Fix basic components failure * Fix tabel spec failure. * Fix runjs and runpy actions * Fix table column options * Add data-cy * version: version updated to 2.13.0 * Version bump --------- Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com> Co-authored-by: Kavin Venkatachalam <50441969+kavinvenkatachalam@users.noreply.github.com> Co-authored-by: Manish Kushare <37823141+manishkushare@users.noreply.github.com> Co-authored-by: Midhun Kumar E <midhun752@gmail.com>
2023-08-09 12:31:48 +00:00
<div className={`col code-hinter-col`}>
<div
className="code-hinter-wrapper position-relative"
style={{ width: '100%', backgroundColor: darkMode && '#272822' }}
>
<div
className={`${defaultClassName} ${className || 'codehinter-default-input'}`}
key={componentName}
style={{
height: height || 'auto',
minHeight,
maxHeight: '320px',
overflow: 'auto',
fontSize: ' .875rem',
}}
data-cy={`${cyLabel}-input-field`}
>
{usePortalEditor && (
<CodeHinter.PopupIcon
callback={handleToggle}
icon="portal-open"
tip="Pop out code editor into a new window"
transformation={componentName === 'transformation'}
/>
)}
<CodeHinter.Portal
isCopilotEnabled={isCopilotEnabled}
isOpen={isOpen}
callback={setIsOpen}
componentName={componentName}
key={componentName}
customComponent={getPreview}
forceUpdate={forceUpdate}
optionalProps={{ styles: { height: 300 }, cls: className }}
darkMode={darkMode}
selectors={{ className: 'preview-block-portal' }}
2022-06-08 06:48:47 +00:00
dragResizePortal={true}
callgpt={callgpt}
>
<CodeMirror
value={typeof initialValue === 'string' ? initialValue : ''}
realState={realState}
scrollbarStyle={null}
height={'100%'}
onFocus={() => setFocused(true)}
onBlur={(editor, e) => {
e.stopPropagation();
const value = editor.getValue()?.trimEnd();
onChange(value);
if (!isPreviewFocused.current) {
setFocused(false);
}
}}
onChange={(editor) => valueChanged(editor, onChange, ignoreBraces)}
onBeforeChange={(editor, change) => onBeforeChange(editor, change, ignoreBraces)}
options={options}
viewportMargin={Infinity}
/>
</CodeHinter.Portal>
</div>
{enablePreview && !isOpen && getPreview()}
</div>
</div>
</div>
{!codeShow && (
<div style={{ display: !codeShow ? 'block' : 'none' }}>
<ElementToRender
value={resolveReferences(initialValue, realState)}
onChange={(value) => {
if (value !== currentValue) {
onChange(value);
setCurrentValue(value);
}
}}
paramName={paramName}
paramLabel={paramLabel}
forceCodeBox={() => {
setForceCodeBox(true);
onFxPress(true);
}}
meta={fieldMeta}
cyLabel={cyLabel}
/>
</div>
)}
</div>
2021-05-03 14:27:32 +00:00
);
}
const PopupIcon = ({ callback, icon, tip, transformation = false }) => {
const size = transformation ? 20 : 12;
return (
<div className="d-flex justify-content-end w-100 position-absolute" style={{ top: 0 }}>
<OverlayTrigger
trigger={['hover', 'focus']}
placement="top"
delay={{ show: 800, hide: 100 }}
overlay={<Tooltip id="button-tooltip">{tip}</Tooltip>}
>
<img
className="svg-icon m-2 popup-btn"
src={`assets/images/icons/${icon}.svg`}
width={size}
height={size}
onClick={(e) => {
e.stopPropagation();
callback();
}}
/>
</OverlayTrigger>
</div>
);
};
const Portal = ({ children, ...restProps }) => {
const renderPortal = usePortal({ children, ...restProps });
return <React.Fragment>{renderPortal}</React.Fragment>;
};
CodeHinter.PopupIcon = PopupIcon;
CodeHinter.Portal = Portal;