Skip to content

Commit

Permalink
fix: Chart form metrics bug (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestii authored May 22, 2024
1 parent 9c45109 commit 4176710
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-apples-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

autofocus on field select after setting a non-count aggfn
15 changes: 14 additions & 1 deletion packages/app/src/ChartUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export function MetricNameSelect({
return (
<MSelect
disabled={isLoading || isError}
autoFocus={!value}
variant="filled"
placeholder={
isLoading
Expand Down Expand Up @@ -517,16 +518,20 @@ export function FieldSelect({
setValue,
types,
className,
autoFocus,
}: {
value: string | undefined | null;
setValue: (value: string | undefined) => void;
types: ('number' | 'string' | 'bool')[];
className?: string;
autoFocus?: boolean;
}) {
const propertyOptions = usePropertyOptions(types);

return (
<AsyncSelect
autoFocus={autoFocus}
placeholder="Select a field..."
loadOptions={input => {
return Promise.resolve([
{ value: undefined, label: 'None' },
Expand Down Expand Up @@ -660,7 +665,12 @@ export function ChartSeriesForm({
</div>
{table === 'logs' && aggFn != 'count' && aggFn != 'count_distinct' ? (
<div className="ms-3 flex-grow-1">
<FieldSelect value={field} setValue={setField} types={['number']} />
<FieldSelect
value={field}
setValue={setField}
types={['number']}
autoFocus={!field}
/>
</div>
) : null}
{table === 'logs' && aggFn != 'count' && aggFn == 'count_distinct' ? (
Expand All @@ -669,6 +679,7 @@ export function ChartSeriesForm({
value={field}
setValue={setField}
types={['string', 'number', 'bool']}
autoFocus={!field}
/>
</div>
) : null}
Expand Down Expand Up @@ -996,6 +1007,7 @@ export function ChartSeriesFormCompact({
value={field}
setValue={setField}
types={['number']}
autoFocus={!field}
/>
</div>
) : null}
Expand All @@ -1006,6 +1018,7 @@ export function ChartSeriesFormCompact({
value={field}
setValue={setField}
types={['string', 'number', 'bool']}
autoFocus={!field}
/>
</div>
) : null}
Expand Down
40 changes: 29 additions & 11 deletions packages/app/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,35 @@ const api = {
},
options?: UseQueryOptions<any, Error>,
) {
const enrichedSeries = series.map(s => {
if (s.type != 'search' && s.type != 'markdown' && s.table === 'metrics') {
const [metricName, metricDataType] = (s.field ?? '').split(' - ');
return {
...s,
field: metricName,
metricDataType,
};
}
const enrichedSeries = series
.filter(s => {
// Skip time series without field
if (s.type === 'time') {
if (s.table === 'metrics' && !s.field) {
return false;
}
if (s.table === 'logs' && !s.field && s.aggFn !== 'count') {
return false;
}
}
return true;
})
.map(s => {
if (
s.type != 'search' &&
s.type != 'markdown' &&
s.table === 'metrics'
) {
const [metricName, metricDataType] = (s.field ?? '').split(' - ');
return {
...s,
field: metricName,
metricDataType,
};
}
return s;
});

return s;
});
const startTime = startDate.getTime();
const endTime = endDate.getTime();
return useQuery<
Expand Down Expand Up @@ -276,6 +293,7 @@ const api = {
},
}).json(),
retry: 1,
enabled: enrichedSeries.length > 0,
...options,
});
},
Expand Down

0 comments on commit 4176710

Please sign in to comment.