Skip to content

Commit

Permalink
chore(rename): rename exposed component (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
svennergr authored Feb 21, 2025
1 parent 84cc8e7 commit 39f1110
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { useReturnToPrevious } from '@grafana/runtime';
import { OpenInExploreLogsButtonProps } from './types';
import OpenInExploreLogsButton from './OpenInExploreLogsButton';
import { OpenInLogsDrilldownButtonProps } from './types';
import OpenInLogsDrilldownButton from './OpenInLogsDrilldownButton';
import { AbstractLabelOperator } from '@grafana/data';
import { addCustomInputPrefixAndValueLabels, encodeFilter } from 'services/extensions/utils';

jest.mock('@grafana/runtime', () => ({
useReturnToPrevious: jest.fn(),
}));

describe('OpenInExploreLogsButton', () => {
describe('OpenInLogsDrilldownButton', () => {
const setReturnToPreviousMock = jest.fn();

beforeEach(() => {
(useReturnToPrevious as jest.Mock).mockReturnValue(setReturnToPreviousMock);
});

it('should render the button with correct href (Equal operator)', () => {
const props: OpenInExploreLogsButtonProps = {
const props: OpenInLogsDrilldownButtonProps = {
datasourceUid: 'test-datasource',
streamSelectors: [{ name: 'job', value: 'test-job', operator: AbstractLabelOperator.Equal }],
from: 'now-1h',
to: 'now',
};

render(<OpenInExploreLogsButton {...props} />);
render(<OpenInLogsDrilldownButton {...props} />);

const linkButton = screen.getByRole('link', { name: /open in explore logs/i });
const linkButton = screen.getByRole('link', { name: /open in logs drilldown/i });
expect(linkButton).toBeInTheDocument();
expect(linkButton).toHaveAttribute(
'href',
Expand All @@ -38,14 +38,14 @@ describe('OpenInExploreLogsButton', () => {
});

it('should handle NotEqual operator correctly', () => {
const props: OpenInExploreLogsButtonProps = {
const props: OpenInLogsDrilldownButtonProps = {
streamSelectors: [
{ name: 'job', value: 'test-job', operator: AbstractLabelOperator.Equal },
{ name: 'test_label_key', value: 'test-label-value', operator: AbstractLabelOperator.NotEqual },
],
};

render(<OpenInExploreLogsButton {...props} />);
render(<OpenInLogsDrilldownButton {...props} />);

const linkButton = screen.getByRole('link');
expect(linkButton).toHaveAttribute(
Expand All @@ -57,14 +57,14 @@ describe('OpenInExploreLogsButton', () => {
});

it('should handle EqualRegEx operator with properly encoded PromQL values', () => {
const props: OpenInExploreLogsButtonProps = {
const props: OpenInLogsDrilldownButtonProps = {
streamSelectors: [
{ name: 'job', value: 'test-job', operator: AbstractLabelOperator.Equal },
{ name: 'test_label_key', value: 'special.(char)+|value$', operator: AbstractLabelOperator.EqualRegEx },
],
};

render(<OpenInExploreLogsButton {...props} />);
render(<OpenInLogsDrilldownButton {...props} />);

const linkButton = screen.getByRole('link');
expect(linkButton).toHaveAttribute(
Expand All @@ -78,14 +78,14 @@ describe('OpenInExploreLogsButton', () => {
});

it('should handle NotEqualRegEx operator with properly encoded PromQL values', () => {
const props: OpenInExploreLogsButtonProps = {
const props: OpenInLogsDrilldownButtonProps = {
streamSelectors: [
{ name: 'job', value: 'test-job', operator: AbstractLabelOperator.Equal },
{ name: 'test_label_key', value: 'special.(char)+|value$', operator: AbstractLabelOperator.NotEqualRegEx },
],
};

render(<OpenInExploreLogsButton {...props} />);
render(<OpenInLogsDrilldownButton {...props} />);

const linkButton = screen.getByRole('link');
expect(linkButton).toHaveAttribute(
Expand All @@ -99,17 +99,17 @@ describe('OpenInExploreLogsButton', () => {
});

it('should not render button if labelMatchers is empty', () => {
render(<OpenInExploreLogsButton streamSelectors={[]} />);
render(<OpenInLogsDrilldownButton streamSelectors={[]} />);
expect(screen.queryByRole('link')).not.toBeInTheDocument();
});

it('should call setReturnToPrevious on click', () => {
const props: OpenInExploreLogsButtonProps = {
const props: OpenInLogsDrilldownButtonProps = {
streamSelectors: [{ name: 'job', value: 'test-job', operator: AbstractLabelOperator.Equal }],
returnToPreviousSource: 'test-source',
};

render(<OpenInExploreLogsButton {...props} />);
render(<OpenInLogsDrilldownButton {...props} />);

const linkButton = screen.getByRole('link');
fireEvent.click(linkButton);
Expand All @@ -120,12 +120,12 @@ describe('OpenInExploreLogsButton', () => {
it('should render using custom renderButton prop', () => {
const renderButtonMock = jest.fn(({ href }) => <a href={href}>Custom Button</a>);

const props: OpenInExploreLogsButtonProps = {
const props: OpenInLogsDrilldownButtonProps = {
streamSelectors: [{ name: 'job', value: 'test-job', operator: AbstractLabelOperator.Equal }],
renderButton: renderButtonMock,
};

render(<OpenInExploreLogsButton {...props} />);
render(<OpenInLogsDrilldownButton {...props} />);
expect(screen.getByText('Custom Button')).toBeInTheDocument();
expect(renderButtonMock).toHaveBeenCalledWith(expect.objectContaining({ href: expect.any(String) }));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
stringifyAdHocValues,
UrlParameters,
} from 'services/extensions/links';
import { OpenInExploreLogsButtonProps } from './types';
import { OpenInLogsDrilldownButtonProps } from './types';
import { AbstractLabelOperator } from '@grafana/data';
import { LabelFilterOp } from 'services/filterTypes';

Expand All @@ -22,14 +22,14 @@ const operatorMap = {
[AbstractLabelOperator.NotEqualRegEx]: LabelFilterOp.RegexNotEqual,
};

export default function OpenInExploreLogsButton({
export default function OpenInLogsDrilldownButton({
datasourceUid,
streamSelectors,
from,
to,
returnToPreviousSource,
renderButton,
}: OpenInExploreLogsButtonProps) {
}: OpenInLogsDrilldownButtonProps) {
const setReturnToPrevious = useReturnToPrevious();

const href = useMemo(() => {
Expand Down Expand Up @@ -86,7 +86,7 @@ export default function OpenInExploreLogsButton({
href={href}
onClick={() => setReturnToPrevious(returnToPreviousSource || 'previous')}
>
Open in Explore Logs
Open in Logs Drilldown
</LinkButton>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractLabelMatcher } from '@grafana/data';

export interface OpenInExploreLogsButtonProps {
export interface OpenInLogsDrilldownButtonProps {
datasourceUid?: string;
streamSelectors: AbstractLabelMatcher[];
from?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"exposedComponents": [
{
"id": "grafana-lokiexplore-app/open-in-explore-logs-button/v1",
"title": "Open in Explore Logs button",
"description": "A button that opens a logs view in the Explore Logs app."
"title": "Open in Logs Drilldown button",
"description": "A button that opens a logs view in the Logs Drilldown app."
}
],
"extensionPoints": [
Expand Down
16 changes: 8 additions & 8 deletions src/services/extensions/exposedComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { LinkButton } from '@grafana/ui';
import { OpenInExploreLogsButtonProps } from 'Components/OpenInExploreLogsButton/types';
import { OpenInLogsDrilldownButtonProps } from 'Components/OpenInLogsDrilldownButton/types';
import React, { lazy, Suspense } from 'react';
const OpenInExploreLogsButton = lazy(() => import('Components/OpenInExploreLogsButton/OpenInExploreLogsButton'));
const OpenInLogsDrilldownButton = lazy(() => import('Components/OpenInLogsDrilldownButton/OpenInLogsDrilldownButton'));

function SuspendedOpenInExploreLogsButton(props: OpenInExploreLogsButtonProps) {
function SuspendedOpenInLogsDrilldownButton(props: OpenInLogsDrilldownButtonProps) {
return (
<Suspense
fallback={
<LinkButton variant="secondary" disabled>
Open in Explore Logs
Open in Logs Drilldown
</LinkButton>
}
>
<OpenInExploreLogsButton {...props} />
<OpenInLogsDrilldownButton {...props} />
</Suspense>
);
}

export const exposedComponents = [
{
id: `grafana-lokiexplore-app/open-in-explore-logs-button/v1`,
title: 'Open in Explore Logs button',
description: 'A button that opens a logs view in the Explore Logs app.',
component: SuspendedOpenInExploreLogsButton,
title: 'Open in Logs Drilldown button',
description: 'A button that opens a logs view in the Logs Drilldown app.',
component: SuspendedOpenInLogsDrilldownButton,
},
];

0 comments on commit 39f1110

Please sign in to comment.