Skip to content

Commit

Permalink
feat(investigations): change investigations plugin id (#1084)
Browse files Browse the repository at this point in the history
* feat(investigations): change investigations plugin id

* feat(investigations): change plugin.json

* feat(investigations): rename file

* feat(investigations): fix import
  • Loading branch information
svennergr authored Feb 20, 2025
1 parent 0c018d5 commit 1a2164a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
38 changes: 19 additions & 19 deletions src/Components/Panels/PanelMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { IndexScene } from '../IndexScene/IndexScene';
import { findObjectOfType, getQueryRunnerFromChildren } from '../../services/scenes';
import { reportAppInteraction, USER_EVENTS_ACTIONS, USER_EVENTS_PAGES } from '../../services/analytics';
import { logger } from '../../services/logger';
import { AddToExplorationButton } from '../ServiceScene/Breakdowns/AddToExplorationButton';
import { AddToInvestigationButton } from '../ServiceScene/Breakdowns/AddToInvestigationButton';
import { getPluginLinkExtensions } from '@grafana/runtime';
import { ExtensionPoints } from '../../services/extensions/links';
import { setLevelColorOverrides } from '../../services/panel';
Expand Down Expand Up @@ -53,8 +53,8 @@ interface InvestigationOptions {

interface PanelMenuState extends SceneObjectState {
body?: VizPanelMenu;
addExplorationsLink?: boolean;
explorationsButton?: AddToExplorationButton;
addInvestigationsLink?: boolean;
investigationsButton?: AddToInvestigationButton;
panelType?: AvgFieldPanelType;

investigationOptions?: InvestigationOptions;
Expand All @@ -65,7 +65,7 @@ interface PanelMenuState extends SceneObjectState {
*/
export class PanelMenu extends SceneObjectBase<PanelMenuState> implements VizPanelMenu, SceneObject {
constructor(state: Partial<PanelMenuState>) {
super({ ...state, addExplorationsLink: state.addExplorationsLink ?? true });
super({ ...state, addInvestigationsLink: state.addInvestigationsLink ?? true });
this.addActivationHandler(() => {
// Navigation options (all panels)
const items: PanelMenuItem[] = [
Expand Down Expand Up @@ -96,7 +96,7 @@ export class PanelMenu extends SceneObjectBase<PanelMenuState> implements VizPan
}

this.setState({
explorationsButton: new AddToExplorationButton({
investigationsButton: new AddToInvestigationButton({
labelName: this.state.investigationOptions?.getLabelName
? this.state.investigationOptions?.getLabelName()
: this.state.investigationOptions?.labelName,
Expand All @@ -106,10 +106,10 @@ export class PanelMenu extends SceneObjectBase<PanelMenuState> implements VizPan
}),
});

if (this.state.addExplorationsLink) {
if (this.state.addInvestigationsLink) {
// @todo rewrite the AddToExplorationButton
// Manually activate scene
this.state.explorationsButton?.activate();
this.state.investigationsButton?.activate();
}

// Visualization options
Expand All @@ -132,8 +132,8 @@ export class PanelMenu extends SceneObjectBase<PanelMenuState> implements VizPan
});

this._subs.add(
this.state.explorationsButton?.subscribeToState(() => {
subscribeToAddToExploration(this);
this.state.investigationsButton?.subscribeToState(() => {
subscribeToAddToInvestigation(this);
})
);
});
Expand Down Expand Up @@ -280,26 +280,26 @@ const onSwitchVizTypeTracking = (newVizType: AvgFieldPanelType) => {
});
};

const getInvestigationLink = (addToExplorations: AddToExplorationButton) => {
const getInvestigationLink = (addToInvestigation: AddToInvestigationButton) => {
const links = getPluginLinkExtensions({
extensionPointId: ExtensionPoints.MetricExploration,
context: addToExplorations.state.context,
extensionPointId: ExtensionPoints.MetricInvestigation,
context: addToInvestigation.state.context,
});

return links.extensions[0];
};

const onAddToInvestigationClick = (event: React.MouseEvent, addToExplorations: AddToExplorationButton) => {
const link = getInvestigationLink(addToExplorations);
const onAddToInvestigationClick = (event: React.MouseEvent, addToInvestigation: AddToInvestigationButton) => {
const link = getInvestigationLink(addToInvestigation);
if (link && link.onClick) {
link.onClick(event);
}
};

function subscribeToAddToExploration(exploreLogsVizPanelMenu: PanelMenu) {
const addToExplorationButton = exploreLogsVizPanelMenu.state.explorationsButton;
if (addToExplorationButton) {
const link = getInvestigationLink(addToExplorationButton);
function subscribeToAddToInvestigation(exploreLogsVizPanelMenu: PanelMenu) {
const addToInvestigationButton = exploreLogsVizPanelMenu.state.investigationsButton;
if (addToInvestigationButton) {
const link = getInvestigationLink(addToInvestigationButton);

const existingMenuItems = exploreLogsVizPanelMenu.state.body?.state.items ?? [];

Expand All @@ -318,7 +318,7 @@ function subscribeToAddToExploration(exploreLogsVizPanelMenu: PanelMenu) {
exploreLogsVizPanelMenu.state.body?.addItem({
text: ADD_TO_INVESTIGATION_MENU_TEXT,
iconClassName: 'plus-square',
onClick: (e) => onAddToInvestigationClick(e, addToExplorationButton),
onClick: (e) => onAddToInvestigationClick(e, addToInvestigationButton),
});
} else {
if (existingAddToExplorationLink) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { findObjectOfType, getLokiDatasource } from 'services/scenes';
import LokiLogo from '../../../img/logo.svg';
import { LokiDatasource, LokiQuery } from '../../../services/lokiQuery';

export interface AddToExplorationButtonState extends SceneObjectState {
export interface AddToInvestigationButtonState extends SceneObjectState {
frame?: DataFrame;
labelName?: string;
fieldName?: string;
Expand All @@ -34,8 +34,8 @@ type ExtensionContext = {
drillDownLabel?: string;
};

export class AddToExplorationButton extends SceneObjectBase<AddToExplorationButtonState> {
constructor(state: Omit<AddToExplorationButtonState, 'queries'>) {
export class AddToInvestigationButton extends SceneObjectBase<AddToInvestigationButtonState> {
constructor(state: Omit<AddToInvestigationButtonState, 'queries'>) {
super({ ...state, queries: [] });
this.addActivationHandler(this.onActivate);
}
Expand Down Expand Up @@ -98,14 +98,14 @@ export class AddToExplorationButton extends SceneObjectBase<AddToExplorationButt
}
};

public static Component = ({ model }: SceneComponentProps<AddToExplorationButton>) => {
public static Component = ({ model }: SceneComponentProps<AddToInvestigationButton>) => {
const { context } = model.useState();
const { links } = usePluginLinks({ extensionPointId: ExtensionPoints.MetricExploration, context });
const { links } = usePluginLinks({ extensionPointId: ExtensionPoints.MetricInvestigation, context });

return (
<>
{links
.filter((link) => link.pluginId === 'grafana-explorations-app' && link.onClick)
.filter((link) => link.pluginId === 'grafana-investigations-app' && link.onClick)
.map((link) => (
<IconButton
tooltip={link.description}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ServiceScene/LogsTableScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class LogsTableScene extends SceneObjectBase<LogsTableSceneState> {

public onActivate() {
this.setState({
menu: new PanelMenu({ addExplorationsLink: false }),
menu: new PanelMenu({ addInvestigationsLink: false }),
});
}
public static Component = ({ model }: SceneComponentProps<LogsTableScene>) => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
],
"extensionPoints": [
{
"id": "grafana-lokiexplore-app/metric-exploration/v1"
"id": "grafana-lokiexplore-app/investigation/v1"
},
{
"id": "grafana-lokiexplore-app/toolbar-open-related/v1",
Expand Down
2 changes: 1 addition & 1 deletion src/services/extensions/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const description = 'Open current query in the Explore Logs view';
const icon = 'gf-logs';

export const ExtensionPoints = {
MetricExploration: 'grafana-lokiexplore-app/metric-exploration/v1',
MetricInvestigation: 'grafana-lokiexplore-app/investigation/v1',
} as const;

export type LinkConfigs = Array<
Expand Down

0 comments on commit 1a2164a

Please sign in to comment.