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

Commit e0da498

Browse files
committed
Removed the getCorrelationById redundant call
1 parent ae476dd commit e0da498

File tree

5 files changed

+34
-65
lines changed

5 files changed

+34
-65
lines changed

src/components/Navbar/components/CorrelationIcon.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ export const CorrelationIcon = forwardRef<
1212
d="M13.3335 17.3335L14.6669 18.6669C15.0205 19.0205 15.5001 19.2192 16.0002 19.2192C16.5003 19.2192 16.9799 19.0205 17.3335 18.6669L22.6669 13.3335C23.0205 12.9799 23.2192 12.5003 23.2192 12.0002C23.2192 11.5001 23.0205 11.0205 22.6669 10.6669L17.3335 5.33353C16.9799 4.97991 16.5003 4.78125 16.0002 4.78125C15.5001 4.78125 15.0205 4.97991 14.6669 5.33353L9.33353 10.6669C8.97991 11.0205 8.78125 11.5001 8.78125 12.0002C8.78125 12.5003 8.97991 12.9799 9.33353 13.3335L10.6669 14.6669"
1313
stroke={stroke}
1414
strokeWidth={strokeWidth}
15-
stroke-linecap="round"
16-
stroke-linejoin="round"
15+
strokeLinecap="round"
16+
strokeLinejoin="round"
1717
/>
1818
<path
1919
d="M10.6669 6.66687L9.33353 5.33353C8.97991 4.97991 8.5003 4.78125 8.0002 4.78125C7.5001 4.78125 7.02049 4.97991 6.66687 5.33353L1.33353 10.6669C0.979912 11.0205 0.78125 11.5001 0.78125 12.0002C0.78125 12.5003 0.979912 12.9799 1.33353 13.3335L6.66687 18.6669C7.02049 19.0205 7.5001 19.2192 8.0002 19.2192C8.5003 19.2192 8.97991 19.0205 9.33353 18.6669L14.6669 13.3335C15.0205 12.9799 15.2192 12.5003 15.2192 12.0002C15.2192 11.5001 15.0205 11.0205 14.6669 10.6669L13.3335 9.33353"
2020
stroke={stroke}
2121
strokeWidth={strokeWidth}
22-
stroke-linecap="round"
23-
stroke-linejoin="round"
22+
strokeLinecap="round"
23+
strokeLinejoin="round"
2424
/>
2525
<rect x="14" y="14" width="9.61539" height="10" rx="4.80769" fill="#F8F9FA" />
2626
<path
2727
d="M17.0771 22.4617V17.077C17.0771 16.669 17.2392 16.2777 17.5278 15.9892C17.8163 15.7007 18.2076 15.5386 18.6156 15.5386H18.8079C19.1649 15.5386 19.5073 15.6804 19.7598 15.9329C20.0122 16.1853 20.1541 16.5277 20.1541 16.8847C20.1541 17.2418 20.0122 17.5841 19.7598 17.8366C19.5073 18.0891 19.1649 18.2309 18.8079 18.2309M18.8079 18.2309H18.6156M18.8079 18.2309C19.1502 18.2309 19.4849 18.3324 19.7695 18.5226C20.0541 18.7127 20.2759 18.9831 20.4069 19.2993C20.5379 19.6156 20.5722 19.9636 20.5054 20.2993C20.4386 20.635 20.2738 20.9434 20.0318 21.1855C19.7897 21.4275 19.4813 21.5924 19.1456 21.6592C18.8098 21.7259 18.4618 21.6917 18.1456 21.5607C17.8293 21.4297 17.559 21.2078 17.3688 20.9232C17.1787 20.6386 17.0771 20.304 17.0771 19.9617V19.7693"
2828
stroke="green"
2929
strokeWidth={strokeWidth}
30-
stroke-linecap="round"
31-
stroke-linejoin="round"
30+
strokeLinecap="round"
31+
strokeLinejoin="round"
3232
/>
3333
</svg>
3434

src/hooks/useCorrelationQueryLogs.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useQuery } from 'react-query';
1414
import { LogsResponseWithHeaders } from '@/@types/parseable/api/query';
1515
import { useState } from 'react';
1616

17-
const { setStreamData } = correlationStoreReducers;
17+
const { setStreamData, setIsCorrelatedFlag } = correlationStoreReducers;
1818

1919
export const useCorrelationQueryLogs = () => {
2020
const [error, setError] = useMountedState<string | null>(null);
@@ -68,6 +68,7 @@ export const useCorrelationQueryLogs = () => {
6868
notifyError({ message: `${currentStream} doesn't have any fields` });
6969
}
7070
});
71+
setCorrelationStore((store) => setIsCorrelatedFlag(store, true));
7172
},
7273
onError: (data: AxiosError) => {
7374
setLoading(false);

src/hooks/useCorrelations.tsx

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { useMutation, useQuery } from 'react-query';
22
import _ from 'lodash';
33

4-
import {
5-
deleteSavedCorrelation,
6-
getCorrelationById,
7-
getCorrelations,
8-
saveCorrelation,
9-
updateCorrelation,
10-
} from '@/api/correlations';
4+
import { deleteSavedCorrelation, getCorrelations, saveCorrelation, updateCorrelation } from '@/api/correlations';
115
import { correlationStoreReducers, useCorrelationStore } from '@/pages/Correlation/providers/CorrelationProvider';
126
import { notifyError, notifySuccess } from '@/utils/notification';
137
import { AxiosError, isAxiosError } from 'axios';
148
import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider';
15-
import dayjs from 'dayjs';
169

1710
const {
1811
setCorrelations,
@@ -22,7 +15,7 @@ const {
2215
cleanCorrelationStore,
2316
toggleSavedCorrelationsModal,
2417
} = correlationStoreReducers;
25-
const { setTimeRange, syncTimeRange } = appStoreReducers;
18+
const { syncTimeRange } = appStoreReducers;
2619
export const useCorrelationsQuery = () => {
2720
const [{ correlationId }, setCorrelatedStore] = useCorrelationStore((store) => store);
2821
const [, setAppStore] = useAppStore((store) => store);
@@ -44,30 +37,6 @@ export const useCorrelationsQuery = () => {
4437
},
4538
});
4639

47-
const {
48-
mutate: getCorrelationByIdMutation,
49-
isError: fetchCorrelationIdError,
50-
isSuccess: fetchCorrelationIdSuccess,
51-
isLoading: fetchCorrelationIdLoading,
52-
} = useMutation((correlationId: string) => getCorrelationById(correlationId), {
53-
onSuccess: (data: any) => {
54-
data.data.startTime &&
55-
data.data.endTime &&
56-
setAppStore((store) =>
57-
setTimeRange(store, {
58-
startTime: dayjs(data.data.startTime),
59-
endTime: dayjs(data.data.endTime),
60-
type: 'custom',
61-
}),
62-
);
63-
setCorrelatedStore((store) => setCorrelationId(store, data.data.id));
64-
setCorrelatedStore((store) => setActiveCorrelation(store, data.data));
65-
},
66-
onError: () => {
67-
notifyError({ message: 'Failed to fetch correlation' });
68-
},
69-
});
70-
7140
const { mutate: deleteSavedCorrelationMutation, isLoading: isDeleting } = useMutation(
7241
(data: { correlationId: string; onSuccess?: () => void }) => deleteSavedCorrelation(data.correlationId),
7342
{
@@ -143,11 +112,6 @@ export const useCorrelationsQuery = () => {
143112
deleteSavedCorrelationMutation,
144113
isDeleting,
145114

146-
fetchCorrelationIdError,
147-
fetchCorrelationIdSuccess,
148-
fetchCorrelationIdLoading,
149-
getCorrelationByIdMutation,
150-
151115
saveCorrelationMutation,
152116
isCorrelationSaving,
153117

src/pages/Correlation/index.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ import SaveCorrelationModal from './components/SaveCorrelationModal';
3434
import { useCorrelationFetchCount } from './hooks/useCorrelationFetchCount';
3535
import CorrleationJSONView from './Views/CorrelationJSONView';
3636
import ViewToggle from './components/CorrelationViewToggle';
37+
import dayjs from 'dayjs';
3738

38-
const { changeStream, syncTimeRange } = appStoreReducers;
39+
const { changeStream, syncTimeRange, setTimeRange } = appStoreReducers;
3940
const {
4041
deleteStreamData,
4142
setSelectedFields,
@@ -64,6 +65,7 @@ const Correlation = () => {
6465
correlationId,
6566
savedCorrelationId,
6667
viewMode,
68+
correlations,
6769
},
6870
setCorrelationData,
6971
] = useCorrelationStore((store) => store);
@@ -83,7 +85,7 @@ const Correlation = () => {
8385

8486
const { getCorrelationData, loadingState, error: errorMessage } = useCorrelationQueryLogs();
8587
const { getFetchStreamData, loading: streamsLoading } = useFetchStreamData();
86-
const { fetchCorrelations, getCorrelationByIdMutation } = useCorrelationsQuery();
88+
const { fetchCorrelations } = useCorrelationsQuery();
8789
const { refetchCount, countLoading } = useCorrelationFetchCount();
8890

8991
// Local State
@@ -116,7 +118,6 @@ const Correlation = () => {
116118

117119
useEffect(() => {
118120
if (multipleSchemasLoading || !activeCorrelation) return;
119-
setCorrelationData((store) => setSelectedFields(store, '', '', true));
120121

121122
const tableOrder = activeCorrelation?.tableConfigs.reduce((acc, config, index) => {
122123
acc[config.tableName] = index;
@@ -143,8 +144,22 @@ const Correlation = () => {
143144

144145
useEffect(() => {
145146
if (!isSavedCorrelation || !correlationId) return;
146-
getCorrelationByIdMutation(correlationId);
147-
}, [correlationId]);
147+
const activeCorrelation = correlations?.find((correlation) => correlation.id === correlationId) || null;
148+
activeCorrelation?.startTime &&
149+
activeCorrelation?.endTime &&
150+
setAppStore((store) =>
151+
setTimeRange(store, {
152+
startTime: dayjs(activeCorrelation?.startTime),
153+
endTime: dayjs(activeCorrelation?.endTime),
154+
type: 'custom',
155+
}),
156+
);
157+
setSelect1Value(null);
158+
setSelect2Value(null);
159+
setCorrelationData((store) => setCorrelationCondition(store, ''));
160+
setCorrelationData((store) => setSelectedFields(store, '', '', true));
161+
setCorrelationData((store) => setActiveCorrelation(store, activeCorrelation));
162+
}, [correlationId, correlations]);
148163

149164
useEffect(() => {
150165
if (currentStream && streamNames.length > 0 && Object.keys(fields).includes(currentStream)) {
@@ -162,21 +177,11 @@ const Correlation = () => {
162177
} else {
163178
getFetchStreamData();
164179
}
165-
}, [currentOffset]);
166-
167-
useEffect(() => {
168-
if (isCorrelatedData) {
169-
refetchCount();
170-
getCorrelationData();
171-
} else {
172-
getFetchStreamData();
173-
}
174-
}, [timeRange]);
180+
}, [currentOffset, timeRange]);
175181

176182
useEffect(() => {
177183
updateCorrelationCondition();
178184
if (activeCorrelation && correlationCondition && isSavedCorrelation) {
179-
setCorrelationData((store) => setIsCorrelatedFlag(store, true));
180185
refetchCount();
181186
getCorrelationData();
182187
}
@@ -196,7 +201,6 @@ const Correlation = () => {
196201
const condition = `"${streamNames[0]}".${select1Value} = "${streamNames[1]}".${select2Value}`;
197202
setAppStore((store) => changeStream(store, 'correlatedStream'));
198203
setCorrelationData((store) => setCorrelationCondition(store, condition));
199-
setIsCorrelationEnabled(true);
200204
}
201205
};
202206

@@ -488,8 +492,8 @@ const Correlation = () => {
488492
<SavedCorrelationsButton />
489493
<ViewToggle />
490494

491-
{isCorrelatedData && (
492-
<Stack style={{ flexDirection: 'row' }} gap={8}>
495+
{isCorrelationEnabled && (
496+
<Stack style={{ flexDirection: 'row', alignItems: 'center' }} gap={8}>
493497
<Pill
494498
withRemoveButton
495499
onRemove={() => {

src/pages/Stream/hooks/useParamsController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const useParamsController = () => {
167167
setLogsStore((store) => setPerPage(store, _.toNumber(presentParams.rows)));
168168
}
169169

170-
if (storeAsParams.fields !== presentParams.fields) {
170+
if (storeAsParams.fields !== presentParams.fields && !_.isEmpty(presentParams.fields)) {
171171
setLogsStore((store) => setTargetColumns(store, joinOrSplit(presentParams.fields) as string[]));
172172
}
173173

0 commit comments

Comments
 (0)