Skip to content

Commit 859ced5

Browse files
authored
feat(chart): Auto-execute chart on chart explorer page load (#1961)
## Summary Updates the chart explorer page so that the chart query is executed automatically once on page load instead of waiting for the user to click the run button. The motivation is external tools that translate queries from other systems into HyperDX chart configs and deeplink the user into the `/chart` page. Today the user lands on a fully-populated form but still has to click once to see results; with this change the chart renders immediately. The form gains an `autoRun` prop. When true, a latched effect calls `onSubmit()` exactly once after the source data has loaded, so form validation has the table metadata it needs. ### How to test locally or on Vercel 1. `yarn dev` in `packages/app` 2. Open `/chart?config=%7B%22name%22%3A%22%22%2C%22select%22%3A%5B%7B%22aggFn%22%3A%22count%22%2C%22aggCondition%22%3A%22%22%2C%22aggConditionLanguage%22%3A%22sql%22%2C%22valueExpression%22%3A%22%22%7D%5D%2C%22where%22%3A%22%22%2C%22whereLanguage%22%3A%22sql%22%2C%22displayType%22%3A%22line%22%2C%22granularity%22%3A%22auto%22%2C%22source%22%3A%22<your-source-id>%22%7D` — replace `<your-source-id>` with a real source id from your instance 3. The chart should render results without clicking the run button
1 parent 76323da commit 859ced5

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
feat: Chart Explorer now auto-executes the chart on load when a valid source is configured. Deeplinks render results without requiring a manual click.

packages/app/src/DBChartPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ function DBChartExplorerPage() {
253253
onTimeRangeSearch={onSearch}
254254
onTimeRangeSelect={onTimeRangeSelect}
255255
submitRef={submitRef}
256+
autoRun
256257
/>
257258
</Box>
258259
);

packages/app/src/components/DBEditTimeChartForm.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ export default function EditTimeChartForm({
546546
'data-testid': dataTestId,
547547
submitRef,
548548
isDashboardForm = false,
549+
autoRun = false,
549550
}: {
550551
dashboardId?: string;
551552
chartConfig: SavedChartConfig;
@@ -562,6 +563,7 @@ export default function EditTimeChartForm({
562563
'data-testid'?: string;
563564
submitRef?: React.MutableRefObject<(() => void) | undefined>;
564565
isDashboardForm?: boolean;
566+
autoRun?: boolean;
565567
}) {
566568
const formValue: ChartEditorFormState = useMemo(
567569
() => convertSavedChartConfigToFormState(chartConfig),
@@ -827,6 +829,14 @@ export default function EditTimeChartForm({
827829
}
828830
}, [onSubmit, submitRef]);
829831

832+
const autoRunFired = useRef(false);
833+
useEffect(() => {
834+
if (autoRun && !autoRunFired.current && tableSource) {
835+
autoRunFired.current = true;
836+
onSubmit(true);
837+
}
838+
}, [autoRun, tableSource, onSubmit]);
839+
830840
const handleSave = useCallback(
831841
(form: ChartEditorFormState) => {
832842
const errors = validateChartForm(form, tableSource, setError);

0 commit comments

Comments
 (0)