@@ -3,7 +3,6 @@ import { EditorContext } from "../../editorState";
33import { BottomTabs } from "pages/editor/bottom/BottomTabs" ;
44import { useSelector } from "react-redux" ;
55import { getDataSource , getDataSourceTypes } from "redux/selectors/datasourceSelectors" ;
6- import { InputStatus } from "antd/es/_util/statusUtils" ;
76import {
87 changeValueAction ,
98 deferAction ,
@@ -27,7 +26,7 @@ import { PreparedStatementConfig } from "../../../api/datasourceApi";
2726import { BottomResTypeEnum } from "types/bottomRes" ;
2827import { PageType } from "../../../constants/pageConstants" ;
2928import { trans } from "i18n" ;
30- import { manualTriggerResource } from "@openblocks-ee/constants/queryConstants" ;
29+ import { manualTriggerResource , ResourceType } from "@openblocks-ee/constants/queryConstants" ;
3130import {
3231 OPENBLOCKS_API_ID ,
3332 QUICK_GRAPHQL_ID ,
@@ -41,7 +40,6 @@ export function QueryPropertyView(props: { comp: InstanceType<typeof QueryComp>
4140
4241 const editorState = useContext ( EditorContext ) ;
4342 const datasource = useSelector ( getDataSource ) ;
44- const datasourceTypes = useSelector ( getDataSourceTypes ) ;
4543
4644 const children = comp . children ;
4745 const dispatch = comp . dispatch ;
@@ -50,24 +48,7 @@ export function QueryPropertyView(props: { comp: InstanceType<typeof QueryComp>
5048 const datasourceConfig = datasource . find ( ( d ) => d . datasource . id === datasourceId ) ?. datasource
5149 . datasourceConfig ;
5250
53- const datasourceStatus : InputStatus = useMemo ( ( ) => {
54- if (
55- datasourceType === "js" ||
56- datasourceType === "libraryQuery" ||
57- datasourceId === QUICK_REST_API_ID ||
58- datasourceId === QUICK_GRAPHQL_ID ||
59- datasourceId === OPENBLOCKS_API_ID
60- ) {
61- return "" ;
62- }
63- if (
64- datasource . find ( ( info ) => info . datasource . id === datasourceId ) &&
65- datasourceTypes . find ( ( type ) => type . id === datasourceType )
66- ) {
67- return "" ;
68- }
69- return "error" ;
70- } , [ datasource , datasourceTypes , datasourceId , datasourceType ] ) ;
51+ const datasourceStatus = useDatasourceStatus ( datasourceId , datasourceType ) ;
7152
7253 return (
7354 < BottomTabs
@@ -77,7 +58,7 @@ export function QueryPropertyView(props: { comp: InstanceType<typeof QueryComp>
7758 {
7859 key : "general" ,
7960 title : trans ( "query.generalTab" ) ,
80- children : < QueryGeneralPropertyView comp = { comp } datasourceStatus = { datasourceStatus } /> ,
61+ children : < QueryGeneralPropertyView comp = { comp } /> ,
8162 } ,
8263 {
8364 key : "notification" ,
@@ -160,10 +141,9 @@ export function QueryPropertyView(props: { comp: InstanceType<typeof QueryComp>
160141
161142export const QueryGeneralPropertyView = ( props : {
162143 comp : InstanceType < typeof QueryComp > ;
163- datasourceStatus ?: InputStatus ;
164144 placement ?: PageType ;
165145} ) => {
166- const { datasourceStatus = "" , comp, placement = "editor" } = props ;
146+ const { comp, placement = "editor" } = props ;
167147 const editorState = useContext ( EditorContext ) ;
168148 const datasource = useSelector ( getDataSource ) ;
169149
@@ -174,6 +154,8 @@ export const QueryGeneralPropertyView = (props: {
174154 const datasourceConfig = datasource . find ( ( d ) => d . datasource . id === datasourceId ) ?. datasource
175155 . datasourceConfig ;
176156
157+ const datasourceStatus = useDatasourceStatus ( datasourceId , datasourceType ) ;
158+
177159 // transfer old quick REST API datasource to new
178160 const oldQuickRestId = useMemo (
179161 ( ) =>
@@ -361,3 +343,27 @@ export const QueryGeneralPropertyView = (props: {
361343 </ QueryPropertyViewWrapper >
362344 ) ;
363345} ;
346+
347+ function useDatasourceStatus ( datasourceId : string , datasourceType : ResourceType ) {
348+ const datasource = useSelector ( getDataSource ) ;
349+ const datasourceTypes = useSelector ( getDataSourceTypes ) ;
350+
351+ return useMemo ( ( ) => {
352+ if (
353+ datasourceType === "js" ||
354+ datasourceType === "libraryQuery" ||
355+ datasourceId === QUICK_REST_API_ID ||
356+ datasourceId === QUICK_GRAPHQL_ID ||
357+ datasourceId === OPENBLOCKS_API_ID
358+ ) {
359+ return "" ;
360+ }
361+ if (
362+ datasource . find ( ( info ) => info . datasource . id === datasourceId ) &&
363+ datasourceTypes . find ( ( type ) => type . id === datasourceType )
364+ ) {
365+ return "" ;
366+ }
367+ return "error" ;
368+ } , [ datasource , datasourceTypes , datasourceId , datasourceType ] ) ;
369+ }
0 commit comments