Skip to content

Commit

Permalink
Fix sampling probability when switching between automatic and manual
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Feb 6, 2023
1 parent 85b481b commit 1a45f6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const DocumentCountContent: FC<Props> = ({
showTicks
showRange={false}
min={RANDOM_SAMPLER_STEP}
max={0.5 * 100}
max={50}
value={(samplingProbability ?? 1) * 100}
ticks={RANDOM_SAMPLER_PROBABILITIES.map((d) => ({
value: d,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import { DataVisualizerDataViewManagement } from '../data_view_management';
import { GetAdditionalLinks } from '../../../common/components/results_links';
import { useDataVisualizerGridData } from '../../hooks/use_data_visualizer_grid_data';
import { DataVisualizerGridInput } from '../../embeddables/grid_embeddable/grid_embeddable';
import { RANDOM_SAMPLER_OPTION } from '../../constants/random_sampler';
import { RANDOM_SAMPLER_OPTION, RandomSamplerOption } from '../../constants/random_sampler';

interface DataVisualizerPageState {
overallStats: OverallStats;
Expand Down Expand Up @@ -316,9 +316,25 @@ export const IndexDataVisualizerView: FC<IndexDataVisualizerViewProps> = (dataVi
]
);

const setSamplingProbability = (value: number | null) => {
setDataVisualizerListState({ ...dataVisualizerListState, probability: value });
};
const setSamplingProbability = useCallback(
(value: number | null) => {
setDataVisualizerListState({ ...dataVisualizerListState, probability: value });
},
[dataVisualizerListState, setDataVisualizerListState]
);

const setRandomSamplerPreference = useCallback(
(pref: RandomSamplerOption) => {
if (
savedRandomSamplerPreference === RANDOM_SAMPLER_OPTION.ON_AUTOMATIC &&
pref === RANDOM_SAMPLER_OPTION.ON_MANUAL
) {
setSamplingProbability(0.5);
}
saveRandomSamplerPreference(pref);
},
[setSamplingProbability, savedRandomSamplerPreference, saveRandomSamplerPreference]
);

useEffect(
function clearFiltersOnLeave() {
Expand Down Expand Up @@ -566,7 +582,7 @@ export const IndexDataVisualizerView: FC<IndexDataVisualizerViewProps> = (dataVi
}
loading={overallStatsProgress.loaded < 100}
randomSamplerPreference={savedRandomSamplerPreference}
setRandomSamplerPreference={saveRandomSamplerPreference}
setRandomSamplerPreference={setRandomSamplerPreference}
/>
</EuiFlexGroup>
</>
Expand Down

0 comments on commit 1a45f6a

Please sign in to comment.