Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Chart form metrics bug #394

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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