Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rafana-datasource into v4-deploy
  • Loading branch information
SpencerTorres committed Jan 22, 2024
2 parents 38c92d6 + 3143db9 commit ff5c995
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/components/queryBuilder/AggregateEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface AggregateProps {
updateAggregate: (index: number, aggregate: AggregateColumn) => void;
}

const aggregateOptions: Array<SelectableValue<AggregateType>> = [
const allAggregateOptions: Array<SelectableValue<AggregateType>> = [
{ label: 'Count', value: AggregateType.Count },
{ label: 'Sum', value: AggregateType.Sum },
{ label: 'Min', value: AggregateType.Min },
Expand All @@ -24,11 +24,25 @@ const aggregateOptions: Array<SelectableValue<AggregateType>> = [
];

const Aggregate = (props: AggregateProps) => {
const { columnOptions, index, aggregate, updateAggregate } = props;
const { index, aggregate, updateAggregate } = props;
const [isOpen, setIsOpen] = useState(false);
const [alias, setAlias] = useState(aggregate.alias || '');
const { aliasLabel } = labels.components.AggregatesEditor;

// Add current value to aggregate functions
const aggregateOptions = allAggregateOptions.slice();
if (!aggregateOptions.find(a => a.value === aggregate.aggregateType)) {
aggregateOptions.push({ label: aggregate.aggregateType, value: aggregate.aggregateType });
}

// Add current value to column options
const columnOptions = props.columnOptions.slice();
if (!columnOptions.find(c => c.value === aggregate.column)) {
columnOptions.push({ label: aggregate.column, value: aggregate.column });
}
console.log(columnOptions)


return (
<>
<Select
Expand All @@ -38,9 +52,10 @@ const Aggregate = (props: AggregateProps) => {
value={aggregate.aggregateType}
onChange={e => updateAggregate(index, { ...aggregate, aggregateType: e.value! })}
menuPlacement={'bottom'}
allowCustomValue
/>
<Select<string>
width={28}
width={40}
className={styles.Common.inlineSelect}
options={columnOptions}
isOpen={isOpen}
Expand All @@ -49,6 +64,7 @@ const Aggregate = (props: AggregateProps) => {
onChange={e => updateAggregate(index, { ...aggregate, column: e.value! })}
value={aggregate.column}
menuPlacement={'bottom'}
allowCustomValue
/>
<InlineFormLabel width={2} className="query-keyword">
{aliasLabel}
Expand Down
2 changes: 1 addition & 1 deletion src/data/CHDatasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class Datasource
database: query.builderOptions.database,
table: query.builderOptions.table,
queryType: QueryType.TimeSeries,
mode: BuilderMode.Aggregate,
mode: BuilderMode.Trend,
filters,
columns,
aggregates,
Expand Down

0 comments on commit ff5c995

Please sign in to comment.