grafana/public/app/features/trails/SelectMetricTrailView.tsx
Torkel Ödegaard 1f1d348e17
DataTrails: Auto query, explore and breakdown/drilldown prototype (#77019)
* First try

* Update

* app with drilldowns

* Progres

* Progress

* update

* Update

* update

* Update

* Update

* Progress

* Update

* Progress

* Update

* Progress

* logs url sync

* related metrics

* Progress

* progress

* Progress

* Update

* Update

* Update

* Update

* Update

* fix

* Update

* update

* Update

* update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* update

* Update

* Update

* Settings

* Update

* Tweaks

* update

* Improve auto queries

* Update

* Update

* Fixes

* Update

* Update

* Update

* fix

* Update

* Removing logs view, cleanup

* Update

* Update

* disabled not implemented buttons

* Update

* Feature toggle on dashboard menu

* remove unused prometheus change

* removed bit

* Fix failing test

* chore: added `/public/app/features/trails/` to CODEOWNERS

* go mod tidy

* go mod tidy

* fix: added missing arg

* Moved panel action

* Moved panel action

---------

Co-authored-by: André Pereira <adrapereira@gmail.com>
Co-authored-by: Darren Janeczek <darren.janeczek@grafana.com>
2023-11-15 11:28:29 +00:00

84 lines
2.4 KiB
TypeScript

import React from 'react';
import {
SceneObjectState,
SceneObjectBase,
VariableDependencyConfig,
sceneGraph,
SceneComponentProps,
SceneVariableSet,
SceneVariable,
QueryVariable,
VariableValueOption,
} from '@grafana/scenes';
import { VariableHide } from '@grafana/schema';
import { Input, Card, Stack } from '@grafana/ui';
import { trailDS } from './shared';
export interface SelectMetricTrailViewState extends SceneObjectState {
metricNames: VariableValueOption[];
}
export class SelectMetricTrailView extends SceneObjectBase<SelectMetricTrailViewState> {
public constructor(state: Partial<SelectMetricTrailViewState>) {
super({
$variables: new SceneVariableSet({
variables: [
new QueryVariable({
name: 'metricNames',
datasource: trailDS,
hide: VariableHide.hideVariable,
includeAll: true,
defaultToAll: true,
skipUrlSync: true,
query: { query: 'label_values({$filters},__name__)', refId: 'A' },
}),
],
}),
metricNames: [],
...state,
});
}
protected _variableDependency = new VariableDependencyConfig(this, {
variableNames: ['filters', 'metricNames'],
onVariableUpdatesCompleted: this._onVariableChanged.bind(this),
});
private _onVariableChanged(changedVariables: Set<SceneVariable>, dependencyChanged: boolean): void {
for (const variable of changedVariables) {
if (variable.state.name === 'filters') {
const variable = sceneGraph.lookupVariable('filters', this)!;
// Temp hack
(this.state.$variables as any)._handleVariableValueChanged(variable);
}
if (variable.state.name === 'metricNames' && variable instanceof QueryVariable) {
this.setState({ metricNames: variable.state.options });
}
}
}
static Component = ({ model }: SceneComponentProps<SelectMetricTrailView>) => {
const { metricNames } = model.useState();
return (
<Stack direction="column" gap={0}>
<Stack direction="column" gap={2}>
<Input placeholder="Search metrics" />
<div></div>
</Stack>
{metricNames.map((option, index) => (
<Card
key={index}
href={sceneGraph.interpolate(model, `\${__url.path}\${__url.params}&metric=${option.value}`)}
>
<Card.Heading>{String(option.value)}</Card.Heading>
</Card>
))}
</Stack>
);
};
}