Skip to content

Commit

Permalink
Rework dataset filtering in with new reducer based hook state
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Jul 13, 2020
1 parent cc546d3 commit 0ec814e
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface ReducerState {
start: number;
end: number;
};
filteredDatasets?: string[];
}

type ReducerStateDefaults = Pick<
Expand All @@ -56,7 +57,8 @@ type ReducerAction =
| { type: 'fetchPreviousPage' }
| { type: 'changeHasNextPage'; payload: { hasNextPage: boolean } }
| { type: 'changeLastReceivedCursors'; payload: { lastReceivedCursors: PaginationCursors } }
| { type: 'changeTimeRange'; payload: { timeRange: { start: number; end: number } } };
| { type: 'changeTimeRange'; payload: { timeRange: { start: number; end: number } } }
| { type: 'changeFilteredDatasets'; payload: { filteredDatasets?: string[] } };

const stateReducer = (state: ReducerState, action: ReducerAction): ReducerState => {
const resetPagination = {
Expand Down Expand Up @@ -108,6 +110,12 @@ const stateReducer = (state: ReducerState, action: ReducerAction): ReducerState
...resetPagination,
...action.payload,
};
case 'changeFilteredDatasets':
return {
...state,
...resetPagination,
...action.payload,
};
default:
return state;
}
Expand Down Expand Up @@ -145,6 +153,7 @@ export const useLogEntryAnomaliesResults = ({
...stateDefaults,
paginationOptions: defaultPaginationOptions,
sortOptions: defaultSortOptions,
filteredDatasets,
timeRange: {
start: startTime,
end: endTime,
Expand All @@ -165,6 +174,7 @@ export const useLogEntryAnomaliesResults = ({
sortOptions,
paginationOptions,
paginationCursor,
filteredDatasets: queryFilteredDatasets,
} = reducerState;
return await callGetLogEntryAnomaliesAPI(
sourceId,
Expand All @@ -174,7 +184,8 @@ export const useLogEntryAnomaliesResults = ({
{
...paginationOptions,
cursor: paginationCursor,
}
},
queryFilteredDatasets
);
},
onResolve: ({ data: { anomalies, paginationCursors: requestCursors, hasMoreEntries } }) => {
Expand Down Expand Up @@ -203,6 +214,7 @@ export const useLogEntryAnomaliesResults = ({
reducerState.sortOptions,
reducerState.paginationOptions,
reducerState.paginationCursor,
reducerState.filteredDatasets,
]
);

Expand Down Expand Up @@ -231,6 +243,14 @@ export const useLogEntryAnomaliesResults = ({
});
}, [startTime, endTime]);

// Selected datasets have changed
useEffect(() => {
dispatch({
type: 'changeFilteredDatasets',
payload: { filteredDatasets },
});
}, [filteredDatasets]);

useEffect(() => {
getLogEntryAnomalies();
}, [getLogEntryAnomalies]);
Expand Down

0 comments on commit 0ec814e

Please sign in to comment.