@@ -3,7 +3,6 @@ import { EditorContext } from "../../editorState";
3
3
import { BottomTabs } from "pages/editor/bottom/BottomTabs" ;
4
4
import { useSelector } from "react-redux" ;
5
5
import { getDataSource , getDataSourceTypes } from "redux/selectors/datasourceSelectors" ;
6
- import { InputStatus } from "antd/es/_util/statusUtils" ;
7
6
import {
8
7
changeValueAction ,
9
8
deferAction ,
@@ -27,7 +26,7 @@ import { PreparedStatementConfig } from "../../../api/datasourceApi";
27
26
import { BottomResTypeEnum } from "types/bottomRes" ;
28
27
import { PageType } from "../../../constants/pageConstants" ;
29
28
import { trans } from "i18n" ;
30
- import { manualTriggerResource } from "@openblocks-ee/constants/queryConstants" ;
29
+ import { manualTriggerResource , ResourceType } from "@openblocks-ee/constants/queryConstants" ;
31
30
import {
32
31
OPENBLOCKS_API_ID ,
33
32
QUICK_GRAPHQL_ID ,
@@ -41,7 +40,6 @@ export function QueryPropertyView(props: { comp: InstanceType<typeof QueryComp>
41
40
42
41
const editorState = useContext ( EditorContext ) ;
43
42
const datasource = useSelector ( getDataSource ) ;
44
- const datasourceTypes = useSelector ( getDataSourceTypes ) ;
45
43
46
44
const children = comp . children ;
47
45
const dispatch = comp . dispatch ;
@@ -50,24 +48,7 @@ export function QueryPropertyView(props: { comp: InstanceType<typeof QueryComp>
50
48
const datasourceConfig = datasource . find ( ( d ) => d . datasource . id === datasourceId ) ?. datasource
51
49
. datasourceConfig ;
52
50
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 ) ;
71
52
72
53
return (
73
54
< BottomTabs
@@ -77,7 +58,7 @@ export function QueryPropertyView(props: { comp: InstanceType<typeof QueryComp>
77
58
{
78
59
key : "general" ,
79
60
title : trans ( "query.generalTab" ) ,
80
- children : < QueryGeneralPropertyView comp = { comp } datasourceStatus = { datasourceStatus } /> ,
61
+ children : < QueryGeneralPropertyView comp = { comp } /> ,
81
62
} ,
82
63
{
83
64
key : "notification" ,
@@ -160,10 +141,9 @@ export function QueryPropertyView(props: { comp: InstanceType<typeof QueryComp>
160
141
161
142
export const QueryGeneralPropertyView = ( props : {
162
143
comp : InstanceType < typeof QueryComp > ;
163
- datasourceStatus ?: InputStatus ;
164
144
placement ?: PageType ;
165
145
} ) => {
166
- const { datasourceStatus = "" , comp, placement = "editor" } = props ;
146
+ const { comp, placement = "editor" } = props ;
167
147
const editorState = useContext ( EditorContext ) ;
168
148
const datasource = useSelector ( getDataSource ) ;
169
149
@@ -174,6 +154,8 @@ export const QueryGeneralPropertyView = (props: {
174
154
const datasourceConfig = datasource . find ( ( d ) => d . datasource . id === datasourceId ) ?. datasource
175
155
. datasourceConfig ;
176
156
157
+ const datasourceStatus = useDatasourceStatus ( datasourceId , datasourceType ) ;
158
+
177
159
// transfer old quick REST API datasource to new
178
160
const oldQuickRestId = useMemo (
179
161
( ) =>
@@ -361,3 +343,27 @@ export const QueryGeneralPropertyView = (props: {
361
343
</ QueryPropertyViewWrapper >
362
344
) ;
363
345
} ;
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