Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit ed84f93

Browse files
committed
fix: Filter join dropdown based on seleciton
1 parent 0289aba commit ed84f93

File tree

1 file changed

+40
-22
lines changed

1 file changed

+40
-22
lines changed

src/pages/Correlation/index.tsx

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useEffect, useState } from 'react';
22
import { useDocumentTitle } from '@mantine/hooks';
3-
import { Stack, Box, TextInput, Text, Select, Button, Center, Stepper, Badge, SelectProps, Group } from '@mantine/core';
3+
import { Stack, Box, TextInput, Text, Select, Button, Center, Stepper, Badge, SelectProps } from '@mantine/core';
44
import { IconTrashX, IconX } from '@tabler/icons-react';
55
import {
66
PRIMARY_HEADER_HEIGHT,
@@ -90,8 +90,20 @@ const Correlation = () => {
9090

9191
// Local State
9292
const [searchText, setSearchText] = useState('');
93-
const [select1Value, setSelect1Value] = useState<string | null>(null);
94-
const [select2Value, setSelect2Value] = useState<string | null>(null);
93+
const [select1Value, setSelect1Value] = useState<{
94+
value: string | null;
95+
dataType?: '' | 'number' | 'boolean' | 'text' | 'timestamp' | 'list' | null;
96+
}>({
97+
value: null,
98+
dataType: '',
99+
});
100+
const [select2Value, setSelect2Value] = useState<{
101+
value: string | null;
102+
dataType?: '' | 'number' | 'boolean' | 'text' | 'timestamp' | 'list' | null;
103+
}>({
104+
value: null,
105+
dataType: '',
106+
});
95107
const [isCorrelationEnabled, setIsCorrelationEnabled] = useState<boolean>(false);
96108
const [isLoading, setIsLoading] = useState<boolean>(true);
97109

@@ -129,10 +141,10 @@ const Correlation = () => {
129141
);
130142

131143
if (sortedJoinConditions[0]) {
132-
setSelect1Value(sortedJoinConditions[0].field);
144+
setSelect1Value({ value: sortedJoinConditions[0].field });
133145
}
134146
if (sortedJoinConditions[1]) {
135-
setSelect2Value(sortedJoinConditions[1].field);
147+
setSelect2Value({ value: sortedJoinConditions[1].field });
136148
}
137149

138150
activeCorrelation?.tableConfigs.flatMap((config) =>
@@ -154,8 +166,8 @@ const Correlation = () => {
154166
type: 'custom',
155167
}),
156168
);
157-
setSelect1Value(null);
158-
setSelect2Value(null);
169+
setSelect1Value({ value: null, dataType: '' });
170+
setSelect2Value({ value: null, dataType: '' });
159171
setCorrelationData((store) => setCorrelationCondition(store, ''));
160172
setCorrelationData((store) => setSelectedFields(store, '', '', true));
161173
setCorrelationData((store) => setActiveCorrelation(store, activeCorrelation));
@@ -193,8 +205,8 @@ const Correlation = () => {
193205
};
194206

195207
const updateCorrelationCondition = () => {
196-
if (select1Value && select2Value) {
197-
const condition = `"${streamNames[0]}".${select1Value} = "${streamNames[1]}".${select2Value}`;
208+
if (select1Value.value && select2Value.value) {
209+
const condition = `"${streamNames[0]}".${select1Value.value} = "${streamNames[1]}".${select2Value.value}`;
198210
setAppStore((store) => changeStream(store, 'correlatedStream'));
199211
setCorrelationData((store) => setCorrelationCondition(store, condition));
200212
}
@@ -209,15 +221,18 @@ const Correlation = () => {
209221

210222
const handleFieldChange = (fieldValue: string | null, isFirstField: boolean) => {
211223
if (isFirstField) {
212-
setSelect1Value(fieldValue);
224+
const fieldType = fieldValue && fields[streamNames[0]]?.fieldTypeMap[fieldValue];
225+
console.log(fieldType);
226+
227+
setSelect1Value({ value: fieldValue, dataType: fieldType });
213228
} else {
214-
setSelect2Value(fieldValue);
229+
setSelect2Value({ value: fieldValue });
215230
}
216231
};
217232

218233
const clearQuery = () => {
219-
setSelect1Value(null);
220-
setSelect2Value(null);
234+
setSelect1Value({ value: null, dataType: '' });
235+
setSelect2Value({ value: null, dataType: '' });
221236
setCorrelationData((store) => setCorrelationCondition(store, ''));
222237
setCorrelationData((store) => setSelectedFields(store, '', '', true));
223238
setCorrelationData((store) => setIsCorrelatedFlag(store, false));
@@ -315,8 +330,8 @@ const Correlation = () => {
315330
onClick={() => {
316331
setAppStore((store) => changeStream(store, ''));
317332
setCorrelationData((store) => setIsCorrelatedFlag(store, false));
318-
setSelect1Value(null);
319-
setSelect2Value(null);
333+
setSelect1Value({ value: null, dataType: '' });
334+
setSelect2Value({ value: null, dataType: '' });
320335
setCorrelationData((store) => deleteStreamData(store, stream));
321336
}}
322337
/>
@@ -460,7 +475,7 @@ const Correlation = () => {
460475
)
461476
: []
462477
}
463-
value={select1Value}
478+
value={select1Value.value}
464479
onChange={(value) => handleFieldChange(value, true)}
465480
renderOption={renderJoinOneOptions}
466481
/>
@@ -476,12 +491,15 @@ const Correlation = () => {
476491
radius="md"
477492
data={
478493
streamNames.length > 1
479-
? Object.keys(fields[streamNames[1]].fieldTypeMap).filter(
480-
(key) => fields[streamNames[1]].fieldTypeMap[key] !== 'list',
481-
)
494+
? Object.keys(fields[streamNames[1]].fieldTypeMap).filter((key) => {
495+
const dataType = fields[streamNames[1]].fieldTypeMap[key];
496+
return (
497+
dataType !== 'list' && (!select1Value.dataType || select1Value.dataType === dataType)
498+
);
499+
})
482500
: []
483501
}
484-
value={select2Value}
502+
value={select2Value.value}
485503
onChange={(value) => handleFieldChange(value, false)}
486504
renderOption={renderJoinTwoOptions}
487505
/>
@@ -504,8 +522,8 @@ const Correlation = () => {
504522
size={12}
505523
color="#535BED"
506524
onClick={() => {
507-
setSelect1Value(null);
508-
setSelect2Value(null);
525+
setSelect1Value({ value: null, dataType: '' });
526+
setSelect2Value({ value: null, dataType: '' });
509527
setCorrelationData((store) => setCorrelationCondition(store, ''));
510528
setCorrelationData((store) => setIsCorrelatedFlag(store, false));
511529
setCorrelationData((store) => setCorrelationId(store, ''));

0 commit comments

Comments
 (0)