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

Commit 52064f3

Browse files
committed
Update saved correlations fix
1 parent 55eb994 commit 52064f3

File tree

2 files changed

+45
-20
lines changed

2 files changed

+45
-20
lines changed

src/hooks/useCorrelations.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ export const useCorrelationsQuery = () => {
7777
const { mutate: saveCorrelationMutation, isLoading: isCorrelationSaving } = useMutation(
7878
(data: { correlationData: any; onSuccess?: () => void }) => saveCorrelation(data.correlationData),
7979
{
80-
onSuccess: (_data, variables) => {
80+
onSuccess: (data, variables) => {
8181
variables.onSuccess && variables.onSuccess();
82+
//set activeCorrelation and id
83+
setCorrelatedStore((store) => setCorrelationId(store, data.data.id));
8284
fetchCorrelations();
8385
notifySuccess({ message: 'Correlation saved successfully' });
8486
},

src/pages/Correlation/components/SaveCorrelationModal.tsx

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ interface FormObjectType extends Omit<Correlation, 'correlation_id' | 'version'>
2222
}
2323

2424
const SaveCorrelationModal = () => {
25-
const [{ isSaveCorrelationModalOpen, selectedFields, fields, correlationCondition }, setCorrelationData] =
26-
useCorrelationStore((store) => store);
25+
const [
26+
{ isSaveCorrelationModalOpen, selectedFields, fields, correlationCondition, activeCorrelation },
27+
setCorrelationData,
28+
] = useCorrelationStore((store) => store);
2729

2830
const [formObject, setFormObject] = useState<FormObjectType | null>(null);
2931
const [timeRange] = useAppStore((store) => store.timeRange);
@@ -38,23 +40,44 @@ const SaveCorrelationModal = () => {
3840
useEffect(() => {
3941
const timeRangeOptions = makeTimeRangeOptions({ selected: null, current: timeRange });
4042
const selectedTimeRangeOption = getDefaultTimeRangeOption(timeRangeOptions);
41-
setFormObject({
42-
version: 'v1',
43-
title: '',
44-
isNew: true,
45-
isError: false,
46-
timeRangeOptions,
47-
selectedTimeRangeOption,
48-
tableConfigs: [],
49-
joinConfig: {
50-
joinConditions: [],
51-
},
52-
id: '',
53-
filter: null,
54-
startTime: '',
55-
endTime: '',
56-
});
57-
}, [timeRange]);
43+
44+
if (activeCorrelation !== null) {
45+
//Modify this after BE changes
46+
setFormObject({
47+
version: 'v1',
48+
title: activeCorrelation.title,
49+
isNew: false,
50+
isError: false,
51+
timeRangeOptions,
52+
selectedTimeRangeOption,
53+
tableConfigs: [],
54+
joinConfig: {
55+
joinConditions: [],
56+
},
57+
id: '',
58+
filter: null,
59+
startTime: '',
60+
endTime: '',
61+
});
62+
} else {
63+
setFormObject({
64+
version: 'v1',
65+
title: '',
66+
isNew: true,
67+
isError: false,
68+
timeRangeOptions,
69+
selectedTimeRangeOption,
70+
tableConfigs: [],
71+
joinConfig: {
72+
joinConditions: [],
73+
},
74+
id: '',
75+
filter: null,
76+
startTime: '',
77+
endTime: '',
78+
});
79+
}
80+
}, [timeRange, activeCorrelation]);
5881

5982
const closeModal = useCallback(() => {
6083
setCorrelationData((store) => toggleSaveCorrelationModal(store, false));

0 commit comments

Comments
 (0)