mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* 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>
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import React from 'react';
|
|
|
|
import { getDataSourceSrv } from '@grafana/runtime';
|
|
import { SceneComponentProps, SceneObjectBase, SceneObjectState, SceneTimeRangeLike } from '@grafana/scenes';
|
|
import { DataSourceRef } from '@grafana/schema';
|
|
import { Drawer } from '@grafana/ui';
|
|
import { PromVisualQuery } from 'app/plugins/datasource/prometheus/querybuilder/types';
|
|
|
|
import { getDashboardSceneFor } from '../dashboard-scene/utils/utils';
|
|
|
|
import { DataTrail } from './DataTrail';
|
|
import { getDataTrailsApp } from './DataTrailsApp';
|
|
import { OpenEmbeddedTrailEvent } from './shared';
|
|
|
|
interface DataTrailDrawerState extends SceneObjectState {
|
|
timeRange: SceneTimeRangeLike;
|
|
query: PromVisualQuery;
|
|
dsRef: DataSourceRef;
|
|
}
|
|
|
|
export class DataTrailDrawer extends SceneObjectBase<DataTrailDrawerState> {
|
|
static Component = DataTrailDrawerRenderer;
|
|
|
|
public trail: DataTrail;
|
|
|
|
constructor(state: DataTrailDrawerState) {
|
|
super(state);
|
|
|
|
this.trail = buildDataTrailFromQuery(state);
|
|
this.trail.addActivationHandler(() => {
|
|
this.trail.subscribeToEvent(OpenEmbeddedTrailEvent, this.onOpenTrail);
|
|
});
|
|
}
|
|
|
|
onOpenTrail = () => {
|
|
getDataTrailsApp().goToUrlForTrail(this.trail.clone({ embedded: false }));
|
|
};
|
|
|
|
onClose = () => {
|
|
const dashboard = getDashboardSceneFor(this);
|
|
dashboard.closeModal();
|
|
};
|
|
}
|
|
|
|
function DataTrailDrawerRenderer({ model }: SceneComponentProps<DataTrailDrawer>) {
|
|
return (
|
|
<Drawer title={'Data trail'} onClose={model.onClose} size="lg">
|
|
<div style={{ display: 'flex', height: '100%' }}>
|
|
<model.trail.Component model={model.trail} />
|
|
</div>
|
|
</Drawer>
|
|
);
|
|
}
|
|
|
|
export function buildDataTrailFromQuery({ query, dsRef, timeRange }: DataTrailDrawerState) {
|
|
const filters = query.labels.map((label) => ({ key: label.label, value: label.value, operator: label.op }));
|
|
|
|
const ds = getDataSourceSrv().getInstanceSettings(dsRef);
|
|
|
|
return new DataTrail({
|
|
$timeRange: timeRange,
|
|
metric: query.metric,
|
|
initialDS: ds?.name,
|
|
initialFilters: filters,
|
|
embedded: true,
|
|
});
|
|
}
|