Skip to content

Commit

Permalink
enable unselecting all but one datastream
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokaditya committed Oct 18, 2024
1 parent b9ec095 commit c99ad95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const ChartsFilter = memo<ChartsFilterProps>(
'data-test-subj': dataTestSubj,
}) => {
const getTestId = useTestIdGenerator(dataTestSubj);

const isMetricsFilter = filterName === 'metricTypes';
const isDataStreamsFilter = filterName === 'dataStreams';

Expand Down Expand Up @@ -87,11 +86,6 @@ export const ChartsFilter = memo<ChartsFilterProps>(

// track popover state to pin selected options
const wasPopoverOpen = useRef(isPopoverOpen);
useEffect(() => {
return () => {
wasPopoverOpen.current = isPopoverOpen;
};
}, [isPopoverOpen, wasPopoverOpen]);

// compute if selected dataStreams should be pinned
const shouldPinSelectedDataStreams = useCallback(
Expand Down Expand Up @@ -121,8 +115,16 @@ export const ChartsFilter = memo<ChartsFilterProps>(

const onOptionsChange = useCallback(
(newOptions: FilterItems) => {
const optionItemsToSet = newOptions.map((option) => option);
const currChecks = optionItemsToSet.filter((option) => option.checked === 'on');

// don't update filter state if trying to uncheck all options
if (currChecks.length < 1) {
return;
}

// update filter UI options state
setItems(newOptions.map((option) => option));
setItems(optionItemsToSet);

// compute a selected list of options
const selectedItems = newOptions.reduce<string[]>((acc, curr) => {
Expand All @@ -146,10 +148,7 @@ export const ChartsFilter = memo<ChartsFilterProps>(
shouldPinSelectedDataStreams(false);
setAreDataStreamsSelectedOnMount(false);

// update overall query state
if (typeof onChangeFilterOptions !== 'undefined') {
onChangeFilterOptions(selectedItems);
}
onChangeFilterOptions(selectedItems);
},
[
setItems,
Expand All @@ -163,6 +162,12 @@ export const ChartsFilter = memo<ChartsFilterProps>(
]
);

useEffect(() => {
return () => {
wasPopoverOpen.current = isPopoverOpen;
};
}, [isPopoverOpen, wasPopoverOpen]);

return (
<ChartsFilterPopover
closePopover={onClosePopover}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const getUsageMetricsHandler = (
logger.debug(`Retrieving usage metrics`);
const { from, to, metricTypes, dataStreams: requestDsNames } = request.body;

// redundant check as we don't allow making requests via UI without data streams,
// but it's here to make sure the request body is validated before requesting metrics from auto-ops
if (!requestDsNames?.length) {
return errorHandler(
logger,
Expand Down

0 comments on commit c99ad95

Please sign in to comment.