ToolJet/frontend/src/AppBuilder/QueryManager/QueryManager.jsx

86 lines
3.3 KiB
React
Raw Normal View History

import React, { useEffect, useState } from 'react';
import cx from 'classnames';
import { QueryManagerHeader } from './Components/QueryManagerHeader';
2025-02-25 06:52:50 +00:00
import QueryManagerBody from './Components/QueryManagerBody';
import { defaultSources } from './constants';
import { CodeHinterContext } from '@/AppBuilder/CodeBuilder/CodeHinterContext';
import { resolveReferences } from '@/_helpers/utils';
import useStore from '@/AppBuilder/_stores/store';
const QueryManager = ({ mode, darkMode }) => {
// TODO to be moved into queryPanelStore and reimplemented
const runQuery = useStore((state) => state.queryPanel.runQuery);
const loadingDataSources = useStore((state) => state.loadingDataSources);
const dataSources = useStore((state) => state.dataSources);
const sampleDataSource = useStore((state) => state.sampleDataSource);
const globalDataSources = useStore((state) => state.globalDataSources);
const queryToBeRun = useStore((state) => state.queryPanel.queryToBeRun);
const selectedQuery = useStore((state) => state.queryPanel.selectedQuery);
const setSelectedDataSource = useStore((state) => state.queryPanel.setSelectedDataSource);
const setQueryToBeRun = useStore((state) => state.queryPanel.setQueryToBeRun);
const [activeTab, setActiveTab] = useState(1);
useEffect(() => {
Enhance TypeScript support in frontend configuration (#15576) * test: verify pre-commit hook * fix: clean up code formatting and improve readability across multiple components * chore: update subproject commit reference in frontend/ee * chore: update eslint to version 9.26.0 and remove unused dependencies from package.json fix: update submodule reference in server/ee * chore: refactor ESLint configuration and add quiet linting script; update components to disable specific ESLint rules * chore: add GitHub Copilot review instructions for App Builder team Covers backward compatibility rules, styling conventions, state management, resolution system, widget definitions, and common review flags. * chore: add review instructions for App Builder, Data Migrations, Server Widget Config, Widget Components, and Widget Config * Enhance TypeScript support in frontend configuration - Added TypeScript parser and linting rules to ESLint configuration. - Updated Babel configuration to include TypeScript preset. - Modified package.json and package-lock.json to include TypeScript and related dependencies. - Introduced tsconfig.json for TypeScript compiler options. - Updated Webpack configuration to support .ts and .tsx file extensions. - Adjusted linting and formatting scripts to include TypeScript files. * chore: update TypeScript ESLint packages and subproject commits --------- Co-authored-by: kavinvenkatachalam <kavin.saratha@gmail.com> Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com>
2026-03-19 07:11:32 +00:00
if (
selectedQuery?.kind == 'runjs' ||
selectedQuery?.kind == 'runpy' ||
selectedQuery?.kind == 'restapi' ||
selectedQuery?.kind == 'postgresql'
) {
setActiveTab(1);
}
}, [selectedQuery?.id]);
2025-09-19 04:31:02 +00:00
useEffect(() => {
if (queryToBeRun !== null) {
runQuery(queryToBeRun.id, queryToBeRun.name);
setQueryToBeRun(null);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [queryToBeRun]);
useEffect(() => {
if (selectedQuery) {
Post modularization fixes (#12420) * [white-labelling] Logo related pending issues (#12243) * Working on refactoring and fixing white-labelling for modularisation * Working on fixes * Fixed: app builder logo issue * Refactored default state behaviour * Removed console logs * Added workspace slug * Adding single image changes from ee lts (#12272) (#12285) Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com> * Moving Vulnerability CI from EE (#12288) * CE modularisation bugs (#12278) * Working on refactoring and fixing white-labelling for modularisation * Working on fixes * Fixed: app builder logo issue * Refactored default state behaviour * Removed console logs * Added workspace slug * Fixed: Able to update group name with space * Adding single image changes from ee lts (#12272) * Fixed: Able to add a user 2 times to the group * Fixed: Builder isn't able to datasiurces * Fixed: updated the builder check * Refactored the changes --------- Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com> * Add data-cy for components in modularisation branch (#12296) * [modularisation-bugs] Fixing rest of the priority bugs (#12301) * Fixed: custom logout url issue * Fixed: fixed all workspace redirection issue * Fixed: made the datsource access same for ce and ee-basicplan builders * Fixed: sample db connection issue * Fixed: sample database query issue * Fixed: page isn't showing the organization list for user whose current organization is archived * Fixed: granular permission datasource page * remove license check for oidc login --------- Co-authored-by: Muhsin Shah C P <muhsinshah21@gmail.com> Co-authored-by: Adish M <44204658+adishM98@users.noreply.github.com> Co-authored-by: Ajith KV <ajith.jaban@gmail.com> Co-authored-by: Anantshree Chandola <anantshreechandola23@gmail.com>
2025-04-01 10:46:01 +00:00
const selectedDS = [...dataSources, ...globalDataSources, !!sampleDataSource && sampleDataSource]
.filter(Boolean)
.find((datasource) => datasource.id === selectedQuery?.data_source_id);
//TODO: currently type is not taken into account. May create issues in importing REST apis. to be revamped when import app is revamped
if (
selectedQuery?.kind in defaultSources &&
(!selectedQuery?.data_source_id || ['runjs', 'runpy'].includes(selectedQuery?.data_source_id) || !selectedDS)
) {
return setSelectedDataSource(defaultSources[selectedQuery?.kind]);
}
setSelectedDataSource(selectedDS || null);
} else if (selectedQuery === null) {
setSelectedDataSource(null);
}
}, [selectedQuery, dataSources, globalDataSources, setSelectedDataSource, mode]);
return (
<div
className={cx(`query-manager ${darkMode ? 'theme-dark' : ''}`, {
'd-none': loadingDataSources,
})}
>
2025-02-25 06:52:50 +00:00
<QueryManagerHeader darkMode={darkMode} setActiveTab={setActiveTab} activeTab={activeTab} />
<CodeHinterContext.Provider
value={{
parameters: selectedQuery?.options?.parameters?.reduce(
(parameters, parameter) => ({
...parameters,
[parameter.name]: resolveReferences(parameter.defaultValue, undefined),
}),
{}
),
}}
>
2025-02-25 06:52:50 +00:00
<QueryManagerBody darkMode={darkMode} activeTab={activeTab} />
</CodeHinterContext.Provider>
</div>
);
};
export default QueryManager;