Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.0] Prevent empty task IDs passed to server side #636

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions public/pages/DetectorResults/containers/AnomalyHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
const backgroundColor = darkModeEnabled() ? '#29017' : '#F7F7F7';
const resultIndex = get(props, 'detector.resultIndex', '');

// Utility fn to only fetch data when either it is non-historical, or historical and
// there is a populated task ID which will be used to fetch the historical results
const isValidToFetch = () => {
return !props.isHistorical || (props.isHistorical && taskId.current);
};

// Tracking which parent category fields the user has selected to filter by.
const [selectedCategoryFields, setSelectedCategoryFields] = useState(
getCategoryFieldOptions(detectorCategoryField)
Expand Down Expand Up @@ -326,7 +332,8 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
useEffect(() => {
if (
!isEmpty(bucketizedAnomalyResults) &&
!isDateRangeOversize(zoomRange, detectorInterval, MAX_ANOMALIES)
!isDateRangeOversize(zoomRange, detectorInterval, MAX_ANOMALIES) &&
isValidToFetch()
) {
setBucketizedAnomalyResults(undefined);
if (isHCDetector && selectedHeatmapCell) {
Expand All @@ -351,14 +358,16 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
}, [zoomRange]);

useEffect(() => {
fetchRawAnomalyResults(isHCDetector);
if (
!isHCDetector &&
isDateRangeOversize(dateRange, detectorInterval, MAX_ANOMALIES)
) {
getBucketizedAnomalyResults();
} else {
setBucketizedAnomalyResults(undefined);
if (isValidToFetch()) {
fetchRawAnomalyResults(isHCDetector);
if (
!isHCDetector &&
isDateRangeOversize(dateRange, detectorInterval, MAX_ANOMALIES)
) {
getBucketizedAnomalyResults();
} else {
setBucketizedAnomalyResults(undefined);
}
}
}, [dateRange, props.detector]);

Expand Down Expand Up @@ -400,13 +409,7 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
);
const detectorResultResponse = props.isHistorical
? await dispatch(
getDetectorResults(
taskId.current || '',
params,
true,
resultIndex,
true
)
getDetectorResults(taskId.current, params, true, resultIndex, true)
).catch((error: any) => {
setIsLoading(false);
setIsLoadingAnomalyResults(false);
Expand Down Expand Up @@ -459,17 +462,19 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
useEffect(() => {
// For any change, we will want to clear any selected heatmap cell to clear any populated charts / graphs
setSelectedHeatmapCell(undefined);
fetchHCAnomalySummaries();
if (isValidToFetch()) {
fetchHCAnomalySummaries();
}
}, [selectedCategoryFields]);

useEffect(() => {
if (isHCDetector) {
if (isHCDetector && isValidToFetch()) {
fetchHCAnomalySummaries();
}
}, [dateRange, heatmapDisplayOption]);

useEffect(() => {
if (selectedHeatmapCell) {
if (selectedHeatmapCell && isValidToFetch()) {
if (
isMultiCategory &&
get(selectedCategoryFields, 'length', 0) <
Expand All @@ -493,7 +498,7 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {

// Getting the latest sets of time series based on the selected parent + child entities
useEffect(() => {
if (selectedHeatmapCell) {
if (selectedHeatmapCell && isValidToFetch()) {
// Get a list of entity lists, where each list represents a unique entity combination of
// all parent + child entities (a single model). And, for each one of these lists, fetch the time series data.
const entityCombosToFetch = getAllEntityCombos(
Expand Down
Loading