Skip to content

Commit

Permalink
fix: table sampling and editor bug (#1525)
Browse files Browse the repository at this point in the history
* fix sampling bug

* update message

* update
  • Loading branch information
jczhong84 authored Dec 5, 2024
1 parent 48bcb34 commit dff25db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,27 @@ const FetchInfo: React.FC<{
<span className="accent-warning-text ml4">
Sampled {sampleRate}%
</span>
)
<span className="accent-warning-text ml4">
Results must be upscaled by {Math.round(100 / sampleRate)}x
</span>
.
{sampleUserGuideLink ? (
<IconButton
className="ml4"
onClick={() => {
window.open(sampleUserGuideLink, '_blank');
}}
icon="Info"
size={16}
noPadding
/>
<>
<span className="ml4">
Learn more about accuracy and opt-out
</span>
<IconButton
className="ml4"
onClick={() => {
window.open(sampleUserGuideLink, '_blank');
}}
icon="Info"
size={16}
noPadding
/>
</>
) : null}
)
</div>
);

Expand Down
1 change: 1 addition & 0 deletions querybook/webapp/components/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export const QueryEditor: React.FC<
extensions={extensions}
basicSetup={basicSetup}
editable={!readOnly}
readOnly={readOnly}
autoFocus={false}
onChange={onChangeHandler}
indentWithTab={false}
Expand Down
15 changes: 10 additions & 5 deletions querybook/webapp/components/QueryRunButton/QueryRunButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,19 @@ const TableSamplingSelector: React.FC<{
onTableSamplingInfoClick: () => void;
}> = ({ sampleRate, setSampleRate, tooltipPos, onTableSamplingInfoClick }) => {
const sampleRateOptions = React.useMemo(getTableSamplingRateOptions, []);
const userDefaultTableSampleRate = useSelector(
(state: IStoreState) => state.user.computedSettings['table_sample_rate']
);
const userDefaultTableSampleRate = useSelector((state: IStoreState) => {
const sampleRateSetting = parseFloat(
state.user.computedSettings['table_sample_rate']
);
return isNaN(sampleRateSetting)
? TABLE_SAMPLING_CONFIG.default_sample_rate
: sampleRateSetting;
});

React.useEffect(() => {
// If it is a new cell without the sample rate selected, use the default sample rate from user settings
if (sampleRate === undefined) {
setSampleRate(parseFloat(userDefaultTableSampleRate));
if (isNaN(sampleRate)) {
setSampleRate(userDefaultTableSampleRate);
}
}, [sampleRate, setSampleRate, userDefaultTableSampleRate]);

Expand Down

0 comments on commit dff25db

Please sign in to comment.